tpa2016d2

Crates.iotpa2016d2
lib.rstpa2016d2
version0.2.0
sourcesrc
created_at2019-05-01 11:26:43.452738
updated_at2019-05-17 05:44:02.829181
descriptionEmbedded-hal driver for the Texas Instruments TPA2016D2 Class-D amplifier
homepage
repositoryhttps://github.com/jkristell/tpa2016d2
max_upload_size
id131369
size14,611
Johan Kristell (jkristell)

documentation

README

TPA2016D2

Embedded-hal Driver for the TI TPA2016D2 Stereo Class-D amplifier.

Notes

Example

#![no_main]
#![no_std]

use cortex_m_rt::entry;
use cortex_m_semihosting::hprintln;
use panic_semihosting as _;

use nucleo_f401re::{i2c::I2c, prelude::*, stm32};
use tpa2016d2::Tpa2016d2;

#[entry]
fn main() -> ! {
    // The Stm32 peripherals
    let device = stm32::Peripherals::take().unwrap();

    let rcc = device.RCC.constrain();
    let clocks = rcc.cfgr.sysclk(84.mhz()).freeze();

    let gpiob = device.GPIOB.split();
    let scl = gpiob
        .pb8
        .into_alternate_af4()
        .internal_pull_up(true)
        .set_open_drain();

    let sda = gpiob
        .pb9
        .into_alternate_af4()
        .internal_pull_up(true)
        .set_open_drain();

    let i2c = I2c::i2c1(device.I2C1, (scl, sda), 200.khz(), clocks);

    let mut tpa = Tpa2016d2::new(i2c);

    // Read all registers
    tpa.sync().unwrap();

    // Get and print  the registers
    for i in 1..=7 {
        let v = tpa.device_reg(i).unwrap();
        hprintln!("{}: {}", i, v).unwrap();
    }

    // Update the gain
    tpa.gain(32).unwrap();

    // Should print 32
    hprintln!("gain: {}", tpa.device_reg(5).unwrap()).unwrap();

    loop {}
}

TODO

  • Agc Presets
  • Features
Commit count: 11

cargo fmt