Add allocator

main
trivernis 2 years ago
parent b2b52ff4cd
commit 05092e9b2b
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

24
Cargo.lock generated

@ -15,12 +15,12 @@ dependencies = [
"cortex-m",
"cortex-m-rt",
"cortex-m-rtic",
"embedded-alloc",
"embedded-graphics",
"embedded-hal",
"embedded-time",
"fugit",
"nb 1.1.0",
"numtoa",
"panic-halt",
"rp2040-boot2 0.3.0",
"rp2040-hal",
@ -206,6 +206,16 @@ version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
[[package]]
name = "embedded-alloc"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8931e47e33c5d3194fbcf9cc82df0919193bd2fa40008f388eb1d28fd9c9ea6b"
dependencies = [
"critical-section",
"linked_list_allocator",
]
[[package]]
name = "embedded-dma"
version = "0.2.0"
@ -328,6 +338,12 @@ dependencies = [
"either",
]
[[package]]
name = "linked_list_allocator"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286"
[[package]]
name = "lock_api"
version = "0.4.9"
@ -442,12 +458,6 @@ dependencies = [
"syn",
]
[[package]]
name = "numtoa"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6aa2c4e539b869820a2b82e1aef6ff40aa85e65decdd5185e83fb4b1249cd00f"
[[package]]
name = "panic-halt"
version = "0.2.0"

@ -21,7 +21,7 @@ systick-monotonic = "1.0.1"
embedded-time = "0.12.1"
ssd1306 = "0.7.1"
embedded-graphics = "0.7.1"
numtoa = "0.2.4"
smart-leds = "0.3.0"
ws2812-pio = "0.6.0"
waveshare-rp2040-zero = "0.6.0"
embedded-alloc = "0.5.0"

@ -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,

Loading…
Cancel
Save