Grzegorz Kaczmarek
/
Max7221
Fix to have load pin working with SPI1.
Fork of Max7221 by
MAX7221/Max7221.h@1:d8589d1f368c, 2013-08-06 (annotated)
- Committer:
- jakowisp
- Date:
- Tue Aug 06 08:18:53 2013 +0000
- Revision:
- 1:d8589d1f368c
- Child:
- 2:828c62cc1861
Library mostly complete. Need to clean up code and document.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jakowisp | 1:d8589d1f368c | 1 | #ifndef Max7221_H |
jakowisp | 1:d8589d1f368c | 2 | #define Max7221_H |
jakowisp | 1:d8589d1f368c | 3 | |
jakowisp | 1:d8589d1f368c | 4 | // define max7219/max7221 registers |
jakowisp | 1:d8589d1f368c | 5 | #define max7219_reg_noop 0x00 |
jakowisp | 1:d8589d1f368c | 6 | #define max7219_reg_digit0 0x01 |
jakowisp | 1:d8589d1f368c | 7 | #define max7219_reg_digit1 0x02 |
jakowisp | 1:d8589d1f368c | 8 | #define max7219_reg_digit2 0x03 |
jakowisp | 1:d8589d1f368c | 9 | #define max7219_reg_digit3 0x04 |
jakowisp | 1:d8589d1f368c | 10 | #define max7219_reg_digit4 0x05 |
jakowisp | 1:d8589d1f368c | 11 | #define max7219_reg_digit5 0x06 |
jakowisp | 1:d8589d1f368c | 12 | #define max7219_reg_digit6 0x07 |
jakowisp | 1:d8589d1f368c | 13 | #define max7219_reg_digit7 0x08 |
jakowisp | 1:d8589d1f368c | 14 | #define max7219_reg_decodeMode 0x09 |
jakowisp | 1:d8589d1f368c | 15 | #define max7219_reg_intensity 0x0a |
jakowisp | 1:d8589d1f368c | 16 | #define max7219_reg_scanLimit 0x0b |
jakowisp | 1:d8589d1f368c | 17 | #define max7219_reg_shutdown 0x0c |
jakowisp | 1:d8589d1f368c | 18 | #define max7219_reg_displayTest 0x0f |
jakowisp | 1:d8589d1f368c | 19 | |
jakowisp | 1:d8589d1f368c | 20 | #define LOW 0 |
jakowisp | 1:d8589d1f368c | 21 | #define HIGH 1 |
jakowisp | 1:d8589d1f368c | 22 | #define MHZ 1000000 |
jakowisp | 1:d8589d1f368c | 23 | #define NUMDIGITS 8 |
jakowisp | 1:d8589d1f368c | 24 | |
jakowisp | 1:d8589d1f368c | 25 | #ifdef NUMDIGITS |
jakowisp | 1:d8589d1f368c | 26 | #define UPPERBOUND 99999999 |
jakowisp | 1:d8589d1f368c | 27 | #define LOWERBOUND -9999999 |
jakowisp | 1:d8589d1f368c | 28 | #endif |
jakowisp | 1:d8589d1f368c | 29 | |
jakowisp | 1:d8589d1f368c | 30 | class Max7221 { |
jakowisp | 1:d8589d1f368c | 31 | public: |
jakowisp | 1:d8589d1f368c | 32 | Max7221(PinName msoi=p5, PinName mclk=p7, PinName load=p8); |
jakowisp | 1:d8589d1f368c | 33 | |
jakowisp | 1:d8589d1f368c | 34 | void Write( unsigned int reg, unsigned int col); |
jakowisp | 1:d8589d1f368c | 35 | |
jakowisp | 1:d8589d1f368c | 36 | void WriteInt( int value ); |
jakowisp | 1:d8589d1f368c | 37 | void WriteFloat( float value); |
jakowisp | 1:d8589d1f368c | 38 | Max7221& operator= (int value){ |
jakowisp | 1:d8589d1f368c | 39 | WriteInt(value); |
jakowisp | 1:d8589d1f368c | 40 | return *this; |
jakowisp | 1:d8589d1f368c | 41 | }; |
jakowisp | 1:d8589d1f368c | 42 | Max7221& operator= (float value){ |
jakowisp | 1:d8589d1f368c | 43 | WriteFloat(value); |
jakowisp | 1:d8589d1f368c | 44 | return *this; |
jakowisp | 1:d8589d1f368c | 45 | }; |
jakowisp | 1:d8589d1f368c | 46 | |
jakowisp | 1:d8589d1f368c | 47 | void Setup (void); |
jakowisp | 1:d8589d1f368c | 48 | |
jakowisp | 1:d8589d1f368c | 49 | static void WriteAll (unsigned int reg, unsigned int col); |
jakowisp | 1:d8589d1f368c | 50 | static void SetupAll (void); |
jakowisp | 1:d8589d1f368c | 51 | |
jakowisp | 1:d8589d1f368c | 52 | private: |
jakowisp | 1:d8589d1f368c | 53 | SPI *max72_spi; |
jakowisp | 1:d8589d1f368c | 54 | DigitalOut *load; |
jakowisp | 1:d8589d1f368c | 55 | int id; |
jakowisp | 1:d8589d1f368c | 56 | int *maxInUse; |
jakowisp | 1:d8589d1f368c | 57 | |
jakowisp | 1:d8589d1f368c | 58 | |
jakowisp | 1:d8589d1f368c | 59 | static SPI *spi1; |
jakowisp | 1:d8589d1f368c | 60 | static SPI *spi2; |
jakowisp | 1:d8589d1f368c | 61 | static DigitalOut *load1; |
jakowisp | 1:d8589d1f368c | 62 | static DigitalOut *load2; |
jakowisp | 1:d8589d1f368c | 63 | static int maxInUseSPI1; |
jakowisp | 1:d8589d1f368c | 64 | static int maxInUseSPI2; |
jakowisp | 1:d8589d1f368c | 65 | |
jakowisp | 1:d8589d1f368c | 66 | }; |
jakowisp | 1:d8589d1f368c | 67 | |
jakowisp | 1:d8589d1f368c | 68 | #endif |