A personal rust firmware for the Badger 2040 W
at 22b7cd8b830d4bc613fe7f3f8a4ff2bb86c8f563 105 lines 3.3 kB view raw
1//! This example test the RP Pico W on board LED. 2//! 3//! It does not work with the RP Pico board. 4 5#![no_std] 6#![no_main] 7use badge_display::display_image::DisplayImage; 8use badge_display::{run_the_display, CHANGE_IMAGE, CURRENT_IMAGE}; 9use defmt::info; 10use embassy_executor::Spawner; 11use embassy_rp::gpio; 12use embassy_rp::gpio::Input; 13use embassy_rp::peripherals::SPI0; 14use embassy_rp::spi::Spi; 15use embassy_rp::spi::{self}; 16use embassy_sync::blocking_mutex::raw::NoopRawMutex; 17use embassy_sync::mutex::Mutex; 18use embassy_time::{Delay, Duration, Timer}; 19use embedded_graphics::{ 20 image::Image, 21 mono_font::{ascii::*, MonoTextStyle}, 22 pixelcolor::BinaryColor, 23 prelude::*, 24 primitives::{PrimitiveStyle, Rectangle}, 25}; 26use embedded_text::{ 27 alignment::HorizontalAlignment, 28 style::{HeightMode, TextBoxStyleBuilder}, 29 TextBox, 30}; 31use gpio::{Level, Output, Pull}; 32use static_cell::StaticCell; 33use {defmt_rtt as _, panic_probe as _}; 34 35mod badge_display; 36mod cyw43_driver; 37 38type Spi0Bus = Mutex<NoopRawMutex, Spi<'static, SPI0, spi::Async>>; 39 40#[embassy_executor::main] 41async fn main(spawner: Spawner) { 42 let p = embassy_rp::init(Default::default()); 43 // let (_net_device, mut control) = setup_cyw43( 44 // p.PIO0, p.PIN_23, p.PIN_24, p.PIN_25, p.PIN_29, p.DMA_CH0, spawner, 45 // ) 46 // .await; 47 48 // let input = gpio::Input::new(p.PIN_29, gpio::Pull::Up); 49 50 let miso = p.PIN_16; 51 let mosi = p.PIN_19; 52 let clk = p.PIN_18; 53 let dc = p.PIN_20; 54 let cs = p.PIN_17; 55 let busy = p.PIN_26; 56 let reset = p.PIN_21; 57 let power = p.PIN_10; 58 59 let reset = Output::new(reset, Level::Low); 60 let _power = Output::new(power, Level::Low); 61 62 let dc = Output::new(dc, Level::Low); 63 let cs = Output::new(cs, Level::High); 64 let busy = Input::new(busy, Pull::Up); 65 66 let _btn_up = Input::new(p.PIN_15, Pull::Down); 67 let _btn_down = Input::new(p.PIN_11, Pull::Down); 68 let _btn_a = Input::new(p.PIN_12, Pull::Down); 69 let _btn_b = Input::new(p.PIN_13, Pull::Down); 70 let btn_c = Input::new(p.PIN_14, Pull::Down); 71 72 // let mut btn_c: Debouncer<'_> = Debouncer::new(Input::new(btn_c, Pull::Up), Duration::from_millis(20)); 73 74 let spi = Spi::new( 75 p.SPI0, 76 clk, 77 mosi, 78 miso, 79 p.DMA_CH1, 80 p.DMA_CH2, 81 spi::Config::default(), 82 ); 83 // let spi_bus: Mutex<NoopRawMutex, _> = Mutex::new(spi); 84 static SPI_BUS: StaticCell<Spi0Bus> = StaticCell::new(); 85 let spi_bus = SPI_BUS.init(Mutex::new(spi)); 86 87 info!("led on!"); 88 // control.gpio_set(0, true).await; 89 spawner.must_spawn(run_the_display(spi_bus, cs, dc, busy, reset)); 90 91 //Input loop 92 loop { 93 //Change Image Button 94 if btn_c.is_high() { 95 info!("Button C pressed"); 96 let current_image = CURRENT_IMAGE.load(core::sync::atomic::Ordering::Relaxed); 97 let new_image = DisplayImage::from_u8(current_image).unwrap().next(); 98 CURRENT_IMAGE.store(new_image.as_u8(), core::sync::atomic::Ordering::Relaxed); 99 CHANGE_IMAGE.store(true, core::sync::atomic::Ordering::Relaxed); 100 Timer::after(Duration::from_millis(500)).await; 101 continue; 102 } 103 Timer::after(Duration::from_millis(100)).await; 104 } 105}