Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Max7221 by
Max7221.h
00001 /** 00002 * @file Max7221.h 00003 * @brief Header file for the MAX7219/7221 driver class. 00004 * 00005 * @author Grzegorz Kaczmarek 00006 * @comment Code inspired on earlier Dwayne S. Dilbeck's work 00007 * @date 20/11/2015 00008 */ 00009 00010 #ifndef Max7221_H 00011 #define Max7221_H 00012 00013 // MAX7219/7221 register map 00014 #define max7221_reg_noop 0x00 00015 #define max7221_reg_digit0 0x01 00016 #define max7221_reg_digit1 0x02 00017 #define max7221_reg_digit2 0x03 00018 #define max7221_reg_digit3 0x04 00019 #define max7221_reg_digit4 0x05 00020 #define max7221_reg_digit5 0x06 00021 #define max7221_reg_digit6 0x07 00022 #define max7221_reg_digit7 0x08 00023 #define max7221_reg_decodeMode 0x09 00024 #define max7221_reg_intensity 0x0A 00025 #define max7221_reg_scanLimit 0x0B 00026 #define max7221_reg_shutdown 0x0C 00027 #define max7221_reg_displayTest 0x0F 00028 00029 // Logical values 00030 #define LOG_0 0 00031 #define LOG_1 1 00032 00033 class Max7221 { 00034 private: 00035 static SPI *mp_spi; // SPI used for this display (no data transmission when NULL) 00036 static DigitalOut *mp_cs; // /CS signal (it should be handled manually when NULL) 00037 static unsigned int m_counter; // Total number of displays on SPI chain 00038 unsigned int m_position; // Display position on SPI chain (0 = 1'st) 00039 public: 00040 /** 00041 * Default constructor. 00042 * At least one instance should set SPI and /CS pointers for display chain to work. 00043 * Use SetSpi() and SetCs() or parametrized constructor. 00044 */ 00045 Max7221(); 00046 00047 /** 00048 * Constructor. 00049 * Sets SPI and /CS pointers. Display chain is operational. 00050 */ 00051 Max7221(SPI *spi, DigitalOut *cs); 00052 00053 /** 00054 * Sets pointer to configured SPI. 00055 * SPI is used by all display instances. 00056 */ 00057 void SetSpi(SPI *spi); 00058 00059 /** 00060 * Sets pointer to configured /CS signal. 00061 * /CS signal is used by all display instances. 00062 */ 00063 void SetCs(DigitalOut *cs); 00064 00065 /** 00066 * Method for setting /CS signal LOW (enable data reception). 00067 */ 00068 void CsLow(void); 00069 00070 /** 00071 * Method for setting /CS signal HIGH (received data is latched and processed). 00072 */ 00073 void CsHigh(void); 00074 00075 /** 00076 * Method used to send data over SPI (no use of /CS signal). 00077 * To be used with display chains and when building display libraries 00078 * where amount of data needs to be pushed via SPI in one transaction. 00079 */ 00080 void WriteRaw(unsigned int reg, unsigned int data); 00081 00082 /** 00083 * Method for sending register-value pair for this diasplay. 00084 * Supports display chain on single SPI (m_position > 0). 00085 */ 00086 void Write(unsigned int reg, unsigned int data); 00087 00088 /** 00089 * Sets test mode which causes all display LEDs to emit light with full brightess. 00090 * @param mode true - test mode, false - normal operation. 00091 */ 00092 void TestMode(bool mode); 00093 00094 /** 00095 * Sets amount of digits to be used by this display. 00096 * @param digits_no 1 - one digit, (2-7), 8 - all 8 digits. 00097 */ 00098 void UseDigitsNo(unsigned int digits_no); 00099 00100 /** 00101 * Selects for which digits Code-B data decoding is used. 00102 * @param mode 0x00 - no decoding, 0x0F - digits 0-3, 0xFF - all digits. 00103 */ 00104 void DecodeMode(unsigned int mode); 00105 00106 /** 00107 * Sends data to selected digit. 00108 * @param digit_no Selected digit (0-7). 00109 * @param digit_no Data to display. 00110 */ 00111 void WriteDigit(unsigned int digit_no, unsigned int value); 00112 00113 /** 00114 * Sets display brightness. 00115 * @param intensity 0x00 - minimum brightness, 0x0F - maximum brightness. 00116 */ 00117 void Intensity(unsigned int intensity); 00118 00119 /** 00120 * Sets display operation mode. 00121 * @param mode true - normal operation, false - shutdown mode. 00122 */ 00123 void OperationMode(bool mode); 00124 00125 /** 00126 * Initial setup of this display. 00127 * 8-digit blank decimal display set to nimimal brightness. 00128 * Supports display chain on single SPI (m_position > 0). 00129 */ 00130 void Setup(void); 00131 }; 00132 00133 #endif
Generated on Sat Jul 16 2022 23:52:39 by
