Display_Lib_RPI 2.3.0
A C++ Library to connect electronic displays to Linux single board computers.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
MAX7219_SS_RPI Class Reference

Drive MAX7219 seven segment displays. More...

#include <MAX7219_7SEG_RDL.hpp>

Public Types

enum  DecodeMode_e : uint8_t { DecodeModeNone = 0x00 , DecodeModeBCDOne = 0x01 , DecodeModeBCDTwo = 0x0F , DecodeModeBCDThree = 0xFF }
 
enum  CodeBFont_e : uint8_t {
  CodeBFontZero = 0x00 , CodeBFontOne = 0x01 , CodeBFontTwo = 0x02 , CodeBFontThree = 0x03 ,
  CodeBFontFour = 0x04 , CodeBFontFive = 0x05 , CodeBFontSix = 0x06 , CodeBFontSeven = 0x07 ,
  CodeBFontEight = 0x08 , CodeBFontNine = 0x09 , CodeBFontDash = 0x0A , CodeBFontE = 0x0B ,
  CodeBFontH = 0x0C , CodeBFontL = 0x0D , CodeBFontP = 0x0E , CodeBFontSpace = 0x0F
}
 
enum  TextAlignment_e : uint8_t { AlignLeft = 0 , AlignRight = 1 , AlignRightZeros = 2 }
 
enum  DecimalPoint_e : uint8_t { DecPointOff = 0 , DecPointOn = 1 }
 
enum  Intensity_e : uint8_t { IntensityMin = 0x00 , IntensityDefault = 0x08 , IntensityMax = 0x0F }
 
enum  ScanLimit_e : uint8_t {
  ScanOneDigit = 0x00 , ScanTwoDigit = 0x01 , ScanThreeDigit = 0x02 , ScanFourDigit = 0x03 ,
  ScanFiveDigit = 0x04 , ScanSixDigit = 0x05 , ScanSevenDigit = 0x06 , ScanEightDigit = 0x07
}
 
enum  RegisterModes_e : uint8_t {
  MAX7219_REG_NOP = 0x00 , MAX7219_REG_DecodeMode = 0x09 , MAX7219_REG_Intensity = 0x0A , MAX7219_REG_ScanLimit = 0x0B ,
  MAX7219_REG_ShutDown = 0x0C , MAX7219_REG_DisplayTest = 0x0F
}
 

Public Member Functions

 MAX7219_SS_RPI (uint8_t clock, uint8_t chipSelect, uint8_t data, int gpioDev)
 Constructor for class MAX7219_SS_RPI software SPI.
 
 MAX7219_SS_RPI (int device, int channel, int speed, int flags)
 Constructor for class MAX7219_SS_RPI hardware SPI.
 
rdlib::Return_Codes_e InitDisplay (ScanLimit_e numDigits, DecodeMode_e decodeMode)
 Init the display.
 
void ClearDisplay (void)
 Clear the display.
 
rdlib::Return_Codes_e DisplayEndOperations (void)
 End display operations, called at end of program.
 
void SetBrightness (uint8_t brightness)
 sets the brighttness of display
 
void DisplayTestMode (bool OnOff)
 Turn on and off the Display Test Mode.
 
void ShutdownMode (bool OnOff)
 Turn on and off the Shutdown Mode.
 
uint16_t GetCommDelay (void)
 Get the communication delay value.
 
void SetCommDelay (uint16_t commDelay)
 Set the communication delay value.
 
bool GetHardwareSPI (void)
 get value of _HardwareSPI , true hardware SPI on , false off.
 
uint8_t GetCurrentDisplayNumber (void)
 Get the Current Display Number.
 
void SetCurrentDisplayNumber (uint8_t)
 Set the Current Display Number.
 
void DisplayChar (uint8_t digit, uint8_t value, DecimalPoint_e decimalPoint)
 Displays a character on display.
 
void DisplayText (char *text, TextAlignment_e TextAlignment)
 Displays a text string on display.
 
void DisplayText (char *text)
 Displays a text string on display.
 
void DisplayIntNum (unsigned long number, TextAlignment_e TextAlignment)
 Display an integer and leading zeros optional.
 
