From aa6b6e08dcb9105a672cece1a9a17bbf3e89a4be Mon Sep 17 00:00:00 2001 From: Robert Williams <1266467+bobdoah@users.noreply.github.com> Date: Tue, 28 Oct 2025 19:51:57 +0000 Subject: split into multiple methods --- embassy-rp/src/pio_programs/ws2812.rs | 36 +++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'embassy-rp') 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> { /// Pio backed RGB ws2812 driver /// Const N is the number of ws2812 leds attached to this pin -pub struct PioWs2812<'d, P: Instance, const S: usize, const N: usize, ORDER = Grb> +pub struct PioWs2812<'d, P: Instance, const S: usize, const N: usize, ORDER> where ORDER: RgbColorOrder, { @@ -103,12 +103,24 @@ where _order: core::marker::PhantomData, } -impl<'d, P: Instance, const S: usize, const N: usize, ORDER = Grb> PioWs2812<'d, P, S, N, ORDER> +impl<'d, P: Instance, const S: usize, const N: usize> PioWs2812<'d, P, S, N, Grb> { + pub fn new( + pio: &mut Common<'d, P>, + sm: StateMachine<'d, P, S>, + dma: Peri<'d, impl Channel>, + pin: Peri<'d, impl PioPin>, + program: &PioWs2812Program<'d, P>, + ) -> Self { + Self::with_color_order(pio, sm, dma, pin, program) + } +} + +impl<'d, P: Instance, const S: usize, const N: usize, ORDER> PioWs2812<'d, P, S, N, ORDER> where ORDER: RgbColorOrder, { /// Configure a pio state machine to use the loaded ws2812 program. - pub fn new( + pub fn with_color_order( pio: &mut Common<'d, P>, mut sm: StateMachine<'d, P, S>, dma: Peri<'d, impl Channel>, @@ -167,7 +179,7 @@ where /// Pio backed RGBW ws2812 driver /// This version is intended for ws2812 leds with 4 addressable lights /// Const N is the number of ws2812 leds attached to this pin -pub struct RgbwPioWs2812<'d, P: Instance, const S: usize, const N: usize, ORDER = Grbw> +pub struct RgbwPioWs2812<'d, P: Instance, const S: usize, const N: usize, ORDER> where ORDER: RgbwColorOrder, { @@ -176,12 +188,24 @@ where _order: core::marker::PhantomData, } -impl<'d, P: Instance, const S: usize, const N: usize, ORDER = Grbw> RgbwPioWs2812<'d, P, S, N, ORDER> +impl<'d, P: Instance, const S: usize, const N: usize> RgbwPioWs2812<'d, P, S, N, Grbw> { + pub fn new( + pio: &mut Common<'d, P>, + sm: StateMachine<'d, P, S>, + dma: Peri<'d, impl Channel>, + pin: Peri<'d, impl PioPin>, + program: &PioWs2812Program<'d, P>, + ) -> Self { + Self::with_color_order(pio, sm, dma, pin, program) + } +} + +impl<'d, P: Instance, const S: usize, const N: usize, ORDER> RgbwPioWs2812<'d, P, S, N, ORDER> where ORDER: RgbwColorOrder, { /// Configure a pio state machine to use the loaded ws2812 program. - pub fn new( + pub fn with_color_order( pio: &mut Common<'d, P>, mut sm: StateMachine<'d, P, S>, dma: Peri<'d, impl Channel>, -- cgit