Skip to content

Commit

Permalink
Debugging session 2024-05-23T15:00
Browse files Browse the repository at this point in the history
  • Loading branch information
lkirkwood committed May 23, 2024
1 parent 0219e9f commit 432aaa2
Showing 1 changed file with 37 additions and 40 deletions.
77 changes: 37 additions & 40 deletions src/bin/minilogger.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
#![no_std]
#![no_main]

use defmt::*;
use core::cell::RefCell;
use core::option::Option::Some;
use core::option::Option::None;
use defmt::{panic, *};
use embassy_executor::Spawner;
use embassy_stm32::pac::I2C1;
//use embassy_stm32::interrupt::typelevel::Binding;
use embassy_executor::Spawner;
use embassy_stm32::{bind_interrupts, i2c, peripherals, dma::NoDma, time::hz, Config};
use embassy_stm32::i2c::I2c;
use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
use embassy_time::Timer;
use embedded_graphics::mono_font::iso_8859_10::FONT_5X7;
use embedded_graphics::{
mono_font::{ascii::FONT_6X10,ascii::FONT_10X20, MonoTextStyle},
mono_font::{ascii::FONT_10X20, MonoTextStyle},
pixelcolor::BinaryColor,
prelude::*,
primitives::{
Circle, PrimitiveStyle, PrimitiveStyleBuilder, Rectangle, StrokeAlignment, Triangle,
},
text::{Alignment, Text},
};
use {defmt_rtt as _, panic_probe as _};
use panic_probe::*;
use adxl345_driver2::{i2c::Device, Adxl345Reader, Adxl345Writer};
use embassy_sync::blocking_mutex::Mutex;


static I2C1_MUTEX: Mutex<ThreadModeRawMutex, RefCell<Option<I2c<'static, I2C1>>>> = Mutex::new(RefCell::new(None));
static DEVICE: Mutex<ThreadModeRawMutex, RefCell<Option<Device<&mut I2c<'static, I2C1>>>>> = Mutex::new(RefCell::new(None));
static DEVICE: Mutex<ThreadModeRawMutex, RefCell<Option<Device<I2c<'static, I2C1>>>>> = Mutex::new(RefCell::new(None));

/// Output scale is 4mg/LSB.
const SCALE_MULTIPLIER: f64 = 0.004;
Expand All @@ -46,9 +42,9 @@ use embassy_stm32::peripherals::*;

#[embassy_executor::task]
async fn adxl() {
I2C1_MUTEX.lock(|i| {
I2C1_MUTEX.lock(|bus_rc| {
DEVICE.lock(|device| {
let mut adxl345 = Device::new(i.borrow_mut().take().unwrap()).unwrap();
let mut adxl345 = Device::new(bus_rc.take().unwrap()).unwrap();
adxl345.init().unwrap();
adxl345
.set_data_format(8)
Expand All @@ -58,8 +54,7 @@ async fn adxl() {
.set_power_control(8)
.unwrap();

*DEVICE.lock().borrow_mut() = Some(adxl);
//device.replace(Some(adxl345));
device.replace(Some(adxl345));
});
});

Expand All @@ -73,45 +68,47 @@ async fn adxl() {
let (x, y, z) = adxl345.acceleration().unwrap();
let x = x as f64 * SCALE_MULTIPLIER * EARTH_GRAVITY_MS2;
let y = y as f64 * SCALE_MULTIPLIER * EARTH_GRAVITY_MS2;
info!("x: {}, y: {}, z: {}", x, y, z);
});
Timer::after_millis(10).await;
}
}

#[embassy_executor::task]
async fn sh1106() {
let mut display: GraphicsMode<_> = Builder::new().connect_i2c(bus).into();

display.init().unwrap();
display.flush().unwrap();

let main_style = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
let small_style = MonoTextStyle::new(&FONT_5X7, BinaryColor::On);
let text = "MINILOGGER";
Text::with_alignment(
text,
display.bounding_box().center() + Point::new(0, 20),
main_style,
Alignment::Center,
)
.draw(&mut display).unwrap();

Text::with_alignment(
"L. Davies & B. Caley",
display.bounding_box().center() + Point::new(0, 0),
small_style,
Alignment::Center,
)
.draw(&mut display).unwrap();

display.flush().unwrap();

I2C1_MUTEX.lock(|bus_rc| {
let mut display: GraphicsMode<_> = Builder::new().connect_i2c(bus_rc.take().unwrap()).into();

display.init().unwrap();
display.flush().unwrap();

let main_style = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
let small_style = MonoTextStyle::new(&FONT_5X7, BinaryColor::On);
let text = "MINILOGGER";
Text::with_alignment(
text,
display.bounding_box().center() + Point::new(0, 20),
main_style,
Alignment::Center,
)
.draw(&mut display).unwrap();

Text::with_alignment(
"L. Davies & B. Caley",
display.bounding_box().center() + Point::new(0, 0),
small_style,
Alignment::Center,
)
.draw(&mut display).unwrap();

display.flush().unwrap();
});
}

#[embassy_executor::main]
async fn main(_spawner: Spawner) {

let mut config = Config::default();
let config = Config::default();
let p = embassy_stm32::init(config);

let i2c = i2c::I2c::new(
Expand Down

0 comments on commit 432aaa2

Please sign in to comment.