A personal rust firmware for the Badger 2040 W

Update for makers day

+65 -109
Cargo.lock
··· 1 1 # This file is automatically @generated by Cargo. 2 2 # It is not intended for manual editing. 3 - version = 3 3 + version = 4 4 4 5 5 [[package]] 6 6 name = "aead" ··· 182 182 183 183 [[package]] 184 184 name = "bt-hci" 185 - version = "0.1.0" 185 + version = "0.1.2" 186 186 source = "registry+https://github.com/rust-lang/crates.io-index" 187 - checksum = "499d74e90e6b1e61660adc8fb5f17aeac9487bced16f57c1f91a8783736ada53" 187 + checksum = "d69e2db053409c36c45a403da58072b8bf75bdc962746c0a12df9dec0fce92d2" 188 188 dependencies = [ 189 189 "defmt", 190 190 "embassy-sync 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 191 - "embassy-time", 192 191 "embedded-io", 193 192 "embedded-io-async", 194 193 "futures-intrusive", ··· 319 318 320 319 [[package]] 321 320 name = "critical-section" 322 - version = "1.1.2" 321 + version = "1.2.0" 323 322 source = "registry+https://github.com/rust-lang/crates.io-index" 324 - checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" 323 + checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" 325 324 326 325 [[package]] 327 326 name = "crunchy" ··· 620 619 [[package]] 621 620 name = "embassy-futures" 622 621 version = "0.1.1" 623 - source = "registry+https://github.com/rust-lang/crates.io-index" 624 - checksum = "1f878075b9794c1e4ac788c95b728f26aa6366d32eeb10c7051389f898f7d067" 625 - 626 - [[package]] 627 - name = "embassy-futures" 628 - version = "0.1.1" 629 622 source = "git+https://github.com/embassy-rs/embassy.git?rev=f0a86070512ad739641cee7d9fa39d63f5c8a9f6#f0a86070512ad739641cee7d9fa39d63f5c8a9f6" 630 623 631 624 [[package]] ··· 867 860 ] 868 861 869 862 [[package]] 870 - name = "embassy_rp_w_template" 871 - version = "0.1.0" 872 - dependencies = [ 873 - "assign-resources", 874 - "bt-hci", 875 - "byte-slice-cast 1.2.2", 876 - "cortex-m", 877 - "cortex-m-rt", 878 - "critical-section", 879 - "cyw43", 880 - "cyw43-pio", 881 - "defmt", 882 - "defmt-rtt", 883 - "display-interface", 884 - "display-interface-spi", 885 - "embassy-embedded-hal", 886 - "embassy-executor", 887 - "embassy-futures 0.1.1 (git+https://github.com/embassy-rs/embassy.git)", 888 - "embassy-net", 889 - "embassy-net-wiznet", 890 - "embassy-rp", 891 - "embassy-sync 0.6.0 (git+https://github.com/embassy-rs/embassy.git?rev=f0a86070512ad739641cee7d9fa39d63f5c8a9f6)", 892 - "embassy-time", 893 - "embassy-usb 0.3.0", 894 - "embassy-usb-logger", 895 - "embedded-graphics", 896 - "embedded-hal 1.0.0", 897 - "embedded-hal-async", 898 - "embedded-hal-bus", 899 - "embedded-io-async", 900 - "embedded-sdmmc", 901 - "embedded-storage", 902 - "embedded-text", 903 - "fixed", 904 - "fixed-macro", 905 - "heapless 0.8.0", 906 - "log", 907 - "panic-probe", 908 - "pio", 909 - "pio-proc", 910 - "portable-atomic", 911 - "postcard", 912 - "rand", 913 - "reqwless", 914 - "serde", 915 - "serde-json-core", 916 - "shtcx", 917 - "smart-leds", 918 - "st7789", 919 - "static_cell", 920 - "tinybmp", 921 - "trouble-host", 922 - "uc8151", 923 - "usbd-hid", 924 - ] 925 - 926 - [[package]] 927 863 name = "embedded-graphics" 928 864 version = "0.8.1" 929 865 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 931 867 dependencies = [ 932 868 "az", 933 869 "byteorder", 934 - "embedded-graphics-core 0.4.0", 870 + "embedded-graphics-core", 935 871 "float-cmp", 936 872 "micromath", 937 - ] 938 - 939 - [[package]] 940 - name = "embedded-graphics-core" 941 - version = "0.3.3" 942 - source = "registry+https://github.com/rust-lang/crates.io-index" 943 - checksum = "b8b1239db5f3eeb7e33e35bd10bd014e7b2537b17e071f726a09351431337cfa" 944 - dependencies = [ 945 - "az", 946 - "byteorder", 947 873 ] 948 874 949 875 [[package]] ··· 2058 1984 checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" 2059 1985 2060 1986 [[package]] 1987 + name = "rusty_badger" 1988 + version = "0.1.0" 1989 + dependencies = [ 1990 + "assign-resources", 1991 + "byte-slice-cast 1.2.2", 1992 + "cortex-m", 1993 + "cortex-m-rt", 1994 + "critical-section", 1995 + "cyw43", 1996 + "cyw43-pio", 1997 + "defmt", 1998 + "defmt-rtt", 1999 + "display-interface-spi", 2000 + "embassy-embedded-hal", 2001 + "embassy-executor", 2002 + "embassy-futures 0.1.1 (git+https://github.com/embassy-rs/embassy.git)", 2003 + "embassy-net", 2004 + "embassy-net-wiznet", 2005 + "embassy-rp", 2006 + "embassy-sync 0.6.0 (git+https://github.com/embassy-rs/embassy.git?rev=f0a86070512ad739641cee7d9fa39d63f5c8a9f6)", 2007 + "embassy-time", 2008 + "embassy-usb 0.3.0", 2009 + "embassy-usb-logger", 2010 + "embedded-graphics", 2011 + "embedded-hal 1.0.0", 2012 + "embedded-hal-async", 2013 + "embedded-hal-bus", 2014 + "embedded-io-async", 2015 + "embedded-sdmmc", 2016 + "embedded-storage", 2017 + "embedded-text", 2018 + "fixed", 2019 + "fixed-macro", 2020 + "heapless 0.8.0", 2021 + "log", 2022 + "panic-probe", 2023 + "pio", 2024 + "pio-proc", 2025 + "portable-atomic", 2026 + "postcard", 2027 + "rand", 2028 + "reqwless", 2029 + "serde", 2030 + "serde-json-core", 2031 + "shtcx", 2032 + "smart-leds", 2033 + "static_cell", 2034 + "tinybmp", 2035 + "uc8151", 2036 + "usbd-hid", 2037 + ] 2038 + 2039 + [[package]] 2061 2040 name = "ryu" 2062 2041 version = "1.0.18" 2063 2042 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 2224 2203 ] 2225 2204 2226 2205 [[package]] 2227 - name = "st7789" 2228 - version = "0.6.1" 2229 - source = "registry+https://github.com/rust-lang/crates.io-index" 2230 - checksum = "cba7306a9ca07ffcafd13ac1eaac2d5cedc8e9fc0d342ef674e0f0d059c8f8a9" 2231 - dependencies = [ 2232 - "display-interface", 2233 - "embedded-graphics-core 0.3.3", 2234 - "embedded-hal 0.2.7", 2235 - "heapless 0.7.17", 2236 - "nb 1.1.0", 2237 - ] 2238 - 2239 - [[package]] 2240 2206 name = "stable_deref_trait" 2241 2207 version = "1.2.0" 2242 2208 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 2357 2323 ] 2358 2324 2359 2325 [[package]] 2360 - name = "trouble-host" 2361 - version = "0.1.0" 2362 - source = "git+https://github.com/embassy-rs/trouble.git?rev=4b8c0f499b34e46ca23a56e2d1640ede371722cf#4b8c0f499b34e46ca23a56e2d1640ede371722cf" 2363 - dependencies = [ 2364 - "bt-hci", 2365 - "defmt", 2366 - "embassy-futures 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 2367 - "embassy-sync 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 2368 - "embassy-time", 2369 - "embedded-io-async", 2370 - "futures", 2371 - "heapless 0.8.0", 2372 - ] 2373 - 2374 - [[package]] 2375 2326 name = "typenum" 2376 2327 version = "1.17.0" 2377 2328 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 2382 2333 version = "0.3.0" 2383 2334 source = "git+https://github.com/9names/uc8151-rs.git#37a7feee23716506b777bd4032327038e7e0786a" 2384 2335 dependencies = [ 2385 - "embedded-graphics-core 0.4.0", 2336 + "embedded-graphics-core", 2386 2337 "embedded-hal 1.0.0", 2387 2338 "embedded-hal-async", 2388 2339 ] ··· 2645 2596 version = "1.8.1" 2646 2597 source = "registry+https://github.com/rust-lang/crates.io-index" 2647 2598 checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" 2599 + 2600 + [[patch.unused]] 2601 + name = "trouble-host" 2602 + version = "0.1.0" 2603 + source = "git+https://github.com/embassy-rs/trouble.git?rev=4b8c0f499b34e46ca23a56e2d1640ede371722cf#4b8c0f499b34e46ca23a56e2d1640ede371722cf"
+1 -6
Cargo.toml
··· 1 1 [package] 2 - name = "embassy_rp_w_template" 2 + name = "rusty_badger" 3 3 version = "0.1.0" 4 4 edition = "2021" 5 5 ··· 55 55 ] } 56 56 cyw43-pio = { version = "0.2.0", git = "https://github.com/embassy-rs/embassy.git", rev = "f0a86070512ad739641cee7d9fa39d63f5c8a9f6", features = [ 57 57 "defmt", 58 - "overclock", 59 58 ] } 60 59 61 60 defmt = "0.3" ··· 78 77 panic-probe = { version = "0.3", features = ["print-defmt"] } 79 78 display-interface-spi = "0.4.1" 80 79 embedded-graphics = "0.8.0" 81 - st7789 = "0.6.1" 82 - display-interface = "0.4.1" 83 80 byte-slice-cast = { version = "1.2.0", default-features = false } 84 81 smart-leds = "0.3.0" 85 82 heapless = { version = "0.8", features = ["serde"] } ··· 97 94 pio = "0.2.1" 98 95 rand = { version = "0.8.5", default-features = false } 99 96 embedded-sdmmc = "0.7.0" 100 - bt-hci = { version = "0.1.0", default-features = false, features = ["defmt"] } 101 - trouble-host = { version = "0.1.0", features = ["defmt", "gatt"] } 102 97 uc8151 = { git = "https://github.com/9names/uc8151-rs.git", features = [ 103 98 "graphics", 104 99 ] }
images/mtras_logo.bmp

