Implement full SSD1306 OLED display support: - Splash screen on boot (1.5s) with project name, version, board - Dashboard showing radio state, config, counters, RSSI/SNR - RSSI history sparkline (64-sample ring buffer, 2px-wide bars) - DisplayOn/DisplayOff host commands routed via dedicated channel - Pure render functions against generic DrawTarget (no hardware coupling) - Display on/off control bypasses radio task entirely Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
63 lines
1.7 KiB
Rust
63 lines
1.7 KiB
Rust
//! Delays.
|
|
|
|
/// Nanoseconds per microsecond
|
|
const NANOS_PER_MICRO: u32 = 1_000;
|
|
/// Nanoseconds per millisecond
|
|
const NANOS_PER_MILLI: u32 = 1_000_000;
|
|
|
|
/// Delay with up to nanosecond precision.
|
|
pub trait DelayNs {
|
|
/// Pauses execution for at minimum `ns` nanoseconds. Pause can be longer
|
|
/// if the implementation requires it due to precision/timing issues.
|
|
fn delay_ns(&mut self, ns: u32);
|
|
|
|
/// Pauses execution for at minimum `us` microseconds. Pause can be longer
|
|
/// if the implementation requires it due to precision/timing issues.
|
|
fn delay_us(&mut self, mut us: u32) {
|
|
const MAX_MICROS: u32 = u32::MAX / NANOS_PER_MICRO;
|
|
|
|
// Avoid potential overflow if micro -> nano conversion is too large
|
|
while us > MAX_MICROS {
|
|
us -= MAX_MICROS;
|
|
self.delay_ns(MAX_MICROS * NANOS_PER_MICRO);
|
|
}
|
|
|
|
self.delay_ns(us * NANOS_PER_MICRO);
|
|
}
|
|
|
|
/// Pauses execution for at minimum `ms` milliseconds. Pause can be longer
|
|
/// if the implementation requires it due to precision/timing issues.
|
|
#[inline]
|
|
fn delay_ms(&mut self, mut ms: u32) {
|
|
const MAX_MILLIS: u32 = u32::MAX / NANOS_PER_MILLI;
|
|
|
|
// Avoid potential overflow if milli -> nano conversion is too large
|
|
while ms > MAX_MILLIS {
|
|
ms -= MAX_MILLIS;
|
|
self.delay_ns(MAX_MILLIS * NANOS_PER_MILLI);
|
|
}
|
|
|
|
self.delay_ns(ms * NANOS_PER_MILLI);
|
|
}
|
|
}
|
|
|
|
impl<T> DelayNs for &mut T
|
|
where
|
|
T: DelayNs + ?Sized,
|
|
{
|
|
#[inline]
|
|
fn delay_ns(&mut self, ns: u32) {
|
|
T::delay_ns(self, ns);
|
|
}
|
|
|
|
#[inline]
|
|
fn delay_us(&mut self, us: u32) {
|
|
T::delay_us(self, us);
|
|
}
|
|
|
|
#[inline]
|
|
fn delay_ms(&mut self, ms: u32) {
|
|
T::delay_ms(self, ms);
|
|
}
|
|
}
|