A personal rust firmware for the Badger 2040 W

Clean up

+11 -46
-10
Cargo.lock
··· 2631 2631 version = "1.8.1" 2632 2632 source = "registry+https://github.com/rust-lang/crates.io-index" 2633 2633 checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" 2634 - 2635 - [[patch.unused]] 2636 - name = "embassy-time" 2637 - version = "0.3.2" 2638 - source = "git+https://github.com/embassy-rs/embassy.git?rev=f0a86070512ad739641cee7d9fa39d63f5c8a9f6#f0a86070512ad739641cee7d9fa39d63f5c8a9f6" 2639 - 2640 - [[patch.unused]] 2641 - name = "trouble-host" 2642 - version = "0.1.0" 2643 - source = "git+https://github.com/embassy-rs/trouble.git?rev=4b8c0f499b34e46ca23a56e2d1640ede371722cf#4b8c0f499b34e46ca23a56e2d1640ede371722cf"
+1 -3
Cargo.toml
··· 108 108 lto = true 109 109 opt-level = "z" 110 110 111 - [patch.crates-io] 112 - trouble-host = { git = "https://github.com/embassy-rs/trouble.git", rev = "4b8c0f499b34e46ca23a56e2d1640ede371722cf" } 113 - embassy-time = { git = "https://github.com/embassy-rs/embassy.git", rev = "f0a86070512ad739641cee7d9fa39d63f5c8a9f6" } 111 +
+1 -1
rust-toolchain-nightly.toml
··· 1 1 [toolchain] 2 - channel = "nightly-202-11-04" 2 + channel = "nightly" 3 3 components = ["rust-src", "rustfmt", "llvm-tools", "miri"] 4 4 targets = ["thumbv6m-none-eabi"]
+5 -19
src/main.rs
··· 14 14 use core::fmt::Write; 15 15 use core::str::from_utf8; 16 16 use cyw43::JoinOptions; 17 - // use cyw43_driver::setup_cyw43; 18 17 use cyw43_pio::{DEFAULT_CLOCK_DIVIDER, PioSpi}; 19 18 use defmt::info; 20 19 use defmt::*; 21 - use embassy_embedded_hal::shared_bus::blocking::i2c::I2cDevice; 22 20 use embassy_executor::Spawner; 21 + use embassy_net::StackResources; 23 22 use embassy_net::dns::DnsSocket; 24 23 use embassy_net::tcp::client::{TcpClient, TcpClientState}; 25 - use embassy_net::{Stack, StackResources}; 26 24 use embassy_rp::clocks::RoscRng; 27 25 use embassy_rp::flash::Async; 28 26 use embassy_rp::gpio::Input; ··· 41 39 use gpio::{Level, Output, Pull}; 42 40 use heapless::{String, Vec}; 43 41 use helpers::easy_format; 44 - use rand::RngCore; 45 42 use reqwless::client::{HttpClient, TlsConfig, TlsVerify}; 46 43 use reqwless::request::Method; 47 44 use save::{Save, read_postcard_from_flash, save_postcard_to_flash}; ··· 95 92 static STATE: StaticCell<cyw43::State> = StaticCell::new(); 96 93 let state = STATE.init(cyw43::State::new()); 97 94 let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; 98 - spawner.spawn(cyw43_task(runner)); 95 + spawner.must_spawn(cyw43_task(runner)); 99 96 100 97 control.init(clm).await; 101 98 control 102 99 .set_power_management(cyw43::PowerManagementMode::PowerSave) 103 100 .await; 104 - // let (net_device, mut control) = setup_cyw43( 105 - // p.PIO0, p.PIN_23, p.PIN_24, p.PIN_25, p.PIN_29, p.DMA_CH0, spawner, 106 - // ) 107 - // .await; 108 101 109 102 let miso = p.PIN_16; 110 103 let mosi = p.PIN_19; ··· 153 146 let seed = rng.next_u64(); 154 147 155 148 // Init network stack 156 - static STACK: StaticCell<Stack> = StaticCell::new(); 157 149 static RESOURCES: StaticCell<StackResources<5>> = StaticCell::new(); 158 150 let (stack, runner) = embassy_net::new( 159 151 net_device, ··· 161 153 RESOURCES.init(StackResources::new()), 162 154 seed, 163 155 ); 164 - // let stack = &*STACK.init(Stack::new( 165 - // net_device, 166 - // config, 167 - // RESOURCES.init(StackResources::<5>::new()), 168 - // seed, 169 - // )); 156 + 170 157 //rtc setup 171 158 let mut rtc = embassy_rp::rtc::Rtc::new(p.RTC); 172 159 173 - spawner.spawn(net_task(runner)); 160 + spawner.must_spawn(net_task(runner)); 174 161 //Attempt to connect to wifi to get RTC time loop for 2 minutes 175 162 let mut wifi_connection_attempts = 0; 176 163 let mut connected_to_wifi = false; ··· 311 298 312 299 //Setup i2c bus 313 300 let config = embassy_rp::i2c::Config::default(); 314 - let mut i2c = i2c::I2c::new_blocking(p.I2C0, p.PIN_5, p.PIN_4, config); 301 + let i2c = i2c::I2c::new_blocking(p.I2C0, p.PIN_5, p.PIN_4, config); 315 302 static I2C_BUS: StaticCell<I2c0Bus> = StaticCell::new(); 316 - // static I2C_BUS: StaticCell<I2c0Bus> = StaticCell::new(); 317 303 let i2c_bus = NoopMutex::new(RefCell::new(i2c)); 318 304 let i2c_bus = I2C_BUS.init(i2c_bus); 319 305
+4 -13
src/temp_sensor.rs
··· 1 + use crate::I2c0Bus; 2 + use crate::badge_display::{HUMIDITY, TEMP}; 1 3 use defmt::*; 2 - use embassy_rp::i2c::{I2c, SclPin, SdaPin}; 3 - use embassy_rp::peripherals::I2C0; 4 + use embassy_embedded_hal::shared_bus::blocking::i2c::I2cDevice; 4 5 use embassy_time::Timer; 5 6 use shtcx::{self, PowerMode}; 6 7 7 - use crate::I2c0Bus; 8 - use crate::badge_display::{HUMIDITY, TEMP}; 9 - use embassy_embedded_hal::shared_bus::blocking::i2c::I2cDevice; 10 - // Import the necessary items from shtcx 11 - 12 8 #[embassy_executor::task] 13 - pub async fn run_the_temp_sensor( 14 - i2c_bus: &'static I2c0Bus, // i2c0: I2C0, 15 - // scl: impl Peripheral<P = impl SclPin<I2C0>> + 'static, 16 - // sda: impl Peripheral<P = impl SdaPin<I2C0>> + 'static, 17 - ) { 9 + pub async fn run_the_temp_sensor(i2c_bus: &'static I2c0Bus) { 18 10 let i2c_dev = I2cDevice::new(i2c_bus); 19 - // let i2c = I2c::new_blocking(i2c0, scl, sda, i2c::Config::default()); 20 11 21 12 let mut sht = shtcx::shtc3(i2c_dev); 22 13 let mut sht_delay = embassy_time::Delay; // Create a delay instance