tick/tock now shows on lcd.

This commit is contained in:
Gabe Venberg 2023-12-01 17:01:49 -06:00
parent 24be0a8f2a
commit 188fb05b25

View file

@ -3,11 +3,11 @@
#[rtic::app( #[rtic::app(
device = rp_pico::hal::pac, device = rp_pico::hal::pac,
dispatchers = [TIMER_IRQ_1] dispatchers = [TIMER_IRQ_1, TIMER_IRQ_2, TIMER_IRQ_3]
)] )]
mod app { mod app {
extern crate alloc; extern crate alloc;
use alloc::format; use alloc::{format, string::{self, String, ToString}};
use core::fmt::Write; use core::fmt::Write;
use cortex_m::delay::Delay; use cortex_m::delay::Delay;
use defmt_rtt as _; use defmt_rtt as _;
@ -49,8 +49,8 @@ mod app {
static HEAP: Heap = Heap::empty(); static HEAP: Heap = Heap::empty();
const MONO_NUM: u32 = 1; const MONO_NUM: u32 = 1;
const MONO_DENOM: u32 = 1000000; const MONO_DENOM: u32 = 1_000_000;
const ONE_SEC_TICKS: u64 = 1000000; const ONE_SEC_TICKS: u64 = 1_000_000;
type Uart = UartPeripheral< type Uart = UartPeripheral<
uart::Enabled, 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] #[shared]
struct Shared { struct Shared {
delay: Delay, delay: Delay,
recent_temp: f32,
} }
#[local] #[local]
@ -220,13 +215,14 @@ mod app {
let mono = Rp2040Mono::new(ctx.device.TIMER); 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(); heartbeat::spawn().unwrap();
second_heartbeat::spawn().unwrap(); second_heartbeat::spawn().unwrap();
( (
Shared { delay }, Shared { delay, recent_temp: 0.0 },
Local { Local {
led: led_pin, led: led_pin,
thermocouple, 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])] #[task(local = [led])]
fn heartbeat(ctx: heartbeat::Context) { fn heartbeat(ctx: heartbeat::Context) {
// Flicker the built-in LED // Flicker the built-in LED
@ -260,7 +272,9 @@ mod app {
// Re-spawn this task after 1 second // Re-spawn this task after 1 second
let one_second = Duration::<u64, MONO_NUM, MONO_DENOM>::from_ticks(ONE_SEC_TICKS); let one_second = Duration::<u64, MONO_NUM, MONO_DENOM>::from_ticks(ONE_SEC_TICKS);
heartbeat::spawn_after(one_second).unwrap(); heartbeat::spawn_after(one_second).unwrap();
display::spawn(ToString::to_string(&"tick")).unwrap();
} }
#[task(local = [external_led])] #[task(local = [external_led])]
fn second_heartbeat(ctx: second_heartbeat::Context) { fn second_heartbeat(ctx: second_heartbeat::Context) {
// Flicker the built-in LED // Flicker the built-in LED
@ -270,5 +284,6 @@ mod app {
let one_and_one_half_second = let one_and_one_half_second =
Duration::<u64, MONO_NUM, MONO_DENOM>::from_ticks((ONE_SEC_TICKS as f64*1.14)as u64); Duration::<u64, MONO_NUM, MONO_DENOM>::from_ticks((ONE_SEC_TICKS as f64*1.14)as u64);
second_heartbeat::spawn_after(one_and_one_half_second).unwrap(); second_heartbeat::spawn_after(one_and_one_half_second).unwrap();
display::spawn(ToString::to_string(&"tock")).unwrap();
} }
} }