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,
impl<F> Display<F> where
F: Frame,
pub fn set_frame(&mut self, frame: &F)
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
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,
F: Send,
impl<F> Sync for Display<F> where
F: Sync,
F: Sync,
impl<F> Unpin for Display<F> where
F: Unpin,
F: Unpin,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> CheckedAs for T
[src]
impl<T> CheckedAs for T
[src]pub fn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
[src]
pub fn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
[src]Casts the value.
impl<Src, Dst> LosslessTryInto<Dst> for Src where
Dst: LosslessTryFrom<Src>,
[src]
impl<Src, Dst> LosslessTryInto<Dst> for Src where
Dst: LosslessTryFrom<Src>,
[src]pub fn lossless_try_into(self) -> Option<Dst>
[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]
impl<Src, Dst> LossyInto<Dst> for Src where
Dst: LossyFrom<Src>,
[src]pub fn lossy_into(self) -> Dst
[src]
pub fn lossy_into(self) -> Dst
[src]Performs the conversion.
impl<T> OverflowingAs for T
[src]
impl<T> OverflowingAs for T
[src]pub fn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
[src]
pub fn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
[src]Casts the value.
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self
impl<T> SaturatingAs for T
[src]
impl<T> SaturatingAs for T
[src]pub fn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
[src]
pub fn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
[src]Casts the value.
impl<T> UnwrappedAs for T
[src]
impl<T> UnwrappedAs for T
[src]pub fn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
[src]
pub fn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
[src]Casts the value.
impl<T> WrappingAs for T
[src]
impl<T> WrappingAs for T
[src]pub fn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
[src]
pub fn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
[src]Casts the value.