stm32/time: add Cargo features to choose tim2/tim3
This commit is contained in:
@ -6,7 +6,7 @@ edition = "2018"
|
||||
resolver = "2"
|
||||
|
||||
[dependencies]
|
||||
embassy = { version = "0.1.0", path = "../embassy", features = ["time-tick-32768hz"] }
|
||||
embassy = { version = "0.1.0", path = "../embassy" }
|
||||
embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["stm32"] }
|
||||
embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" }
|
||||
embassy-traits = {version = "0.1.0", path = "../embassy-traits" }
|
||||
@ -44,6 +44,12 @@ sdmmc-rs = ["embedded-sdmmc"]
|
||||
net = ["embassy-net", "vcell"]
|
||||
memory-x = ["stm32-metapac/memory-x"]
|
||||
|
||||
# Features starting with `_` are for internal use only. They're not intended
|
||||
# to be enabled by other crates, and are not covered by semver guarantees.
|
||||
_time-driver = ["embassy/time-tick-32768hz"]
|
||||
time-driver-tim2 = ["_time-driver"]
|
||||
time-driver-tim3 = ["_time-driver"]
|
||||
|
||||
# Reexport stm32-metapac at `embassy_stm32::pac`.
|
||||
# This is unstable because semver-minor (non-breaking) releases of embassy-stm32 may major-bump (breaking) the stm32-metapac version.
|
||||
# If this is an issue for you, you're encouraged to directly depend on a fixed version of the PAC.
|
||||
|
@ -20,6 +20,7 @@ pub mod time;
|
||||
pub mod dma;
|
||||
pub mod gpio;
|
||||
pub mod rcc;
|
||||
#[cfg(feature = "_time-driver")]
|
||||
mod time_driver;
|
||||
|
||||
// Sometimes-present hardware
|
||||
@ -88,6 +89,7 @@ pub fn init(config: Config) -> Peripherals {
|
||||
rcc::init(config.rcc);
|
||||
|
||||
// must be after rcc init
|
||||
#[cfg(feature = "_time-driver")]
|
||||
time_driver::init();
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,23 @@ use crate::rcc::sealed::RccPeripheral;
|
||||
use self::sealed::Instance as _;
|
||||
|
||||
const ALARM_COUNT: usize = 3;
|
||||
|
||||
#[cfg(feature = "time-driver-tim2")]
|
||||
type T = peripherals::TIM2;
|
||||
#[cfg(feature = "time-driver-tim3")]
|
||||
type T = peripherals::TIM3;
|
||||
|
||||
#[cfg(feature = "time-driver-tim2")]
|
||||
#[interrupt]
|
||||
fn TIM2() {
|
||||
STATE.on_interrupt()
|
||||
}
|
||||
#[cfg(feature = "time-driver-tim3")]
|
||||
#[interrupt]
|
||||
fn TIM3() {
|
||||
STATE.on_interrupt()
|
||||
}
|
||||
|
||||
// Clock timekeeping works with something we call "periods", which are time intervals
|
||||
// of 2^15 ticks. The Clock counter value is 16 bits, so one "overflow cycle" is 2 periods.
|
||||
//
|
||||
@ -275,11 +290,6 @@ impl Driver for RtcDriver {
|
||||
}
|
||||
}
|
||||
|
||||
#[interrupt]
|
||||
fn TIM3() {
|
||||
STATE.on_interrupt()
|
||||
}
|
||||
|
||||
pub(crate) fn init() {
|
||||
STATE.init()
|
||||
}
|
||||
|
Reference in New Issue
Block a user