void DisplayDecNumNibble (uint16_t numberUpper, uint16_t numberLower, TextAlignment_e TextAlignment)
 Display an integer in a nibble (4 digits on display)
 
void DisplayBCDChar (uint8_t digit, CodeBFont_e value)
 Displays a character on display using MAX7219 Built in BCD code B font.
 
void DisplayBCDText (char *text)
 Displays a BCD text string on display using MAX7219 Built in BCD code B font.
 
void SetSegment (uint8_t digit, uint8_t segment)
 Set a seven segment LED ON.
 

Private Member Functions

void HighFreqshiftOut (uint8_t value)
 Shifts out a uint8_t of data on to the MAX7219 SPI-like bus.
 
void WriteDisplay (uint8_t RegisterCode, uint8_t data)
 Write to the MAX7219 display register.
 
uint8_t ASCIIFetch (uint8_t character, DecimalPoint_e decimalPoint)
 Fetch's the seven segment code for a given ASCII code from the font.
 
void SetDecodeMode (DecodeMode_e mode)
 Set the decode mode of the MAX7219 decode mode register.
 
void SetScanLimit (ScanLimit_e numDigits)
 Set the decode mode of the MAX7219 decode mode register.
 
uint8_t flipBitsPreserveMSB (uint8_t byte)
 Flips the positions of bits in a byte while preserving the MSB bit.
 

Private Attributes

uint8_t _Display_CS
 
uint8_t _Display_SDATA
 
uint8_t _Display_SCLK
 
uint16_t _CommDelay = 0
 
uint8_t _NoDigits = 8
 
int _DeviceNumGpioChip = 0
 
int _GpioHandle = 0
 
int _spiHandle = 0
 
int _spiDev = 0
 
int _spiChan = 0
 
int _spiBaud = 50000
 
int _spiFlags = 0
 
bool _HardwareSPI = false
 
DecodeMode_e CurrentDecodeMode
 
uint8_t _CurrentDisplayNumber = 1
 

Detailed Description

Drive MAX7219 seven segment displays.

Member Enumeration Documentation

◆ CodeBFont_e

sets BCD code B font (0-9, E, H, L,P, and -) Built-in font

Enumerator
CodeBFontZero 

Code B decode for Zero

CodeBFontOne 

Code B decode for One

CodeBFontTwo 

Code B decode for Two

CodeBFontThree 

Code B decode for Three

CodeBFontFour 

Code B decode for Four

CodeBFontFive 

Code B decode for Five

CodeBFontSix 

Code B decode for Six

CodeBFontSeven 

Code B decode for Seven

CodeBFontEight 

Code B decode for Eight

CodeBFontNine 

Code B decode for Nine

CodeBFontDash 

Code B decode for Dash

CodeBFontE 

Code B decode for letter E

CodeBFontH 

Code B decode for letter H

CodeBFontL 

Code B decode for letter L

CodeBFontP 

Code B decode for letter P

CodeBFontSpace 

Code B decode for Space

◆ DecimalPoint_e

Activate Decimal point segment

Enumerator
DecPointOff 

Decimal point segment off

DecPointOn 

Decimal point segment on

◆ DecodeMode_e

The decode-mode register sets BCD code B or no-decode operation for each digit

Enumerator
DecodeModeNone 

No decode for digits 7–0

DecodeModeBCDOne 

Code B decode for digit 0, No decode for digits 7–1

DecodeModeBCDTwo 

Code B decode for digits 3–0, No decode for digits 7–4

DecodeModeBCDThree 

Code B decode for digits 7–0

◆ Intensity_e

Set intensity/brightness of Display

Enumerator
IntensityMin 

Minimum Intensity

IntensityDefault 

Default Intensity

IntensityMax 

Maximum Intensity

◆ RegisterModes_e

Register opcodes of the MAZ7219 chip, Register Address Map

Enumerator
MAX7219_REG_NOP 

No operation

MAX7219_REG_DecodeMode 

Decode-Mode Register

MAX7219_REG_Intensity 

Intensity Register, brightness of display

MAX7219_REG_ScanLimit 

Scan Limit, The scan-limit register sets how many digits are displayed

