aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreZio Pan <[email protected]>2023-12-18 01:02:58 +0800
committereZio Pan <[email protected]>2023-12-18 01:02:58 +0800
commit05b8818de01866fa988a8f65a395690f02176b34 (patch)
treea525bab59e2c03e76e77047ea18d1d61b16445af
parent1934c2abc81f0dd981fad625ec2712964d0a1a91 (diff)
typo fix
-rw-r--r--examples/stm32f4/src/bin/ws2812_spi.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/examples/stm32f4/src/bin/ws2812_spi.rs b/examples/stm32f4/src/bin/ws2812_spi.rs
index 170f0b59b..eca657900 100644
--- a/examples/stm32f4/src/bin/ws2812_spi.rs
+++ b/examples/stm32f4/src/bin/ws2812_spi.rs
@@ -5,7 +5,7 @@
5// Thus we can adjust SPI to send each *round* of data at 800 kHz, and in each *round*, we can adjust each *bit* to mimic 2 different PWM waveform. 5// Thus we can adjust SPI to send each *round* of data at 800 kHz, and in each *round*, we can adjust each *bit* to mimic 2 different PWM waveform.
6// such that the output waveform meet the bit representation of ws2812. 6// such that the output waveform meet the bit representation of ws2812.
7// 7//
8// If you want to save SPI for other purpose, you may want to take a look at `ws2812_tim_dma.rs` file, which make use of TIM and DMA. 8// If you want to save SPI for other purpose, you may want to take a look at `ws2812_pwm_dma.rs` file, which make use of TIM and DMA.
9// 9//
10// Warning: 10// Warning:
11// DO NOT stare at ws2812 directy (especially after each MCU Reset), its (max) brightness could easily make your eyes feel burn. 11// DO NOT stare at ws2812 directy (especially after each MCU Reset), its (max) brightness could easily make your eyes feel burn.
@@ -20,11 +20,12 @@ use embassy_time::{Duration, Ticker, Timer};
20use {defmt_rtt as _, panic_probe as _}; 20use {defmt_rtt as _, panic_probe as _};
21 21
22// we use 16 bit data frame format of SPI, to let timing as accurate as possible. 22// we use 16 bit data frame format of SPI, to let timing as accurate as possible.
23// thanks to loose tolerance of ws2812 timing, you can also use 8 bit data frame format, thus you need want to adjust the bit representation. 23// thanks to loose tolerance of ws2812 timing, you can also use 8 bit data frame format, thus you will need to adjust the bit representation.
24const N0: u16 = 0b1111100000000000u16; // ws2812 Bit 0 high level timing 24const N0: u16 = 0b1111100000000000u16; // ws2812 Bit 0 high level timing
25const N1: u16 = 0b1111111111000000u16; // ws2812 Bit 1 high level timing 25const N1: u16 = 0b1111111111000000u16; // ws2812 Bit 1 high level timing
26 26
27// ws2812 only need 24 bits for each LED, but we add one bit more to keep SPI output low 27// ws2812 only need 24 bits for each LED,
28// but we add one bit more to keep SPI output low at the end
28 29
29static TURN_OFF: [u16; 25] = [ 30static TURN_OFF: [u16; 25] = [
30 N0, N0, N0, N0, N0, N0, N0, N0, // Green 31 N0, N0, N0, N0, N0, N0, N0, N0, // Green
@@ -77,7 +78,7 @@ async fn main(_spawner: embassy_executor::Spawner) {
77 let mut spi_config = spi::Config::default(); 78 let mut spi_config = spi::Config::default();
78 spi_config.frequency = khz(12_800); 79 spi_config.frequency = khz(12_800);
79 80
80 // Since we only output waveform, then the Rx and Sck it is not considered 81 // Since we only output waveform, then the Rx and Sck and RxDma it is not considered
81 let mut ws2812_spi = spi::Spi::new_txonly_nosck(dp.SPI1, dp.PB5, dp.DMA2_CH3, dma::NoDma, spi_config); 82 let mut ws2812_spi = spi::Spi::new_txonly_nosck(dp.SPI1, dp.PB5, dp.DMA2_CH3, dma::NoDma, spi_config);
82 83
83 // flip color at 2 Hz 84 // flip color at 2 Hz