|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
#![no_std]
|
|
|
|
|
#![no_main]
|
|
|
|
|
|
|
|
|
|
use embedded_alloc::Heap;
|
|
|
|
|
use panic_halt as _;
|
|
|
|
|
|
|
|
|
|
use fugit::RateExtU32;
|
|
|
|
@ -20,6 +21,9 @@ use embedded_graphics::{
|
|
|
|
|
};
|
|
|
|
|
use smart_leds::{SmartLedsWrite, RGB8};
|
|
|
|
|
|
|
|
|
|
extern crate alloc;
|
|
|
|
|
use alloc::format;
|
|
|
|
|
|
|
|
|
|
use fugit::MicrosDurationU32;
|
|
|
|
|
use hal::{
|
|
|
|
|
gpio::{
|
|
|
|
@ -32,6 +36,11 @@ use hal::{
|
|
|
|
|
Adc,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[global_allocator]
|
|
|
|
|
static HEAP: Heap = Heap::empty();
|
|
|
|
|
|
|
|
|
|
const HEAP_SIZE: usize = 1024;
|
|
|
|
|
|
|
|
|
|
const XTAL_FREQ_HZ: u32 = 12_000_000u32;
|
|
|
|
|
const MVG_AVG_COUNT: u16 = 20;
|
|
|
|
|
|
|
|
|
@ -75,10 +84,12 @@ mod app {
|
|
|
|
|
|
|
|
|
|
#[init()]
|
|
|
|
|
fn init(c: init::Context) -> (Shared, Local, init::Monotonics) {
|
|
|
|
|
let mut resets = c.device.RESETS;
|
|
|
|
|
init_heap();
|
|
|
|
|
|
|
|
|
|
let mut resets = c.device.RESETS;
|
|
|
|
|
let sio = hal::Sio::new(c.device.SIO);
|
|
|
|
|
let mut watchdog = hal::Watchdog::new(c.device.WATCHDOG);
|
|
|
|
|
|
|
|
|
|
let clocks = hal::clocks::init_clocks_and_plls(
|
|
|
|
|
XTAL_FREQ_HZ,
|
|
|
|
|
c.device.XOSC,
|
|
|
|
@ -151,6 +162,12 @@ mod app {
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn init_heap() {
|
|
|
|
|
use core::mem::MaybeUninit;
|
|
|
|
|
static mut HEAP_MEM: [MaybeUninit<u8>; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE];
|
|
|
|
|
unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn init_display(i2c: DisplayI2C) -> Display {
|
|
|
|
|
let interface = I2CDisplayInterface::new(i2c);
|
|
|
|
|
let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0)
|
|
|
|
@ -173,17 +190,12 @@ mod app {
|
|
|
|
|
|
|
|
|
|
#[task(binds = TIMER_IRQ_0, priority = 1, shared = [alarm0, sensor_value], local = [display])]
|
|
|
|
|
fn update_display(mut c: update_display::Context) {
|
|
|
|
|
let mut buf = [0u8; 20];
|
|
|
|
|
|
|
|
|
|
let text = c.shared.sensor_value.lock(|val| {
|
|
|
|
|
use numtoa::NumToA;
|
|
|
|
|
val.numtoa_str(10, &mut buf)
|
|
|
|
|
});
|
|
|
|
|
let text = c.shared.sensor_value.lock(|val| format!("{val}"));
|
|
|
|
|
|
|
|
|
|
let display = c.local.display;
|
|
|
|
|
display.clear();
|
|
|
|
|
Text::with_alignment(
|
|
|
|
|
text,
|
|
|
|
|
&text,
|
|
|
|
|
display.bounding_box().center(),
|
|
|
|
|
MonoTextStyle::new(&FONT_10X20, BinaryColor::On),
|
|
|
|
|
Alignment::Center,
|
|
|
|
|