Struct max7219::MAX7219

source ·
pub struct MAX7219<CONNECTOR> { /* private fields */ }
Expand description

Handles communication with the MAX7219 chip for segmented displays. Each display can be connected in series with another and controlled via a single connection. The actual connection interface is selected via constructor functions.

Implementations§

source§

impl<CONNECTOR> MAX7219<CONNECTOR>
where CONNECTOR: Connector,

source

pub fn power_on(&mut self) -> Result<(), DataError>

Powers on all connected displays

Errors
  • DataError - returned in case there was an error during data transfer
source

pub fn power_off(&mut self) -> Result<(), DataError>

Powers off all connected displays

Errors
  • DataError - returned in case there was an error during data transfer
source

pub fn clear_display(&mut self, addr: usize) -> Result<(), DataError>

Clears display by settings all digits to empty

Arguments
  • addr - display to address as connected in series (0 -> last)
Errors
  • DataError - returned in case there was an error during data transfer
source

pub fn set_intensity( &mut self, addr: usize, intensity: u8 ) -> Result<(), DataError>

Sets intensity level on the display

Arguments
  • addr - display to address as connected in series (0 -> last)
  • intensity - intensity value to set to 0x00 to 0x0F`
Errors
  • DataError - returned in case there was an error during data transfer
source

pub fn set_decode_mode( &mut self, addr: usize, mode: DecodeMode ) -> Result<(), DataError>

Sets decode mode to be used on input sent to the display chip.

Arguments
  • addr - display to address as connected in series (0 -> last)
  • mode - the decode mode to set
Errors
  • DataError - returned in case there was an error during data transfer
source

pub fn write_str( &mut self, addr: usize, string: &[u8; 8], dots: u8 ) -> Result<(), DataError>

Writes byte string to the display

Arguments
  • addr - display to address as connected in series (0 -> last)
  • string - the byte string to send 8 bytes long. Unknown characters result in question mark.
  • dots - u8 bit array specifying where to put dots in the string (1 = dot, 0 = not)
Errors
  • DataError - returned in case there was an error during data transfer
source

pub fn write_bcd(&mut self, addr: usize, bcd: &[u8; 8]) -> Result<(), DataError>

Writes BCD encoded string to the display

Arguments
  • addr - display to address as connected in series (0 -> last)
  • bcd - the bcd encoded string slice consisting of [0-9,-,E,L,H,P] where upper case input for alphabetic characters results in dot being set. Length of string is always 8 bytes, use spaces for blanking.
Errors
  • DataError - returned in case there was an error during data transfer
source

pub fn write_integer( &mut self, addr: usize, value: i32 ) -> Result<(), DataError>

Writes a right justified integer with sign

Arguments
  • addr - display to address as connected in series (0 -> last)
  • val - an integer i32
Errors
  • DataError - returned in case there was an integer over flow
source

pub fn write_hex(&mut self, addr: usize, value: u32) -> Result<(), DataError>

Writes a right justified hex formatted integer with sign

Arguments
  • addr - display to address as connected in series (0 -> last)
  • val - an integer i32
Errors
  • DataError - returned in case there was an integer over flow
source

pub fn write_raw(&mut self, addr: usize, raw: &[u8; 8]) -> Result<(), DataError>

Writes a raw value to the display

Arguments
  • addr - display to address as connected in series (0 -> last)
  • raw - an array of raw bytes to write. Each bit represents a pixel on the display
Errors
  • DataError - returned in case there was an error during data transfer
source

pub fn write_raw_byte( &mut self, addr: usize, header: u8, data: u8 ) -> Result<(), DataError>

Writes a single byte to the underlying display. This method is very low-level: most users will prefer to use one of the other write_* methods.

Arguments
  • addr - display to address as connected in series (0 -> last)
  • header - the register to write the value to
  • data - the value to write
Errors
  • DataError - returned in case there was an error during data transfer
source

pub fn test(&mut self, addr: usize, is_on: bool) -> Result<(), DataError>

Set test mode on/off

Arguments
  • addr - display to address as connected in series (0 -> last)
  • is_on - whether to turn test mode on or off
Errors
  • DataError - returned in case there was an error during data transfer
source§

impl<DATA, CS, SCK> MAX7219<PinConnector<DATA, CS, SCK>>
where DATA: OutputPin, CS: OutputPin, SCK: OutputPin,

source

pub fn from_pins( displays: usize, data: DATA, cs: CS, sck: SCK ) -> Result<Self, DataError>

Construct a new MAX7219 driver instance from DATA, CS and SCK pins.

Arguments
  • displays - number of displays connected in series
  • data - the MOSI/DATA PIN used to send data through to the display set to output mode
  • cs - the CS PIN used to LOAD register on the display set to output mode
  • sck - the SCK clock PIN used to drive the clock set to output mode
Errors
  • DataError - returned in case there was an error during data transfer
source§

impl<SPI> MAX7219<SpiConnector<SPI>>
where SPI: Write<u8>,

source

pub fn from_spi(displays: usize, spi: SPI) -> Result<Self, DataError>

Construct a new MAX7219 driver instance from pre-existing SPI in full hardware mode. The SPI will control CS (LOAD) line according to it’s internal mode set. If you need the CS line to be controlled manually use MAX7219::from_spi_cs

  • NOTE - make sure the SPI is initialized in MODE_0 with max 10 Mhz frequency.
Arguments
  • displays - number of displays connected in series
  • spi - the SPI interface initialized with MOSI, MISO(unused) and CLK
Errors
  • DataError - returned in case there was an error during data transfer
source§

impl<SPI, CS> MAX7219<SpiConnectorSW<SPI, CS>>
where SPI: Write<u8>, CS: OutputPin,

source

pub fn from_spi_cs(displays: usize, spi: SPI, cs: CS) -> Result<Self, DataError>

Construct a new MAX7219 driver instance from pre-existing SPI and CS pin set to output. This version of the connection uses the CS pin manually to avoid issues with how the CS mode is handled in hardware SPI implementations.

  • NOTE - make sure the SPI is initialized in MODE_0 with max 10 Mhz frequency.
Arguments
  • displays - number of displays connected in series
  • spi - the SPI interface initialized with MOSI, MISO(unused) and CLK
  • cs - the CS PIN used to LOAD register on the display set to output mode
Errors
  • DataError - returned in case there was an error during data transfer

Auto Trait Implementations§

§

impl<CONNECTOR> RefUnwindSafe for MAX7219<CONNECTOR>
where CONNECTOR: RefUnwindSafe,

§

impl<CONNECTOR> Send for MAX7219<CONNECTOR>
where CONNECTOR: Send,

§

impl<CONNECTOR> Sync for MAX7219<CONNECTOR>
where CONNECTOR: Sync,

§

impl<CONNECTOR> Unpin for MAX7219<CONNECTOR>
where CONNECTOR: Unpin,

§

impl<CONNECTOR> UnwindSafe for MAX7219<CONNECTOR>
where CONNECTOR: UnwindSafe,

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.