1 个不稳定版本
0.9.0 | 2024年1月26日 |
---|
#1468 in 硬件支持
165KB
2K SLoC
NAU88C22 CODEC 驱动程序
Nuvoton NAU88C22 CODEC 芯片寄存器接口的 Rust 驱动程序。
变更日志
未发布变更
- 无
v0.9.0 - 2024-01-26
- 首次发布
许可证
根据您的选择,许可为 MIT 或 Apache-2.0。
- SPDX-FileCopyrightText: 2023 Jonathan 'theJPster' Pallant [email protected]
- SPDX-License-Identifier: MIT OR Apache-2.0
贡献
除非您明确声明,否则您提交的任何有意包含在作品中的贡献均应按上述方式许可,不附加任何额外条款或条件。
lib.rs
:
Nuvoton NAU88C22 CODEC 寄存器接口的驱动程序
目前仅支持 I²C 模式。
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
})?;
依赖项
~96–255KB