tick/tock now shows on lcd.
This commit is contained in:
parent
24be0a8f2a
commit
188fb05b25
39
src/main.rs
39
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::<u64, MONO_NUM, MONO_DENOM>::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::<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();
|
||||
display::spawn(ToString::to_string(&"tock")).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue