macro_rules! led2d {
($($tt:tt)*) => { ... };
}host only.Expand description
Macro to generate an LED-panel struct type (includes syntax details). See Led2dGenerated for a sample of a generated type.
See the led2d module for usage examples.
Syntax:
led2d! {
[<visibility>] <Name> {
pin: <pin_ident>,
led_layout: <LedLayout_expr>,
font: <Led2dFont_expr>,
pio: <pio_ident>, // optional
dma: <dma_ident>, // optional
max_current: <Current_expr>, // optional
gamma: <Gamma_expr>, // optional
max_frames: <usize_expr>, // optional
}
}§Fields
Required fields:
pin— GPIO pin for LED dataled_layout— LED strip physical layout (seeLedLayout); this defines the panel sizefont— Built-in font variant (seeLed2dFont), e.g.Led2dFont::Font4x6Trim. BringLed2dFontinto scope or use a full path likedevice_envoy::led2d::Led2dFont::Font4x6Trim.
The led_layout value must be a const so its dimensions can be derived at compile time.
Optional fields:
pio— PIO resource to use (default:PIO0)dma— DMA channel (default:DMA_CH0)max_current— Electrical current budget (default: 250 mA)gamma— Color curve (default:Gamma::Srgb)max_frames— Maximum number of animation frames for the generated strip (default: 16 frames)
max_frames = 0 disables animation and allocates no frame storage; write_frame() is still supported.
§Current Limiting
The max_current field automatically scales brightness to stay within your electrical current budget.
Each WS2812 LED is assumed to draw 60 mA at full brightness. For example:
- 16 LEDs × 60 mA = 960 mA at full brightness
- With
max_current: Current::Milliamps(1000), all LEDs fit at 100% brightness - With the default electrical current limit (250 mA), the generated
MAX_BRIGHTNESSlimits LEDs to ~26% brightness
The electrical current limit is compiled into a lookup table at device initialization, so it has no per-frame runtime cost.
Powering LEDs from the Pico’s pin 40 (VBUS): Pin 40 is the USB 5 V rail pass-through, but the Pico itself has practical electrical current limits — the USB connector, cable, and internal circuitry aren’t designed for heavy loads. Small LED panels (a few hundred mA) can usually power from pin 40 with a decent USB supply; for larger loads (1 A+), use a separate 5 V supply and share ground with the Pico.
§Color Correction (Gamma)
The gamma field applies a color response curve to make colors look more natural:
Gamma::Linear— No correction (raw values)Gamma::Srgb— Perceptual sRGB semantics (default; preserves named color constants)Gamma::SmartLeds—smart_leds::gamma()compatibility (2.8)
The gamma curve is compiled into a lookup table at device initialization, so it has no per-frame runtime cost.
§Related Macros
led_strips!— Alternative macro to share a PIO resource with other panels or LED strips (includes examples)led_strip!— For 1-dimensional LED strips