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