#dac #driver #embedded-hal #embedded-hal-driver #async

nct3933

适用于Nuvoton 3通道源/汇电流DAC NCT3933U的平台无关Rust驱动程序

3个不稳定版本

0.2.0 2024年6月25日
0.1.2 2024年6月25日
0.1.1 2024年6月24日
0.1.0 2024年6月18日

#557硬件支持

Download history 150/week @ 2024-06-14 416/week @ 2024-06-21 16/week @ 2024-06-28

141 每月下载量

MIT/Apache

23KB
254

crates.io

NCT3933U 3通道源/汇电流DAC的Rust驱动程序

这是一个针对NCT3933的平台无关Rust驱动程序,提供同步和异步版本,分别基于embedded-halembedded-hal-async特性。

设备

NCT3933U包含三个可调节的电流DAC,每个DAC均可通过SMBusTM接口进行源电流和汇电流。每个输出有128个源电流和汇电流设置,由SMBusTM接口编程。输出电流也可编程,以实现两倍源电流和汇电流的增加。NCT3933U具有步进速度控制功能,可轻松与通用DC/DC转换器接口以调整电压。NCT3933U还提供省电功能,在系统进入待机模式时可降低60%的功耗。

NCT3933U

使用方法

以下是如何使用该库的方法

同步版本

使用STM32G031G8Ux,在Cargo.toml中添加以下内容:nct3933 = {version = "0.2.0" , features = ["sync"]}

#![no_std]
#![no_main]

#![allow(dead_code)]
#![allow(unused_imports)]

use nct3933::NCT3933Sync as NCT3933;
use nct3933::errors::NCT3933Error;
use defmt:: info;
use embassy_stm32::i2c::Config;
use embassy_time::Timer;
use {defmt_rtt as _, panic_probe as _};
use embassy_stm32::i2c::{self, I2c};
use embassy_stm32::{bind_interrupts, peripherals};
use embassy_stm32::time::Hertz;

bind_interrupts!(struct Irqs {
    I2C1 => i2c::EventInterruptHandler<peripherals::I2C1>, i2c::ErrorInterruptHandler<peripherals::I2C1>;
});

#[embassy_executor::main]
async fn main(_spawner: embassy_executor::Spawner) {
    let p = embassy_stm32::init(Default::default());

    let i2c = I2c::new(
        p.I2C1,
        p.PB6,
        p.PB7,
        Irqs,
        p.DMA1_CH1,
        p.DMA1_CH2,
        Hertz(100_000),
        Default::default(),
    );

    let mut nct3933 = NCT3933::new(i2c, 0x2A).unwrap();

    
    match nct3933.check_id() {
        Ok(()) => { info!("NCT3933 found"); },
        Err(e) => { info!("NCT3933 not found :{:?}",e); },
    }
    match nct3933.set_wdt_state(1,0) {
        Ok(()) => { info!("WDT state set");},
        Err(e) => { panic!("WDT state not set :{:?}",e);},
    }

    match nct3933.set_current(1,10) {
        Ok(()) => { info!("Current set");},
        Err(e) => { panic!("Current not set :{:?}",e);},
    }

    loop { 
        Timer::after_millis(2000).await;
    }
}

异步版本

使用STM32G031G8Ux,在Cargo.toml中添加以下内容:nct3933 = {version = "0.2.0" , features = ["async"]}

#![no_std]
#![no_main]

#![allow(dead_code)]
#![allow(unused_imports)]

use nct3933::NCT3933Async as NCT3933;
use nct3933::errors::NCT3933Error;
use defmt:: info;
use embassy_stm32::i2c::Config;
use embassy_time::Timer;
use {defmt_rtt as _, panic_probe as _};
use embassy_stm32::i2c::{self, I2c};
use embassy_stm32::{bind_interrupts, peripherals};
use embassy_stm32::time::Hertz;

bind_interrupts!(struct Irqs {
    I2C1 => i2c::EventInterruptHandler<peripherals::I2C1>, i2c::ErrorInterruptHandler<peripherals::I2C1>;
});

#[embassy_executor::main]
async fn main(_spawner: embassy_executor::Spawner) {
    let p = embassy_stm32::init(Default::default());

    let i2c = I2c::new(
        p.I2C1,
        p.PB6,
        p.PB7,
        Irqs,
        p.DMA1_CH1,
        p.DMA1_CH2,
        Hertz(100_000),
        Default::default(),
    );

    let mut nct3933 = NCT3933::new(i2c, 0x2A).unwrap();

    
    match nct3933.check_id().await {
        Ok(()) => { info!("NCT3933 found"); },
        Err(e) => { info!("NCT3933 not found :{:?}",e); },
    }
    match nct3933.set_wdt_state(1,0).await {
        Ok(()) => { info!("WDT state set");},
        Err(e) => { panic!("WDT state not set :{:?}",e);},
    }

    match nct3933.set_current(1,10).await {
        Ok(()) => { info!("Current set");},
        Err(e) => { panic!("Current not set :{:?}",e);},
    }

    loop { 
        Timer::after_millis(2000).await;
    }
}
 

许可证

根据以下之一许可

依赖项

~0.5–1MB
~22K SLoC