diff options
| author | Robert Williams <[email protected]> | 2025-10-28 19:51:57 +0000 |
|---|---|---|
| committer | Robert Williams <[email protected]> | 2025-11-03 21:37:09 +0000 |
| commit | aa6b6e08dcb9105a672cece1a9a17bbf3e89a4be (patch) | |
| tree | 5c00bb1b01cd1d80f81f691e284d8c87f5c6016e | |
| parent | 07f45bd12a355a9775e1dac472ee127e47ed3624 (diff) | |
split into multiple methods
| -rw-r--r-- | embassy-rp/src/pio_programs/ws2812.rs | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/embassy-rp/src/pio_programs/ws2812.rs b/embassy-rp/src/pio_programs/ws2812.rs index 38f95facb..20f7d827b 100644 --- a/embassy-rp/src/pio_programs/ws2812.rs +++ b/embassy-rp/src/pio_programs/ws2812.rs | |||
| @@ -94,7 +94,7 @@ impl<'a, PIO: Instance> PioWs2812Program<'a, PIO> { | |||
| 94 | 94 | ||
| 95 | /// Pio backed RGB ws2812 driver | 95 | /// Pio backed RGB ws2812 driver |
| 96 | /// Const N is the number of ws2812 leds attached to this pin | 96 | /// Const N is the number of ws2812 leds attached to this pin |
| 97 | pub struct PioWs2812<'d, P: Instance, const S: usize, const N: usize, ORDER = Grb> | 97 | pub struct PioWs2812<'d, P: Instance, const S: usize, const N: usize, ORDER> |
| 98 | where | 98 | where |
| 99 | ORDER: RgbColorOrder, | 99 | ORDER: RgbColorOrder, |
| 100 | { | 100 | { |
| @@ -103,12 +103,24 @@ where | |||
| 103 | _order: core::marker::PhantomData<ORDER>, | 103 | _order: core::marker::PhantomData<ORDER>, |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | impl<'d, P: Instance, const S: usize, const N: usize, ORDER = Grb> PioWs2812<'d, P, S, N, ORDER> | 106 | impl<'d, P: Instance, const S: usize, const N: usize> PioWs2812<'d, P, S, N, Grb> { |
| 107 | pub fn new( | ||
| 108 | pio: &mut Common<'d, P>, | ||
| 109 | sm: StateMachine<'d, P, S>, | ||
| 110 | dma: Peri<'d, impl Channel>, | ||
| 111 | pin: Peri<'d, impl PioPin>, | ||
| 112 | program: &PioWs2812Program<'d, P>, | ||
| 113 | ) -> Self { | ||
| 114 | Self::with_color_order(pio, sm, dma, pin, program) | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | impl<'d, P: Instance, const S: usize, const N: usize, ORDER> PioWs2812<'d, P, S, N, ORDER> | ||
| 107 | where | 119 | where |
| 108 | ORDER: RgbColorOrder, | 120 | ORDER: RgbColorOrder, |
| 109 | { | 121 | { |
| 110 | /// Configure a pio state machine to use the loaded ws2812 program. | 122 | /// Configure a pio state machine to use the loaded ws2812 program. |
| 111 | pub fn new( | 123 | pub fn with_color_order( |
| 112 | pio: &mut Common<'d, P>, | 124 | pio: &mut Common<'d, P>, |
| 113 | mut sm: StateMachine<'d, P, S>, | 125 | mut sm: StateMachine<'d, P, S>, |
| 114 | dma: Peri<'d, impl Channel>, | 126 | dma: Peri<'d, impl Channel>, |
| @@ -167,7 +179,7 @@ where | |||
| 167 | /// Pio backed RGBW ws2812 driver | 179 | /// Pio backed RGBW ws2812 driver |
| 168 | /// This version is intended for ws2812 leds with 4 addressable lights | 180 | /// This version is intended for ws2812 leds with 4 addressable lights |
| 169 | /// Const N is the number of ws2812 leds attached to this pin | 181 | /// Const N is the number of ws2812 leds attached to this pin |
| 170 | pub struct RgbwPioWs2812<'d, P: Instance, const S: usize, const N: usize, ORDER = Grbw> | 182 | pub struct RgbwPioWs2812<'d, P: Instance, const S: usize, const N: usize, ORDER> |
| 171 | where | 183 | where |
| 172 | ORDER: RgbwColorOrder, | 184 | ORDER: RgbwColorOrder, |
| 173 | { | 185 | { |
| @@ -176,12 +188,24 @@ where | |||
| 176 | _order: core::marker::PhantomData<ORDER>, | 188 | _order: core::marker::PhantomData<ORDER>, |
| 177 | } | 189 | } |
| 178 | 190 | ||
| 179 | impl<'d, P: Instance, const S: usize, const N: usize, ORDER = Grbw> RgbwPioWs2812<'d, P, S, N, ORDER> | 191 | impl<'d, P: Instance, const S: usize, const N: usize> RgbwPioWs2812<'d, P, S, N, Grbw> { |
| 192 | pub fn new( | ||
| 193 | pio: &mut Common<'d, P>, | ||
| 194 | sm: StateMachine<'d, P, S>, | ||
| 195 | dma: Peri<'d, impl Channel>, | ||
| 196 | pin: Peri<'d, impl PioPin>, | ||
| 197 | program: &PioWs2812Program<'d, P>, | ||
| 198 | ) -> Self { | ||
| 199 | Self::with_color_order(pio, sm, dma, pin, program) | ||
| 200 | } | ||
| 201 | } | ||
| 202 | |||
| 203 | impl<'d, P: Instance, const S: usize, const N: usize, ORDER> RgbwPioWs2812<'d, P, S, N, ORDER> | ||
| 180 | where | 204 | where |
| 181 | ORDER: RgbwColorOrder, | 205 | ORDER: RgbwColorOrder, |
| 182 | { | 206 | { |
| 183 | /// Configure a pio state machine to use the loaded ws2812 program. | 207 | /// Configure a pio state machine to use the loaded ws2812 program. |
| 184 | pub fn new( | 208 | pub fn with_color_order( |
| 185 | pio: &mut Common<'d, P>, | 209 | pio: &mut Common<'d, P>, |
| 186 | mut sm: StateMachine<'d, P, S>, | 210 | mut sm: StateMachine<'d, P, S>, |
| 187 | dma: Peri<'d, impl Channel>, | 211 | dma: Peri<'d, impl Channel>, |
