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