#led-driver #led #driver #embedded-hal-driver #embedded-hal #lp5012 #lp5009

无需std lp50xx

适用于德州仪器LP50XX LED驱动器的简单平台无关库

6个版本

0.1.1 2024年8月14日
0.0.5 2024年7月15日
0.0.4 2022年7月8日
0.0.3 2021年11月21日
0.0.2 2021年8月29日

#232嵌入式开发

Download history 4/week @ 2024-07-05 106/week @ 2024-07-12 10/week @ 2024-07-19 20/week @ 2024-07-26 2/week @ 2024-08-02 121/week @ 2024-08-09 98/week @ 2024-08-16

241 每月下载量

MIT 许可证

18KB
272

lp50xx

德州仪器LP5009和LP5012 LED驱动器的嵌入式驱动程序

描述

LP50xx设备是一种9或12通道恒流LED驱动器。LP50xx设备包含集成颜色混合和亮度控制,预先配置简化了软件开发过程。每个通道集成的12位、29-kHz PWM发生器为LED提供平滑、生动的颜色,并消除可听噪声。

示例

示例基于stm32h7xx_hal

// 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), 100.khz(), prec, clocks);

// Initialize with blocking I2C
let interface = LP50xx::init_with_i2c(Model::LP5012, i2c, en);
// Use the LP50xx in monochromatic mode
let mut monochromatic_controller = interface.into_monochromatic_mode();
// Enable it, this requires a delay provider
monochromatic_controller.enable(delay).ok();
// Set LED 5 to 255
monochromatic_controller.set(5, 0xFF).ok();

// The continuous addressing feature is enabled by default, allowing you to address
// multiple LP50xx devices on the same bus in an intuitive way.
// There are 12 LEDs available per LP5012, therefore the following command
// will illuminate the 1st LED on the on the second LP5012:
monochromatic_controller.set(13, 0xFF).ok();
// You can turn this feature off and set the active address manually also:
monochromatic_controller.set_continuous_addressing(false);
// Set the active address to be the second device
monochromatic_controller.set_active_address(0x01);
// And then turn off the same 1st LED on the second device
monochromatic_controller.set(1, 0x00).ok();

// Alternatively, if you are using RGB LEDs you can use the LP50xx in color mode
let mut color_controller = monochromatic_controller.into_color_mode();
// Set channel 1 brightness and RGB values
color_controller.set(1, (1, [255, 100, 95])).ok();

// Release the blocking i2c example to regain access to its underyling resources
let (_i2c, en) = color_controller.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; 256] = [0; 256];
let interface = LP50xx::init_with_callback(Model::LP5012, en, |addr, data| unsafe {
    // Copy the data from the LP50xx into the DMA buffer for processing
    DMA_BUFFER[0..data.len()].copy_from_slice(data);
})
.into_monochromatic_mode();

贡献

请自由创建一个票据和MR,以供在此库中看到任何更改。

依赖关系

~56KB