Fix to have load pin working with SPI1.

Dependencies:   mbed

Fork of Max7221 by Dwayne Dilbeck

Committer:
jakowisp
Date:
Wed Aug 07 02:34:59 2013 +0000
Revision:
3:5abc4047af8d
Parent:
MAX7221/Max7221.h@2:828c62cc1861
Child:
4:e2b160410338
Fix Library file locations

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jakowisp 2:828c62cc1861 1 /**
jakowisp 2:828c62cc1861 2 * @file Max7221.h
jakowisp 2:828c62cc1861 3 * @brief This file contains the class defnition of Max7221 and define statements related to the class, and max7221 device
jakowisp 2:828c62cc1861 4 * The methods in this class are derived from posts on the mbed forum written by Igor Skochinsky on October 2009
jakowisp 2:828c62cc1861 5 *
jakowisp 2:828c62cc1861 6 * @author Dwayne S. Dilbeck
jakowisp 2:828c62cc1861 7 *
jakowisp 2:828c62cc1861 8 * @date 8/6/2013
jakowisp 2:828c62cc1861 9 */
jakowisp 1:d8589d1f368c 10 #ifndef Max7221_H
jakowisp 1:d8589d1f368c 11 #define Max7221_H
jakowisp 1:d8589d1f368c 12
jakowisp 2:828c62cc1861 13 /** Max7221 Example
jakowisp 2:828c62cc1861 14 * @code
jakowisp 2:828c62cc1861 15 * #include "mbed.h"
jakowisp 2:828c62cc1861 16 * #include "Max7221.h"
jakowisp 2:828c62cc1861 17 *
jakowisp 2:828c62cc1861 18 *
jakowisp 2:828c62cc1861 19 * // p5: DIN, p7: CLK, p8: LOAD/CS
jakowisp 2:828c62cc1861 20 * Max7221 max7221disp1(p5, p7, p8);
jakowisp 2:828c62cc1861 21 * //Max7221 max7221disp2(p5, p7, p8);
jakowisp 2:828c62cc1861 22 * //Max7221 max7221disp3(p11, p13, p14);
jakowisp 2:828c62cc1861 23 * //Max7221 max7221disp4(p11, p13, p14);
jakowisp 2:828c62cc1861 24 *
jakowisp 2:828c62cc1861 25 * int count=-99;
jakowisp 2:828c62cc1861 26 *
jakowisp 2:828c62cc1861 27 * void loop(void) {
jakowisp 2:828c62cc1861 28 * max7221disp1.WriteInt(count);
jakowisp 2:828c62cc1861 29 * if (count < 100)
jakowisp 2:828c62cc1861 30 * count=count+1;
jakowisp 2:828c62cc1861 31 * else
jakowisp 2:828c62cc1861 32 * count=-99;
jakowisp 2:828c62cc1861 33 * }
jakowisp 2:828c62cc1861 34 *
jakowisp 2:828c62cc1861 35 * int main() {
jakowisp 2:828c62cc1861 36 * max7221disp1.Setup();
jakowisp 2:828c62cc1861 37 * //Max7221::SetupALl();
jakowisp 2:828c62cc1861 38 * max7221disp1.WriteFloat(123.125);
jakowisp 2:828c62cc1861 39 * wait(1.0);
jakowisp 2:828c62cc1861 40 *
jakowisp 2:828c62cc1861 41 * while (1) {
jakowisp 2:828c62cc1861 42 * loop();
jakowisp 2:828c62cc1861 43 * wait(1.0);
jakowisp 2:828c62cc1861 44 * }
jakowisp 2:828c62cc1861 45 * }
jakowisp 2:828c62cc1861 46 * @endcode
jakowisp 2:828c62cc1861 47 */
jakowisp 2:828c62cc1861 48
jakowisp 1:d8589d1f368c 49 // define max7219/max7221 registers
jakowisp 1:d8589d1f368c 50 #define max7219_reg_noop 0x00
jakowisp 1:d8589d1f368c 51 #define max7219_reg_digit0 0x01
jakowisp 1:d8589d1f368c 52 #define max7219_reg_digit1 0x02
jakowisp 1:d8589d1f368c 53 #define max7219_reg_digit2 0x03
jakowisp 1:d8589d1f368c 54 #define max7219_reg_digit3 0x04
jakowisp 1:d8589d1f368c 55 #define max7219_reg_digit4 0x05
jakowisp 1:d8589d1f368c 56 #define max7219_reg_digit5 0x06
jakowisp 1:d8589d1f368c 57 #define max7219_reg_digit6 0x07
jakowisp 1:d8589d1f368c 58 #define max7219_reg_digit7 0x08
jakowisp 1:d8589d1f368c 59 #define max7219_reg_decodeMode 0x09
jakowisp 1:d8589d1f368c 60 #define max7219_reg_intensity 0x0a
jakowisp 1:d8589d1f368c 61 #define max7219_reg_scanLimit 0x0b
jakowisp 1:d8589d1f368c 62 #define max7219_reg_shutdown 0x0c
jakowisp 1:d8589d1f368c 63 #define max7219_reg_displayTest 0x0f
jakowisp 1:d8589d1f368c 64
jakowisp 1:d8589d1f368c 65 #define LOW 0
jakowisp 1:d8589d1f368c 66 #define HIGH 1
jakowisp 1:d8589d1f368c 67 #define MHZ 1000000
jakowisp 1:d8589d1f368c 68 #define NUMDIGITS 8
jakowisp 1:d8589d1f368c 69
jakowisp 1:d8589d1f368c 70 #ifdef NUMDIGITS
jakowisp 1:d8589d1f368c 71 #define UPPERBOUND 99999999
jakowisp 1:d8589d1f368c 72 #define LOWERBOUND -9999999
jakowisp 1:d8589d1f368c 73 #endif
jakowisp 1:d8589d1f368c 74
jakowisp 1:d8589d1f368c 75 class Max7221 {
jakowisp 1:d8589d1f368c 76 public:
jakowisp 2:828c62cc1861 77 /**
jakowisp 2:828c62cc1861 78 * Constructor. This is the default constructor
jakowisp 2:828c62cc1861 79 * @author Dwayne S. Dilbeck
jakowisp 2:828c62cc1861 80 * @param msoi The SPI pin used as input to the device. Valid values for LPC1768 are p5 or p11
jakowisp 2:828c62cc1861 81 * @param mclk The SPI pin used as clock for the device. Valid values for LPC1768 are p7 or p13
jakowisp 2:828c62cc1861 82 * @param load The pin used to control load for the device. Any pin capable for DigitalOut can be used, but the same load pin must be used for
jakowisp 2:828c62cc1861 83 * device that share the same msoi and mclk pins
jakowisp 2:828c62cc1861 84 * @date 8/6/2013
jakowisp 2:828c62cc1861 85 */
jakowisp 1:d8589d1f368c 86 Max7221(PinName msoi=p5, PinName mclk=p7, PinName load=p8);
jakowisp 1:d8589d1f368c 87
jakowisp 2:828c62cc1861 88 /**
jakowisp 2:828c62cc1861 89 * This method is used to write a byte of data to a specified register for only the device defined in this class instance
jakowisp 2:828c62cc1861 90 * @author Dwayne S. Dilbeck
jakowisp 2:828c62cc1861 91 * @param reg The register to write to.
jakowisp 2:828c62cc1861 92 * @param data The value to be written.
jakowisp 2:828c62cc1861 93 * @date 8/6/2013
jakowisp 2:828c62cc1861 94 */
jakowisp 2:828c62cc1861 95 void Write( unsigned int reg, unsigned int data);
jakowisp 2:828c62cc1861 96
jakowisp 2:828c62cc1861 97 /**
jakowisp 2:828c62cc1861 98 * This method is used to display an integer to the specified device instance. Underflow and overflow result in '-' written to all digits
jakowisp 2:828c62cc1861 99 * @author Dwayne S. Dilbeck
jakowisp 2:828c62cc1861 100 * @param value An integer value to display
jakowisp 2:828c62cc1861 101 * @date 8/6/2013
jakowisp 2:828c62cc1861 102 */
jakowisp 2:828c62cc1861 103 void WriteInt( int value );
jakowisp 2:828c62cc1861 104
jakowisp 2:828c62cc1861 105 /**
jakowisp 2:828c62cc1861 106 * This method is used to display a floating point number to the specified device instance.
jakowisp 2:828c62cc1861 107 * Underflow and overflow result in '-' written to all digits. The digits after the decimal
jakowisp 2:828c62cc1861 108 * point are truncated to fit the display.
jakowisp 2:828c62cc1861 109 * @author Dwayne S. Dilbeck
jakowisp 2:828c62cc1861 110 * @param value A float value to display
jakowisp 2:828c62cc1861 111 * @date 8/6/2013
jakowisp 2:828c62cc1861 112 */
jakowisp 2:828c62cc1861 113 void WriteFloat( float value);
jakowisp 1:d8589d1f368c 114
jakowisp 2:828c62cc1861 115 /**
jakowisp 2:828c62cc1861 116 * Overload of the EQUALS operator to provide easy use of the class.
jakowisp 2:828c62cc1861 117 * @author Dwayne S. Dilbeck
jakowisp 2:828c62cc1861 118 * @param value An integer value to display
jakowisp 2:828c62cc1861 119 * @date 8/6/2013
jakowisp 2:828c62cc1861 120 */
jakowisp 2:828c62cc1861 121
jakowisp 1:d8589d1f368c 122 Max7221& operator= (int value){
jakowisp 1:d8589d1f368c 123 WriteInt(value);
jakowisp 1:d8589d1f368c 124 return *this;
jakowisp 1:d8589d1f368c 125 };
jakowisp 2:828c62cc1861 126 /**
jakowisp 2:828c62cc1861 127 * Overload of the EQUALS operator to provide easy use of the class.
jakowisp 2:828c62cc1861 128 * @author Dwayne S. Dilbeck
jakowisp 2:828c62cc1861 129 * @param value A float value to display
jakowisp 2:828c62cc1861 130 * @date 8/6/2013
jakowisp 2:828c62cc1861 131 */
jakowisp 2:828c62cc1861 132
jakowisp 1:d8589d1f368c 133 Max7221& operator= (float value){
jakowisp 1:d8589d1f368c 134 WriteFloat(value);
jakowisp 1:d8589d1f368c 135 return *this;
jakowisp 1:d8589d1f368c 136 };
jakowisp 2:828c62cc1861 137 /**
jakowisp 2:828c62cc1861 138 * This method is used to write an intial set off values to the device to prepare it for use.
jakowisp 2:828c62cc1861 139 * @author Dwayne S. Dilbeck
jakowisp 2:828c62cc1861 140 * @date 8/6/2013
jakowisp 2:828c62cc1861 141 */
jakowisp 1:d8589d1f368c 142 void Setup (void);
jakowisp 2:828c62cc1861 143
jakowisp 2:828c62cc1861 144 /**
jakowisp 2:828c62cc1861 145 * This method is used to write a byte of data to a specified register for all the devices instantiated.
jakowisp 2:828c62cc1861 146 * @author Dwayne S. Dilbeck
jakowisp 2:828c62cc1861 147 * @param reg The register to write to.
jakowisp 2:828c62cc1861 148 * @param data The value to be written.
jakowisp 2:828c62cc1861 149 * @date 8/6/2013
jakowisp 2:828c62cc1861 150 */
jakowisp 2:828c62cc1861 151 static void WriteAll (unsigned int reg, unsigned int data);
jakowisp 2:828c62cc1861 152
jakowisp 2:828c62cc1861 153 /**
jakowisp 2:828c62cc1861 154 * This method is used to write an intial set off values to ALL device to prepare them for use.
jakowisp 2:828c62cc1861 155 * @author Dwayne S. Dilbeck
jakowisp 2:828c62cc1861 156 * @date 8/6/2013
jakowisp 2:828c62cc1861 157 */
jakowisp 1:d8589d1f368c 158 static void SetupAll (void);
jakowisp 1:d8589d1f368c 159
jakowisp 1:d8589d1f368c 160 private:
jakowisp 2:828c62cc1861 161 /// Pointer for the class instance to a particular SPI bus
jakowisp 1:d8589d1f368c 162 SPI *max72_spi;
jakowisp 2:828c62cc1861 163 /// pointer for the class instance of a particular load signal
jakowisp 1:d8589d1f368c 164 DigitalOut *load;
jakowisp 2:828c62cc1861 165 /// id of the class instance
jakowisp 1:d8589d1f368c 166 int id;
jakowisp 2:828c62cc1861 167 /// pointer to the number of devices connected to the SPI bus instance this device instance is connected to.
jakowisp 1:d8589d1f368c 168 int *maxInUse;
jakowisp 1:d8589d1f368c 169
jakowisp 2:828c62cc1861 170 ///For the class we have a static set of values. There are 2 SPI buses, 2 load signals, and 2 counters of the number of devices connected to a SPI bus.
jakowisp 1:d8589d1f368c 171 static SPI *spi1;
jakowisp 1:d8589d1f368c 172 static SPI *spi2;
jakowisp 1:d8589d1f368c 173 static DigitalOut *load1;
jakowisp 1:d8589d1f368c 174 static DigitalOut *load2;
jakowisp 1:d8589d1f368c 175 static int maxInUseSPI1;
jakowisp 1:d8589d1f368c 176 static int maxInUseSPI2;
jakowisp 1:d8589d1f368c 177 };
jakowisp 1:d8589d1f368c 178
jakowisp 1:d8589d1f368c 179 #endif