Skip to content

Commit

Permalink
feat: update eh1
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Jan 12, 2024
1 parent 07e2a2b commit 20eac4f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 55 deletions.
17 changes: 8 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ license = "MIT/Apache-2.0"

[features]
default = ["ble", "embassy"]
embassy = ["dep:embassy-time", "dep:embassy-sync"]
embassy = ["dep:embassy-sync"]
ble = []

[dependencies]
Expand All @@ -36,15 +36,12 @@ nb = "1.1.0"
embedded-hal-02 = { package = "embedded-hal", version = "0.2.7", features = [
"unproven",
] }
embedded-hal-1 = { version = "=1.0.0-rc.2", package = "embedded-hal" }
embedded-hal-nb = "1.0.0-rc.1"
embedded-hal-async = "1.0.0-rc.1"
embedded-hal-1 = { version = "1.0.0", package = "embedded-hal" }
embedded-hal-nb = "1.0.0"
embedded-hal-async = "1.0.0"

# embassy time driver
embassy-time = { version = "0.2.0", features = [
"tick-hz-32_768",
], optional = true }
embassy-sync = { version = "0.5.0", optional = true }
embassy-time-driver = { version = "0.1.0", features = ["tick-hz-32_768"] }

[dev-dependencies]
display-interface = "0.4.1"
Expand All @@ -54,12 +51,14 @@ panic-halt = "0.2.0"
ssd1306 = "0.8.4"

