Skip to content

Commit

Permalink
ws2812 prerendered
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Aug 29, 2022
1 parent 36349c3 commit f7f9abe
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions examples/ws2812_spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,32 @@ use ws2812_spi as ws2812;
fn main() -> ! {
let dp = pac::Peripherals::take().expect("cannot take peripherals");

// Configure APB bus clock to 56MHz, cause ws2812b requires 3.5Mbps SPI
// Configure APB bus clock to 48 MHz, cause ws2812b requires 3 Mbps SPI
let rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.use_hse(25.MHz()).sysclk(56.MHz()).freeze();
let clocks = rcc.cfgr.use_hse(25.MHz()).sysclk(48.MHz()).freeze();

let mut delay = dp.TIM1.delay_us(&clocks);
let gpioa = dp.GPIOA.split();

let spi = dp.SPI1.spi(
(gpioa.pa5, NoPin, gpioa.pa7),
ws2812::MODE,
3500.kHz(),
3000.kHz(),
&clocks,
);

let mut ws = ws2812::Ws2812::new(spi);

const NUM_LEDS: usize = 8;
let mut data = [RGB8::default(); NUM_LEDS];
const NUM_LEDS: usize = 20;
let mut buffer = [0; NUM_LEDS * 12 + 20];
let mut ws = ws2812::prerendered::Ws2812::new(spi, buffer.as_mut_slice());

// Wait before start write for syncronization
delay.delay(200.micros());

loop {
for j in 0..(256 * 5) {
for (i, b) in data.iter_mut().enumerate() {
*b = wheel((((i * 256) as u16 / NUM_LEDS as u16 + j as u16) & 255) as u8);
}
ws.write(brightness(data.iter().cloned(), 32)).unwrap();
let data = (0..NUM_LEDS)
.map(|i| wheel((((i * 256) as u16 / NUM_LEDS as u16 + j as u16) & 255) as u8));
ws.write(brightness(data, 32)).unwrap();
delay.delay(10.millis());
}
}
Expand Down

0 comments on commit f7f9abe

Please sign in to comment.