#i2c #embedded-hal-i2c #nuvoton #embedded-hal #nau882cc

nau88c22

Driver for the I2C register interface on the Nuvoton NAU882CC Audio CODEC

1 unstable release

0.9.0 Jan 26, 2024

#673 in Hardware support

MIT/Apache

165KB
2K SLoC

NAU88C22 CODEC driver

Rust driver for the register interface on the Nuvoton NAU88C22 CODEC chip.

Changelog

Unreleased Changes

  • None

v0.9.0 - 2024-01-26

  • First release

Licence

Licensed under either MIT or Apache-2.0 at your option.

  • SPDX-FileCopyrightText: 2023 Jonathan 'theJPster' Pallant github@thejpster.org.uk
  • SPDX-License-Identifier: MIT OR Apache-2.0

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be licensed as above, without any additional terms or conditions.


lib.rs:

A driver for the register interface on the Nuvoton NAU88C22 CODEC

Works in I²C mode only, for now.

use core::fmt::Write;
let mut uart = hal.uart();
let i2c = hal.i2c();
let mut codec = nau88c22::Codec::new(i2c);
// Do a Software Reset on the chip to put registers into a known state. This
// fails if we don't get an I2C ACK:
codec.reset()?;
// You can then either poll a register for a known value, or just wait for
// the reset sequence to complete:
hal.delay_ms(100);
// First you should check the Device ID is correct:
codec.check_device_id()?;
// Every register has a `read_xxx()` method:
let pm1 = codec.read_powermanagement1()?;
// You can view the fields with a debug print:
writeln!(uart, "powermanagement1 = {:?}", pm1).unwrap();
// Or access them individually:
writeln!(uart, "powermanagement1.dcbufen = {}", pm1.dcbufen()).unwrap();
// You can also modify registers with a closure:
codec.modify_powermanagement1(|mut w| {
    // the closure is given a proxy object, usually called `w`
    // use it to turn the fields on or off
    w.iobufen_set(true);
    w.dcbufen_set(true);
    // you must return the proxy object from the closure
    w
})?;

Dependencies

~96–255KB