Skip to main content

rgb_sequencer/
lib.rs

1#![no_std]
2#![forbid(unsafe_code)]
3#![warn(missing_docs)]
4
5//! `no_std` RGB LED animation library for embedded systems.
6//!
7//! Provides step-based and function-based color sequences with trait abstractions for LED hardware and timing.
8//! Zero heap allocation, platform-independent, type-safe colors via `palette::Srgb<f32>`.
9//!
10//! # Core Types
11//!
12//! - **`RgbSequence`** - Defines an animation (steps, loops, transitions, colors)
13//! - **`RgbSequencer`** - Controls a single LED through sequences with state management
14//! - **`RgbLed`** - Trait for LED hardware abstraction
15//! - **`TimeSource`** - Trait for timing system abstraction
16//! - **`TransitionStyle`** - How to animate between colors (Step, Linear, EaseIn/Out)
17//!
18//! # Color Helpers
19//!
20//! - **`colors`** module - HSV color space helpers for intuitive color creation
21//!
22//! Uses f32 extensively - performance varies by FPU availability.
23
24// Re-export Srgb from palette for user convenience
25pub use palette::Srgb;
26
27pub mod colors;
28pub mod command;
29pub mod sequence;
30pub mod sequencer;
31pub mod time;
32pub mod types;
33
34pub use command::{SequencerAction, SequencerCommand};
35pub use sequence::{RgbSequence, SequenceBuilder, StepPosition};
36pub use sequencer::{
37    DEFAULT_COLOR_EPSILON, Position, RgbLed, RgbSequencer, SequencerError, SequencerState,
38    ServiceTiming,
39};
40pub use time::{TimeDuration, TimeInstant, TimeSource};
41pub use types::{LoopCount, SequenceError, SequenceStep, TransitionStyle};
42
43/// Black color (all channels off).
44pub const BLACK: Srgb = Srgb::new(0.0, 0.0, 0.0);
45
46/// Red color (full red channel).
47pub const RED: Srgb = Srgb::new(1.0, 0.0, 0.0);
48
49/// Green color (full green channel).
50pub const GREEN: Srgb = Srgb::new(0.0, 1.0, 0.0);
51
52/// Blue color (full blue channel).
53pub const BLUE: Srgb = Srgb::new(0.0, 0.0, 1.0);
54
55/// White color (all channels full).
56pub const WHITE: Srgb = Srgb::new(1.0, 1.0, 1.0);
57
58/// Yellow color (red + green).
59pub const YELLOW: Srgb = Srgb::new(1.0, 1.0, 0.0);
60
61/// Cyan color (green + blue).
62pub const CYAN: Srgb = Srgb::new(0.0, 1.0, 1.0);
63
64/// Magenta color (red + blue).
65pub const MAGENTA: Srgb = Srgb::new(1.0, 0.0, 1.0);
66
67// Type aliases for common sequencer capacities
68
69/// RGB sequencer with capacity for 4 steps.
70pub type RgbSequencer4<'t, I, L, T> = RgbSequencer<'t, I, L, T, 4>;
71
72/// RGB sequencer with capacity for 8 steps.
73pub type RgbSequencer8<'t, I, L, T> = RgbSequencer<'t, I, L, T, 8>;
74
75/// RGB sequencer with capacity for 16 steps.
76pub type RgbSequencer16<'t, I, L, T> = RgbSequencer<'t, I, L, T, 16>;
77
78/// RGB sequence with capacity for 4 steps.
79pub type RgbSequence4<D> = RgbSequence<D, 4>;
80
81/// RGB sequence with capacity for 8 steps.
82pub type RgbSequence8<D> = RgbSequence<D, 8>;
83
84/// RGB sequence with capacity for 16 steps.
85pub type RgbSequence16<D> = RgbSequence<D, 16>;
86
87/// Sequencer action with capacity for 4 steps.
88pub type SequencerAction4<D> = SequencerAction<D, 4>;
89
90/// Sequencer action with capacity for 8 steps.
91pub type SequencerAction8<D> = SequencerAction<D, 8>;
92
93/// Sequencer action with capacity for 16 steps.
94pub type SequencerAction16<D> = SequencerAction<D, 16>;
95
96/// Sequencer command with capacity for 4 steps.
97pub type SequencerCommand4<Id, D> = SequencerCommand<Id, D, 4>;
98
99/// Sequencer command with capacity for 8 steps.
100pub type SequencerCommand8<Id, D> = SequencerCommand<Id, D, 8>;
101
102/// Sequencer command with capacity for 16 steps.
103pub type SequencerCommand16<Id, D> = SequencerCommand<Id, D, 16>;