feat(status): blink the on-board LED as a heartbeat
Also moves the encoder and button onto XIAO ESP32C6 pads: GPIO4/5/6 are JTAG pins and are not broken out on this board.
This commit is contained in:
1 parent
ebc2f3be7a
commit
74b3a4a06b
4 files changed
+42
-6
No files matched your search
+6
-2
@@ -7,8 +7,8 @@ pub const LED_COUNT: usize = 60;
|
||||
|
||||
/// Ceiling on the duty cycle applied to every channel, as a fraction of 255.
|
||||
///
|
||||
/// Keeps the supply current within what the dev board's regulator can source
|
||||
/// when every pixel is driven white.
|
||||
/// Takes the top off peak current draw. This is a brightness cap, not a
|
||||
/// current limit: a strip of this length still needs its own 5V supply.
|
||||
pub const MAX_DUTY: u8 = 200;
|
||||
|
||||
/// Rotary encoder detents per full revolution, used to scale a turn into a
|
||||
@@ -20,3 +20,7 @@ pub const LONG_PRESS_MS: u64 = 600;
|
||||
|
||||
/// Contact settle time for the encoder push button.
|
||||
pub const DEBOUNCE_MS: u64 = 15;
|
||||
|
||||
/// Heartbeat blink: a brief pulse, repeated once a second.
|
||||
pub const HEARTBEAT_ON_MS: u64 = 50;
|
||||
pub const HEARTBEAT_PERIOD_MS: u64 = 1000;
|
||||
+13
-3
@@ -4,6 +4,7 @@
|
||||
mod config;
|
||||
mod encoder;
|
||||
mod light;
|
||||
mod status;
|
||||
mod strip;
|
||||
mod zigbee_stack;
|
||||
|
||||
@@ -12,6 +13,9 @@ use esp_alloc as _;
|
||||
use esp_backtrace as _;
|
||||
use esp_hal::gpio::Input;
|
||||
use esp_hal::gpio::InputConfig;
|
||||
use esp_hal::gpio::Level;
|
||||
use esp_hal::gpio::Output;
|
||||
use esp_hal::gpio::OutputConfig;
|
||||
use esp_hal::gpio::Pull;
|
||||
use esp_hal::rmt::Rmt;
|
||||
use esp_hal::time::Rate;
|
||||
@@ -55,15 +59,20 @@ async fn main(spawner: embassy_executor::Spawner) -> ! {
|
||||
let rmt = Rmt::new(peripherals.RMT, rmt_freq)
|
||||
.expect("init RMT")
|
||||
.into_async();
|
||||
// XIAO ESP32C6 pads: D2, D3, D4, D5. GPIO4/5/6 are JTAG and are not
|
||||
// broken out on this board; GPIO3 and GPIO14 drive the antenna switch.
|
||||
let strip = Strip::new(WS2812B_TIMING, rmt.channel0, peripherals.GPIO2, rmt_freq)
|
||||
.expect("configure WS2812B adapter");
|
||||
|
||||
// the encoder's common pin is grounded, so both phases and the switch idle
|
||||
// high and are driven low; the pull-ups make an open contact well defined
|
||||
let pull_up = InputConfig::default().with_pull(Pull::Up);
|
||||
let encoder_a = Input::new(peripherals.GPIO4, pull_up);
|
||||
let encoder_b = Input::new(peripherals.GPIO5, pull_up);
|
||||
let button = Input::new(peripherals.GPIO6, pull_up);
|
||||
let encoder_a = Input::new(peripherals.GPIO21, pull_up);
|
||||
let encoder_b = Input::new(peripherals.GPIO22, pull_up);
|
||||
let button = Input::new(peripherals.GPIO23, pull_up);
|
||||
|
||||
// on-board user LED, starting dark
|
||||
let led = Output::new(peripherals.GPIO15, Level::High, OutputConfig::default());
|
||||
|
||||
// the stack owns persistence: the information bases are restored here and
|
||||
// written back whenever the stack changes them
|
||||
@@ -81,6 +90,7 @@ async fn main(spawner: embassy_executor::Spawner) -> ! {
|
||||
storage,
|
||||
));
|
||||
|
||||
spawner.spawn(status::heartbeat_task(led).expect("spawn heartbeat_task"));
|
||||
spawner.spawn(light::render_task(strip).expect("spawn render_task"));
|
||||
spawner.spawn(encoder::encoder_task(encoder_a, encoder_b).expect("spawn encoder_task"));
|
||||
spawner.spawn(encoder::button_task(button).expect("spawn button_task"));
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
//! Heartbeat on the XIAO's on-board user LED.
|
||||
//!
|
||||
//! A short pulse once a second: if it stops, the executor has stalled or a
|
||||
//! task has panicked, which is otherwise invisible without a serial console.
|
||||
|
||||
use embassy_time::Duration;
|
||||
use embassy_time::Timer;
|
||||
use esp_hal::gpio::Output;
|
||||
|
||||
use crate::config::HEARTBEAT_ON_MS;
|
||||
use crate::config::HEARTBEAT_PERIOD_MS;
|
||||
|
||||
#[embassy_executor::task]
|
||||
pub async fn heartbeat_task(mut led: Output<'static>) {
|
||||
loop {
|
||||
// the LED's anode sits on 3V3, so a low level lights it
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(HEARTBEAT_ON_MS)).await;
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(HEARTBEAT_PERIOD_MS - HEARTBEAT_ON_MS)).await;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -43,7 +43,7 @@ use crate::light;
|
||||
///
|
||||
/// MUST match the partition table: erase-sector aligned (4 KiB) and at least
|
||||
/// two sectors so sequential-storage has a spare for garbage collection. The
|
||||
/// address assumes the 4 MiB flash of the ESP32-C6-DevKitC-1.
|
||||
/// address assumes the 4 MiB flash of the XIAO ESP32C6.
|
||||
pub const FLASH_RANGE: Range<u32> = 0x3f_0000..0x3f_4000;
|
||||
|
||||
/// Extended PAN ID of the network to join.
|
||||
|
||||
Reference in new issue
Block a user