Struct DisplayPort

Source
pub struct DisplayPort(/* private fields */);
Expand description

Write access to the GPIO pins connected to the 5×5 LED display.

DisplayPort permits writing to the display’s GPIO pins and ignores requests to write to any other part of the GPIO port.

DisplayPort implements the DisplayControl trait, so it can be used with a Display.

To light an LED, set its row pin and clear its column pin.

Use the pin_constants to find the GPIO pin numbers for each row and column.

See the DAL documentation for how these rows and columns correspond to the physical LED layout.

§Example

use rmicrobit::prelude::*;
use rmicrobit::gpio::PinsByKind;
use rmicrobit::pin_constants::{col_pin_number, row_pin_number, COL_PINS_MASK};
let p: nrf51::Peripherals = _;
let PinsByKind {display_pins, ..} = p.GPIO.split_by_kind();
let mut display_port = DisplayPort::new(display_pins);
// Row whose third column is the top-right led
const UPPER_RIGHT_ROW : u32 = row_pin_number(0);
// Row whose third column is the bottom-left led
const LOWER_LEFT_ROW : u32 = row_pin_number(2);

// Set all cols except the third high
display_port.set(COL_PINS_MASK ^ 1<<col_pin_number(2));

// Light the top-right LED
display_port.set(1<<UPPER_RIGHT_ROW);
// (sleep a short time here)
// Clear the top-right LED
display_port.clear(1<<UPPER_RIGHT_ROW);
// (sleep a short time here)

// Light the bottom-left LED
display_port.set(1<<LOWER_LEFT_ROW);
// (sleep a short time here)
// Clear the bottom-left LED
display_port.clear(1<<LOWER_LEFT_ROW);
// (sleep a short time here)

A runnable example is available as examples/use_display_port.rs.

Implementations§

Source§

impl DisplayPort

Source

pub fn new(pins: DisplayPins) -> DisplayPort

Takes ownership of the display’s GPIO pins and returns a DisplayPort.

Sets the pins to output mode.

Sets all the pins low (blanking the display).

Source

pub fn free(self) -> DisplayPins

Gives the underlying DisplayPins instance back.

Source

pub fn set(&mut self, pins: u32)

Sets the specified pins high, leaving the others unchanged.

The u32 pins parameter is a bitmask representing the set of pins to affect: a 1 in bit position n says to set GPIO pin n.

Bits in pins not representing row or column pins are ignored.

Source

pub fn clear(&mut self, pins: u32)

Sets the specified pins low, leaving the others unchanged.

The u32 pins parameter is a bitmask representing the set of pins to affect: a 1 in bit position n says to clear GPIO pin n.

Bits in pins not representing row or column pins are ignored.

Source

pub fn blank(&mut self)

Sets all pins low, blanking the display.

Trait Implementations§

Source§

impl DisplayControl for DisplayPort

Implementation of DisplayControl for the micro:bit’s GPIO peripheral.

This controls the micro:bit’s 5×5 LED display.

Source§

fn initialise_for_display(&mut self)

Performs any required hardware initialisation. Read more
Source§

fn display_row_leds(&mut self, row: usize, cols: u32)

Lights LEDs in a single matrix row. Read more
Source§

fn light_current_row_leds(&mut self, cols: u32)

Lights additional LEDs in the current matrix row. Read more

Auto Trait Implementations§

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.