MAX7219_REG_ShutDown 

When the MAX7219 is in shutdown mode, the scan oscillator is halted, all segment current sources are pulled to ground, and all digit drivers are pulled to V+, thereby blanking the display.

MAX7219_REG_DisplayTest 

Display-test mode turns all LEDs on by overriding, but not altering, all controls and digit registers

◆ ScanLimit_e

The scan-limit register sets how many digits are displayed

Enumerator
ScanOneDigit 

Scan One digit

ScanTwoDigit 

Scan Two digit

ScanThreeDigit 

Scan Three digit

ScanFourDigit 

Scan Four digit

ScanFiveDigit 

Scan Five digit

ScanSixDigit 

Scan Six digit

ScanSevenDigit 

Scan Seven digit

ScanEightDigit 

Scan Eight digit

◆ TextAlignment_e

Alignment of text on display

Enumerator
AlignLeft 

Align text to the left on display

AlignRight 

Align text to the right on display

AlignRightZeros 

Add leading zeros to the text

Constructor & Destructor Documentation

◆ MAX7219_SS_RPI() [1/2]

MAX7219_SS_RPI::MAX7219_SS_RPI ( uint8_t  clock,
uint8_t  chipSelect,
uint8_t  data,
int  gpioDev 
)

Constructor for class MAX7219_SS_RPI software SPI.

Parameters
clockCLk pin
chipSelectCS pin
dataDIO pin
gpioDevThe device number of a gpiochip. @
Note
overloaded this one is for Software SPI

◆ MAX7219_SS_RPI() [2/2]

MAX7219_SS_RPI::MAX7219_SS_RPI ( int  device,
int  channel,
int  speed,
int  flags 
)

Constructor for class MAX7219_SS_RPI hardware SPI.

Parameters
deviceA SPI device, >= 0.
channelA SPI channel, >= 0.
speedThe speed of serial communication in bits per second.
flagsThe flags may be used to modify the default behaviour. Set to 0(mode 0) for this device.
Note
overloaded this one is for Hardware SPI

Member Function Documentation

◆ ASCIIFetch()

uint8_t MAX7219_SS_RPI::ASCIIFetch ( uint8_t  character,
DecimalPoint_e  decimalPoint 
)
private

Fetch's the seven segment code for a given ASCII code from the font.

Parameters
characterThe ASCII character to lookup
decimalPointIs the decimal point(dp) to be set or not.
Returns
The seven segment representation of the ASCII character in a byte dpabcdefg

◆ DisplayBCDChar()

void MAX7219_SS_RPI::DisplayBCDChar ( uint8_t  digit,
CodeBFont_e  value 
)

Displays a character on display using MAX7219 Built in BCD code B font.

Parameters
digitThe digit to display character in, 7-0 ,7 = LHS 0 =RHS
valueThe BCD character to display
Note
sets BCD code B font (0-9, E, H, L,P, and -) Built-in font

◆ DisplayBCDText()

void MAX7219_SS_RPI::DisplayBCDText ( char *  text)

Displays a BCD text string on display using MAX7219 Built in BCD code B font.

Parameters
textpointer to character array containg text string
Note
sets BCD code B font (0-9, E, H, L,P, and -) Built-in font

◆ DisplayChar()

void MAX7219_SS_RPI::DisplayChar ( uint8_t  digit,
uint8_t  character,
DecimalPoint_e  decimalPoint 
)

Displays a character on display.

Parameters
digitThe digit to display character in, 7-0 ,7 = LHS 0 =RHS
characterThe ASCII character to display
decimalPointIs the decimal point(dp) to be set or not.

◆ DisplayDecNumNibble()

void MAX7219_SS_RPI::DisplayDecNumNibble ( uint16_t  numberUpper,
uint16_t  numberLower,
TextAlignment_e  TextAlignment 
)

Display an integer in a nibble (4 digits on display)

Parameters
numberUpperupper nibble integer 2^16
numberLowerlower nibble integer 2^16
TextAlignmentleft or right alignment or leading zeros
Note
Divides the display into two nibbles and displays a Decimal number in each. takes in two numbers 0-9999 for each nibble.

