#led-driver #driver #embedded-hal-driver #embedded-hal #lumissil #is31fl3205 #is31fl3237

无std is31fl32xx

为 Lumissil 微系统 IS31FL3205 LED 驱动提供的 rust-嵌入式驱动程序

2 个版本

0.1.1 2024年7月15日
0.1.0 2023年11月9日

#1745 in 嵌入式开发

Download history 110/week @ 2024-07-13 7/week @ 2024-07-20 15/week @ 2024-07-27

每月 132 次下载

MIT 许可证

18KB
256

is31fl32xx

为 Lumissil 微系统 IS31FL32xx LED 驱动提供的 rust-嵌入式驱动程序

关于

IS31FL3205 和 IS31FL3237 分别具有 12 和 36 个恒流通道的 LED 驱动器。每个通道可以通过 16 位脉冲宽度调制 (PWM) 实现平滑的 LED 亮度控制。此外,每个通道都有一个 8 位输出电流控制寄存器,允许对电流进行精细调整以实现丰富的 RGB 颜色混合,例如纯白色 LED 应用。每个通道的最大输出电流可以通过一个 8 位的全局控制寄存器进行调整。

此 crate 提供了与 embedded_hal 特性兼容的阻塞和 DMA 兼容的 API(通过静态回调)。

示例

示例基于 stm32h7xx_hal

// Initialize a delay provider
let mut delay: Delay = Delay::new(cp.SYST, ccdr.clocks);

// Initialize I2C pins, SCL, SDA
let scl = scl
    .into_alternate_af4()
    .internal_pull_up(true)
    .set_open_drain();
let sda = sda
    .into_alternate_af4()
    .internal_pull_up(true)
    .set_open_drain();

// Initialize the Enable line
let en = en.into_push_pull_output();

// Initialize 
let i2c: stm32h7xx_hal::i2c::I2c<I2C1> =
    i2c.i2c((scl, sda), 1_u32.MHz(), prec, clocks);

// Initialize with blocking I2C for device at address 0x00.
// The either the IS31FL3205 or IS31FL3237 models are supported
let mut interface = Is31fl32xx::<IS31FL3237, _, _>::init_with_i2c(0x00, en, i2c);

// Enable the device, bringing the enable line high and configuring the oscillator clock, pwm resolution
interface.enable_device(
    delay,
    OscillatorClock::SixteenMHz,
    PwmResolution::SixteenBit,
    SoftwareShutdownMode::Normal,
)
.unwrap();

// Set maximum current drain as specified by the current resistance
interface.set_global_current(0xFF).unwrap();

// Set brightness scaling for all leds
interface.set_all_led_scaling(0xFF).unwrap();

/// Finally set the first LED to maximum 16bit brightness. For drivers configured for less than 16bit Only the required bits are used
interface.set(0, 0xFFFF).unwrap()

// Release the blocking i2c example to regain access to its underlying resources
let (_i2c, _en) = interface.release();

// Additionally, if you need to integrate this driver with platform specific DMA controllers then
// a flexible callback can be used rather than blocking i2c
static mut DMA_BUFFER: [u8; 3] = [0; 3];
let interface = Is31fl32xx::<IS31FL3237, _, _>::init_with_callback(0x00, en, |addr, data| unsafe {
    // Copy the data from the Is31fl32xx into the DMA buffer for processing
    // NOTE: data can change in size depending on the message, the DMA implementation will
    // need to be able to handle changing slice lengths
    DMA_BUFFER[0..data.len()].copy_from_slice(data);
});

贡献

请随意创建一个工单和一个 MR,以提出您希望在此库中看到的所有更改。

依赖项

~71KB