Skip to content
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

Improve LowPowerTimer. #321

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/lptimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::rcc::{Clocks, Enable, RccBus, Reset, CCIPR};
use crate::stm32::{LPTIM1, LPTIM2, RCC};

/// Clock sources available for timers
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ClockSource {
/// Use PCLK as clock source
PCLK = 0b00,
Expand All @@ -19,6 +20,7 @@ pub enum ClockSource {
///
/// Allow missing docs because the type is self explanatory
#[allow(missing_docs)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum PreScaler {
U1 = 0b000,
U2 = 0b001,
Expand All @@ -33,14 +35,15 @@ pub enum PreScaler {
/// Count modes that are available.
///
/// All ClockSources currently supported require the Internal count mode
#[derive(PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum CountMode {
/// Use an internal clock source (which also includes LSE)
Internal,
// External,
}

/// All currently supported interrupt events
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Event {
/// Occurs when the compare value is the same as the counter value
CompareMatch,
Expand Down Expand Up @@ -293,6 +296,11 @@ macro_rules! hal {
self.lptim.cnt.read().bits() as u16
}

pub fn count() -> u16 {
let lptim = unsafe { &*<$timer_type>::ptr() };
lptim.cnt.read().bits() as u16
}

/// Get the value of the ARR register for this
/// LowPowerTimer
#[inline]
Expand Down