pcm4104
Platform-agnostic Rust driver for the Texas Instruments PCM4104 4-channel audio DAC.
The driver is based on embedded-hal-async and allows the chip configuration via SPI.
Prerequisites
- The HAL must implement the embedded-hal-async traits. An example for a compatible HAL is embassy.
- The DAC must be wired for software-controlled mode by setting the
MODEpin high. - A minimum of 1024 system clock cycles need to be applied to the
SCKpin to initialize the chip after power-on or reset. Otherwise, the internal registers will be reset to their default values again after this number of clock cycles have been elapsed.
Usage
The following example shows the configuration of the DAC using embassy on an RP2350.
use block_on;
use ;
use SPI1;
use ;
use NoopRawMutex;
use Mutex;
use *;
use StaticCell;
// Alias for convenience.
type Spi1Bus = ;
// Get the peripherals.
let p = init;
// Setup a shared SPI bus, so multiple chips can be managed via their CS pins.
let spi_cfg = default;
let spi = new;
static SPI_BUS: = new;
let spi_bus = SPI_BUS.init;
// Chip select pin for the DAC.
let cs_pin = new;
// Instantiate the driver.
let spi_device = new;
let mut pcm4104 = new;
// Configure the chip for TDM 4-channel use. Apply other options as needed.
// `block_on` is used here exemplary to show how to use the driver in blocking mode.
// That can be handy on startup when the executor is not running yet.
let config = Pcm4104Config ;
block_on.expect;
// Here, a channel is muted in an async context.
pcm4104.set_mute.await.expect;
License
Published under the MIT license. Any contribution to this project must be provided under the same license conditions.
Author: Oliver Rockstedt info@sourcebox.de