blinksy_esp/lib.rs
1#![no_std]
2
3//! # ESP32 Blinksy Extensions
4//!
5//! ESP32-specific extensions for the [Blinksy][blinksy] LED control library using [`esp-hal`][esp_hal].
6//!
7//! ## Features
8//!
9//! - ESP-specific driver for clockless (e.g. WS2812) LEDs, using [RMT (Remote Control Module)][RMT] peripheral
10//! - ESP-specific elapsed time helper
11//!
12//! [RMT]: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/rmt.html
13//!
14//! ## Example
15//!
16//! ```rust
17//! #![no_std]
18//! #![no_main]
19//!
20//! use esp_hal as hal;
21//!
22//! use blinksy::{
23//! driver::ClocklessLed,
24//! drivers::ws2812::Ws2812Led,
25//! layout::Layout1d,
26//! layout1d,
27//! patterns::rainbow::{Rainbow, RainbowParams},
28//! ControlBuilder,
29//! };
30//! use blinksy_esp::{create_rmt_buffer, time::elapsed, Ws2812Rmt};
31//!
32//! #[hal::main]
33//! fn main() -> ! {
34//! let cpu_clock = hal::clock::CpuClock::max();
35//! let config = hal::Config::default().with_cpu_clock(cpu_clock);
36//! let p = hal::init(config);
37//!
38//! // Define the LED layout (1D strip of 300 pixels)
39//! layout1d!(Layout, 60 * 5);
40//!
41//! // Setup the WS2812 driver using RMT.
42//! let ws2812_driver = {
43//! // IMPORTANT: Change `p.GPIO16` to the GPIO pin connected to your WS2812 data line.
44//! let data_pin = p.GPIO16;
45//!
46//! // Initialize RMT peripheral (typical base clock 80 MHz).
47//! let rmt_clk_freq = hal::time::Rate::from_mhz(80);
48//! let rmt = hal::rmt::Rmt::new(p.RMT, rmt_clk_freq).unwrap();
49//! let rmt_channel = rmt.channel0;
50//!
51//! // Create the driver using the ClocklessRmt builder."]
52//! blinksy::driver::ClocklessDriver::default()
53//! .with_led::<Ws2812>()
54//! .with_writer(ClocklessRmtBuilder::default()
55//! .with_rmt_buffer_size::<{ Layout::PIXEL_COUNT * 3 * 8 + 1 }>()
56//! .with_led::<Ws2812>()
57//! .with_channel(rmt_channel)
58//! .with_pin(data_pin)
59//! .build())
60//! };
61//!
62//! // Build the Blinky controller
63//! let mut control = ControlBuilder::new_1d()
64//! .with_layout::<Layout, { Layout::PIXEL_COUNT }>()
65//! .with_pattern::<Rainbow>(RainbowParams {
66//! ..Default::default()
67//! })
68//! .with_driver(ws2812_driver)
69//! .with_frame_buffer_size::<{ Ws2812::frame_buffer_size(Layout::PIXEL_COUNT) }>()
70//! .build();
71//!
72//! control.set_brightness(0.2); // Set initial brightness (0.0 to 1.0)
73//!
74//! loop {
75//! let elapsed_in_ms = elapsed().as_millis();
76//! control.tick(elapsed_in_ms).unwrap();
77//! }
78//! }
79//! ```
80//!
81//! ## Getting started
82//!
83//! For more help to get started, see [`blinksy-quickstart-gledopto`][blinksy-quickstart-gledopto]
84//! project template and [`gledopto`][gledopto] library.
85//!
86//! As the Gledopto controller is an ESP32 board, the project template and library should provide
87//! an entry point to understand how to use Blinksy with an ESP board.
88//!
89//! [blinksy-quickstart-gledopto]: https://github.com/ahdinosaur/blinksy-quickstart-gledopto
90//! [gledopto]: https://docs.rs/gledopto/0.10/gledopto
91
92pub mod rmt;
93pub mod time;
94pub(crate) mod util;
95
96pub use crate::rmt::{ClocklessRmt, ClocklessRmtBuilder, ClocklessRmtError};