This is a binary file and will not be displayed.

+7 -1
src/badge_display/display_image.rs
··· 2 2 3 3 use super::CURRENT_IMAGE; 4 4 5 - static NUMBER_OF_IMAGES: u8 = 2; 5 + static NUMBER_OF_IMAGES: u8 = 3; 6 6 static FERRIS_IMG: &[u8; 15722] = include_bytes!("../../images/ferris_w_a_knife.bmp"); 7 7 static REPO_IMG: &[u8; 11262] = include_bytes!("../../images/repo.bmp"); 8 + static MTRAS_LOGO: &[u8; 10378] = include_bytes!("../../images/mtras_logo.bmp"); 8 9 9 10 pub enum DisplayImage { 10 11 Ferris = 0, 11 12 Repo = 1, 13 + MtrasLogo = 2, 12 14 } 13 15 14 16 pub fn get_current_image() -> DisplayImage { ··· 20 22 match value { 21 23 0 => Some(Self::Ferris), 22 24 1 => Some(Self::Repo), 25 + 2 => Some(Self::MtrasLogo), 23 26 _ => None, 24 27 } 25 28 } ··· 28 31 match self { 29 32 Self::Ferris => 0, 30 33 Self::Repo => 1, 34 + Self::MtrasLogo => 2, 31 35 } 32 36 } 33 37 ··· 35 39 match self { 36 40 Self::Ferris => FERRIS_IMG, 37 41 Self::Repo => REPO_IMG, 42 + Self::MtrasLogo => MTRAS_LOGO, 38 43 } 39 44 } 40 45 ··· 57 62 match self { 58 63 Self::Ferris => Point::new(150, 26), 59 64 Self::Repo => Point::new(190, 26), 65 + Self::MtrasLogo => Point::new(190, 26), 60 66 } 61 67 } 62 68 }
+13 -9
src/badge_display/mod.rs
··· 32 32 use uc8151::{asynch::Uc8151, HEIGHT}; 33 33 use {defmt_rtt as _, panic_probe as _}; 34 34 35 - use crate::{env::env_value, helpers::easy_format, Spi0Bus}; 35 + use crate::{ 36 + env::env_value, 37 + helpers::{easy_format, easy_format_str}, 38 + Spi0Bus, 39 + }; 36 40 37 41 pub type RecentWifiNetworksVec = Vec<String<32>, 4>; 38 42 ··· 91 95 .into_styled(PrimitiveStyle::with_fill(BinaryColor::On)) 92 96 .draw(&mut display) 93 97 .unwrap(); 94 - 95 - // Create the text box and apply styling options. 96 - let display_text = easy_format::<29>(format_args!( 97 - "{}\n{}", 98 - env_value("NAME"), 99 - env_value("DETAILS") 100 - )); 98 + info!("Name: {}", env_value("NAME")); 99 + info!("Details: {}", env_value("DETAILS")); 100 + let mut name_and_details_buffer = [0; 128]; 101 + let name_and_details = easy_format_str( 102 + format_args!("{}\n{}", env_value("NAME"), env_value("DETAILS")), 103 + &mut name_and_details_buffer, 104 + ); 101 105 102 106 let name_and_detail_box = TextBox::with_textbox_style( 103 - &display_text, 107 + &name_and_details.unwrap(), 104 108 name_and_detail_bounds, 105 109 character_style, 106 110 textbox_style,
+2 -3
src/cyw43_driver.rs
··· 32 32 ) -> (Device<'a>, Control<'a>) { 33 33 let fw = include_bytes!("../cyw43-firmware/43439A0.bin"); 34 34 let clm = include_bytes!("../cyw43-firmware/43439A0_clm.bin"); 35 - let btfw = include_bytes!("../cyw43-firmware/43439A0_btfw.bin"); 35 + // let btfw = include_bytes!("../cyw43-firmware/43439A0_btfw.bin"); 36 36 37 37 // To make flashing faster for development, you may want to flash the firmwares independently 38 38 // at hardcoded addresses, instead of baking them into the program with `include_bytes!`: ··· 51 51 52 52 static STATE: StaticCell<cyw43::State> = StaticCell::new(); 53 53 let state = STATE.init(cyw43::State::new()); 54 - let (net_device, _bt_device, mut control, runner) = 55 - cyw43::new_with_bluetooth(state, pwr, spi, fw, btfw).await; 54 + let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; 56 55 unwrap!(spawner.spawn(cyw43_task(runner))); 57 56 58 57 control.init(clm).await;
+48
src/helpers.rs
··· 12 12 } 13 13 } 14 14 } 15 + 16 + pub fn easy_format_str<'a>( 17 + args: Arguments<'_>, 18 + buffer: &'a mut [u8], 19 + ) -> Result<&'a str, core::fmt::Error> { 20 + let mut writer = BufWriter::new(buffer); 21 + let result = core::fmt::write(&mut writer, args); 22 + 23 + match result { 24 + Ok(_) => { 25 + let len = writer.len(); 26 + let response_str = core::str::from_utf8(&buffer[..len]).unwrap(); 27 + Ok(response_str) 28 + } 29 + Err(_) => { 30 + panic!("Error formatting the string") 31 + } 32 + } 33 + } 34 + 35 + // A simple wrapper struct to use core::fmt::Write on a [u8] buffer 36 + pub struct BufWriter<'a> { 37 + buf: &'a mut [u8], 38 + pos: usize, 39 + } 40 + 41 + impl<'a> BufWriter<'a> { 42 + pub fn new(buf: &'a mut [u8]) -> Self { 43 + BufWriter { buf, pos: 0 } 44 + } 45 + 46 + pub fn len(&self) -> usize { 47 + self.pos 48 + } 49 + } 50 + 51 + impl<'a> core::fmt::Write for BufWriter<'a> { 52 + fn write_str(&mut self, s: &str) -> core::fmt::Result { 53 + let bytes = s.as_bytes(); 54 + if self.pos + bytes.len() > self.buf.len() { 55 + return Err(core::fmt::Error); // Buffer overflow 56 + } 57 + 58 + self.buf[self.pos..self.pos + bytes.len()].copy_from_slice(bytes); 59 + self.pos += bytes.len(); 60 + Ok(()) 61 + } 62 + }
+5 -2
src/main.rs
··· 328 328 329 329 let mut recent_networks = RecentWifiNetworksVec::new(); 330 330 let mut scanner = control.scan(Default::default()).await; 331 + 331 332 while let Some(bss) = scanner.next().await { 332 333 process_bssid(bss.bssid, &mut save.wifi_counted, &mut save.bssid); 333 334 if recent_networks.len() < 8 { 334 335 let possible_ssid = core::str::from_utf8(&bss.ssid); 335 336 match possible_ssid { 336 337 Ok(ssid) => { 337 - info!("ssid: {}", ssid); 338 - let ssid_string = easy_format::<32>(format_args!("{}", ssid.trim())); 338 + let removed_zeros = ssid.trim_end_matches(char::from(0)); 339 + let ssid_string: String<32> = 340 + easy_format::<32>(format_args!("{}", removed_zeros)); 341 + 339 342 if recent_networks.contains(&ssid_string) { 340 343 continue; 341 344 }