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:
17624 files changed
+4564928
-38
No files matched your search
+99
@@ -0,0 +1,99 @@
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::{quote, ToTokens};
|
||||
use syn::{parse_macro_input, parse_quote};
|
||||
|
||||
use crate::{cargo, construct};
|
||||
|
||||
use self::input::Input;
|
||||
|
||||
mod input;
|
||||
|
||||
pub(crate) fn expand(input: TokenStream) -> TokenStream {
|
||||
let bitflags_input = TokenStream2::from(input.clone());
|
||||
let input = parse_macro_input!(input as Input);
|
||||
|
||||
// Encode package and disambiguator to provide the decoder with all info it needs (even if
|
||||
// technically redundant, since it's also stored in the symbol we create).
|
||||
let format_string = format!(
|
||||
"{{={}:__internal_bitflags_{}@{}@{}@{}}}",
|
||||
input.ty().to_token_stream(),
|
||||
input.ident(),
|
||||
cargo::package_name(),
|
||||
construct::crate_local_disambiguator(),
|
||||
cargo::crate_name(),
|
||||
);
|
||||
let format_tag = construct::interned_string(
|
||||
&format_string,
|
||||
"bitflags",
|
||||
false,
|
||||
None,
|
||||
&parse_quote!(defmt),
|
||||
);
|
||||
|
||||
let ident = input.ident();
|
||||
let ty = input.ty();
|
||||
let flag_statics = codegen_flag_statics(&input);
|
||||
quote!(
|
||||
const _: () = {
|
||||
fn assert<T: defmt::export::UnsignedInt>() {}
|
||||
assert::<#ty>;
|
||||
|
||||
#(#flag_statics)*
|
||||
};
|
||||
|
||||
defmt::export::bitflags! {
|
||||
#bitflags_input
|
||||
}
|
||||
|
||||
impl defmt::Format for #ident {
|
||||
fn format(&self, f: defmt::Formatter) {
|
||||
defmt::unreachable!()
|
||||
}
|
||||
|
||||
fn _format_tag() -> defmt::Str {
|
||||
#format_tag
|
||||
}
|
||||
|
||||
fn _format_data(&self) {
|
||||
// There's a method available for every supported bitflags type.
|
||||
defmt::export::#ty(&self.bits());
|
||||
}
|
||||
}
|
||||
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn codegen_flag_statics(input: &Input) -> Vec<TokenStream2> {
|
||||
input
|
||||
.flags()
|
||||
.enumerate()
|
||||
.map(|(i, flag)| {
|
||||
let cfg_attrs = flag.cfg_attrs();
|
||||
let var_name = flag.ident();
|
||||
let struct_name = input.ident();
|
||||
let repr_ty = input.ty();
|
||||
|
||||
let sym_name = construct::mangled_symbol_name(
|
||||
"bitflags_value",
|
||||
&format!("{}::{i}::{}", input.ident(), flag.ident()),
|
||||
);
|
||||
|
||||
quote! {
|
||||
#(#cfg_attrs)*
|
||||
#[cfg_attr(target_os = "macos", link_section = ".defmt,end")]
|
||||
#[cfg_attr(not(target_os = "macos"), link_section = ".defmt.end")]
|
||||
#[export_name = #sym_name]
|
||||
static #var_name: u128 = {
|
||||
// NB: It might be tempting to just do `#value as u128` here, but that
|
||||
// causes a value such as `1 << 127` to be evaluated as an `i32`, which
|
||||
// overflows. So we instead coerce (but don't cast) it to the bitflags' raw
|
||||
// type, and then cast that to u128.
|
||||
let coerced_value: #repr_ty = #struct_name::#var_name.bits;
|
||||
coerced_value as u128
|
||||
};
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
use syn::{
|
||||
parse::{Parse, ParseStream},
|
||||
punctuated::Punctuated,
|
||||
token, Attribute, Expr, Ident, Token, Type, Visibility,
|
||||
};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(super) struct Input {
|
||||
struct_attrs: Vec<Attribute>,
|
||||
vis: Visibility,
|
||||
struct_token: Token![struct],
|
||||
ident: Ident,
|
||||
colon_token: Token![:],
|
||||
ty: Type,
|
||||
brace_token: token::Brace,
|
||||
flags: Punctuated<Flag, Token![;]>,
|
||||
}
|
||||
|
||||
impl Parse for Input {
|
||||
fn parse(input: ParseStream) -> syn::Result<Self> {
|
||||
let flags;
|
||||
Ok(Self {
|
||||
struct_attrs: Attribute::parse_outer(input)?,
|
||||
vis: input.parse()?,
|
||||
struct_token: input.parse()?,
|
||||
ident: input.parse()?,
|
||||
colon_token: input.parse()?,
|
||||
ty: input.parse()?,
|
||||
brace_token: syn::braced!(flags in input),
|
||||
flags: Punctuated::parse_terminated(&flags)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Input {
|
||||
pub(super) fn flags(&self) -> impl Iterator<Item = &Flag> {
|
||||
self.flags.iter()
|
||||
}
|
||||
|
||||
pub(super) fn ident(&self) -> &Ident {
|
||||
&self.ident
|
||||
}
|
||||
|
||||
pub(super) fn ty(&self) -> &Type {
|
||||
&self.ty
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(super) struct Flag {
|
||||
cfg_attrs: Vec<Attribute>,
|
||||
const_attrs: Vec<Attribute>,
|
||||
const_token: Token![const],
|
||||
ident: Ident,
|
||||
eq_token: Token![=],
|
||||
value: Expr,
|
||||
}
|
||||
|
||||
impl Parse for Flag {
|
||||
fn parse(input: ParseStream) -> syn::Result<Self> {
|
||||
let const_attrs = Attribute::parse_outer(input)?;
|
||||
Ok(Self {
|
||||
cfg_attrs: extract_cfgs(&const_attrs),
|
||||
const_attrs,
|
||||
const_token: input.parse()?,
|
||||
ident: input.parse()?,
|
||||
eq_token: input.parse()?,
|
||||
value: input.parse()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Flag {
|
||||
pub(super) fn cfg_attrs(&self) -> &[Attribute] {
|
||||
&self.cfg_attrs
|
||||
}
|
||||
|
||||
pub(super) fn ident(&self) -> &Ident {
|
||||
&self.ident
|
||||
}
|
||||
}
|
||||
|
||||
fn extract_cfgs(attrs: &[Attribute]) -> Vec<Attribute> {
|
||||
let mut cfgs = vec![];
|
||||
|
||||
for attr in attrs {
|
||||
if attr.path().is_ident("cfg") {
|
||||
cfgs.push(attr.clone());
|
||||
}
|
||||
}
|
||||
|
||||
cfgs
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
use defmt_parser::ParserMode;
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro_error2::abort;
|
||||
use quote::format_ident;
|
||||
use quote::quote;
|
||||
use syn::parse_macro_input;
|
||||
|
||||
use crate::{construct, function_like::log};
|
||||
|
||||
pub(crate) fn expand(args: TokenStream) -> TokenStream {
|
||||
let args = parse_macro_input!(args as log::Args);
|
||||
|
||||
let format_string = args.format_string.value();
|
||||
|
||||
let fragments = match defmt_parser::parse(&format_string, ParserMode::Strict) {
|
||||
Ok(args) => args,
|
||||
Err(e) => abort!(args.format_string, "{}", e),
|
||||
};
|
||||
|
||||
let formatting_exprs: Vec<_> = args
|
||||
.formatting_args
|
||||
.map(|punctuated| punctuated.into_iter().collect())
|
||||
.unwrap_or_default();
|
||||
|
||||
let log::Codegen { patterns, exprs } = log::Codegen::new(
|
||||
&fragments,
|
||||
formatting_exprs.len(),
|
||||
args.format_string.span(),
|
||||
);
|
||||
|
||||
let var_name = format_ident!("S");
|
||||
let var_item = construct::static_variable(&var_name, &format_string, "timestamp", None);
|
||||
|
||||
quote!(
|
||||
const _: () = {
|
||||
#[export_name = "_defmt_timestamp"]
|
||||
#[inline(never)]
|
||||
fn defmt_timestamp(fmt: defmt::Formatter<'_>) {
|
||||
match (#(&(#formatting_exprs)),*) {
|
||||
(#(#patterns),*) => {
|
||||
// NOTE: No format string index, and no finalize call.
|
||||
#(#exprs;)*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#var_item;
|
||||
|
||||
// Unique symbol name to prevent multiple `timestamp!` invocations in the crate graph.
|
||||
// Uses `#var_name` to ensure it is not discarded by the linker.
|
||||
// This symbol itself is retained via a `EXTERN` directive in the linker script.
|
||||
#[no_mangle]
|
||||
#[cfg_attr(target_os = "macos", link_section = ".defmt,end.timestamp")]
|
||||
#[cfg_attr(not(target_os = "macos"), link_section = ".defmt.end.timestamp")]
|
||||
static __DEFMT_MARKER_TIMESTAMP_WAS_DEFINED: &u8 = &#var_name;
|
||||
};
|
||||
)
|
||||
.into()
|
||||
}
|
||||
Reference in new issue
Block a user