Struct Display

Source
pub struct Display<F: Frame> { /* private fields */ }
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§

Source§

impl<F: Frame> Display<F>

Source

pub fn new() -> Display<F>

Creates a Display instance, initially holding a blank image.

Source

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

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() and 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(), enable_secondary(), and/or 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> Freeze for Display<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for Display<F>
where F: RefUnwindSafe,

§

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,

§

impl<F> UnwindSafe for Display<F>
where F: 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, 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.