diff --git a/examples/ws2812_spi.rs b/examples/ws2812_spi.rs index b0347de02..d8eb743c1 100644 --- a/examples/ws2812_spi.rs +++ b/examples/ws2812_spi.rs @@ -14,9 +14,9 @@ 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(); @@ -24,24 +24,22 @@ fn main() -> ! { 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()); } }