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
impl DisplayPort
Sourcepub fn new(pins: DisplayPins) -> DisplayPort
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).
Sourcepub fn free(self) -> DisplayPins
pub fn free(self) -> DisplayPins
Gives the underlying DisplayPins
instance back.
Sourcepub fn set(&mut self, pins: u32)
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.
Trait Implementations§
Source§impl DisplayControl for DisplayPort
Implementation of DisplayControl
for the micro:bit’s GPIO peripheral.
impl DisplayControl for DisplayPort
Implementation of DisplayControl
for the micro:bit’s GPIO peripheral.
This controls the micro:bit’s 5×5 LED display.