pub struct Enabled<T, N = U0>(_, _);
Expand description
An enabled, 1:N clock with a compile-time counter for N
This struct is a wrapper around other clock types from this module. It
represents a clock, T
, that has been enabled, and it maintains a
compile-time counter, N
, of its consumer clocks in the clock tree.
Compile-time counting allows the API to restrict when clocks may be modified
or disabled. For example, Enabled
clocks can only be disabled when their
counter is U0
.
The type-level counter is implemented using Unsigned
integers from
the typenum
crate, and it is modified using the Increment
and
Decrement
traits.
See the Enabled
wrapper documentation for more
details.
Implementations
sourceimpl<M, N> Enabled<Dfll<I>, N>where
M: Mode,
N: Default,
impl<M, N> Enabled<Dfll<I>, N>where
M: Mode,
N: Default,
sourcepub fn into_mode<T, F>(self, mode: T, f: F) -> (EnabledDfll<T, N>, M)where
T: Mode,
F: FnOnce(&mut Dfll<T>),
pub fn into_mode<T, F>(self, mode: T, f: F) -> (EnabledDfll<T, N>, M)where
T: Mode,
F: FnOnce(&mut Dfll<T>),
Change the Dfll
Mode
while it remains enabled
Take ownership of an EnabledDfll
and convert it to use a new
Mode
. This requires an instance of the new Mode
type and returns
an instance of the old Mode
type. Users can also supply a closure to
alter the Dfll
settings before they are applied. The closure takes
&mut Dfll<T>
as its input, so it can only modify those settings with a
set_
method.
See the dfll
module documentation for more details on why and how
this function would be used.
sourceimpl<D, I> Enabled<Dpll<D, I>, N>where
D: DpllId,
I: DpllSourceId,
impl<D, I> Enabled<Dpll<D, I>, N>where
D: DpllId,
I: DpllSourceId,
sourceimpl<D, I, N> Enabled<Dpll<D, I>, N>where
D: DpllId,
I: DpllSourceId,
impl<D, I, N> Enabled<Dpll<D, I>, N>where
D: DpllId,
I: DpllSourceId,
sourceimpl<G, I> Enabled<Gclk<G, I>, N>where
G: GclkId,
I: GclkSourceId,
impl<G, I> Enabled<Gclk<G, I>, N>where
G: GclkId,
I: GclkSourceId,
sourceimpl<I: GclkSourceId> Enabled<Gclk<Gclk0Id, I>, N>
impl<I: GclkSourceId> Enabled<Gclk<Gclk0Id, I>, N>
Special methods for an Enabled
Gclk0
Gclk0
is special, because it drives the processor’s main clock, which
can never be disabled. As discussed in the module-level documentation,
this fact is represented by permanently Increment
ing the counter for
EnabledGclk0
. Thus, the minimum value for N
is U1
and
EnabledGclk0
can never be disabled.
These methods represent actions that can be taken when N = U1
, i.e. the
Enabled
counter is at its minimum value. This is the only time it’s
safe to change the Gclk0
Source
or change its GclkDivider
value.
sourcepub fn swap_sources<O, N>(
self,
old: O,
new: N
) -> (EnabledGclk0<N::Id, U1>, O::Dec, N::Inc)where
O: Source<Id = I> + Decrement,
N: Source + Increment,
N::Id: NotGclkIo,
pub fn swap_sources<O, N>(
self,
old: O,
new: N
) -> (EnabledGclk0<N::Id, U1>, O::Dec, N::Inc)where
O: Source<Id = I> + Decrement,
N: Source + Increment,
N::Id: NotGclkIo,
sourcepub fn swap_pins<P>(
self,
pin: P,
freq: impl Into<Hertz>
) -> (EnabledGclk0<P::Id, U1>, Pin<I, AlternateM>)where
I: Gclk0Io,
P: AnyPin,
P::Id: Gclk0Io,
pub fn swap_pins<P>(
self,
pin: P,
freq: impl Into<Hertz>
) -> (EnabledGclk0<P::Id, U1>, Pin<I, AlternateM>)where
I: Gclk0Io,
P: AnyPin,
P::Id: Gclk0Io,
sourcepub fn swap_source_for_pin<S, P>(
self,
source: S,
pin: P,
freq: impl Into<Hertz>
) -> (EnabledGclk0<P::Id, U1>, S::Dec)where
S: Source<Id = I> + Decrement,
P: AnyPin,
P::Id: Gclk0Io,
pub fn swap_source_for_pin<S, P>(
self,
source: S,
pin: P,
freq: impl Into<Hertz>
) -> (EnabledGclk0<P::Id, U1>, S::Dec)where
S: Source<Id = I> + Decrement,
P: AnyPin,
P::Id: Gclk0Io,
sourcepub fn swap_pin_for_source<S>(
self,
source: S
) -> (EnabledGclk0<S::Id, U1>, Pin<I, AlternateM>, S::Inc)where
I: Gclk0Io,
S: Source + Increment,
S::Id: NotGclkIo,
pub fn swap_pin_for_source<S>(
self,
source: S
) -> (EnabledGclk0<S::Id, U1>, Pin<I, AlternateM>, S::Inc)where
I: Gclk0Io,
S: Source + Increment,
S::Id: NotGclkIo,
sourcepub fn div(&mut self, div: GclkDiv8)
pub fn div(&mut self, div: GclkDiv8)
Set the GclkDivider
value for Gclk0
See Gclk::div
documentation for more details.
sourcepub fn improve_duty_cycle(&mut self, flag: bool)
pub fn improve_duty_cycle(&mut self, flag: bool)
Output a 50-50 duty cycle clock when using an odd GclkDivider
sourcepub fn freq(&self) -> Hertz
pub fn freq(&self) -> Hertz
Return the Gclk0
frequency
See Gclk::freq
documentation for more details.
sourcepub fn output_off_value(&mut self, high: bool)
pub fn output_off_value(&mut self, high: bool)
Set the state of GclkOut
pins when GclkIo
output is disabled
See Gclk::output_off_value
documentation for more details.
sourceimpl<G, S, N> Enabled<Gclk<G, I>, N>where
G: GclkId,
S: NotGclkIo,
impl<G, S, N> Enabled<Gclk<G, I>, N>where
G: GclkId,
S: NotGclkIo,
sourcepub fn enable_gclk_out<P>(
self,
pin: P
) -> (EnabledGclk<G, S, N::Inc>, GclkOut<P::Id>)where
N: Increment,
P: AnyPin,
P::Id: GclkIo<GclkId = G>,
pub fn enable_gclk_out<P>(
self,
pin: P
) -> (EnabledGclk<G, S, N::Inc>, GclkOut<P::Id>)where
N: Increment,
P: AnyPin,
P::Id: GclkIo<GclkId = G>,
Create and enable a GclkOut
Enabling GclkIo
output will Increment
the EnabledGclk
counter, which will prevent it from being disabled while the
GclkOut
exists.
Note that a given Gclk
can only use GclkIo
for input or
output, but not both simultaneously. The NotGclkIo
trait exists to
enforce this requirement.
Finally, when a GclkOut
is disabled, but the Pin
is still in
AlternateM
mode, it takes the “output off value” of the Gclk
. See
the Gclk::output_off_value
documentation for more details.
sourcepub fn disable_gclk_out<I>(
self,
gclk_out: GclkOut<I>
) -> (EnabledGclk<G, S, N::Dec>, Pin<I, AlternateM>)where
N: Decrement,
I: GclkIo<GclkId = G>,
pub fn disable_gclk_out<I>(
self,
gclk_out: GclkOut<I>
) -> (EnabledGclk<G, S, N::Dec>, Pin<I, AlternateM>)where
N: Decrement,
I: GclkIo<GclkId = G>,
Disable a GclkOut
and free its Pin
Disabling GclkIo
output will Decrement
the EnabledGclk
counter. When a GclkOut
is disabled, but the Pin
is still in
AlternateM
mode, it takes the “output off value” of the Gclk
. See
the Gclk::output_off_value
documentation for more details.
sourceimpl<N> Enabled<OscUlp32kBase, N>
impl<N> Enabled<OscUlp32kBase, N>
sourcepub fn set_calibration(&mut self, calib: u8)
pub fn set_calibration(&mut self, calib: u8)
Override the factory-default calibration value
sourcepub fn write_lock(self)
pub fn write_lock(self)
Freeze the OSCULP32K configuration until power-on reset
This function sets the write-lock bit, which freezes the OSCULP32K
configuration at the hardware level until power-on reset. At the API
level, it also consumes and drops the OscUlp32kBase
clock, which
prevents any further modifications.
sourceimpl Enabled<OscUlp1k, N>
impl Enabled<OscUlp1k, N>
sourcepub fn disable<N: Decrement>(
self,
base: EnabledOscUlp32kBase<N>
) -> (OscUlp1kToken, EnabledOscUlp32kBase<N::Dec>)
pub fn disable<N: Decrement>(
self,
base: EnabledOscUlp32kBase<N>
) -> (OscUlp1kToken, EnabledOscUlp32kBase<N::Dec>)
Disable 1 kHz output from the OscUlp32kBase
clock
This will Decrement
the EnabledOscUlp32kBase
counter.
sourceimpl Enabled<OscUlp32k, N>
impl Enabled<OscUlp32k, N>
sourcepub fn disable<N: Decrement>(
self,
base: EnabledOscUlp32kBase<N>
) -> (OscUlp32kToken, EnabledOscUlp32kBase<N::Dec>)
pub fn disable<N: Decrement>(
self,
base: EnabledOscUlp32kBase<N>
) -> (OscUlp32kToken, EnabledOscUlp32kBase<N::Dec>)
Disable 32 kHz output from the OscUlp32kBase
clock
This will Decrement
the EnabledOscUlp32kBase
counter.
sourceimpl<X, M, N> Enabled<Xosc<X, M>, N>where
X: XoscId,
M: Mode,
impl<X, M, N> Enabled<Xosc<X, M>, N>where
X: XoscId,
M: Mode,
sourcepub fn enable_failure_detection<S>(
&mut self,
dfll: S,
div: SafeClockDiv
) -> S::Incwhere
S: Source<Id = DfllId> + Increment,
pub fn enable_failure_detection<S>(
&mut self,
dfll: S,
div: SafeClockDiv
) -> S::Incwhere
S: Source<Id = DfllId> + Increment,
Enable continuous monitoring of the Xosc
for clock failure
Failure detection will continuously monitor the Xosc
to verify it is
still running. In the event of a failure, the Xosc
output will be
switched to the “safe clock”.
The safe clock is derived from the DFLL, which runs at 48 MHz. The XOSC
peripheral provides a prescaler to divide down the 48 MHz DFLL to better
match the clock it replaces. The prescaler division factor can be any
power of two, 2^N
, with N
in the range 0..16
.
For example, if the Xosc
input frequency is 16 MHz, a reasonable
divider would be 4, becuase the safe clock frequency would be 12 MHz,
which is closest to 16 MHz.
Note that clock failure is triggered when four safe clock periods pass
without seeing a rising & falling edge pair on the XOSC clock. Once
failure is detected, the corresponding bit in the STATUS
register will
go high and an interrupt will be triggered.
If the external clock can be fixed, the Xosc
can be switched back to
it using EnabledXosc::switch_back
.
Because the safe clock makes use of the DFLL, the Xosc
must register
as a consumer of the EnabledDfll
and Increment
its counter.
sourcepub fn has_failed(&self) -> bool
pub fn has_failed(&self) -> bool
Check whether the Xosc
has triggered clock failure detection
Failure detection must be enabled for this to return true
. Failure is
triggered when four safe clock periods pass without seeing a rising &
falling edge pair on the XOSC clock.
See EnabledXosc::enable_failure_detection
for more details.
sourcepub fn is_switched(&self) -> bool
pub fn is_switched(&self) -> bool
sourcepub fn switch_back(&mut self)
pub fn switch_back(&mut self)
Attempt to switch from the safe clock back to the external clock
This function will set the switch back bit (SWBEN
) in the XOSCCTRL
register. Once the hardware has successfully switched back, this bit
will be automatically cleared.
Users can check whether switching back was successful by checking the
STATUS
register with EnabledXosc::is_switched
.
sourcepub fn disable_failure_detection<S>(&mut self, dfll: S) -> S::Decwhere
S: Source<Id = DfllId> + Decrement,
pub fn disable_failure_detection<S>(&mut self, dfll: S) -> S::Decwhere
S: Source<Id = DfllId> + Decrement,
Disable continuous monitoring of the Xosc
for clock failure
Once failure monitoring is disabled, the DFLL is no longer used as the
safe clock, so the EnabledDfll
counter can be Decrement
ed.
sourceimpl<M: Mode> Enabled<Xosc32kBase<M>, N>
impl<M: Mode> Enabled<Xosc32kBase<M>, N>
sourcepub fn disable(self) -> Xosc32kBase<M>
pub fn disable(self) -> Xosc32kBase<M>
Disable the Xosc32kBase
clock
This method is only implemented for N = U0
, which means the clock can
only be disabled when no other clocks consume this Xosc32kBase
clock.
sourceimpl<M: Mode, N> Enabled<Xosc32kBase<M>, N>
impl<M: Mode, N> Enabled<Xosc32kBase<M>, N>
sourcepub fn is_ready(&self) -> bool
pub fn is_ready(&self) -> bool
Check whether the XOSC32K is stable and ready to be used as a clock
Source
sourcepub fn write_lock(self)
pub fn write_lock(self)
Freeze the XOSC32K configuration until power-on reset
This function sets the write-lock bit, which freezes the XOSC32K
configuration at the hardware level until power-on reset. At the API
level, it also consumes and drops the Xosc32kBase
clock, which
prevents any further modifications.
sourceimpl Enabled<Xosc1k, N>
impl Enabled<Xosc1k, N>
sourcepub fn disable<M, N>(
self,
base: EnabledXosc32kBase<M, N>
) -> (Xosc1kToken, EnabledXosc32kBase<M, N::Dec>)where
M: Mode,
N: Decrement,
pub fn disable<M, N>(
self,
base: EnabledXosc32kBase<M, N>
) -> (Xosc1kToken, EnabledXosc32kBase<M, N::Dec>)where
M: Mode,
N: Decrement,
Disable 1 kHz output from the Xosc32kBase
clock
This will Decrement
the EnabledXosc32kBase
counter.
sourceimpl Enabled<Xosc32k, N>
impl Enabled<Xosc32k, N>
sourcepub fn disable<M, N>(
self,
base: EnabledXosc32kBase<M, N>
) -> (Xosc32kToken, EnabledXosc32kBase<M, N::Dec>)where
M: Mode,
N: Decrement,
pub fn disable<M, N>(
self,
base: EnabledXosc32kBase<M, N>
) -> (Xosc32kToken, EnabledXosc32kBase<M, N::Dec>)where
M: Mode,
N: Decrement,
Disable 1 kHz output from the Xosc32kBase
clock
This will Decrement
the EnabledXosc32kBase
counter.