[][src]Trait lpc8xx_hal::clock::Enabled

pub trait Enabled { }

Marker trait that identifies a clock as currently being enabled

A clock that is always enabled can just implement this trait unconditionally. Clocks that can be disabled can use a different type or a type parameter to implement this trait conditionally.

HAL users will typically use this trait to ensure that a clock that is passed as a parameter is enabled.

Examples

This is a function that takes a clock. The function uses this trait to ensure the passed clock is enabled.

use lpc82x_hal::clock;

fn use_clock<C>(clock: C) where C: clock::Frequency + clock::Enabled {
    // do something with the clock
}

The following example shows how to use a type parameter to track whether a clock is enabled, and implement the Enabled trait conditionally.

use lpc82x_hal::{
    clock,
    init_state,
};


struct MyClock<State> {
    _state: State,
}

impl MyClock<init_state::Disabled> {
    /// Consume the instance with disabled state, return one with enabled
    /// state.
    pub fn enable(self) -> MyClock<init_state::Enabled> {
        // Enable the clock
        // ...

        MyClock {
            _state: init_state::Enabled(()),
        }
    }
}

impl clock::Enabled for MyClock<init_state::Enabled> {}

Implementors

impl Enabled for LowPowerClock<Enabled>[src]

impl Enabled for IoscDerivedClock<Enabled>[src]

Loading content...