◆ DisplayEndOperations()

rdlib::Return_Codes_e MAX7219_SS_RPI::DisplayEndOperations ( void  )

End display operations, called at end of program.

Returns
a rdlib::Return_Codes_e code
  1. rdlib::Success
  2. rdlib::GpioPinFree
  3. rdlib::SPICloseFailure
  4. rdlib::GpioChipDevice

◆ DisplayIntNum()

void MAX7219_SS_RPI::DisplayIntNum ( unsigned long  number,
TextAlignment_e  TextAlignment 
)

Display an integer and leading zeros optional.

Parameters
numberinteger to display 2^32
TextAlignmentenum text alignment, left or right alignment or leading zeros

◆ DisplayTestMode()

void MAX7219_SS_RPI::DisplayTestMode ( bool  OnOff)

Turn on and off the Display Test Mode.

Parameters
OnOfftrue = display test mode on , false display Test Mode off
Note
Display-test mode turns all LEDs on

◆ DisplayText() [1/2]

void MAX7219_SS_RPI::DisplayText ( char *  text)

Displays a text string on display.

Parameters
textpointer to character array containg text string
Note
This method is overloaded, see also DisplayText(char *, TextAlignment_e )

◆ DisplayText() [2/2]

void MAX7219_SS_RPI::DisplayText ( char *  text,
TextAlignment_e  TextAlignment 
)

Displays a text string on display.

Parameters
textpointer to character array containg text string
TextAlignmentleft or right alignment or leading zeros
Note
This method is overloaded, see also DisplayText(char *)

◆ flipBitsPreserveMSB()

uint8_t MAX7219_SS_RPI::flipBitsPreserveMSB ( uint8_t  byte)
private

Flips the positions of bits in a byte while preserving the MSB bit.

Parameters
byteA byte of data, ASCII character
Returns
A byte from font representing LED segment data with bits positions flipped and MSB bit value preserved

The reason for this function is that the MAX7219 requires ASCII segment data in following order : dp-abcdefg but the font we use is dp-gfedcba where letters represent seven segment LEDS, and dp represents decimal point.. We flip the bits in the code rather than change the font data in font file because the font data is used by other modules(TM1638 + TM1637) and they use dp-gfedcba order. Thus we can share same font file between all seven segment modules.

◆ GetCommDelay()

uint16_t MAX7219_SS_RPI::GetCommDelay ( void  )

Get the communication delay value.

Returns
Get the communication delay value uS Software SPi

◆ GetCurrentDisplayNumber()

uint8_t MAX7219_SS_RPI::GetCurrentDisplayNumber ( void  )

Get the Current Display Number.

Returns
Get the Current Display Number

◆ GetHardwareSPI()

bool MAX7219_SS_RPI::GetHardwareSPI ( void  )

get value of _HardwareSPI , true hardware SPI on , false off.

Returns
_HardwareSPI , true hardware SPI on , false off.

◆ HighFreqshiftOut()

void MAX7219_SS_RPI::HighFreqshiftOut ( uint8_t  value)
private

Shifts out a uint8_t of data on to the MAX7219 SPI-like bus.

Parameters
valueThe uint8_t of data to shift out
Note
_CommDelay microsecond delay may have to be adjusted depending on processor

◆ InitDisplay()

rdlib::Return_Codes_e MAX7219_SS_RPI::InitDisplay ( ScanLimit_e  numDigits,
DecodeMode_e  decodeMode 
)

Init the display.

Parameters
numDigitsscan limit set to 8 normally , advanced use only
decodeModeMust users will use 0x00 here
Returns
a rdlib::Return_Codes_e code
  1. rdlib::Success
  2. rdlib::GpioPinCliam
  3. rdlib::SPIOpenFailure
  4. rdlib::GpioChipDevice
Note
when cascading supplies init display one first always!

◆ SetBrightness()

void MAX7219_SS_RPI::SetBrightness ( uint8_t  brightness)

sets the brighttness of display

Parameters
brightnessrang 0x00 to 0x0F , 0x00 being least bright.

◆ SetCommDelay()

void MAX7219_SS_RPI::SetCommDelay ( uint16_t  commDelay)

