[][src]Struct rmicrobit::display::MicrobitDisplay

pub struct MicrobitDisplay<T: As16BitTimer> { /* fields omitted */ }

The micro:bit's display, and one timer to drive it.

Methods

impl<T: As16BitTimer> MicrobitDisplay<T>[src]

pub fn new(port: DisplayPort, timer: T) -> MicrobitDisplay<T>[src]

Takes ownership of the display port and one TIMER, and returns a MicrobitDisplay.

The timer parameter can be any of the three nrf51::TIMERn peripherals.

Initialises the micro:bit hardware to use the display driver.

The display is initially clear.

Example

This example is not tested
use rmicrobit::prelude::*;
use rmicrobit::gpio::PinsByKind;
use rmicrobit::display::{DisplayPort, MicrobitDisplay};
let p: nrf51::Peripherals = _;
let PinsByKind {display_pins, ..} = p.GPIO.split_by_kind();
let display_port = DisplayPort::new(display_pins);
let mut display = MicrobitDisplay::new(display_port, p.TIMER1);

pub fn free(self) -> (DisplayPort, T)[src]

Gives the underlying devices back.

Returns the DisplayPort and nrf51::TIMERn instance.

Turns all the LEDs off and stops the TIMER.

pub fn handle_event(&mut self) -> DisplayEvent[src]

Updates the LEDs and timer state during a timer interrupt.

Call this in an interrupt handler for the MicrobitDisplay's timer.

See Display::handle_event() for details.

Returns a DisplayEvent indicating the reason for the interrupt. You can check this if you wish to perform some other action once every 6ms.

Example

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

This example is not tested
#[task(binds = TIMER1, priority = 2, resources = [display])]
fn timer1(cx: timer1::Context) {
    let display_event = cx.resources.display.handle_event();
    if display_event.is_new_row() {
        ...
    }
}

pub fn set_frame(&mut self, frame: &MicrobitFrame)[src]

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).

Example

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

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

Auto Trait Implementations

impl<T> Unpin for MicrobitDisplay<T> where
    T: Unpin

impl<T> Send for MicrobitDisplay<T> where
    T: Send

impl<T> Sync for MicrobitDisplay<T> where
    T: Sync

Blanket Implementations

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

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

type Error = !

The type returned in the event of a conversion error.

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

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.

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

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

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

impl<T> Same<T> for T

type Output = T

Should always be Self