A RPi Pico powered Lightning Detector

feat: Optional defmt dep, reset panic handler

+53 -27
+33 -26
Cargo.toml
··· 7 7 version = "0.1.0" 8 8 edition = "2024" 9 9 10 + [features] 11 + default = ["defmt"] 12 + defmt = [ 13 + "dep:defmt", 14 + "dep:defmt-rtt", 15 + "dep:panic-probe", 16 + "postcard/defmt", 17 + "postcard/use-defmt", 18 + "sachy-sntp/defmt", 19 + "sachy-mdns/defmt", 20 + "sachy-fmt/defmt", 21 + "embassy-embedded-hal/defmt", 22 + "embassy-sync/defmt", 23 + "embassy-executor/defmt", 24 + "embassy-time/defmt", 25 + "embassy-time/defmt-timestamp-uptime", 26 + "embassy-rp/defmt", 27 + "embassy-net/defmt", 28 + "cyw43/defmt", 29 + "cyw43-pio/defmt", 30 + ] 31 + 10 32 [dependencies] 11 33 cortex-m = { version = "0.7.6", features = ["inline-asm"] } 12 34 cortex-m-rt = "0.7.0" 13 - defmt = "1.0" 14 - defmt-rtt = "1.0" 15 - panic-probe = { version = "1.0", features = ["print-defmt"] } 35 + defmt = { version = "1.0", optional = true } 36 + defmt-rtt = { version = "1.0", optional = true } 37 + panic-probe = { version = "1.0", features = ["print-defmt"], optional = true } 16 38 critical-section = "1.2.0" 17 39 static_cell = "2.1" 18 40 heapless = { version = "0.8" } 19 41 chrono = { version = "0.4", default-features = false } 20 42 portable-atomic = { version = "1.5", features = ["critical-section"] } 21 43 serde = { version = "1.0.210", default-features = false, features = ["alloc"] } 22 - postcard = { version = "1.1.3", features = [ 23 - "alloc", 24 - "defmt", 25 - "use-defmt", 26 - ], default-features = false } 44 + postcard = { version = "1.1.3", features = ["alloc"], default-features = false } 27 45 rlsf = { version = "0.2.1", default-features = false } 28 46 sachy-sntp = { git = "https://tangled.org/sachy.dev/sachy-embed-core", package = "sachy-sntp", default-features = false, features = [ 29 - "defmt", 30 47 "embassy-net", 31 48 "chrono", 32 49 ] } 33 - sachy-mdns = { git = "https://tangled.org/sachy.dev/sachy-embed-core", package = "sachy-mdns", features = [ 34 - "defmt", 35 - ] } 36 - sachy-fmt = { git = "https://tangled.org/sachy.dev/sachy-embed-core", package = "sachy-fmt", features = [ 37 - "defmt", 38 - ] } 50 + sachy-mdns = { git = "https://tangled.org/sachy.dev/sachy-embed-core", package = "sachy-mdns" } 51 + sachy-fmt = { git = "https://tangled.org/sachy.dev/sachy-embed-core", package = "sachy-fmt" } 39 52 40 - embassy-embedded-hal = { version = "0.5.0", features = ["defmt"] } 41 - embassy-sync = { version = "0.7.2", features = ["defmt"] } 53 + embassy-embedded-hal = { version = "0.5.0" } 54 + embassy-sync = { version = "0.7.2" } 42 55 embassy-executor = { version = "0.9.0", features = [ 43 56 "arch-cortex-m", 44 57 "executor-thread", 45 58 "executor-interrupt", 46 - "defmt", 47 - ] } 48 - embassy-time = { version = "0.5.0", features = [ 49 - "defmt", 50 - "defmt-timestamp-uptime", 51 59 ] } 60 + embassy-time = { version = "0.5.0" } 52 61 embassy-rp = { version = "0.9.0", features = [ 53 - "defmt", 54 62 "unstable-pac", 55 63 "time-driver", 56 64 "critical-section-impl", ··· 61 69 ] } 62 70 embassy-futures = { version = "0.1.2" } 63 71 embassy-net = { version = "0.7.1", features = [ 64 - "defmt", 65 72 "icmp", 66 73 "udp", 67 74 "tcp", ··· 75 82 "medium-ip", 76 83 "medium-ethernet", 77 84 ] } 78 - cyw43 = { version = "0.6.0", features = ["defmt", "firmware-logs"] } 79 - cyw43-pio = { version = "0.9.0", features = ["defmt"] } 85 + cyw43 = { version = "0.6.0", features = ["firmware-logs"] } 86 + cyw43-pio = { version = "0.9.0" } 80 87 81 88 [build-dependencies] 82 89 sachy-config = { git = "https://tangled.org/sachy.dev/sachy-embed-core", package = "sachy-config" }
+2 -1
src/allocator.rs
··· 20 20 block: ConstStaticCell<[u8; MEMORY_SIZE]>, 21 21 } 22 22 23 - #[derive(Debug, defmt::Format)] 23 + #[derive(Debug)] 24 + #[cfg_attr(feature = "defmt", derive(defmt::Format))] 24 25 pub enum HeapError { 25 26 MemoryBlockTooSmall, 26 27 BlockAlreadyTaken,
+3
src/main.rs
··· 15 15 mod updates; 16 16 mod utils; 17 17 mod wifi; 18 + #[cfg(not(feature = "defmt"))] 19 + mod panic_handler; 18 20 19 21 use crate::{allocator::PicoHeap, rtc::GlobalRtc}; 20 22 use cyw43_pio::{DEFAULT_CLOCK_DIVIDER, PioSpi}; ··· 33 35 34 36 extern crate alloc; 35 37 38 + #[cfg(feature = "defmt")] 36 39 use {defmt_rtt as _, panic_probe as _}; 37 40 38 41 mod constants {
+15
src/panic_handler.rs
··· 1 + use core::{ 2 + panic::PanicInfo, 3 + sync::atomic::{Ordering, compiler_fence}, 4 + }; 5 + 6 + #[cfg(not(feature = "defmt"))] 7 + #[inline(never)] 8 + #[panic_handler] 9 + fn panic_reset(_info: &PanicInfo) -> ! { 10 + cortex_m::interrupt::disable(); 11 + 12 + // Halt execution and reset the chip. 13 + compiler_fence(Ordering::SeqCst); 14 + cortex_m::peripheral::SCB::sys_reset(); 15 + }