[][src]Struct rmicrobit::display::DisplayPort

pub struct DisplayPort(_);

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.

Methods

impl DisplayPort[src]

pub fn new(pins: DisplayPins) -> DisplayPort[src]

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).

pub fn free(self) -> DisplayPins[src]

Gives the underlying DisplayPins instance back.

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

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.

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

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.

pub fn blank(&mut self)[src]

Sets all pins low, blanking the display.

Trait Implementations

impl DisplayControl for DisplayPort[src]

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

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

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self