Struct microbit::display::Display[]

pub struct Display<F> where
    F: Frame
{ /* fields omitted */ }
Expand description

Manages a small LED display.

There should normally be a single Display instance for a single piece of display hardware.

Display is generic over a Frame type, which holds image data suitable for display on a particular piece of hardware.

Call [initialise_control()] and [initialise_timer()] before using a Display.

Example

Using cortex-m-rtfm v0.5:

#[app(device = nrf51, peripherals = true)]
const APP: () = {

    struct Resources {
        gpio: nrf51::GPIO,
        timer1: nrf51::TIMER1,
        display: Display<MyFrame>,
    }

    #[init]
    fn init(cx: init::Context) -> init::LateResources {
        let mut p: nrf51::Peripherals = cx.device;
        display::initialise_control(&mut MyDisplayControl(&mut p.GPIO));
        display::initialise_timer(&mut MyDisplayTimer(&mut p.TIMER1));
        init::LateResources {
            gpio : p.GPIO,
            timer1 : p.TIMER1,
            display : Display::new(),
        }
    }
}

Implementations

impl<F> Display<F> where
    F: Frame

pub fn new() -> Display<F>

Creates a Display instance, initially holding a blank image.

pub fn set_frame(&mut self, frame: &F)

Accepts a new image to be displayed.

The code that calls this method must not be interrupting, or interruptable by, handle_event().

After calling this, it’s safe to modify the frame again (its data is copied into the Display).

Example

In the style of cortex-m-rtfm v0.5:

#[task(binds = RTC0, priority = 1, resources = [rtc0, display])]
fn rtc0(mut cx: rtc0::Context) {
    static mut FRAME: MyFrame = MyFrame::const_default();
    &cx.resources.rtc0.clear_tick_event();
    FRAME.set(GreyscaleImage::blank());
    cx.resources.display.lock(|display| {
        display.set_frame(FRAME);
    });
}

pub fn handle_event(
    &mut self,
    timer: &mut impl DisplayTimer,
    control: &mut impl DisplayControl
) -> Event

Updates the LEDs and timer state during a timer interrupt.

You should call this each time the timer’s interrupt is signalled.

The timer parameter must represent the same device each time you call this method, and the same as originally passed to [initialise_timer()].

The control parameter must represent the same device each time you call this method, and the same as originally passed to [initialise_control()].

This method always calls the timer’s [check_primary()][DisplayTimer::check_primary] and [check_secondary()][DisplayTimer::check_secondary] methods.

As well as updating the LED state by calling [DisplayControl] methods, it may update the timer state by calling the timer’s [program_secondary()][DisplayTimer::program_secondary], [enable_secondary()][DisplayTimer::enable_secondary], and/or [disable_secondary()][DisplayTimer::disable_secondary] methods.

Returns a value indicating the reason for the interrupt. You can check this if you wish to perform some other action once per primary cycle.

Example

In the style of cortex-m-rtfm v0.5:

#[task(binds = TIMER1, priority = 2,
       resources = [timer1, gpio, display])]
fn timer1(cx: timer1::Context) {
    let display_event = cx.resources.display.handle_event(
        &mut MyDisplayControl(&mut cx.resources.timer1),
        &mut MyDisplayControl(&mut cx.resources.gpio),
    );
    if display_event.is_new_row() {
        ...
    }
}

Auto Trait Implementations

impl<F> Send for Display<F> where
    F: Send

impl<F> Sync for Display<F> where
    F: Sync

impl<F> Unpin for Display<F> where
    F: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Az for T[src]

pub fn az<Dst>(self) -> Dst where
    T: Cast<Dst>, 
[src]

Casts the value.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> CheckedAs for T[src]

pub fn checked_as<Dst>(self) -> Option<Dst> where
    T: CheckedCast<Dst>, 
[src]

Casts the value.

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<Src, Dst> LosslessTryInto<Dst> for Src where
    Dst: LosslessTryFrom<Src>, 
[src]

pub fn lossless_try_into(self) -> Option<Dst>[src]

Performs the conversion.

impl<Src, Dst> LossyInto<Dst> for Src where
    Dst: LossyFrom<Src>, 
[src]

pub fn lossy_into(self) -> Dst[src]

Performs the conversion.

impl<T> OverflowingAs for T[src]

pub fn overflowing_as<Dst>(self) -> (Dst, bool) where
    T: OverflowingCast<Dst>, 
[src]

Casts the value.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> SaturatingAs for T[src]

pub fn saturating_as<Dst>(self) -> Dst where
    T: SaturatingCast<Dst>, 
[src]

Casts the value.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<T> UnwrappedAs for T[src]

pub fn unwrapped_as<Dst>(self) -> Dst where
    T: UnwrappedCast<Dst>, 
[src]

Casts the value.

impl<T> WrappingAs for T[src]

pub fn wrapping_as<Dst>(self) -> Dst where
    T: WrappingCast<Dst>, 
[src]

Casts the value.