Skip to main content

Crate sn3218_hal

Crate sn3218_hal 

Source
Expand description

SN3218 [embedded-hal] driver for 18-channel LED driver SN3218

The SN3218 is an 18-channel LED driver with PWM control, commonly arranged as 6 RGB channels. This LED driver is used on the Raspberry Pi GFX HAT by Pimoroni and other SN3218-based boards.

§Features

  • 18-channel PWM LED control (typically 6 RGB LEDs)
  • Automatic gamma correction for natural brightness curves
  • Simple enable/disable control
  • Mask-based channel selection
  • Built on embedded-hal for platform independence

§Examples

use sn3218::SN3218;

let mut led_driver = SN3218::new(i2c);

// Enable output and all LEDs
led_driver.enable().unwrap();
led_driver.enable_leds(0x3FFFF).unwrap(); // All 18 channels

// Set RGB values for 6 LEDs (18 channels total)
let values = [
    255, 0, 0,     // LED 0: Red
    0, 255, 0,     // LED 1: Green
    0, 0, 255,     // LED 2: Blue
    255, 255, 0,   // LED 3: Yellow
    255, 0, 255,   // LED 4: Magenta
    0, 255, 255,   // LED 5: Cyan
];
led_driver.output(&values).unwrap();

§Channel Layout

The 18 channels are organized as 6 RGB LEDs:

  • LED 0: channels 0 (R), 1 (G), 2 (B)
  • LED 1: channels 3 (R), 4 (G), 5 (B)
  • LED 2: channels 6 (R), 7 (G), 8 (B)
  • LED 3: channels 9 (R), 10 (G), 11 (B)
  • LED 4: channels 12 (R), 13 (G), 14 (B)
  • LED 5: channels 15 (R), 16 (G), 17 (B)

Based on the Python implementation: https://github.com/pimoroni/sn3218

Structs§

SN3218
SN3218 LED driver instance