Struct MicrobitDisplay

Source
pub struct MicrobitDisplay<T: As16BitTimer> { /* private fields */ }
Expand description

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

Implementations§

Source§

impl<T: As16BitTimer> MicrobitDisplay<T>

Source

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

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
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);
Source

pub fn free(self) -> (DisplayPort, T)

Gives the underlying devices back.

Returns the DisplayPort and nrf51::TIMERn instance.

Turns all the LEDs off and stops the TIMER.

Source

pub fn handle_event(&mut self) -> DisplayEvent

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:

#[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() {
        ...
    }
}
Source

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

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:

#[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> Freeze for MicrobitDisplay<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for MicrobitDisplay<T>
where T: RefUnwindSafe,

§

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

§

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

§

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

§

impl<T> UnwindSafe for MicrobitDisplay<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.