embassy-futures = "0.1.1"
embassy-executor = { version = "0.4.0", features = [
embassy-executor = { version = "0.5.0", features = [
"nightly",
"integrated-timers",
"arch-riscv32",
"executor-thread",
] }
embassy-time = { version = "0.3.0" }
# embassy time driver
heapless = "0.8.0"
embedded-alloc = "0.5.0"
embedded-sdmmc = "0.6.0"
Expand Down
10 changes: 4 additions & 6 deletions src/embassy/time_driver_systick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::sync::atomic::{AtomicU32, AtomicU8, Ordering};
use core::{mem, ptr};

use critical_section::{CriticalSection, Mutex};
use embassy_time::driver::{AlarmHandle, Driver};
use embassy_time_driver::{AlarmHandle, Driver};

// use super::AlarmState;
use crate::pac;
Expand Down Expand Up @@ -40,7 +40,7 @@ pub struct SystickDriver {
}

const ALARM_STATE_NEW: AlarmState = AlarmState::new();
embassy_time::time_driver_impl!(static DRIVER: SystickDriver = SystickDriver {
embassy_time_driver::time_driver_impl!(static DRIVER: SystickDriver = SystickDriver {
period: AtomicU32::new(1), // avoid div by zero
alarm_count: AtomicU8::new(0),
alarms: Mutex::new([ALARM_STATE_NEW; ALARM_COUNT]),
Expand All @@ -52,15 +52,15 @@ impl SystickDriver {
let hclk = crate::sysctl::clocks().hclk.to_Hz() as u64;

let cnt_per_second = hclk / 8;
let cnt_per_tick = cnt_per_second / embassy_time::TICK_HZ;
let cnt_per_tick = cnt_per_second / embassy_time_driver::TICK_HZ;

self.period.store(cnt_per_tick as u32, Ordering::Relaxed);

// UNDOCUMENTED: Avoid initial interrupt
rb.cmp().write(|w| unsafe { w.bits(u64::MAX - 1) });
critical_section::with(|_| {
rb.sr().write(|w| w.cntif().bit(false)); // clear
// Configration: Upcount, No reload, HCLK/8 as clock source
// Configration: Upcount, No reload, HCLK/8 as clock source
rb.ctlr().modify(|_, w| {
w.init()
.set_bit()
Expand Down Expand Up @@ -163,8 +163,6 @@ impl Driver for SystickDriver {
}
}



#[allow(non_snake_case)]
#[link_section = ".trap"]
#[no_mangle]
Expand Down
59 changes: 22 additions & 37 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,11 @@ pub(crate) unsafe fn init() {
fn irq_handler<const N: usize>(port: u8, wakers: &[AtomicWaker; N]) {
let gpioctl = unsafe { &*pac::GPIOCTL::PTR };

let int_if =
if port == 0 {
gpioctl.pa_int_if().read().bits()
} else {
gpioctl.pb_int_if().read().bits()
};
let int_if = if port == 0 {
gpioctl.pa_int_if().read().bits()
} else {
gpioctl.pb_int_if().read().bits()
};
for pin in 0..16 {
if int_if & (1 << pin) == 0 {
continue;
Expand Down Expand Up @@ -866,7 +865,7 @@ mod eh02 {
mod eh1 {
use core::convert::Infallible;

use embedded_hal_1::digital::{ErrorType, InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin};
use embedded_hal_1::digital::{ErrorType, InputPin, OutputPin, StatefulOutputPin};

use super::*;

Expand All @@ -876,13 +875,13 @@ mod eh1 {

impl<'d, T: Pin> InputPin for Input<'d, T> {
#[inline]
fn is_high(&self) -> Result<bool, Self::Error> {
Ok(self.is_high())
fn is_high(&mut self) -> Result<bool, Self::Error> {
Ok((*self).is_high())
}

#[inline]
fn is_low(&self) -> Result<bool, Self::Error> {
Ok(self.is_low())
fn is_low(&mut self) -> Result<bool, Self::Error> {
Ok((*self).is_low())
}
}

Expand All @@ -904,33 +903,26 @@ mod eh1 {

impl<'d, T: Pin> StatefulOutputPin for Output<'d, T> {
#[inline]
fn is_set_high(&self) -> Result<bool, Self::Error> {
Ok(self.is_set_high())
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
Ok((*self).is_set_high())
}

/// Is the output pin set as low?
#[inline]
fn is_set_low(&self) -> Result<bool, Self::Error> {
Ok(self.is_set_low())
}
}

impl<'d, T: Pin> ToggleableOutputPin for Output<'d, T> {
#[inline]
fn toggle(&mut self) -> Result<(), Self::Error> {
Ok(self.toggle())
fn is_set_low(&mut self) -> Result<bool, Self::Error> {
Ok((*self).is_set_low())
}
}

impl<'d, T: Pin> InputPin for Flex<'d, T> {
#[inline]
fn is_high(&self) -> Result<bool, Self::Error> {
Ok(self.is_high())
fn is_high(&mut self) -> Result<bool, Self::Error> {
Ok((*self).is_high())
}

#[inline]
fn is_low(&self) -> Result<bool, Self::Error> {
Ok(self.is_low())
fn is_low(&mut self) -> Result<bool, Self::Error> {
Ok((*self).is_low())
}
}

Expand All @@ -946,27 +938,20 @@ mod eh1 {
}
}

impl<'d, T: Pin> ToggleableOutputPin for Flex<'d, T> {
#[inline]
fn toggle(&mut self) -> Result<(), Self::Error> {
Ok(self.toggle())
}
}

impl<'d, T: Pin> ErrorType for Flex<'d, T> {
type Error = Infallible;
}

impl<'d, T: Pin> StatefulOutputPin for Flex<'d, T> {
#[inline]
fn is_set_high(&self) -> Result<bool, Self::Error> {
Ok(self.is_set_high())
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
Ok((*self).is_set_high())
}

/// Is the output pin set as low?
#[inline]
fn is_set_low(&self) -> Result<bool, Self::Error> {
Ok(self.is_set_low())
fn is_set_low(&mut self) -> Result<bool, Self::Error> {
Ok((*self).is_set_low())
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ impl Rtc {
}
let millisecond = ((cnt_32k % 0x8000) as u32 * 1000 / 32768) as u16;


let mut year: u16 = YEAR_OFFSET;
while days >= days_in_year(year) {
days -= days_in_year(year);
Expand All @@ -138,15 +137,14 @@ impl Rtc {
sec %= 60;
let second = (sec) as u8;


DateTime {
year,
month,
day: (days + 1) as u8,
hour,
minute,
second,
millisecond
millisecond,
}
}
}
Expand Down

0 comments on commit 20eac4f

Please sign in to comment.