aboutsummaryrefslogtreecommitdiff
path: root/embassy-rp/src
diff options
context:
space:
mode:
authorRobert Williams <[email protected]>2025-10-29 19:59:12 +0000
committerRobert Williams <[email protected]>2025-11-03 21:37:09 +0000
commit52d514652b2388812ba6547c0e4743938206cf42 (patch)
treeff53772b5d862530a90d74111978213b69b63290 /embassy-rp/src
parentaa6b6e08dcb9105a672cece1a9a17bbf3e89a4be (diff)
docs: color order methods traits missing docs
Diffstat (limited to 'embassy-rp/src')
-rw-r--r--embassy-rp/src/pio_programs/ws2812.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/embassy-rp/src/pio_programs/ws2812.rs b/embassy-rp/src/pio_programs/ws2812.rs
index 20f7d827b..3c4de6b56 100644
--- a/embassy-rp/src/pio_programs/ws2812.rs
+++ b/embassy-rp/src/pio_programs/ws2812.rs
@@ -18,12 +18,14 @@ const CYCLES_PER_BIT: u32 = (T1 + T2 + T3) as u32;
18 18
19/// Color orders for WS2812B, type RGB8 19/// Color orders for WS2812B, type RGB8
20pub trait RgbColorOrder { 20pub trait RgbColorOrder {
21 /// Pack an 8-bit RGB color into a u32
21 fn pack(color: RGB8) -> u32; 22 fn pack(color: RGB8) -> u32;
22} 23}
23 24
24/// Green, Red, Blue order is the common default for WS2812B 25/// Green, Red, Blue order is the common default for WS2812B
25pub struct Grb; 26pub struct Grb;
26impl RgbColorOrder for Grb { 27impl RgbColorOrder for Grb {
28 /// Pack an 8-bit RGB color into a u32 in GRB order
27 fn pack(color: RGB8) -> u32 { 29 fn pack(color: RGB8) -> u32 {
28 (u32::from(color.g) << 24) | (u32::from(color.r) << 16) | (u32::from(color.b) << 8) 30 (u32::from(color.g) << 24) | (u32::from(color.r) << 16) | (u32::from(color.b) << 8)
29 } 31 }
@@ -32,6 +34,7 @@ impl RgbColorOrder for Grb {
32/// Red, Green, Blue is used by some WS2812B implementations 34/// Red, Green, Blue is used by some WS2812B implementations
33pub struct Rgb; 35pub struct Rgb;
34impl RgbColorOrder for Rgb { 36impl RgbColorOrder for Rgb {
37 /// Pack an 8-bit RGB color into a u32 in RGB order
35 fn pack(color: RGB8) -> u32 { 38 fn pack(color: RGB8) -> u32 {
36 (u32::from(color.r) << 24) | (u32::from(color.g) << 16) | (u32::from(color.b) << 8) 39 (u32::from(color.r) << 24) | (u32::from(color.g) << 16) | (u32::from(color.b) << 8)
37 } 40 }
@@ -39,12 +42,14 @@ impl RgbColorOrder for Rgb {
39 42
40/// Color orders RGBW strips 43/// Color orders RGBW strips
41pub trait RgbwColorOrder { 44pub trait RgbwColorOrder {
45 /// Pack an RGB+W color into a u32
42 fn pack(color: RGBW<u8>) -> u32; 46 fn pack(color: RGBW<u8>) -> u32;
43} 47}
44 48
45/// Green, Red, Blue, White order is the common default for RGBW strips 49/// Green, Red, Blue, White order is the common default for RGBW strips
46pub struct Grbw; 50pub struct Grbw;
47impl RgbwColorOrder for Grbw { 51impl RgbwColorOrder for Grbw {
52 /// Pack an RGB+W color into a u32 in GRBW order
48 fn pack(color: RGBW<u8>) -> u32 { 53 fn pack(color: RGBW<u8>) -> u32 {
49 (u32::from(color.g) << 24) | (u32::from(color.r) << 16) | (u32::from(color.b) << 8) | u32::from(color.a.0) 54 (u32::from(color.g) << 24) | (u32::from(color.r) << 16) | (u32::from(color.b) << 8) | u32::from(color.a.0)
50 } 55 }
@@ -53,6 +58,7 @@ impl RgbwColorOrder for Grbw {
53/// Red, Green, Blue, White order 58/// Red, Green, Blue, White order
54pub struct Rgbw; 59pub struct Rgbw;
55impl RgbwColorOrder for Rgbw { 60impl RgbwColorOrder for Rgbw {
61 /// Pack an RGB+W color into a u32 in RGBW order
56 fn pack(color: RGBW<u8>) -> u32 { 62 fn pack(color: RGBW<u8>) -> u32 {
57 (u32::from(color.r) << 24) | (u32::from(color.g) << 16) | (u32::from(color.b) << 8) | u32::from(color.a.0) 63 (u32::from(color.r) << 24) | (u32::from(color.g) << 16) | (u32::from(color.b) << 8) | u32::from(color.a.0)
58 } 64 }
@@ -104,6 +110,8 @@ where
104} 110}
105 111
106impl<'d, P: Instance, const S: usize, const N: usize> PioWs2812<'d, P, S, N, Grb> { 112impl<'d, P: Instance, const S: usize, const N: usize> PioWs2812<'d, P, S, N, Grb> {
113 /// Configure a pio state machine to use the loaded ws2812 program.
114 /// Uses the default GRB order.
107 pub fn new( 115 pub fn new(
108 pio: &mut Common<'d, P>, 116 pio: &mut Common<'d, P>,
109 sm: StateMachine<'d, P, S>, 117 sm: StateMachine<'d, P, S>,
@@ -120,6 +128,7 @@ where
120 ORDER: RgbColorOrder, 128 ORDER: RgbColorOrder,
121{ 129{
122 /// Configure a pio state machine to use the loaded ws2812 program. 130 /// Configure a pio state machine to use the loaded ws2812 program.
131 /// Uses the specified color order.
123 pub fn with_color_order( 132 pub fn with_color_order(
124 pio: &mut Common<'d, P>, 133 pio: &mut Common<'d, P>,
125 mut sm: StateMachine<'d, P, S>, 134 mut sm: StateMachine<'d, P, S>,
@@ -189,6 +198,8 @@ where
189} 198}
190 199
191impl<'d, P: Instance, const S: usize, const N: usize> RgbwPioWs2812<'d, P, S, N, Grbw> { 200impl<'d, P: Instance, const S: usize, const N: usize> RgbwPioWs2812<'d, P, S, N, Grbw> {
201 /// Configure a pio state machine to use the loaded ws2812 program.
202 /// Uses the default GRBW color order
192 pub fn new( 203 pub fn new(
193 pio: &mut Common<'d, P>, 204 pio: &mut Common<'d, P>,
194 sm: StateMachine<'d, P, S>, 205 sm: StateMachine<'d, P, S>,
@@ -205,6 +216,7 @@ where
205 ORDER: RgbwColorOrder, 216 ORDER: RgbwColorOrder,
206{ 217{
207 /// Configure a pio state machine to use the loaded ws2812 program. 218 /// Configure a pio state machine to use the loaded ws2812 program.
219 /// Uses the specified color order
208 pub fn with_color_order( 220 pub fn with_color_order(
209 pio: &mut Common<'d, P>, 221 pio: &mut Common<'d, P>,
210 mut sm: StateMachine<'d, P, S>, 222 mut sm: StateMachine<'d, P, S>,