blinksy 0.11.0

no-std, no-alloc LED control library designed for 1D, 2D, and 3D layouts
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
#![no_std]

//! # Blinksy
//!
//! Blinksy is a no-std, no-alloc LED control library designed for 1D, 2D, and 3D
//! LED setups, inspired by [FastLED](https://fastled.io/) and [WLED](https://kno.wled.ge/).
//!
//! ## How Blinksy works
//!
//! - Define your LED [`layout`] in 1D, 2D, or 3D space
//! - Create your visual [`pattern`] (effect), or choose from our built-in [`patterns`] library
//!   - The pattern will compute colors for each LED based on its position
//! - Setup a [`driver`] to send each frame of colors to your [`leds`]
//!
//! ## Features
//!
//! - **No-std, no-alloc**: Designed for embedded targets.
//! - **Spatial in 1D, 2D, or 3D**: Map out the shape of your LEDs in space.
//! - **Async support**: Supports blocking or asynchronous execution.
//! - **Full color support**: Supports modern and classic color spaces.
//! - **Global settings**: Control overall brightness and color correction.
//! - **Desktop simulation**: Simulate your LEDs on your desktop to play with ideas.
//! - **RGB+W support**: Supports RGB + White color channels
//!
//! ### LED Support
//!
//! #### [Clockless](crate::driver::clockless): One-wire (only data, no clock)
//!
//! - **[WS2812B]**: Affordable RGB LED, aka NeoPixel
//! - **[SK6812]**: RGBW LED
//!
//! #### [Clocked](crate::driver::clocked): Two-wire (data and clock)
//!
//! - **[APA102]**: High-FPS RGB LED, aka DotStar
//!
//! If you want help to support a new LED chipset, [make an issue](https://github.com/ahdinosaur/blinksy/issues)!
//!
//! [WS2812B]: leds::Ws2812
//! [SK6812]: leds::Sk6812
//! [APA102]: leds::Apa102
//!
//! ### Pattern (Effect) Library:
//!
//! - **[Rainbow]**: A basic scrolling rainbow
//! - **[Noise]**: A flow through random noise functions
//!
//! If you want help to port a pattern from FastLED / WLED to Rust, [make an issue](https://github.com/ahdinosaur/blinksy/issues)!
//!
//! [Rainbow]: patterns::rainbow
//! [Noise]: patterns::noise
//!
//! ### Microcontroller Family Support
//!
//! **Clocked LED support (e.g. APA102):**
//!
//! | Micro | HAL            | Blinksy     | Recommended Writer | Backup Writer
//! |-------|----------------|-------------|--------------------|------------------|
//! | ALL   | [embedded-hal] | [blinksy]   | [embedded_hal::spi::SpiBus] / [embedded_hal_async::spi::SpiBus] | [Delay][clocked-delay] |
//!
//! [embedded-hal]: embedded_hal
//! [blinksy]: crate
//! [clocked-delay]: crate::driver::clocked::ClockedDelay
//!
//! **Clockless LED support (e.g. WS2812):**
//!
//! | Micro          | HAL         | Blinksy       | Recommended Driver     | Backup Driver |
//! |----------------|-------------|---------------|------------------------|---------------|
//! | ALL            | [embedded-hal] | [blinksy]  | -                      | TODO [Spi #12][clockless-spi] |
//! | ESP32          | [esp-hal]   | [blinksy-esp] | [Rmt][rmt]             | - |
//! | RP (2040/2350) | [rp-hal]    | TODO          | TODO [#36][rp-issue]   | - |
//! | STM32          | [stm32-hal] | TODO          | TODO [#78][stm32-issue] | - |
//! | nRF            | [nrf-hal]   | TODO          | TODO [#77][nrf-issue]  | - |
//! | atsamd         | [atsamd]    | TODO          | TODO [#67][atsamd-issue] | - |
//! | AVR (Arduino)  | [avr-hal]   | TODO          | TODO [#79][avr-issue]  | - |
//! | CH32           | [ch32-hal]  | TODO          | TODO [#80][ch32-issue] | - |
//! | ???            | -           | -             | -                      | - |
//!
//! [clockless-spi]: https://github.com/ahdinosaur/blinksy/issues/12
//! [esp-hal]: https://docs.espressif.com/projects/rust/esp-hal/latest/
//! [blinksy-esp]: https://docs.rs/blinksy-esp/0.10/
//! [rmt]: https://docs.espressif.com/projects/rust/esp-hal/latest/
//! [rp-hal]: https://github.com/rp-rs/rp-hal/
//! [rp-issue]: https://github.com/ahdinosaur/blinksy/issues/36
//! [stm32-hal]: https://github.com/David-OConnor/stm32-hal
//! [stm32-issue]: https://github.com/ahdinosaur/blinksy/issues/78
//! [nrf-hal]: https://github.com/nrf-rs/nrf-hal
//! [nrf-issue]: https://github.com/ahdinosaur/blinksy/issues/77
//! [atsamd]: https://github.com/atsamd-rs/atsamd
//! [atsamd-issue]: https://github.com/ahdinosaur/blinksy/issues/67
//! [avr-hal]: https://github.com/Rahix/avr-hal
//! [avr-issue]: https://github.com/ahdinosaur/blinksy/issues/79
//! [ch32-hal]: https://github.com/ch32-rs/ch32-hal
//! [ch32-issue]: https://github.com/ahdinosaur/blinksy/issues/80
//!
//! If you want help to support a new microcontroller family, [make an issue](https://github.com/ahdinosaur/blinksy/issues)!
//!
//! ### Board Support Packages
//!
//! - **[Gledopto]**: A great LED controller available on AliExpress: [Gledopto GL-C-016WL-D](https://www.aliexpress.com/item/1005008707989546.html)
//! - (TODO) [**QuinLED**](https://quinled.info/): The best DIY and pre-assembled LED controller boards
//!
//! If you want help to support a new target, [make an issue](https://github.com/ahdinosaur/blinksy/issues)!
//!
//! [Gledopto]: https://docs.rs/gledopto/0.10/gledopto
//!
//! ## Quick Start
//!
//! To quickstart a project, see:
//!
//! - [`blinksy-quickstart-1d-rope`][blinksy-quickstart-1d-rope]
//! - [`blinksy-quickstart-3d-grid`][blinksy-quickstart-3d-grid]
//!
//! To start using the library, see [control][control].
//!
//! [blinksy-quickstart-1d-rope]: https://github.com/ahdinosaur/blinksy-quickstart-1d-rope
//! [blinksy-quickstart-3d-grid]: https://github.com/ahdinosaur/blinksy-quickstart-3d-grid
//! [control]: https://docs.rs/blinksy/0.10/blinksy/control/index.html
//!
//! ### 1D Strip with Rainbow Pattern (Blocking)
//!
//! ### 1D Strip with Rainbow Pattern (Blocking)
//!
//! ```rust,ignore
//! # use blinksy::{ControlBuilder, layout::Layout1d, layout1d, patterns::rainbow::{Rainbow, RainbowParams}};
//! #
//! // Define a 1D layout with 60 LEDs
//! layout1d!(Layout, 60);
//!
//! let mut control = ControlBuilder::new_1d()
//!     .with_layout::<Layout, { Layout::PIXEL_COUNT }>()
//!     .with_pattern::<Rainbow>(RainbowParams::default())
//!     .with_driver(/* Insert your LED driver here */)
//!     .with_frame_buffer_size::</* Length of frame buffer */>()
//!     .build();
//!
//! control.set_brightness(0.5);
//!
//! loop {
//!     control.tick(/* current time in milliseconds */).unwrap();
//! }
//! ```
//!
//! ### 1D Strip with Rainbow Pattern (Async)
//!
//! ```rust,ignore
//! # use blinksy::{ControlBuilder, layout::Layout1d, layout1d, patterns::rainbow::{Rainbow, RainbowParams}};
//! #
//! // Define a 1D layout with 60 LEDs
//! layout1d!(Layout, 60);
//!
//! let mut control = ControlBuilder::new_1d_async()
//!     .with_layout::<Layout, { Layout::PIXEL_COUNT }>()
//!     .with_pattern::<Rainbow>(RainbowParams::default())
//!     .with_driver(/* Insert your LED driver here */)
//!     .with_frame_buffer_size::</* Length of frame buffer */>()
//!     .build();
//!
//! control.set_brightness(0.5);
//!
//! loop {
//!     control.tick(/* current time in milliseconds */).await.unwrap();
//! }
//! ```
//!
//! ### 2D Grid with Noise Pattern (Blocking)
//!
//! ```rust,ignore
//! # use blinksy::{
//! #     ControlBuilder,
//! #     layout::{Layout2d, Shape2d, Vec2},
//! #     layout2d,
//! #     patterns::noise::{noise_fns, Noise2d, NoiseParams},
//! # };
//! #
//! layout2d!(
//!     Layout,
//!     [Shape2d::Grid {
//!         start: Vec2::new(-1., -1.),
//!         horizontal_end: Vec2::new(1., -1.),
//!         vertical_end: Vec2::new(-1., 1.),
//!         horizontal_pixel_count: 16,
//!         vertical_pixel_count: 16,
//!         serpentine: true,
//!     }]
//! );
//! let mut control = ControlBuilder::new_2d()
//!     .with_layout::<Layout, { Layout::PIXEL_COUNT }>()
//!     .with_pattern::<Noise2d<noise_fns::Perlin>>(NoiseParams::default())
//!     .with_driver(/* Insert your LED driver here */)
//!     .with_frame_buffer_size::</* Length of frame buffer */>()
//!     .build();
//!
//! control.set_brightness(0.5);
//!
//! loop {
//!     control.tick(/* current time in milliseconds */).unwrap();
//! }
//! ```
//!
//! ### 3D Cube with Noise Pattern (Blocking)
//!
//! ```rust,ignore
//! # use blinksy::{
//! #     layout::{Layout3d, Shape3d, Vec3},
//! #     layout3d,
//! #     patterns::noise::{noise_fns, Noise3d, NoiseParams},
//! #     ControlBuilder,
//! # };
//! #
//! layout3d!(
//!     Layout,
//!     [
//!         // bottom face
//!         Shape3d::Grid {
//!             start: Vec3::new(1., -1., 1.),           // right bottom front
//!             horizontal_end: Vec3::new(-1., -1., 1.), // left bottom front
//!             vertical_end: Vec3::new(1., -1., -1.),   // right bottom back
//!             horizontal_pixel_count: 16,
//!             vertical_pixel_count: 16,
//!             serpentine: true,
//!         },
//!         // back face
//!         Shape3d::Grid {
//!             start: Vec3::new(-1., -1., -1.),         // left bottom back
//!             horizontal_end: Vec3::new(-1., 1., -1.), // left top back
//!             vertical_end: Vec3::new(1., -1., -1.),   // right bottom back
//!             horizontal_pixel_count: 16,
//!             vertical_pixel_count: 16,
//!             serpentine: true,
//!         },
//!         // right face
//!         Shape3d::Grid {
//!             start: Vec3::new(1., 1., -1.),         // right top back
//!             horizontal_end: Vec3::new(1., 1., 1.), // right top front
//!             vertical_end: Vec3::new(1., -1., -1.), // right bottom back
//!             horizontal_pixel_count: 16,
//!             vertical_pixel_count: 16,
//!             serpentine: true,
//!         },
//!         // front face
//!         Shape3d::Grid {
//!             start: Vec3::new(-1., -1., 1.),         // left bottom front
//!             horizontal_end: Vec3::new(1., -1., 1.), // right bottom front
//!             vertical_end: Vec3::new(-1., 1., 1.),   // left top front
//!             horizontal_pixel_count: 16,
//!             vertical_pixel_count: 16,
//!             serpentine: true,
//!         },
//!         // left face
//!         Shape3d::Grid {
////!             start: Vec3::new(-1., 1., -1.),           // left top back
//!             horizontal_end: Vec3::new(-1., -1., -1.), // left bottom back
//!             vertical_end: Vec3::new(-1., 1., 1.),     // left top front
//!             horizontal_pixel_count: 16,
//!             vertical_pixel_count: 16,
//!             serpentine: true,
//!         },
//!         // top face
//!         Shape3d::Grid {
//!             start: Vec3::new(1., 1., 1.),           // right top front
//!             horizontal_end: Vec3::new(1., 1., -1.), // right top back
//!             vertical_end: Vec3::new(-1., 1., 1.),   // left top front
//!             horizontal_pixel_count: 16,
//!             vertical_pixel_count: 16,
//!             serpentine: true,
//!         }
//!     ]
//! );
//!
//! let mut control = ControlBuilder::new_3d()
//!     .with_layout::<Layout, { Layout::PIXEL_COUNT }>()
//!     .with_pattern::<Noise3d<noise_fns::Perlin>>(NoiseParams::default())
//!     .with_driver(/* Insert your LED driver here */)
//!     .with_frame_buffer_size::</* Length of frame buffer */>()
//!     .build();
//!
//! control.set_brightness(0.2);
//!
//! loop {
//!     control.tick(/* current time in milliseconds */).unwrap();
//! }
//! ```
//!
//! ### 2D Grid with Noise Pattern (Blocking)
//!
//! ```rust,ignore
//! # use blinksy::{
//! #     ControlBuilder,
//! #     layout::{Layout2d, Shape2d, Vec2},
//! #     layout2d,
//! #     patterns::noise::{noise_fns, Noise2d, NoiseParams},
//! # };
//! #
//! layout2d!(
//!     Layout,
//!     [Shape2d::Grid {
//!         start: Vec2::new(-1., -1.),
//!         horizontal_end: Vec2::new(1., -1.),
//!         vertical_end: Vec2::new(-1., 1.),
//!         horizontal_pixel_count: 16,
//!         vertical_pixel_count: 16,
//!         serpentine: true,
//!     }]
//! );
//! let mut control = ControlBuilder::new_2d()
//!     .with_layout::<Layout, { Layout::PIXEL_COUNT }>()
//!     .with_pattern::<Noise2d<noise_fns::Perlin>>(NoiseParams::default())
//!     .with_driver(/* Insert your LED driver here */)
//!     .build();
//!
//! control.set_brightness(0.5);
//!
//! loop {
//!     control.tick(/* current time in milliseconds */).unwrap();
//! }
//! ```
//!
//! ### 3D Cube with Noise Pattern (Blocking)
//!
//! ```rust,ignore
//! # use blinksy::{
//! #     layout::{Layout3d, Shape3d, Vec3},
//! #     layout3d,
//! #     patterns::noise::{noise_fns, Noise3d, NoiseParams},
//! #     ControlBuilder,
//! # };
//! #
//! layout3d!(
//!     Layout,
//!     [
//!         // bottom face
//!         Shape3d::Grid {
//!             start: Vec3::new(1., -1., 1.),           // right bottom front
//!             horizontal_end: Vec3::new(-1., -1., 1.), // left bottom front
//!             vertical_end: Vec3::new(1., -1., -1.),   // right bottom back
//!             horizontal_pixel_count: 16,
//!             vertical_pixel_count: 16,
//!             serpentine: true,
//!         },
//!         // back face
//!         Shape3d::Grid {
//!             start: Vec3::new(-1., -1., -1.),         // left bottom back
//!             horizontal_end: Vec3::new(-1., 1., -1.), // left top back
//!             vertical_end: Vec3::new(1., -1., -1.),   // right bottom back
//!             horizontal_pixel_count: 16,
//!             vertical_pixel_count: 16,
//!             serpentine: true,
//!         },
//!         // right face
//!         Shape3d::Grid {
//!             start: Vec3::new(1., 1., -1.),         // right top back
//!             horizontal_end: Vec3::new(1., 1., 1.), // right top front
//!             vertical_end: Vec3::new(1., -1., -1.), // right bottom back
//!             horizontal_pixel_count: 16,
//!             vertical_pixel_count: 16,
//!             serpentine: true,
//!         },
//!         // front face
//!         Shape3d::Grid {
//!             start: Vec3::new(-1., -1., 1.),         // left bottom front
//!             horizontal_end: Vec3::new(1., -1., 1.), // right bottom front
//!             vertical_end: Vec3::new(-1., 1., 1.),   // left top front
//!             horizontal_pixel_count: 16,
//!             vertical_pixel_count: 16,
//!             serpentine: true,
//!         },
//!         // left face
//!         Shape3d::Grid {
//!             start: Vec3::new(-1., 1., -1.),           // left top back
//!             horizontal_end: Vec3::new(-1., -1., -1.), // left bottom back
//!             vertical_end: Vec3::new(-1., 1., 1.),     // left top front
//!             horizontal_pixel_count: 16,
//!             vertical_pixel_count: 16,
//!             serpentine: true,
//!         },
//!         // top face
//!         Shape3d::Grid {
//!             start: Vec3::new(1., 1., 1.),           // right top front
//!             horizontal_end: Vec3::new(1., 1., -1.), // right top back
//!             vertical_end: Vec3::new(-1., 1., 1.),   // left top front
//!             horizontal_pixel_count: 16,
//!             vertical_pixel_count: 16,
//!             serpentine: true,
//!         }
//!     ]
//! );
//!
//! let mut control = ControlBuilder::new_3d()
//!     .with_layout::<Layout, { Layout::PIXEL_COUNT }>()
//!     .with_pattern::<Noise3d<noise_fns::Perlin>>(NoiseParams::default())
//!     .with_driver(/* Insert your LED driver here */)
//!     .build();
//!
//! control.set_brightness(0.2);
//!
//! loop {
//!     control.tick(/* current time in milliseconds */).unwrap();
//! }
//! ```
//!

pub mod color;
pub mod control;
pub mod driver;
pub mod layout;
pub mod leds;
pub mod markers;
pub mod pattern;
pub mod patterns;
pub mod time;
pub mod util;

pub use self::control::*;