Skip to content

Feature/embedded time #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 11, 2021
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ nb = "0.1"
paste = "1"
rtcc = "0.2"
stm32f3 = "0.12"
embedded-time = "0.10"

[dependencies.embedded-hal-can]
version = "0.1.0"
Expand Down
4 changes: 2 additions & 2 deletions src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

use core::convert::TryFrom;
use core::ops::Deref;
use embedded_time::rate::Hertz;

use crate::{
gpio::{gpioa, gpiob, AF4},
hal::blocking::i2c::{Read, Write, WriteRead},
pac::{i2c1::RegisterBlock, rcc::cfgr3::I2C1SW_A, I2C1, RCC},
rcc::{Clocks, APB1},
time::{Hertz, U32Ext},
};

#[cfg(not(feature = "gpio-f333"))]
Expand Down Expand Up @@ -451,7 +451,7 @@ macro_rules! i2c {
fn clock(clocks: &Clocks) -> Hertz {
// NOTE(unsafe) atomic read with no side effects
match unsafe { (*RCC::ptr()).cfgr3.read().$i2cXsw().variant() } {
I2C1SW_A::HSI => 8.mhz().into(),
I2C1SW_A::HSI => Hertz(8_000_000),
I2C1SW_A::SYSCLK => clocks.sysclk(),
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ pub use crate::flash::FlashExt as _stm32f3xx_hal_flash_FlashExt;
pub use crate::gpio::GpioExt as _stm32f3xx_hal_gpio_GpioExt;
pub use crate::hal::prelude::*;
pub use crate::rcc::RccExt as _stm32f3xx_hal_rcc_RccExt;
pub use crate::time::U32Ext as _stm32f3xx_hal_time_U32Ext;
pub use embedded_time::duration::*;
pub use embedded_time::rate::*;
#[cfg(feature = "unproven")]
pub use crate::{
hal::digital::v2::InputPin as _embedded_hal_digital_InputPin,
Expand Down
4 changes: 2 additions & 2 deletions src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ use crate::{
gpio::{self, gpioa, gpiob},
hal::PwmPin,
pac::{RCC, TIM15, TIM16, TIM17, TIM2},
rcc::Clocks,
time::Hertz,
rcc::Clocks
};
use core::marker::PhantomData;
use embedded_time::rate::Hertz;

#[cfg(any(
feature = "stm32f302xb",
Expand Down
2 changes: 1 addition & 1 deletion src/rcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use crate::pac::{
};

use crate::flash::ACR;
use crate::time::Hertz;
use embedded_time::rate::Hertz;

/// Extension trait that constrains the `RCC` peripheral
pub trait RccExt {
Expand Down
5 changes: 3 additions & 2 deletions src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use crate::{
hal::{blocking, serial},
pac::{USART1, USART2, USART3},
rcc::{Clocks, APB1, APB2},
time::Bps,
};

use cfg_if::cfg_if;
use core::{convert::Infallible, marker::PhantomData, ptr};
use embedded_time::rate::Baud;

cfg_if! {
if #[cfg(any(feature = "stm32f302", feature = "stm32f303"))] {
Expand Down Expand Up @@ -111,7 +112,7 @@ macro_rules! hal {
pub fn $usartX(
usart: $USARTX,
pins: (TX, RX),
baud_rate: Bps,
baud_rate: Baud,
clocks: Clocks,
apb: &mut $APB,
) -> Self
Expand Down
2 changes: 1 addition & 1 deletion src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ use crate::rcc::APB1;
feature = "stm32f398"
))]
use crate::rcc::APB2;
use crate::time::Hertz;
use core::marker::PhantomData;
use embedded_time::rate::Hertz;

/// SPI error
#[derive(Debug)]
Expand Down
2 changes: 2 additions & 0 deletions src/time.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Time units

/*
use cortex_m::peripheral::DWT;

use crate::rcc::Clocks;
Expand Down Expand Up @@ -126,3 +127,4 @@ impl Instant {
DWT::get_cycle_count().wrapping_sub(self.now)
}
}
*/
3 changes: 2 additions & 1 deletion src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ use crate::pac::{TIM15, TIM16, TIM17, TIM2, TIM6};
use crate::pac::{TIM3, TIM7};

use void::Void;
use embedded_time::rate::Hertz;

use crate::rcc::{Clocks, APB1, APB2};
use crate::time::Hertz;


/// Associated clocks with timers
pub trait PclkSrc {
Expand Down
8 changes: 4 additions & 4 deletions src/watchdog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use crate::hal::watchdog::{Watchdog, WatchdogEnable};

use crate::pac::{DBGMCU, IWDG};
use crate::time::MilliSeconds;
use embedded_time::duration::Milliseconds;

const LSI_KHZ: u32 = 40;
const MAX_PR: u8 = 8;
Expand Down Expand Up @@ -54,13 +54,13 @@ impl IndependentWatchDog {
}

/// Returns the interval in ms
pub fn interval(&self) -> MilliSeconds {
pub fn interval(&self) -> Milliseconds {
while self.is_pr_updating() {}

let pr = self.iwdg.pr.read().pr().bits();
let rl = self.iwdg.rlr.read().rl().bits();
let ms = Self::timeout_period(pr, rl);
MilliSeconds(ms)
Milliseconds(ms)
}

/// pr: Prescaler divider bits, rl: reload value
Expand Down Expand Up @@ -93,7 +93,7 @@ impl IndependentWatchDog {
}

impl WatchdogEnable for IndependentWatchDog {
type Time = MilliSeconds;
type Time = Milliseconds;

fn start<T: Into<Self::Time>>(&mut self, period: T) {
self.setup(period.into().0);
Expand Down