From 188fb05b25cd6cfe29fd1078e80ee21c541f425b Mon Sep 17 00:00:00 2001 From: Gabe Venberg Date: Fri, 1 Dec 2023 17:01:49 -0600 Subject: [PATCH] tick/tock now shows on lcd. --- src/main.rs | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index e8e7e0b..f4dab01 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,11 +3,11 @@ #[rtic::app( device = rp_pico::hal::pac, - dispatchers = [TIMER_IRQ_1] + dispatchers = [TIMER_IRQ_1, TIMER_IRQ_2, TIMER_IRQ_3] )] mod app { extern crate alloc; - use alloc::format; + use alloc::{format, string::{self, String, ToString}}; use core::fmt::Write; use cortex_m::delay::Delay; use defmt_rtt as _; @@ -49,8 +49,8 @@ mod app { static HEAP: Heap = Heap::empty(); const MONO_NUM: u32 = 1; - const MONO_DENOM: u32 = 1000000; - const ONE_SEC_TICKS: u64 = 1000000; + const MONO_DENOM: u32 = 1_000_000; + const ONE_SEC_TICKS: u64 = 1_000_000; type Uart = UartPeripheral< uart::Enabled, @@ -103,15 +103,10 @@ mod app { } } - fn write_lcd(lcd: &mut Lcd, delay: &mut Delay, string: &str) { - lcd.reset(delay).unwrap(); - lcd.clear(delay).unwrap(); - lcd.write_str(string, delay).unwrap(); - } - #[shared] struct Shared { delay: Delay, + recent_temp: f32, } #[local] @@ -220,13 +215,14 @@ mod app { let mono = Rp2040Mono::new(ctx.device.TIMER); - write_lcd(&mut lcd, &mut delay, "Starting"); + // write_lcd(&mut lcd, &mut delay, "Starting"); + display::spawn(ToString::to_string(&"Starting")).unwrap(); heartbeat::spawn().unwrap(); second_heartbeat::spawn().unwrap(); ( - Shared { delay }, + Shared { delay, recent_temp: 0.0 }, Local { led: led_pin, thermocouple, @@ -252,6 +248,22 @@ mod app { // }; // } } + + fn write_lcd(lcd: &mut Lcd, delay: &mut Delay, string: &str) { + lcd.reset(delay).unwrap(); + lcd.clear(delay).unwrap(); + lcd.write_str(string, delay).unwrap(); + } + + #[task(local = [lcd], shared = [delay], capacity = 5)] + fn display(mut ctx: display::Context, str: String){ + ctx.shared.delay.lock(|d|{ + ctx.local.lcd.reset(d).unwrap(); + ctx.local.lcd.clear(d).unwrap(); + ctx.local.lcd.write_str(&str, d).unwrap(); + }); + } + #[task(local = [led])] fn heartbeat(ctx: heartbeat::Context) { // Flicker the built-in LED @@ -260,7 +272,9 @@ mod app { // Re-spawn this task after 1 second let one_second = Duration::::from_ticks(ONE_SEC_TICKS); heartbeat::spawn_after(one_second).unwrap(); + display::spawn(ToString::to_string(&"tick")).unwrap(); } + #[task(local = [external_led])] fn second_heartbeat(ctx: second_heartbeat::Context) { // Flicker the built-in LED @@ -270,5 +284,6 @@ mod app { let one_and_one_half_second = Duration::::from_ticks((ONE_SEC_TICKS as f64*1.14)as u64); second_heartbeat::spawn_after(one_and_one_half_second).unwrap(); + display::spawn(ToString::to_string(&"tock")).unwrap(); } }