Skip to main content

device_envoy/led2d/
led2d_generated.rs

1// @generated by `cargo xtask led2d-generated` or `cargo check-all`. Do not edit by hand.
2//! Module containing [`Led2dGenerated`], the sample struct type generated by the [`led2d!`](macro@crate::led2d) macro.
3//!
4//! Auto-generated.
5
6#[cfg(not(feature = "host"))]
7use crate::led_strip::{Current, Gamma};
8#[cfg(not(feature = "host"))]
9use crate::led2d;
10#[cfg(not(feature = "host"))]
11use crate::led2d::Led2dFont;
12#[cfg(not(feature = "host"))]
13use crate::led2d::layout::LedLayout;
14
15// 12×4 panel wired serpentine column-major (sample configuration)
16#[cfg(not(feature = "host"))]
17const LED_LAYOUT: LedLayout<48, 12, 4> = LedLayout::serpentine_column_major();
18
19#[cfg(all(not(doc), not(feature = "host")))]
20led2d! {
21    pub Led2dGenerated {
22        // PIO resource (default: PIO0)
23        pio: PIO0,
24        // GPIO pin for LED data signal
25        pin: PIN_3,
26        // DMA channel for LED data transfer (default: DMA_CH0)
27        dma: DMA_CH0,
28        // LED layout mapping (defines panel dimensions)
29        led_layout: LED_LAYOUT,
30        // Power budget (default: unlimited)
31        max_current: Current::Unlimited,
32        // Gamma correction mode (default: Gamma::Srgb)
33        gamma: Gamma::Srgb,
34        // Maximum number of animation frames (default: 16)
35        max_frames: 16,
36        // Font variant (see [`Led2dFont`](crate::led2d::Led2dFont) for available fonts)
37        font: Led2dFont::Font3x4Trim,
38    }
39}
40
41#[cfg(doc)]
42/// Sample struct type generated by the [`led2d!`](macro@crate::led2d) macro, showing all methods and constants.
43///
44/// This page serves as the definitive reference for what a generated LED panel type
45/// provides. For first-time readers, start with the examples in the [`led2d`](mod@crate::led2d) module
46/// documentation, then return here for a complete list of available methods and
47/// associated constants.
48/// 
49/// Auto-generated.
50pub struct Led2dGenerated;
51
52#[cfg(doc)]
53use crate::led2d::{Frame2d, Point, Size};
54#[cfg(doc)]
55use crate::led_strip::RGB8;
56#[cfg(doc)]
57use crate::Result;
58
59#[cfg(doc)]
60#[cfg(doc)]
61// Must be public for macro expansion in downstream crates, but not user-facing API.
62#[doc(hidden)]
63/// LED strip type generated by `led2d!` for this example.
64/// 
65/// See the [`led2d`](mod@crate::led2d) module docs for usage.
66pub struct Led2dGeneratedLedStrip;
67
68#[cfg(doc)]
69impl Led2dGenerated {
70    /// The width of the panel.
71    pub const WIDTH: usize = 12;
72    /// The height of the panel.
73    pub const HEIGHT: usize = 4;
74    /// Panel dimensions as a [`Size`].
75    ///
76    /// For [`embedded-graphics`](https://docs.rs/embedded-graphics) drawing operation.
77    pub const SIZE: Size = Frame2d::<12, 4>::SIZE;
78    /// Top-left corner coordinate as a [`Point`].
79    ///
80    /// For [`embedded-graphics`](https://docs.rs/embedded-graphics) drawing operation.
81    pub const TOP_LEFT: Point = Frame2d::<12, 4>::TOP_LEFT;
82    /// Top-right corner coordinate as a [`Point`].
83    ///
84    /// For [`embedded-graphics`](https://docs.rs/embedded-graphics) drawing operation.
85    pub const TOP_RIGHT: Point = Frame2d::<12, 4>::TOP_RIGHT;
86    /// Bottom-left corner coordinate as a [`Point`].
87    ///
88    /// For [`embedded-graphics`](https://docs.rs/embedded-graphics) drawing operation.
89    pub const BOTTOM_LEFT: Point = Frame2d::<12, 4>::BOTTOM_LEFT;
90    /// Bottom-right corner coordinate as a [`Point`].
91    ///
92    /// For [`embedded-graphics`](https://docs.rs/embedded-graphics) drawing operation.
93    pub const BOTTOM_RIGHT: Point = Frame2d::<12, 4>::BOTTOM_RIGHT;
94    /// Total LEDs in this panel (width × height).
95    pub const LEN: usize = 48;
96    /// Maximum brightness level, automatically limited by the power budget specified in `max_current`.
97    ///
98    /// We assume each LED draws 60 mA at full brightness. The actual limit depends on
99    /// the power budget you specified in the [`led2d!`] or [`led_strips!`](crate::led_strips!) macro.
100    /// This constant is the result
101    /// of calculating how much brightness is safe given that budget and the number of LEDs.
102    pub const MAX_BRIGHTNESS: u8 =
103        Current::Unlimited.max_brightness(Self::LEN as u32 * 60);
104    /// Maximum number of animation frames allowed.
105    /// 
106    /// Specified in the [`led2d!`] or [`led_strips!`](crate::led_strips!) macro.
107    pub const MAX_FRAMES: usize = 16;
108
109    /// Create a new LED panel instance of the struct type
110    /// defined by [`led2d!`].
111    ///
112    /// See the [`led2d`](mod@crate::led2d) module docs for usage.
113    ///
114    /// The `pin`, `pio`, and `dma` parameters must correspond to the
115    /// GPIO pin, PIO resource, and DMA channel specified in the macro.
116    ///
117    /// The [`led2d!`] macro defaults to `PIO0` and `DMA_CH0` if not specified.
118    ///
119    /// # Parameters
120    ///
121    /// - `pin`: GPIO pin for LED data signal
122    /// - `pio`: PIO resource
123    /// - `dma`: DMA channel for LED data transfer
124    /// - `spawner`: Task spawner for background operations
125    pub fn new(
126        pin: embassy_rp::Peri<'static, embassy_rp::peripherals::PIN_3>,
127        pio: embassy_rp::Peri<'static, embassy_rp::peripherals::PIO0>,
128        dma: embassy_rp::Peri<'static, embassy_rp::peripherals::DMA_CH0>,
129        spawner: embassy_executor::Spawner,
130    ) -> Result<Self> {
131        let _ = (pin, pio, dma, spawner);
132        Ok(Self)
133    }
134
135    /// Create a new LED panel instance from a strip.
136    ///
137    /// See the [`led2d`](mod@crate::led2d) module docs for usage.
138    pub(crate) fn from_strip(
139        led_strip: &'static Led2dGeneratedLedStrip,
140    ) -> Result<Self> {
141        let _ = led_strip;
142        Ok(Self)
143    }
144
145    /// Write a frame to the LED panel.
146    ///
147    /// See the [`led2d`](mod@crate::led2d) module docs for usage.
148    pub fn write_frame(
149        &self,
150        frame: Frame2d<{ Self::WIDTH }, { Self::HEIGHT }>,
151    ) -> Result<()> {
152        let _ = frame;
153        Ok(())
154    }
155
156    /// Write text to the LED panel.
157    ///
158    /// See the [`led2d`](mod@crate::led2d) module docs for usage.
159    pub async fn write_text(&self, text: &str, colors: &[RGB8]) -> Result<()> {
160        let _ = (text, colors);
161        Ok(())
162    }
163
164    /// Write text into a frame.
165    ///
166    /// See the [`led2d`](mod@crate::led2d) module docs for usage.
167    pub fn write_text_to_frame(
168        &self,
169        text: &str,
170        colors: &[RGB8],
171        frame: &mut Frame2d<{ Self::WIDTH }, { Self::HEIGHT }>,
172    ) -> Result<()> {
173        let _ = (text, colors, frame);
174        Ok(())
175    }
176
177    /// Animate frames on the LED panel.
178    ///
179    /// See the [`led2d`](mod@crate::led2d) module docs for usage.
180    pub fn animate<const N: usize>(
181        &self,
182        frames: [(Frame2d<{ Self::WIDTH }, { Self::HEIGHT }>, embassy_time::Duration); N],
183    ) -> Result<()> {
184        let _ = frames;
185        Ok(())
186    }
187}