Set the communication delay value.

Parameters
commDelaySet the communication delay value uS software SPI

◆ SetCurrentDisplayNumber()

void MAX7219_SS_RPI::SetCurrentDisplayNumber ( uint8_t  DisplayNum)

Set the Current Display Number.

Parameters
DisplayNumSet the Current Display Number

◆ SetDecodeMode()

void MAX7219_SS_RPI::SetDecodeMode ( DecodeMode_e  mode)
private

Set the decode mode of the MAX7219 decode mode register.

Parameters
modeSet to 0x00 for most users

◆ SetScanLimit()

void MAX7219_SS_RPI::SetScanLimit ( ScanLimit_e  numDigits)
private

Set the decode mode of the MAX7219 decode mode register.

Parameters
numDigitsUsually set to 7(digit 8) The scan-limit register sets how many digits are displayed, from 1 to 8.
Note
Advanced users only , read datasheet

◆ SetSegment()

void MAX7219_SS_RPI::SetSegment ( uint8_t  digit,
uint8_t  segment 
)

Set a seven segment LED ON.

Parameters
digitThe digit to set segment in, 7-0 ,7 = LHS 0 =RHS
segmentThe segment of seven segment to set dpabcdefg

◆ ShutdownMode()

void MAX7219_SS_RPI::ShutdownMode ( bool  OnOff)

Turn on and off the Shutdown Mode.

Parameters
OnOfftrue = Shutdown mode on , false shutdown mode off
Note
power saving mode

◆ WriteDisplay()

void MAX7219_SS_RPI::WriteDisplay ( uint8_t  RegisterCode,
uint8_t  data 
)
private

Write to the MAX7219 display register.

Parameters
RegisterCodethe register to write to
dataThe data byte to send to register

Member Data Documentation

◆ _CommDelay

uint16_t MAX7219_SS_RPI::_CommDelay = 0
private

uS delay used in communications SW SPI, User adjust

◆ _CurrentDisplayNumber

uint8_t MAX7219_SS_RPI::_CurrentDisplayNumber = 1
private

Which display the user wishes to write to in a cascade of connected displays

◆ _DeviceNumGpioChip

int MAX7219_SS_RPI::_DeviceNumGpioChip = 0
private

SWSPI The device number of a gpiochip ls /dev/gpio

◆ _Display_CS

uint8_t MAX7219_SS_RPI::_Display_CS
private

GPIO connected to CS on MAX7219, SW SPI only

◆ _Display_SCLK

uint8_t MAX7219_SS_RPI::_Display_SCLK
private

GPIO connected to CLK on MAX7219, SW SPI only

◆ _Display_SDATA

uint8_t MAX7219_SS_RPI::_Display_SDATA
private

GPIO connected to DIO on MAX7219, SW SPI only

◆ _GpioHandle

int MAX7219_SS_RPI::_GpioHandle = 0
private

This holds a handle to a device opened by lgGpiochipOpen

◆ _HardwareSPI

bool MAX7219_SS_RPI::_HardwareSPI = false
private

Is the Hardware SPI on , true yes , false SW SPI

◆ _NoDigits

uint8_t MAX7219_SS_RPI::_NoDigits = 8
private

Number of digits in display

◆ _spiBaud

int MAX7219_SS_RPI::_spiBaud = 50000
private

The speed of serial communication in bits per second.

◆ _spiChan

int MAX7219_SS_RPI::_spiChan = 0
private

A SPI channel, >= 0.

◆ _spiDev

int MAX7219_SS_RPI::_spiDev = 0
private

A SPI device, >= 0.

◆ _spiFlags

int MAX7219_SS_RPI::_spiFlags = 0
private

The flags 2 LSB defines SPI mode See MAX7219_SS_RPI constructor notes

◆ _spiHandle

int MAX7219_SS_RPI::_spiHandle = 0
private

Hold a handle for the SPI device on the channel lgSpiOpen(

◆ CurrentDecodeMode

DecodeMode_e MAX7219_SS_RPI::CurrentDecodeMode
private

Enum to store current decode mode


The documentation for this class was generated from the following files: