1 unstable release

0.1.0 Jan 4, 2024

#1670 in Embedded development

0BSD license

21KB
369 lines

A minimal i2s driver for WM8994 audio codec using Rust and embedded-hal.


lib.rs:

A minimal i2s driver for WM8994 audio codec.

Usage example

use wm8994::Wm8994;

let mut delay = ctx.core.SYST.delay(ccdr.clocks);
let gpiod = ctx.device.GPIOD.split(ccdr.peripheral.GPIOD);
let scl = gpiod.pd12.into_alternate_open_drain();
let sda = gpiod.pd13.into_alternate_open_drain();

let i2c = ctx.device.I2C4.i2c((scl, sda), 100.kHz(), ccdr.peripheral.I2C4, &ccdr.clocks);
let mut driver = Wm8994::new(wm8994::Config { address: 0x1a }, &i2c, &delay);

// init_headphone() expects MCLK to be present
driver.init_headphone().unwrap();

Limitations

This driver configures wm8994 to play audio from I2S to headphone outputs. The format is fixed to 48 Khz, 16-bit I2S.

Probing for the i2c the address

use wm8994::Wm8994;

for addr in 0..0b111110 {
    let mut driver = Wm8994::new(wm8994::Config { address: addr }, &i2c, &delay);
    if let Ok(wm8994::registers::FAMILY_ID) = driver.get_family() {
        info!("Found at {:#04x}", addr);
    }
}

Dependencies

~71KB