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.
N_5110_Display.cpp@0:bb60966d6de1, 2011-10-11 (annotated)
- Committer:
- Fenwiz
- Date:
- Tue Oct 11 01:14:45 2011 +0000
- Revision:
- 0:bb60966d6de1
Revision 1.00. initial release. stable and fairly robust
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Fenwiz | 0:bb60966d6de1 | 1 | #include "mbed.h" |
Fenwiz | 0:bb60966d6de1 | 2 | #include "N_5110_Display.h" |
Fenwiz | 0:bb60966d6de1 | 3 | #include "N_5110_Font.h" |
Fenwiz | 0:bb60966d6de1 | 4 | |
Fenwiz | 0:bb60966d6de1 | 5 | |
Fenwiz | 0:bb60966d6de1 | 6 | N_5110_Display::N_5110_Display( PinName _mosi, PinName _miso, PinName _sclk, PinName _dc, PinName _reset, PinName _cs): |
Fenwiz | 0:bb60966d6de1 | 7 | spi( _mosi, _miso, _sclk ), dc( _dc ), rst( _reset ), cs( _cs ) |
Fenwiz | 0:bb60966d6de1 | 8 | { |
Fenwiz | 0:bb60966d6de1 | 9 | initDisplay(); |
Fenwiz | 0:bb60966d6de1 | 10 | } |
Fenwiz | 0:bb60966d6de1 | 11 | |
Fenwiz | 0:bb60966d6de1 | 12 | //---------------------------------------------------------------------- |
Fenwiz | 0:bb60966d6de1 | 13 | |
Fenwiz | 0:bb60966d6de1 | 14 | void N_5110_Display::initDisplay() |
Fenwiz | 0:bb60966d6de1 | 15 | { |
Fenwiz | 0:bb60966d6de1 | 16 | rst=0; //display reset |
Fenwiz | 0:bb60966d6de1 | 17 | cs=1; //Chip Disabled |
Fenwiz | 0:bb60966d6de1 | 18 | |
Fenwiz | 0:bb60966d6de1 | 19 | wait(0.5); //allow chip to settle for half second |
Fenwiz | 0:bb60966d6de1 | 20 | |
Fenwiz | 0:bb60966d6de1 | 21 | spi.format(8,3); //set the SPI interface perameters for the Display |
Fenwiz | 0:bb60966d6de1 | 22 | spi.frequency(1000000); //1 MHz clock speed |
Fenwiz | 0:bb60966d6de1 | 23 | PixX = 0; //zero the x, y variables |
Fenwiz | 0:bb60966d6de1 | 24 | CharX = 0; |
Fenwiz | 0:bb60966d6de1 | 25 | CharY = 0; |
Fenwiz | 0:bb60966d6de1 | 26 | |
Fenwiz | 0:bb60966d6de1 | 27 | rst=1; //display reset done |
Fenwiz | 0:bb60966d6de1 | 28 | |
Fenwiz | 0:bb60966d6de1 | 29 | dc=0; //select Control mode |
Fenwiz | 0:bb60966d6de1 | 30 | cs=0; //Chip Enabled |
Fenwiz | 0:bb60966d6de1 | 31 | |
Fenwiz | 0:bb60966d6de1 | 32 | spi.write(0x21); //Function Set (Extenden Instructions) |
Fenwiz | 0:bb60966d6de1 | 33 | spi.write(0x04); //set 'Temp Coef' value |
Fenwiz | 0:bb60966d6de1 | 34 | spi.write(0x13); //set 'Bias' value |
Fenwiz | 0:bb60966d6de1 | 35 | spi.write(0xBF); //set 'V_op' value |
Fenwiz | 0:bb60966d6de1 | 36 | spi.write(0x22); //Function Set (Basic Instructions) |
Fenwiz | 0:bb60966d6de1 | 37 | spi.write(0x0C); //Display Control |
Fenwiz | 0:bb60966d6de1 | 38 | |
Fenwiz | 0:bb60966d6de1 | 39 | clrDisp(); //Clear the Display |
Fenwiz | 0:bb60966d6de1 | 40 | } |
Fenwiz | 0:bb60966d6de1 | 41 | |
Fenwiz | 0:bb60966d6de1 | 42 | //---------------------------------------------------------------------- |
Fenwiz | 0:bb60966d6de1 | 43 | |
Fenwiz | 0:bb60966d6de1 | 44 | void N_5110_Display::clrDisp() |
Fenwiz | 0:bb60966d6de1 | 45 | { |
Fenwiz | 0:bb60966d6de1 | 46 | long x; |
Fenwiz | 0:bb60966d6de1 | 47 | |
Fenwiz | 0:bb60966d6de1 | 48 | dc=1; //select Data mode |
Fenwiz | 0:bb60966d6de1 | 49 | cs=0; //Chip Enabled |
Fenwiz | 0:bb60966d6de1 | 50 | |
Fenwiz | 0:bb60966d6de1 | 51 | for (x=0; x<504; x++) //Clear the display memory |
Fenwiz | 0:bb60966d6de1 | 52 | { |
Fenwiz | 0:bb60966d6de1 | 53 | spi.write( 0 ); |
Fenwiz | 0:bb60966d6de1 | 54 | } |
Fenwiz | 0:bb60966d6de1 | 55 | |
Fenwiz | 0:bb60966d6de1 | 56 | cs=1; //Chip Disabled |
Fenwiz | 0:bb60966d6de1 | 57 | } |
Fenwiz | 0:bb60966d6de1 | 58 | |
Fenwiz | 0:bb60966d6de1 | 59 | //---------------------------------------------------------------------- |
Fenwiz | 0:bb60966d6de1 | 60 | |
Fenwiz | 0:bb60966d6de1 | 61 | void N_5110_Display::setDispPos(int DispX, int DispY) |
Fenwiz | 0:bb60966d6de1 | 62 | { |
Fenwiz | 0:bb60966d6de1 | 63 | unsigned char Xtemp, Ytemp; |
Fenwiz | 0:bb60966d6de1 | 64 | |
Fenwiz | 0:bb60966d6de1 | 65 | Xtemp = DispX | 0x80; //add in the column select BIT |
Fenwiz | 0:bb60966d6de1 | 66 | Ytemp = (DispY & 0x07) | 0x40; |
Fenwiz | 0:bb60966d6de1 | 67 | |
Fenwiz | 0:bb60966d6de1 | 68 | dc=0; //select Control mode |
Fenwiz | 0:bb60966d6de1 | 69 | cs=0; //Chip Enabled |
Fenwiz | 0:bb60966d6de1 | 70 | |
Fenwiz | 0:bb60966d6de1 | 71 | spi.write(Xtemp); //Set the column value |
Fenwiz | 0:bb60966d6de1 | 72 | spi.write(Ytemp); //set the row value |
Fenwiz | 0:bb60966d6de1 | 73 | |
Fenwiz | 0:bb60966d6de1 | 74 | cs=1; //Chip Disabled |
Fenwiz | 0:bb60966d6de1 | 75 | } |
Fenwiz | 0:bb60966d6de1 | 76 | |
Fenwiz | 0:bb60966d6de1 | 77 | //---------------------------------------------------------------------- |
Fenwiz | 0:bb60966d6de1 | 78 | |
Fenwiz | 0:bb60966d6de1 | 79 | int N_5110_Display::setCharPos(int x, int y) |
Fenwiz | 0:bb60966d6de1 | 80 | //x is the character column number 0 to 13. y is the character row number 0 to 5. |
Fenwiz | 0:bb60966d6de1 | 81 | //The column is multiplied by 6 to get the display column value, as each 5 x 8 char occupies a 6 x 8 space |
Fenwiz | 0:bb60966d6de1 | 82 | { |
Fenwiz | 0:bb60966d6de1 | 83 | unsigned char Xacc; |
Fenwiz | 0:bb60966d6de1 | 84 | |
Fenwiz | 0:bb60966d6de1 | 85 | if (x>13 || y>5) return -1; //check magnitude of co-ordinates and store |
Fenwiz | 0:bb60966d6de1 | 86 | |
Fenwiz | 0:bb60966d6de1 | 87 | Xacc = x<<2; //multiply the char column (x) by 6 to get the Display column |
Fenwiz | 0:bb60966d6de1 | 88 | Xacc = Xacc + (x<<1); |
Fenwiz | 0:bb60966d6de1 | 89 | |
Fenwiz | 0:bb60966d6de1 | 90 | PixX = Xacc; |
Fenwiz | 0:bb60966d6de1 | 91 | CharX = x; |
Fenwiz | 0:bb60966d6de1 | 92 | CharY = y; |
Fenwiz | 0:bb60966d6de1 | 93 | |
Fenwiz | 0:bb60966d6de1 | 94 | setDispPos(PixX, CharY); |
Fenwiz | 0:bb60966d6de1 | 95 | |
Fenwiz | 0:bb60966d6de1 | 96 | return 0; |
Fenwiz | 0:bb60966d6de1 | 97 | } |
Fenwiz | 0:bb60966d6de1 | 98 | |
Fenwiz | 0:bb60966d6de1 | 99 | //---------------------------------------------------------------------- |
Fenwiz | 0:bb60966d6de1 | 100 | |
Fenwiz | 0:bb60966d6de1 | 101 | void N_5110_Display::clrMagArray( unsigned char Xmag, unsigned char Ymag, bool FullWidth ) |
Fenwiz | 0:bb60966d6de1 | 102 | { |
Fenwiz | 0:bb60966d6de1 | 103 | unsigned char magDataX, magDataY, width; |
Fenwiz | 0:bb60966d6de1 | 104 | |
Fenwiz | 0:bb60966d6de1 | 105 | width = FullWidth?6:5; |
Fenwiz | 0:bb60966d6de1 | 106 | |
Fenwiz | 0:bb60966d6de1 | 107 | for (magDataX=0; magDataX<Xmag*width; magDataX++) //clear the magnification array |
Fenwiz | 0:bb60966d6de1 | 108 | { |
Fenwiz | 0:bb60966d6de1 | 109 | for (magDataY=0; magDataY<Ymag; magDataY++) |
Fenwiz | 0:bb60966d6de1 | 110 | { |
Fenwiz | 0:bb60966d6de1 | 111 | magData[magDataX][magDataY] = 0; |
Fenwiz | 0:bb60966d6de1 | 112 | } |
Fenwiz | 0:bb60966d6de1 | 113 | } |
Fenwiz | 0:bb60966d6de1 | 114 | } |
Fenwiz | 0:bb60966d6de1 | 115 | |
Fenwiz | 0:bb60966d6de1 | 116 | //---------------------------------------------------------------------- |
Fenwiz | 0:bb60966d6de1 | 117 | |
Fenwiz | 0:bb60966d6de1 | 118 | void N_5110_Display::smoothEdges( unsigned char Xmag, unsigned char Ymag ) |
Fenwiz | 0:bb60966d6de1 | 119 | //Quick and dirty character smoothing but only if there is magnification in both X and Y directions. Intended to improve readability |
Fenwiz | 0:bb60966d6de1 | 120 | //at higher magnifications but doesn't realy smooth very well. |
Fenwiz | 0:bb60966d6de1 | 121 | //I'm sure that someone can come up with a better solution than this, but I didn't have time to code an Interpolation algorithm or |
Fenwiz | 0:bb60966d6de1 | 122 | //creata vectored drawing system. |
Fenwiz | 0:bb60966d6de1 | 123 | { |
Fenwiz | 0:bb60966d6de1 | 124 | unsigned char Xpos, Ypos, tempByte1, tempByte2, tempByte3, and1, and2, totaland, repeater; |
Fenwiz | 0:bb60966d6de1 | 125 | |
Fenwiz | 0:bb60966d6de1 | 126 | if (Xmag<2 || Ymag<2) return; //check for enough magnification to work with |
Fenwiz | 0:bb60966d6de1 | 127 | |
Fenwiz | 0:bb60966d6de1 | 128 | for (repeater=0; repeater<(Xmag*Ymag)/(Xmag+Ymag); repeater++) //calc sensible number of itterations |
Fenwiz | 0:bb60966d6de1 | 129 | { |
Fenwiz | 0:bb60966d6de1 | 130 | |
Fenwiz | 0:bb60966d6de1 | 131 | for (Ypos=0; Ypos<Ymag; Ypos++) |
Fenwiz | 0:bb60966d6de1 | 132 | { |
Fenwiz | 0:bb60966d6de1 | 133 | for (Xpos=0; Xpos<Xmag*6-1; Xpos++) //scan left to right |
Fenwiz | 0:bb60966d6de1 | 134 | { |
Fenwiz | 0:bb60966d6de1 | 135 | tempByte1 = magData[Xpos+1][Ypos]; //get the following byte |
Fenwiz | 0:bb60966d6de1 | 136 | tempByte2 = magData[Xpos][Ypos]; //get the current byte |
Fenwiz | 0:bb60966d6de1 | 137 | tempByte3 = tempByte1 ^ tempByte2; //check for a change |
Fenwiz | 0:bb60966d6de1 | 138 | |
Fenwiz | 0:bb60966d6de1 | 139 | if (tempByte3 != 0) |
Fenwiz | 0:bb60966d6de1 | 140 | { |
Fenwiz | 0:bb60966d6de1 | 141 | tempByte2 >>= 1; //shift up (Right towards LSB) |
Fenwiz | 0:bb60966d6de1 | 142 | |
Fenwiz | 0:bb60966d6de1 | 143 | if (Ypos+1 <= Ymag) |
Fenwiz | 0:bb60966d6de1 | 144 | { |
Fenwiz | 0:bb60966d6de1 | 145 | tempByte3 = magData[Xpos][Ypos+1]; //get missing BIT from byte below |
Fenwiz | 0:bb60966d6de1 | 146 | tempByte3 <<= 7; |
Fenwiz | 0:bb60966d6de1 | 147 | tempByte2 |= tempByte3; |
Fenwiz | 0:bb60966d6de1 | 148 | } |
Fenwiz | 0:bb60966d6de1 | 149 | |
Fenwiz | 0:bb60966d6de1 | 150 | and1 = tempByte1 & tempByte2; |
Fenwiz | 0:bb60966d6de1 | 151 | |
Fenwiz | 0:bb60966d6de1 | 152 | tempByte2 = magData[Xpos][Ypos]; //re-load the current byte |
Fenwiz | 0:bb60966d6de1 | 153 | tempByte2 <<= 1; //shift down (Left towards the MSB) |
Fenwiz | 0:bb60966d6de1 | 154 | |
Fenwiz | 0:bb60966d6de1 | 155 | if (Ypos > 0) |
Fenwiz | 0:bb60966d6de1 | 156 | { |
Fenwiz | 0:bb60966d6de1 | 157 | tempByte3 = magData[Xpos][Ypos-1]; //get missing BIT from byte above |
Fenwiz | 0:bb60966d6de1 | 158 | tempByte3 >>= 7; |
Fenwiz | 0:bb60966d6de1 | 159 | tempByte2 |= tempByte3; |
Fenwiz | 0:bb60966d6de1 | 160 | } |
Fenwiz | 0:bb60966d6de1 | 161 | |
Fenwiz | 0:bb60966d6de1 | 162 | and2 = tempByte1 & tempByte2; |
Fenwiz | 0:bb60966d6de1 | 163 | |
Fenwiz | 0:bb60966d6de1 | 164 | totaland = (and1 | and2); |
Fenwiz | 0:bb60966d6de1 | 165 | magData[Xpos][Ypos] |= totaland; //incorpoate the extra bits into the magData } |
Fenwiz | 0:bb60966d6de1 | 166 | } |
Fenwiz | 0:bb60966d6de1 | 167 | } |
Fenwiz | 0:bb60966d6de1 | 168 | |
Fenwiz | 0:bb60966d6de1 | 169 | for (Xpos=Xmag*6; Xpos>0; Xpos--) //scan right to left |
Fenwiz | 0:bb60966d6de1 | 170 | { |
Fenwiz | 0:bb60966d6de1 | 171 | tempByte1 = magData[Xpos-2][Ypos]; //get following byte |
Fenwiz | 0:bb60966d6de1 | 172 | tempByte2 = magData[Xpos-1][Ypos]; //get the current byte |
Fenwiz | 0:bb60966d6de1 | 173 | tempByte3 = tempByte1 ^ tempByte2; //check for change |
Fenwiz | 0:bb60966d6de1 | 174 | |
Fenwiz | 0:bb60966d6de1 | 175 | if (tempByte3 != 0) |
Fenwiz | 0:bb60966d6de1 | 176 | { |
Fenwiz | 0:bb60966d6de1 | 177 | tempByte2 >>= 1; //shift up (Right towards the LSB) |
Fenwiz | 0:bb60966d6de1 | 178 | |
Fenwiz | 0:bb60966d6de1 | 179 | if (Ypos+1 <= Ymag) |
Fenwiz | 0:bb60966d6de1 | 180 | { |
Fenwiz | 0:bb60966d6de1 | 181 | tempByte3 = magData[Xpos-1][Ypos+1]; //get missing BIT from byte below |
Fenwiz | 0:bb60966d6de1 | 182 | tempByte3 <<= 7; |
Fenwiz | 0:bb60966d6de1 | 183 | tempByte2 |= tempByte3; |
Fenwiz | 0:bb60966d6de1 | 184 | } |
Fenwiz | 0:bb60966d6de1 | 185 | |
Fenwiz | 0:bb60966d6de1 | 186 | and1 = tempByte1 & tempByte2; |
Fenwiz | 0:bb60966d6de1 | 187 | |
Fenwiz | 0:bb60966d6de1 | 188 | tempByte2 = magData[Xpos-1][Ypos]; //re-load the current byte |
Fenwiz | 0:bb60966d6de1 | 189 | tempByte2 <<= 1; //shift down (Left towards the MSB) |
Fenwiz | 0:bb60966d6de1 | 190 | |
Fenwiz | 0:bb60966d6de1 | 191 | if (Ypos > 0) |
Fenwiz | 0:bb60966d6de1 | 192 | { |
Fenwiz | 0:bb60966d6de1 | 193 | tempByte3 = magData[Xpos-1][Ypos-1]; //get missing Bits from byte above |
Fenwiz | 0:bb60966d6de1 | 194 | tempByte3 >>= 7; |
Fenwiz | 0:bb60966d6de1 | 195 | tempByte2 |= tempByte3; |
Fenwiz | 0:bb60966d6de1 | 196 | } |
Fenwiz | 0:bb60966d6de1 | 197 | and2 = tempByte1 & tempByte2; |
Fenwiz | 0:bb60966d6de1 | 198 | |
Fenwiz | 0:bb60966d6de1 | 199 | totaland = (and1 | and2); |
Fenwiz | 0:bb60966d6de1 | 200 | magData[Xpos - 1][Ypos] |= totaland; |
Fenwiz | 0:bb60966d6de1 | 201 | } |
Fenwiz | 0:bb60966d6de1 | 202 | } |
Fenwiz | 0:bb60966d6de1 | 203 | } |
Fenwiz | 0:bb60966d6de1 | 204 | } |
Fenwiz | 0:bb60966d6de1 | 205 | } |
Fenwiz | 0:bb60966d6de1 | 206 | |
Fenwiz | 0:bb60966d6de1 | 207 | //---------------------------------------------------------------------- |
Fenwiz | 0:bb60966d6de1 | 208 | |
Fenwiz | 0:bb60966d6de1 | 209 | void N_5110_Display::magChar( unsigned char c, unsigned char Xmag, unsigned char Ymag ) |
Fenwiz | 0:bb60966d6de1 | 210 | //Expand the basic 5 x 8 char def to the required X and y magnification using an buffer Array |
Fenwiz | 0:bb60966d6de1 | 211 | { |
Fenwiz | 0:bb60966d6de1 | 212 | unsigned char tempPat, count, Idx, Xexp, Yexp, bitCounter, bitAcc, srcBit, magDataX, magDataY; |
Fenwiz | 0:bb60966d6de1 | 213 | |
Fenwiz | 0:bb60966d6de1 | 214 | clrMagArray( Xmag, Ymag, false ); |
Fenwiz | 0:bb60966d6de1 | 215 | |
Fenwiz | 0:bb60966d6de1 | 216 | Idx = c - 32; //shift the ASCII code so it starts from zero |
Fenwiz | 0:bb60966d6de1 | 217 | |
Fenwiz | 0:bb60966d6de1 | 218 | magDataX = 0; |
Fenwiz | 0:bb60966d6de1 | 219 | |
Fenwiz | 0:bb60966d6de1 | 220 | for (count=0; count<5; count++) //5 bytes per char def |
Fenwiz | 0:bb60966d6de1 | 221 | { |
Fenwiz | 0:bb60966d6de1 | 222 | bitCounter = Ymag/2; //offset the image Y position by half the Y magnification factor |
Fenwiz | 0:bb60966d6de1 | 223 | bitAcc = 0; |
Fenwiz | 0:bb60966d6de1 | 224 | magDataY = 0; |
Fenwiz | 0:bb60966d6de1 | 225 | tempPat = font_data[Idx][count]; //get column Bit pattern to expand in the y direction by bit replication |
Fenwiz | 0:bb60966d6de1 | 226 | //LSB is top Bit position |
Fenwiz | 0:bb60966d6de1 | 227 | |
Fenwiz | 0:bb60966d6de1 | 228 | for (srcBit=0; srcBit<8; srcBit++) //process each of the 8 bits in the source byte |
Fenwiz | 0:bb60966d6de1 | 229 | { |
Fenwiz | 0:bb60966d6de1 | 230 | for (Yexp=0; Yexp<Ymag; Yexp++) //each Bit in each def byte is duplicated Ymag times in the Y direction |
Fenwiz | 0:bb60966d6de1 | 231 | { |
Fenwiz | 0:bb60966d6de1 | 232 | bitAcc >>= 1; //shift the accumulator 1 bit to the left |
Fenwiz | 0:bb60966d6de1 | 233 | |
Fenwiz | 0:bb60966d6de1 | 234 | if ((tempPat & 1) > 0) |
Fenwiz | 0:bb60966d6de1 | 235 | { |
Fenwiz | 0:bb60966d6de1 | 236 | bitAcc |= 0x80; //set msb |
Fenwiz | 0:bb60966d6de1 | 237 | } else { |
Fenwiz | 0:bb60966d6de1 | 238 | bitAcc &= 0x7F; //clear msb |
Fenwiz | 0:bb60966d6de1 | 239 | } |
Fenwiz | 0:bb60966d6de1 | 240 | |
Fenwiz | 0:bb60966d6de1 | 241 | bitCounter++; |
Fenwiz | 0:bb60966d6de1 | 242 | |
Fenwiz | 0:bb60966d6de1 | 243 | if (bitCounter > 7) //if the bit accumulator is full then store it and clear it to continue |
Fenwiz | 0:bb60966d6de1 | 244 | { |
Fenwiz | 0:bb60966d6de1 | 245 | for (Xexp=0; Xexp<Xmag; Xexp++) //do the X magnification while storingthe Bit Accumulator |
Fenwiz | 0:bb60966d6de1 | 246 | { |
Fenwiz | 0:bb60966d6de1 | 247 | magData[magDataX + Xexp][magDataY] = bitAcc; |
Fenwiz | 0:bb60966d6de1 | 248 | } |
Fenwiz | 0:bb60966d6de1 | 249 | |
Fenwiz | 0:bb60966d6de1 | 250 | bitAcc = 0; |
Fenwiz | 0:bb60966d6de1 | 251 | magDataY++; |
Fenwiz | 0:bb60966d6de1 | 252 | bitCounter = 0; |
Fenwiz | 0:bb60966d6de1 | 253 | } |
Fenwiz | 0:bb60966d6de1 | 254 | } |
Fenwiz | 0:bb60966d6de1 | 255 | tempPat>>=1; |
Fenwiz | 0:bb60966d6de1 | 256 | } |
Fenwiz | 0:bb60966d6de1 | 257 | magDataX += Xmag; |
Fenwiz | 0:bb60966d6de1 | 258 | } |
Fenwiz | 0:bb60966d6de1 | 259 | smoothEdges( Xmag, Ymag ); |
Fenwiz | 0:bb60966d6de1 | 260 | } |
Fenwiz | 0:bb60966d6de1 | 261 | |
Fenwiz | 0:bb60966d6de1 | 262 | //---------------------------------------------------------------------- |
Fenwiz | 0:bb60966d6de1 | 263 | |
Fenwiz | 0:bb60966d6de1 | 264 | int N_5110_Display::outputMagData (unsigned char Xmag, unsigned char Ymag, bool FullWidth ) |
Fenwiz | 0:bb60966d6de1 | 265 | { |
Fenwiz | 0:bb60966d6de1 | 266 | unsigned char XpixTemp, mx, my, width; |
Fenwiz | 0:bb60966d6de1 | 267 | |
Fenwiz | 0:bb60966d6de1 | 268 | XpixTemp = PixX; |
Fenwiz | 0:bb60966d6de1 | 269 | width = FullWidth?6:5; |
Fenwiz | 0:bb60966d6de1 | 270 | |
Fenwiz | 0:bb60966d6de1 | 271 | if (FullWidth == false) |
Fenwiz | 0:bb60966d6de1 | 272 | { |
Fenwiz | 0:bb60966d6de1 | 273 | for (mx=0; mx<Xmag/2; mx++) |
Fenwiz | 0:bb60966d6de1 | 274 | { |
Fenwiz | 0:bb60966d6de1 | 275 | dc=1; //select Data mode |
Fenwiz | 0:bb60966d6de1 | 276 | cs=0; //Chip Enabled |
Fenwiz | 0:bb60966d6de1 | 277 | |
Fenwiz | 0:bb60966d6de1 | 278 | for (my=0; my<Ymag; my++) |
Fenwiz | 0:bb60966d6de1 | 279 | { |
Fenwiz | 0:bb60966d6de1 | 280 | spi.write( 0 ); |
Fenwiz | 0:bb60966d6de1 | 281 | } |
Fenwiz | 0:bb60966d6de1 | 282 | |
Fenwiz | 0:bb60966d6de1 | 283 | cs=1; //Chip Disabled |
Fenwiz | 0:bb60966d6de1 | 284 | |
Fenwiz | 0:bb60966d6de1 | 285 | XpixTemp += 1; |
Fenwiz | 0:bb60966d6de1 | 286 | setDispPos(XpixTemp, CharY); |
Fenwiz | 0:bb60966d6de1 | 287 | } |
Fenwiz | 0:bb60966d6de1 | 288 | } |
Fenwiz | 0:bb60966d6de1 | 289 | |
Fenwiz | 0:bb60966d6de1 | 290 | for (mx=0; mx<Xmag*width; mx++) |
Fenwiz | 0:bb60966d6de1 | 291 | { |
Fenwiz | 0:bb60966d6de1 | 292 | dc=1; //select Data mode |
Fenwiz | 0:bb60966d6de1 | 293 | cs=0; //Chip Enabled |
Fenwiz | 0:bb60966d6de1 | 294 | |
Fenwiz | 0:bb60966d6de1 | 295 | for (my=0; my<Ymag; my++) |
Fenwiz | 0:bb60966d6de1 | 296 | { |
Fenwiz | 0:bb60966d6de1 | 297 | spi.write( magData[mx][my] ); |
Fenwiz | 0:bb60966d6de1 | 298 | } |
Fenwiz | 0:bb60966d6de1 | 299 | |
Fenwiz | 0:bb60966d6de1 | 300 | cs=1; //Chip Disabled |
Fenwiz | 0:bb60966d6de1 | 301 | |
Fenwiz | 0:bb60966d6de1 | 302 | XpixTemp += 1; |
Fenwiz | 0:bb60966d6de1 | 303 | setDispPos( XpixTemp, CharY ); |
Fenwiz | 0:bb60966d6de1 | 304 | } |
Fenwiz | 0:bb60966d6de1 | 305 | |
Fenwiz | 0:bb60966d6de1 | 306 | if (FullWidth == false) |
Fenwiz | 0:bb60966d6de1 | 307 | { |
Fenwiz | 0:bb60966d6de1 | 308 | for (mx=0; mx<(Xmag+1)/2; mx++) |
Fenwiz | 0:bb60966d6de1 | 309 | { |
Fenwiz | 0:bb60966d6de1 | 310 | dc=1; //select Data mode |
Fenwiz | 0:bb60966d6de1 | 311 | cs=0; //Chip Enabled |
Fenwiz | 0:bb60966d6de1 | 312 | |
Fenwiz | 0:bb60966d6de1 | 313 | for (my=0; my<Ymag; my++) |
Fenwiz | 0:bb60966d6de1 | 314 | { |
Fenwiz | 0:bb60966d6de1 | 315 | spi.write( 0 ); |
Fenwiz | 0:bb60966d6de1 | 316 | } |
Fenwiz | 0:bb60966d6de1 | 317 | |
Fenwiz | 0:bb60966d6de1 | 318 | cs=1; //Chip Disabled |
Fenwiz | 0:bb60966d6de1 | 319 | |
Fenwiz | 0:bb60966d6de1 | 320 | XpixTemp += 1; |
Fenwiz | 0:bb60966d6de1 | 321 | setDispPos(XpixTemp, CharY); |
Fenwiz | 0:bb60966d6de1 | 322 | } |
Fenwiz | 0:bb60966d6de1 | 323 | } |
Fenwiz | 0:bb60966d6de1 | 324 | |
Fenwiz | 0:bb60966d6de1 | 325 | PixX = XpixTemp; |
Fenwiz | 0:bb60966d6de1 | 326 | CharX += Xmag; |
Fenwiz | 0:bb60966d6de1 | 327 | |
Fenwiz | 0:bb60966d6de1 | 328 | return 0; |
Fenwiz | 0:bb60966d6de1 | 329 | } |
Fenwiz | 0:bb60966d6de1 | 330 | |
Fenwiz | 0:bb60966d6de1 | 331 | //---------------------------------------------------------------------- |
Fenwiz | 0:bb60966d6de1 | 332 | |
Fenwiz | 0:bb60966d6de1 | 333 | int N_5110_Display::print1char(unsigned char c, unsigned char Xmag, unsigned char Ymag) |
Fenwiz | 0:bb60966d6de1 | 334 | { |
Fenwiz | 0:bb60966d6de1 | 335 | if (c<32 | c>127) return -1; //Exit if char is out of range |
Fenwiz | 0:bb60966d6de1 | 336 | |
Fenwiz | 0:bb60966d6de1 | 337 | if (Xmag<1) Xmag=1; //Clamp the magnification values |
Fenwiz | 0:bb60966d6de1 | 338 | if (Ymag<1) Ymag=1; |
Fenwiz | 0:bb60966d6de1 | 339 | if (Xmag>6) Xmag=6; |
Fenwiz | 0:bb60966d6de1 | 340 | if (Ymag>6) Ymag=6; |
Fenwiz | 0:bb60966d6de1 | 341 | |
Fenwiz | 0:bb60966d6de1 | 342 | magChar( c, Xmag, Ymag ); |
Fenwiz | 0:bb60966d6de1 | 343 | |
Fenwiz | 0:bb60966d6de1 | 344 | outputMagData( Xmag, Ymag, false ); |
Fenwiz | 0:bb60966d6de1 | 345 | |
Fenwiz | 0:bb60966d6de1 | 346 | return 0; |
Fenwiz | 0:bb60966d6de1 | 347 | } |
Fenwiz | 0:bb60966d6de1 | 348 | |
Fenwiz | 0:bb60966d6de1 | 349 | //---------------------------------------------------------------------- |
Fenwiz | 0:bb60966d6de1 | 350 | |
Fenwiz | 0:bb60966d6de1 | 351 | void N_5110_Display::printString( char * str2prt, unsigned char Xmag, unsigned char Ymag) |
Fenwiz | 0:bb60966d6de1 | 352 | { |
Fenwiz | 0:bb60966d6de1 | 353 | unsigned char c; |
Fenwiz | 0:bb60966d6de1 | 354 | |
Fenwiz | 0:bb60966d6de1 | 355 | for (c=0; c<strlen(str2prt); c++) |
Fenwiz | 0:bb60966d6de1 | 356 | { |
Fenwiz | 0:bb60966d6de1 | 357 | print1char( str2prt[c], Xmag, Ymag ); |
Fenwiz | 0:bb60966d6de1 | 358 | } |
Fenwiz | 0:bb60966d6de1 | 359 | } |
Fenwiz | 0:bb60966d6de1 | 360 | |
Fenwiz | 0:bb60966d6de1 | 361 | //---------------------------------------------------------------------- |
Fenwiz | 0:bb60966d6de1 | 362 | |
Fenwiz | 0:bb60966d6de1 | 363 | void N_5110_Display::VertBarGraph( int Percentage, unsigned char Xmag, unsigned char Ymag ) |
Fenwiz | 0:bb60966d6de1 | 364 | { |
Fenwiz | 0:bb60966d6de1 | 365 | unsigned char Xidx, Yidx, activeHeight, wholeBytes, pixRemaining, mask, count, dither; |
Fenwiz | 0:bb60966d6de1 | 366 | |
Fenwiz | 0:bb60966d6de1 | 367 | if (Xmag<1) Xmag=1; //Clamp the magnification values |
Fenwiz | 0:bb60966d6de1 | 368 | if (Ymag<1) Ymag=1; |
Fenwiz | 0:bb60966d6de1 | 369 | if (Xmag>6) Xmag=6; |
Fenwiz | 0:bb60966d6de1 | 370 | if (Ymag>6) Ymag=6; |
Fenwiz | 0:bb60966d6de1 | 371 | |
Fenwiz | 0:bb60966d6de1 | 372 | clrMagArray( Xmag, Ymag, true ); |
Fenwiz | 0:bb60966d6de1 | 373 | |
Fenwiz | 0:bb60966d6de1 | 374 | activeHeight = 8 * Ymag * Percentage /100; //Calc the magnitude of the Bar |
Fenwiz | 0:bb60966d6de1 | 375 | wholeBytes = activeHeight / 8; |
Fenwiz | 0:bb60966d6de1 | 376 | pixRemaining = activeHeight % 8; |
Fenwiz | 0:bb60966d6de1 | 377 | |
Fenwiz | 0:bb60966d6de1 | 378 | mask = 0xFF; |
Fenwiz | 0:bb60966d6de1 | 379 | for(count=0; count<8-pixRemaining; count++) //creat the mask for pixRemaining |
Fenwiz | 0:bb60966d6de1 | 380 | { |
Fenwiz | 0:bb60966d6de1 | 381 | mask <<= 1; |
Fenwiz | 0:bb60966d6de1 | 382 | } |
Fenwiz | 0:bb60966d6de1 | 383 | |
Fenwiz | 0:bb60966d6de1 | 384 | for (Xidx=0; Xidx<6*Xmag-1; Xidx++) //step along the pixel columns |
Fenwiz | 0:bb60966d6de1 | 385 | { |
Fenwiz | 0:bb60966d6de1 | 386 | dither = Xidx&1?0x55:0xAA; //Dither value alternates for each odd, ecen pixel column |
Fenwiz | 0:bb60966d6de1 | 387 | |
Fenwiz | 0:bb60966d6de1 | 388 | for (Yidx=0; Yidx<Ymag; Yidx++) //step through each row |
Fenwiz | 0:bb60966d6de1 | 389 | { |
Fenwiz | 0:bb60966d6de1 | 390 | if (Yidx == Ymag - wholeBytes - 1) //do the remainder |
Fenwiz | 0:bb60966d6de1 | 391 | { |
Fenwiz | 0:bb60966d6de1 | 392 | magData[Xidx][Yidx] |= dither; |
Fenwiz | 0:bb60966d6de1 | 393 | magData[Xidx][Yidx] &= mask; |
Fenwiz | 0:bb60966d6de1 | 394 | } |
Fenwiz | 0:bb60966d6de1 | 395 | else if (Yidx >= Ymag-wholeBytes) //else do the whole bytes |
Fenwiz | 0:bb60966d6de1 | 396 | { |
Fenwiz | 0:bb60966d6de1 | 397 | magData[Xidx][Yidx] |= dither; |
Fenwiz | 0:bb60966d6de1 | 398 | } |
Fenwiz | 0:bb60966d6de1 | 399 | //now add the border |
Fenwiz | 0:bb60966d6de1 | 400 | if (Xidx==0 || Xidx==6*Xmag-2) //Left & Right |
Fenwiz | 0:bb60966d6de1 | 401 | { |
Fenwiz | 0:bb60966d6de1 | 402 | magData[Xidx][Yidx] |= 0xFF; |
Fenwiz | 0:bb60966d6de1 | 403 | } |
Fenwiz | 0:bb60966d6de1 | 404 | |
Fenwiz | 0:bb60966d6de1 | 405 | if (Yidx==0) //Top |
Fenwiz | 0:bb60966d6de1 | 406 | { |
Fenwiz | 0:bb60966d6de1 | 407 | magData[Xidx][Yidx] |= 0x01; |
Fenwiz | 0:bb60966d6de1 | 408 | } |
Fenwiz | 0:bb60966d6de1 | 409 | |
Fenwiz | 0:bb60966d6de1 | 410 | if (Yidx==Ymag-1) //Bottom |
Fenwiz | 0:bb60966d6de1 | 411 | { |
Fenwiz | 0:bb60966d6de1 | 412 | magData[Xidx][Yidx] |= 0x40; |
Fenwiz | 0:bb60966d6de1 | 413 | magData[Xidx][Yidx] &= 0x7F; |
Fenwiz | 0:bb60966d6de1 | 414 | } |
Fenwiz | 0:bb60966d6de1 | 415 | } |
Fenwiz | 0:bb60966d6de1 | 416 | } |
Fenwiz | 0:bb60966d6de1 | 417 | |
Fenwiz | 0:bb60966d6de1 | 418 | outputMagData( Xmag, Ymag, true ); |
Fenwiz | 0:bb60966d6de1 | 419 | } |
Fenwiz | 0:bb60966d6de1 | 420 |