RKTK API Docs RKTK Home Repo

rktk/drivers/interface/
rgb.rs

1//! RGBBB driver type
2
3// TODO: Split backlight and underglow
4
5pub use blinksy::color::{ColorCorrection, LedChannels, LedRgb, LinearSrgb};
6use serde::{Deserialize, Serialize};
7
8/// Commands for controlling RGB LEDs.
9///
10/// This value can be send using [`crate::hooks::channels::rgb::rgb_sender`].
11/// In master side, command sent from above channel will also be sent to slave side.
12#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
13#[cfg_attr(feature = "defmt", derive(defmt::Format))]
14pub enum RgbCommand {
15    /// Set RGB mode and start it
16    Start(RgbMode),
17    /// Set brightness
18    ///
19    /// Range: 0.0 to 1.0
20    Brightness(f32),
21    BrightnessDelta(f32),
22    /// Reset RGB state and restart current RgbMode
23    Reset,
24}
25
26/// RGB mode for controlling RGB LEDs.
27#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
28#[cfg_attr(feature = "defmt", derive(defmt::Format))]
29pub enum RgbMode {
30    /// Turn off RGB
31    Off,
32    /// Set solid color
33    ///
34    /// Value range: 0 to 255
35    /// (Red, Green, Blue)
36    SolidColor(u8, u8, u8),
37    /// Set built-in RGB pattern
38    Pattern(RgbPattern),
39    /// Call user-defined RGB hook
40    Custom,
41}
42
43/// Built-in RGB patterns.
44#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
45#[cfg_attr(feature = "defmt", derive(defmt::Format))]
46pub enum RgbPattern {
47    Rainbow(f32, f32),
48    NoisePerlin,
49}
50
51/// Driver for controlling the RGB leds.
52///
53/// Basically, this is just async version trait of [`blinksy::driver::Driver`]. But color is
54/// limited to LinearSrgb to avoid complexity.
55/// TODO: When blinksy implements async drivers, remove this trait and use the blinksy one
56/// directly.
57pub trait RgbDriver: 'static {
58    type Error: super::Error;
59
60    // Required method
61    async fn write<I: IntoIterator<Item = LedRgb<u8>>>(
62        &mut self,
63        pixels: I,
64    ) -> Result<(), Self::Error>;
65}