From 07f45bd12a355a9775e1dac472ee127e47ed3624 Mon Sep 17 00:00:00 2001 From: Robert Williams <1266467+bobdoah@users.noreply.github.com> Date: Mon, 27 Oct 2025 21:44:53 +0000 Subject: fix: split traits to avoid inference problems --- embassy-rp/src/pio_programs/ws2812.rs | 42 ++++++++++++++++------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/embassy-rp/src/pio_programs/ws2812.rs b/embassy-rp/src/pio_programs/ws2812.rs index 3c16367e6..38f95facb 100644 --- a/embassy-rp/src/pio_programs/ws2812.rs +++ b/embassy-rp/src/pio_programs/ws2812.rs @@ -16,48 +16,44 @@ const T2: u8 = 5; // data bit const T3: u8 = 3; // stop bit const CYCLES_PER_BIT: u32 = (T1 + T2 + T3) as u32; -/// This trait defines the contract for color ordering -pub trait ColorOrder { - type ColorType; - - // Pack the type specific struct into a u32 word in the correct order - fn pack(color: Self::ColorType) -> u32; +/// Color orders for WS2812B, type RGB8 +pub trait RgbColorOrder { + fn pack(color: RGB8) -> u32; } -/// Color orders for WS2812B, type RGB8 /// Green, Red, Blue order is the common default for WS2812B pub struct Grb; -impl ColorOrder for Grb { - type ColorType = RGB8; - fn pack(color: Self::ColorType) -> u32 { +impl RgbColorOrder for Grb { + fn pack(color: RGB8) -> u32 { (u32::from(color.g) << 24) | (u32::from(color.r) << 16) | (u32::from(color.b) << 8) } } /// Red, Green, Blue is used by some WS2812B implementations pub struct Rgb; -impl ColorOrder for Rgb { - type ColorType = RGB8; - fn pack(color: Self::ColorType) -> u32 { +impl RgbColorOrder for Rgb { + fn pack(color: RGB8) -> u32 { (u32::from(color.r) << 24) | (u32::from(color.g) << 16) | (u32::from(color.b) << 8) } } /// Color orders RGBW strips +pub trait RgbwColorOrder { + fn pack(color: RGBW) -> u32; +} + /// Green, Red, Blue, White order is the common default for RGBW strips pub struct Grbw; -impl ColorOrder for Grbw { - type ColorType = RGBW; - fn pack(color: Self::ColorType) -> u32 { +impl RgbwColorOrder for Grbw { + fn pack(color: RGBW) -> u32 { (u32::from(color.g) << 24) | (u32::from(color.r) << 16) | (u32::from(color.b) << 8) | u32::from(color.a.0) } } /// Red, Green, Blue, White order pub struct Rgbw; -impl ColorOrder for Rgbw { - type ColorType = RGBW; - fn pack(color: Self::ColorType) -> u32 { +impl RgbwColorOrder for Rgbw { + fn pack(color: RGBW) -> u32 { (u32::from(color.r) << 24) | (u32::from(color.g) << 16) | (u32::from(color.b) << 8) | u32::from(color.a.0) } } @@ -100,7 +96,7 @@ impl<'a, PIO: Instance> PioWs2812Program<'a, PIO> { /// 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> where - ORDER: ColorOrder, + ORDER: RgbColorOrder, { dma: Peri<'d, AnyChannel>, sm: StateMachine<'d, P, S>, @@ -109,7 +105,7 @@ where impl<'d, P: Instance, const S: usize, const N: usize, ORDER = Grb> PioWs2812<'d, P, S, N, ORDER> where - ORDER: ColorOrder, + ORDER: RgbColorOrder, { /// Configure a pio state machine to use the loaded ws2812 program. pub fn new( @@ -173,7 +169,7 @@ where /// 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> where - ORDER: ColorOrder>, + ORDER: RgbwColorOrder, { dma: Peri<'d, AnyChannel>, sm: StateMachine<'d, P, S>, @@ -182,7 +178,7 @@ where impl<'d, P: Instance, const S: usize, const N: usize, ORDER = Grbw> RgbwPioWs2812<'d, P, S, N, ORDER> where - ORDER: ColorOrder>, + ORDER: RgbwColorOrder, { /// Configure a pio state machine to use the loaded ws2812 program. pub fn new( -- cgit