feat: add display UI with splash screen, dashboard, and RSSI sparkline

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>
This commit is contained in:
swaitsandClaude Opus 4.6 committed 2026-03-29 20:42:54 -06:00
1 parent 7064110293
commit 3102fc747a
17624 files changed
+4564928 -38

No files matched your search

+317
View File
@@ -0,0 +1,317 @@
use crate::repr::primitive::PrimitiveIter;
use crate::repr::EnumSetTypeRepr;
use core::ops::*;
/// An implementation of `EnumSetTypeRepr` based on an arbitrary size array.
///
/// `N` **must** not be `0`, or else everything will break.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub struct ArrayRepr<const N: usize>(pub [u64; N]);
impl<const N: usize> ArrayRepr<N> {
fn split_bit(bit: u32) -> (usize, u32) {
(bit as usize / 64, bit % 64)
}
}
impl<const N: usize> BitAnd for ArrayRepr<N> {
type Output = Self;
fn bitand(mut self, rhs: Self) -> Self::Output {
for i in 0..N {
self.0[i] &= rhs.0[i];
}
self
}
}
impl<const N: usize> BitOr for ArrayRepr<N> {
type Output = Self;
fn bitor(mut self, rhs: Self) -> Self::Output {
for i in 0..N {
self.0[i] |= rhs.0[i];
}
self
}
}
impl<const N: usize> BitXor for ArrayRepr<N> {
type Output = Self;
fn bitxor(mut self, rhs: Self) -> Self::Output {
for i in 0..N {
self.0[i] ^= rhs.0[i];
}
self
}
}
impl<const N: usize> Not for ArrayRepr<N> {
type Output = Self;
fn not(mut self) -> Self::Output {
for i in 0..N {
self.0[i] = !self.0[i];
}
self
}
}
impl<const N: usize> EnumSetTypeRepr for ArrayRepr<N> {
const PREFERRED_ARRAY_LEN: usize = N;
const WIDTH: u32 = N as u32 * 64;
const EMPTY: Self = ArrayRepr([0; N]);
fn is_empty(&self) -> bool {
self.0.iter().all(|x| *x == 0)
}
fn add_bit(&mut self, bit: u32) {
let (idx, bit) = Self::split_bit(bit);
self.0[idx].add_bit(bit);
}
fn remove_bit(&mut self, bit: u32) {
let (idx, bit) = Self::split_bit(bit);
self.0[idx].remove_bit(bit);
}
fn has_bit(&self, bit: u32) -> bool {
let (idx, bit) = Self::split_bit(bit);
self.0[idx].has_bit(bit)
}
fn count_ones(&self) -> u32 {
self.0.iter().map(|x| x.count_ones()).sum()
}
fn and_not(&self, other: Self) -> Self {
let mut new = Self([0; N]);
for i in 0..N {
new.0[i] = self.0[i] & !other.0[i];
}
new
}
type Iter = ArrayIter<N>;
fn iter(self) -> Self::Iter {
ArrayIter::new(self)
}
fn from_u8(v: u8) -> Self {
Self::from_u64(v as u64)
}
fn from_u16(v: u16) -> Self {
Self::from_u64(v as u64)
}
fn from_u32(v: u32) -> Self {
Self::from_u64(v as u64)
}
fn from_u64(v: u64) -> Self {
let mut new = Self([0; N]);
new.0[0] = v;
new
}
fn from_u128(v: u128) -> Self {
let mut new = Self([0; N]);
new.0[0] = v as u64;
if N != 1 {
new.0[1] = (v >> 64) as u64;
}
new
}
fn from_usize(v: usize) -> Self {
Self::from_u64(v as u64)
}
fn from_u8_opt(v: u8) -> Option<Self> {
Some(Self::from_u8(v))
}
fn from_u16_opt(v: u16) -> Option<Self> {
Some(Self::from_u16(v))
}
fn from_u32_opt(v: u32) -> Option<Self> {
Some(Self::from_u32(v))
}
fn from_u64_opt(v: u64) -> Option<Self> {
Some(Self::from_u64(v))
}
fn from_u128_opt(v: u128) -> Option<Self> {
if N == 1 && (v >> 64) != 0 {
None
} else {
Some(Self::from_u128(v))
}
}
fn from_usize_opt(v: usize) -> Option<Self> {
Some(Self::from_usize(v))
}
fn to_u8(&self) -> u8 {
self.to_u64().to_u8()
}
fn to_u16(&self) -> u16 {
self.to_u64().to_u16()
}
fn to_u32(&self) -> u32 {
self.to_u64().to_u32()
}
fn to_u64(&self) -> u64 {
self.0[0]
}
fn to_u128(&self) -> u128 {
let hi = if N == 1 { 0 } else { (self.0[1] as u128) << 64 };
self.0[0] as u128 | hi
}
fn to_usize(&self) -> usize {
self.to_u64().to_usize()
}
fn to_u8_opt(&self) -> Option<u8> {
self.to_u64_opt().and_then(|x| x.to_u8_opt())
}
fn to_u16_opt(&self) -> Option<u16> {
self.to_u64_opt().and_then(|x| x.to_u16_opt())
}
fn to_u32_opt(&self) -> Option<u32> {
self.to_u64_opt().and_then(|x| x.to_u32_opt())
}
fn to_u64_opt(&self) -> Option<u64> {
for i in 1..N {
if self.0[i] != 0 {
return None;
}
}
Some(self.to_u64())
}
fn to_u128_opt(&self) -> Option<u128> {
for i in 2..N {
if self.0[i] != 0 {
return None;
}
}
Some(self.to_u128())
}
fn to_usize_opt(&self) -> Option<usize> {
self.to_u64_opt().and_then(|x| x.to_usize_opt())
}
fn to_u64_array<const O: usize>(&self) -> [u64; O] {
let mut array = [0; O];
let copy_len = if N < O { N } else { O };
array[..copy_len].copy_from_slice(&self.0[..copy_len]);
array
}
fn to_u64_array_opt<const O: usize>(&self) -> Option<[u64; O]> {
if N > O {
for i in O..N {
if self.0[i] != 0 {
return None;
}
}
}
Some(self.to_u64_array())
}
fn from_u64_array<const O: usize>(v: [u64; O]) -> Self {
ArrayRepr(ArrayRepr::<O>(v).to_u64_array::<N>())
}
fn from_u64_array_opt<const O: usize>(v: [u64; O]) -> Option<Self> {
ArrayRepr::<O>(v).to_u64_array_opt::<N>().map(ArrayRepr)
}
fn to_u64_slice(&self, out: &mut [u64]) {
let copy_len = if N < out.len() { N } else { out.len() };
out[..copy_len].copy_from_slice(&self.0[..copy_len]);
for i in copy_len..out.len() {
out[i] = 0;
}
}
fn to_u64_slice_opt(&self, out: &mut [u64]) -> Option<()> {
if N > out.len() {
for i in out.len()..N {
if self.0[i] != 0 {
return None;
}
}
}
self.to_u64_slice(out);
Some(())
}
fn from_u64_slice(v: &[u64]) -> Self {
let mut new = ArrayRepr([0; N]);
let copy_len = if N < v.len() { N } else { v.len() };
new.0[..copy_len].copy_from_slice(&v[..copy_len]);
new
}
fn from_u64_slice_opt(v: &[u64]) -> Option<Self> {
if v.len() > N {
for i in N..v.len() {
if v[i] != 0 {
return None;
}
}
}
Some(Self::from_u64_slice(v))
}
}
#[derive(Clone, Debug)]
pub struct ArrayIter<const N: usize> {
data: [PrimitiveIter<u64>; N],
done: bool,
idx_f: usize,
idx_r: usize,
}
impl<const N: usize> ArrayIter<N> {
pub fn new(array: ArrayRepr<N>) -> Self {
let mut new = [PrimitiveIter(0); N];
for i in 0..N {
new[i] = PrimitiveIter(array.0[i])
}
ArrayIter { data: new, done: false, idx_f: 0, idx_r: N - 1 }
}
}
impl<const N: usize> Iterator for ArrayIter<N> {
type Item = u32;
fn next(&mut self) -> Option<Self::Item> {
if self.done {
return None;
}
loop {
if let Some(x) = unsafe { self.data.get_unchecked_mut(self.idx_f).next() } {
return Some(self.idx_f as u32 * 64 + x);
} else {
if self.idx_f == N - 1 || self.idx_f > self.idx_r {
break;
}
self.idx_f += 1;
}
}
self.done = true;
None
}
fn size_hint(&self) -> (usize, Option<usize>) {
let mut sum = 0;
for i in self.idx_f..self.idx_r + 1 {
sum += self.data[i].0.count_ones() as usize;
}
(sum, Some(sum))
}
}
impl<const N: usize> DoubleEndedIterator for ArrayIter<N> {
fn next_back(&mut self) -> Option<Self::Item> {
if self.done {
return None;
}
loop {
if let Some(x) = unsafe { self.data.get_unchecked_mut(self.idx_r).next_back() } {
return Some(self.idx_r as u32 * 64 + x);
} else {
if self.idx_r == 0 || self.idx_f > self.idx_r {
break;
}
self.idx_r -= 1;
}
}
self.done = true;
None
}
}
+90
View File
@@ -0,0 +1,90 @@
#![allow(missing_docs)]
mod array;
mod primitive;
use core::fmt::Debug;
use core::hash::Hash;
use core::ops::*;
/// A trait marking valid underlying bitset storage types and providing the
/// operations `EnumSet` and related types use.
///
/// # Safety
///
/// Note that `iter` *MUST* be implemented correctly and only return bits that
/// are actually set in the representation, or else it will cause undefined
/// behavior upstream in `EnumSet`.
pub trait EnumSetTypeRepr :
// Basic traits used to derive traits
Copy +
Ord +
Eq +
Debug +
Hash +
// Operations used by enumset
BitAnd<Output = Self> +
BitOr<Output = Self> +
BitXor<Output = Self> +
Not<Output = Self> +
{
const PREFERRED_ARRAY_LEN: usize;
const WIDTH: u32;
const EMPTY: Self;
fn is_empty(&self) -> bool;
fn add_bit(&mut self, bit: u32);
fn remove_bit(&mut self, bit: u32);
fn has_bit(&self, bit: u32) -> bool;
fn count_ones(&self) -> u32;
fn and_not(&self, other: Self) -> Self;
type Iter: Iterator<Item = u32> + DoubleEndedIterator + Clone + Debug;
fn iter(self) -> Self::Iter;
fn from_u8(v: u8) -> Self;
fn from_u16(v: u16) -> Self;
fn from_u32(v: u32) -> Self;
fn from_u64(v: u64) -> Self;
fn from_u128(v: u128) -> Self;
fn from_usize(v: usize) -> Self;
fn to_u8(&self) -> u8;
fn to_u16(&self) -> u16;
fn to_u32(&self) -> u32;
fn to_u64(&self) -> u64;
fn to_u128(&self) -> u128;
fn to_usize(&self) -> usize;
fn from_u8_opt(v: u8) -> Option<Self>;
fn from_u16_opt(v: u16) -> Option<Self>;
fn from_u32_opt(v: u32) -> Option<Self>;
fn from_u64_opt(v: u64) -> Option<Self>;
fn from_u128_opt(v: u128) -> Option<Self>;
fn from_usize_opt(v: usize) -> Option<Self>;
fn to_u8_opt(&self) -> Option<u8>;
fn to_u16_opt(&self) -> Option<u16>;
fn to_u32_opt(&self) -> Option<u32>;
fn to_u64_opt(&self) -> Option<u64>;
fn to_u128_opt(&self) -> Option<u128>;
fn to_usize_opt(&self) -> Option<usize>;
fn to_u64_array<const O: usize>(&self) -> [u64; O];
fn to_u64_array_opt<const O: usize>(&self) -> Option<[u64; O]>;
fn from_u64_array<const O: usize>(v: [u64; O]) -> Self;
fn from_u64_array_opt<const O: usize>(v: [u64; O]) -> Option<Self>;
fn to_u64_slice(&self, out: &mut [u64]);
#[must_use]
fn to_u64_slice_opt(&self, out: &mut [u64]) -> Option<()>;
fn from_u64_slice(v: &[u64]) -> Self;
fn from_u64_slice_opt(v: &[u64]) -> Option<Self>;
}
pub use array::ArrayRepr;
+309
View File
@@ -0,0 +1,309 @@
use crate::repr::EnumSetTypeRepr;
pub trait Primitive {
fn leading_zeros(&self) -> u32;
fn trailing_zeros(&self) -> u32;
}
macro_rules! prim {
($name:ty, $width:expr, $preferred_array_len:expr) => {
const _: () = {
fn lo(v: $name) -> u64 {
v as u64
}
fn hi(v: $name) -> u64 {
((v as u128) >> 64) as u64
}
impl EnumSetTypeRepr for $name {
const PREFERRED_ARRAY_LEN: usize = $preferred_array_len;
const WIDTH: u32 = $width;
const EMPTY: Self = 0;
#[inline(always)]
fn is_empty(&self) -> bool {
*self == 0
}
#[inline(always)]
fn add_bit(&mut self, bit: u32) {
*self |= 1 << bit as $name;
}
#[inline(always)]
fn remove_bit(&mut self, bit: u32) {
*self &= !(1 << bit as $name);
}
#[inline(always)]
fn has_bit(&self, bit: u32) -> bool {
(self & (1 << bit as $name)) != 0
}
#[inline(always)]
fn count_ones(&self) -> u32 {
(*self).count_ones()
}
#[inline(always)]
fn and_not(&self, other: Self) -> Self {
(*self) & !other
}
type Iter = PrimitiveIter<Self>;
#[inline]
fn iter(self) -> Self::Iter {
PrimitiveIter(self)
}
#[inline(always)]
fn from_u8(v: u8) -> Self {
v as $name
}
#[inline(always)]
fn from_u16(v: u16) -> Self {
v as $name
}
#[inline(always)]
fn from_u32(v: u32) -> Self {
v as $name
}
#[inline(always)]
fn from_u64(v: u64) -> Self {
v as $name
}
#[inline(always)]
fn from_u128(v: u128) -> Self {
v as $name
}
#[inline(always)]
fn from_usize(v: usize) -> Self {
v as $name
}
#[inline(always)]
fn to_u8(&self) -> u8 {
(*self) as u8
}
#[inline(always)]
fn to_u16(&self) -> u16 {
(*self) as u16
}
#[inline(always)]
fn to_u32(&self) -> u32 {
(*self) as u32
}
#[inline(always)]
fn to_u64(&self) -> u64 {
(*self) as u64
}
#[inline(always)]
fn to_u128(&self) -> u128 {
(*self) as u128
}
#[inline(always)]
fn to_usize(&self) -> usize {
(*self) as usize
}
#[inline(always)]
fn from_u8_opt(v: u8) -> Option<Self> {
v.try_into().ok()
}
#[inline(always)]
fn from_u16_opt(v: u16) -> Option<Self> {
v.try_into().ok()
}
#[inline(always)]
fn from_u32_opt(v: u32) -> Option<Self> {
v.try_into().ok()
}
#[inline(always)]
fn from_u64_opt(v: u64) -> Option<Self> {
v.try_into().ok()
}
#[inline(always)]
fn from_u128_opt(v: u128) -> Option<Self> {
v.try_into().ok()
}
#[inline(always)]
fn from_usize_opt(v: usize) -> Option<Self> {
v.try_into().ok()
}
#[inline(always)]
fn to_u8_opt(&self) -> Option<u8> {
(*self).try_into().ok()
}
#[inline(always)]
fn to_u16_opt(&self) -> Option<u16> {
(*self).try_into().ok()
}
#[inline(always)]
fn to_u32_opt(&self) -> Option<u32> {
(*self).try_into().ok()
}
#[inline(always)]
fn to_u64_opt(&self) -> Option<u64> {
(*self).try_into().ok()
}
#[inline(always)]
fn to_u128_opt(&self) -> Option<u128> {
(*self).try_into().ok()
}
#[inline(always)]
fn to_usize_opt(&self) -> Option<usize> {
(*self).try_into().ok()
}
#[inline(always)]
fn to_u64_array<const O: usize>(&self) -> [u64; O] {
let mut array = [0; O];
if O > 0 {
array[0] = lo(*self);
}
if O > 1 && $preferred_array_len == 2 {
array[1] = hi(*self);
}
array
}
#[inline(always)]
fn to_u64_array_opt<const O: usize>(&self) -> Option<[u64; O]> {
if O == 0 && *self != 0 {
None
} else if O == 1 && hi(*self) != 0 {
None
} else {
Some(self.to_u64_array())
}
}
#[inline(always)]
fn from_u64_array<const O: usize>(v: [u64; O]) -> Self {
if O == 0 {
0
} else if O > 1 && $preferred_array_len == 2 {
Self::from_u128(v[0] as u128 | ((v[1] as u128) << 64))
} else {
Self::from_u64(v[0])
}
}
#[inline(always)]
fn from_u64_array_opt<const O: usize>(v: [u64; O]) -> Option<Self> {
if O == 0 {
Some(0)
} else if O == 1 {
Self::from_u64_opt(v[0])
} else {
for i in 2..O {
if v[i] != 0 {
return None;
}
}
Self::from_u128_opt(v[0] as u128 | ((v[1] as u128) << 64))
}
}
#[inline(always)]
fn to_u64_slice(&self, out: &mut [u64]) {
if out.len() > 0 {
out[0] = lo(*self);
}
if out.len() > 1 && $preferred_array_len == 2 {
out[1] = hi(*self);
}
for i in $preferred_array_len..out.len() {
out[i] = 0;
}
}
#[inline(always)]
fn to_u64_slice_opt(&self, out: &mut [u64]) -> Option<()> {
if out.len() == 0 && *self != 0 {
None
} else if out.len() == 1 && hi(*self) != 0 {
None
} else {
self.to_u64_slice(out);
Some(())
}
}
#[inline(always)]
fn from_u64_slice(v: &[u64]) -> Self {
if v.len() == 0 {
0
} else if v.len() > 1 && $preferred_array_len == 2 {
Self::from_u128(v[0] as u128 | ((v[1] as u128) << 64))
} else {
Self::from_u64(v[0])
}
}
#[inline(always)]
fn from_u64_slice_opt(v: &[u64]) -> Option<Self> {
if v.len() == 0 {
Some(0)
} else if v.len() == 1 {
Self::from_u64_opt(v[0])
} else {
for i in 2..v.len() {
if v[i] != 0 {
return None;
}
}
Self::from_u128_opt(v[0] as u128 | ((v[1] as u128) << 64))
}
}
}
impl Primitive for $name {
#[inline(always)]
fn leading_zeros(&self) -> u32 {
(*self).leading_zeros()
}
#[inline(always)]
fn trailing_zeros(&self) -> u32 {
(*self).trailing_zeros()
}
}
};
};
}
prim!(u8, 8, 1);
prim!(u16, 16, 1);
prim!(u32, 32, 1);
prim!(u64, 64, 1);
prim!(u128, 128, 2);
#[derive(Copy, Clone, Debug)]
#[repr(transparent)]
pub struct PrimitiveIter<T: EnumSetTypeRepr + Primitive>(pub T);
impl<T: EnumSetTypeRepr + Primitive> Iterator for PrimitiveIter<T> {
type Item = u32;
fn next(&mut self) -> Option<Self::Item> {
if self.0.is_empty() {
None
} else {
let bit = self.0.trailing_zeros();
self.0.remove_bit(bit);
Some(bit)
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
let left = self.0.count_ones() as usize;
(left, Some(left))
}
}
impl<T: EnumSetTypeRepr + Primitive> DoubleEndedIterator for PrimitiveIter<T> {
fn next_back(&mut self) -> Option<Self::Item> {
if self.0.is_empty() {
None
} else {
let bit = T::WIDTH - 1 - self.0.leading_zeros();
self.0.remove_bit(bit);
Some(bit)
}
}
}
impl<T: EnumSetTypeRepr + Primitive> ExactSizeIterator for PrimitiveIter<T> {}