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>
impl<T: As16BitTimer> MicrobitDisplay<T>
Sourcepub fn new(port: DisplayPort, timer: T) -> MicrobitDisplay<T>
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::TIMER
n
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);
Sourcepub fn free(self) -> (DisplayPort, T)
pub fn free(self) -> (DisplayPort, T)
Gives the underlying devices back.
Returns the DisplayPort
and nrf51::TIMER
n instance.
Turns all the LEDs off and stops the TIMER.
Sourcepub fn handle_event(&mut self) -> DisplayEvent
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() {
...
}
}
Sourcepub fn set_frame(&mut self, frame: &MicrobitFrame)
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);
});
}