Skip to content

Commit

Permalink
Change spelling of "*PitChan" timers
Browse files Browse the repository at this point in the history
It only varied by one letter from "*PitChain." Rename it to
"BlockingPit" and "RawCountDownPit" which is easier to type and maps to
the structure it's adapting (a "Pit"). Rename the constructors for
simplicity, and to better match the thing it's converting.
  • Loading branch information
mciantyre committed Mar 7, 2023
1 parent bdba22e commit 4362096
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 16 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ imxrt-hal feature, and separately select your imxrt-ral feature.
_Deprecate_ the `clko2::Selection::TracClk` item. Prefer the correctly-spelled
variant, `clko2::Selection::TraceClk`.

_Deprecate_ the following items in the `timer` module:

- `timer::BlockingPitChan` and constructor `from_pit_channel`.
- `timer::RawCountDownPitChan`and constructor `from_pit_channel`.

The type names differ from `*PitChain` by one letter. Prefer the spellings
without `*Chan` and `*_channel`.

## [0.5.0] 2022-01-05

`imxrt-hal` provides common peripherals for all chips supported by `imxrt-ral`,
Expand Down
6 changes: 3 additions & 3 deletions examples/rtic_gpio_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#[rtic::app(device = board, peripherals = false)]
mod app {
use hal::{gpio::Trigger, timer::BlockingPitChan};
use hal::{gpio::Trigger, timer::BlockingPit};
use imxrt_hal as hal;

#[shared]
Expand All @@ -19,7 +19,7 @@ mod app {
struct Local {
led: board::Led,
button: board::Button,
delay: BlockingPitChan<2, { board::PIT_FREQUENCY }>,
delay: BlockingPit<2, { board::PIT_FREQUENCY }>,
}

#[init]
Expand All @@ -37,7 +37,7 @@ mod app {
},
) = board::new();
led.set();
let delay = BlockingPitChan::from_pit_channel(pit);
let delay = BlockingPit::from_pit(pit);
let button_port = ports.button_mut();
button_port.set_interrupt(&button, Some(Trigger::FallingEdge));
(Shared {}, Local { led, button, delay }, init::Monotonics())
Expand Down
60 changes: 47 additions & 13 deletions src/common/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl<const HZ: u32> TimerDurationExt for fugit::TimerDurationU64<HZ> {
///
/// use hal::{
/// ccm::{self, clock_gate, perclk_clk},
/// timer::BlockingPitChan,
/// timer::BlockingPit,
/// };
///
/// let mut ccm = unsafe { ral::ccm::CCM::instance() };
Expand All @@ -210,7 +210,7 @@ impl<const HZ: u32> TimerDurationExt for fugit::TimerDurationU64<HZ> {
/// let pit = unsafe { ral::pit::PIT::instance() };
/// let (pit0, _, _, _) = hal::pit::new(pit);
///
/// let mut blocking = BlockingPitChan::<0, PIT_FREQUENCY_HZ>::from_pit_channel(pit0);
/// let mut blocking = BlockingPit::<0, PIT_FREQUENCY_HZ>::from_pit(pit0);
/// // Block for milliseconds:
/// blocking.block_ms(1000);
/// // Block for microseconds:
Expand Down Expand Up @@ -265,7 +265,7 @@ where
/// ```compile_fail
/// // See struct-level documentation for configuration...
/// # let pit0 = unsafe { imxrt_hal::pit::Pit::<0>::new(&imxrt_ral::pit::PIT::instance()) };
/// # let mut blocking = imxrt_hal::timer::BlockingPitChan::<0, PIT_FREQUENCY_HZ>::from_pit_channel(pit0);
/// # let mut blocking = imxrt_hal::timer::BlockingPit::<0, PIT_FREQUENCY_HZ>::from_pit(pit0);
/// # const PIT_FREQUENCY_HZ: u32 = 75000000;
/// // 99 seconds, expressed in microseconds, cannot fit within a u32 counter
/// // that counts at PIT_FREQUENCY_HZ. This fails to compile:
Expand All @@ -276,7 +276,7 @@ where
///
/// ```no_run
/// # let pit0 = unsafe { imxrt_hal::pit::Pit::<0>::new(&imxrt_ral::pit::PIT::instance()) };
/// # let mut blocking = imxrt_hal::timer::BlockingPitChan::<0, PIT_FREQUENCY_HZ>::from_pit_channel(pit0);
/// # let mut blocking = imxrt_hal::timer::BlockingPit::<0, PIT_FREQUENCY_HZ>::from_pit(pit0);
/// # const PIT_FREQUENCY_HZ: u32 = 75000000;
/// // However, 99 milliseconds, expressed in microseconds, can fit within a u32
/// // counter that counts at PIT_FREQENCY_HZ.
Expand Down Expand Up @@ -346,7 +346,7 @@ where

/// Prepares a PIT channel to be adapted by blocking / count down
/// adapters.
fn prepare_pit_channel<const N: u8>(pit: &mut pit::Pit<N>) {
fn prepare_pit<const N: u8>(pit: &mut pit::Pit<N>) {
pit.disable();
pit.clear_elapsed();
pit.set_chained(false);
Expand Down Expand Up @@ -381,14 +381,31 @@ fn prepare_gpt<const N: u8>(gpt: &mut gpt::Gpt<N>) {
}

/// A single PIT channel that acts as a blocking timer.
pub type BlockingPitChan<const N: u8, const HZ: u32> = Blocking<pit::Pit<N>, HZ>;
pub type BlockingPit<const N: u8, const HZ: u32> = Blocking<pit::Pit<N>, HZ>;

impl<const N: u8, const HZ: u32> BlockingPitChan<N, HZ> {
/// A single PIT channel that acts as a blocking timer.
///
/// Prefer [`BlockingPit`], which is easier to type. It is also more
/// distinct than [`BlockingPitChain`], which varies from `BlockingPitChan`
/// by only one letter.
#[deprecated(since = "0.5.1", note = "Use BlockingPit")]
pub type BlockingPitChan<const N: u8, const HZ: u32> = BlockingPit<N, HZ>;

impl<const N: u8, const HZ: u32> BlockingPit<N, HZ> {
/// Create a blocking adapter from a PIT channel.
pub fn from_pit_channel(mut pit: pit::Pit<N>) -> Self {
prepare_pit_channel(&mut pit);
pub fn from_pit(mut pit: pit::Pit<N>) -> Self {
prepare_pit(&mut pit);
Self::new(pit)
}

/// Create a blocking adapter from a PIT channel.
///
/// Prefer [`from_pit`](Self::from_pit), which is easier to type
/// and matches the name of the type we're converting.
#[deprecated(since = "0.5.1", note = "Use from_pit")]
pub fn from_pit_channel(pit: pit::Pit<N>) -> Self {
Self::from_pit(pit)
}
}

/// A chain of PIT channels that act as a blocking timer.
Expand Down Expand Up @@ -510,14 +527,31 @@ where
}

/// A count down timer over a PIT channel.
pub type RawCountDownPitChan<const N: u8> = RawCountDown<pit::Pit<N>>;
pub type RawCountDownPit<const N: u8> = RawCountDown<pit::Pit<N>>;

impl<const N: u8> RawCountDownPitChan<N> {
/// A count down timer over a PIT channel.
///
/// Prefer [`RawCountDownPit`], which is easier to type. It is also more
/// distinct than [`RawCountDownPitChain`], which varies from `RawCountDownPitChan`
/// by only one letter.
#[deprecated(since = "0.5.1", note = "Use RawCountDownPit")]
pub type RawCountDownPitChan<const N: u8> = RawCountDownPit<N>;

impl<const N: u8> RawCountDownPit<N> {
/// Create a count down timer from a PIT channel.
pub fn from_pit_channel(mut pit: pit::Pit<N>) -> Self {
prepare_pit_channel(&mut pit);
pub fn from_pit(mut pit: pit::Pit<N>) -> Self {
prepare_pit(&mut pit);
Self::new(pit)
}

/// Create a count down timer from a PIT channel.
///
/// Prefer [`from_pit`](Self::from_pit), which is easier to type
/// and matches the name of the type we're converting.
#[deprecated(since = "0.5.1", note = "Use from_pit")]
pub fn from_pit_channel(pit: pit::Pit<N>) -> Self {
Self::from_pit(pit)
}
}

/// A count down timer over two chained PIT channels.
Expand Down

0 comments on commit 4362096

Please sign in to comment.