-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimple.rs
35 lines (29 loc) · 1.23 KB
/
simple.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use embedded_hal::{delay::DelayNs, digital::OutputPin};
use lp586x::{ConfigBuilder, Lp586x, PwmAccess};
fn main() {
// placeholders, replace with instances from your HAL
let i2c_bus = embedded_hal_mock::eh1::i2c::Mock::new(&[]);
let mut delay = embedded_hal_mock::eh1::delay::NoopDelay::new();
let mut vsync_pin = embedded_hal_mock::eh1::pin::Mock::new(&[]);
let config = ConfigBuilder::new_lp5864()
.pwm_frequency(lp586x::PwmFrequency::Pwm62_5kHz)
.maximum_current(lp586x::CurrentSettingNonT::Max40mA)
.data_mode_16bit();
let mut led_driver = Lp586x::new_with_i2c(&config, i2c_bus, 0x00, &mut delay).unwrap();
let mut framebuffer = [0u16; 72];
framebuffer[0] = u16::MAX;
loop {
// display current framebuffer
led_driver.set_pwm(0, &framebuffer).unwrap();
// do vsync
vsync_pin.set_high().unwrap();
delay.delay_us(lp586x::T_CHIP_EN_US);
vsync_pin.set_low().unwrap();
// roll framebuffer around to have some kind of animation
for i in 0..framebuffer.len() {
framebuffer[if i == 0 { framebuffer.len() - 1 } else { i - 1 }] = framebuffer[i];
}
// update at roughly 50Hz
delay.delay_ms(20);
}
}