Simple library for interfacing to Nokia 5110 LCD display (as found on the SparkFun website). Edited to include additional feaatures, such as 2d array loading, multiple screen buffers, and better backlight control

Dependencies:   N5110

Dependents:   Main_code_ver18

Fork of N5110 by Craig Evans

Committer:
el14pjgn
Date:
Mon May 09 14:18:12 2016 +0000
Revision:
18:d2140be00144
Parent:
17:780a542d5f8b
Expanded to include 2d array printing, backlight setting adjustment, and other similar features.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eencae 1:df68f34cd32d 1 /**
eencae 2:e93021cfb0a9 2 @file N5110.h
eencae 1:df68f34cd32d 3
eencae 5:6ea180eef702 4 @brief Header file containing member functions and variables
eencae 4:e923c54c1c7d 5
eencae 0:d563e74f0ae9 6 */
eencae 0:d563e74f0ae9 7
eencae 0:d563e74f0ae9 8 #ifndef N5110_H
eencae 0:d563e74f0ae9 9 #define N5110_H
eencae 0:d563e74f0ae9 10
eencae 0:d563e74f0ae9 11 // Command Bytes - taken from Chris Yan's library
eencae 2:e93021cfb0a9 12 // More information can be found in the display datasheet
eencae 2:e93021cfb0a9 13 // H = 0 - Basic instructions
eencae 0:d563e74f0ae9 14 #define CMD_DC_CLEAR_DISPLAY 0x08
eencae 0:d563e74f0ae9 15 #define CMD_DC_NORMAL_MODE 0x0C
eencae 0:d563e74f0ae9 16 #define CMD_DC_FILL_DISPLAY 0x09
eencae 0:d563e74f0ae9 17 #define CMD_DC_INVERT_VIDEO 0x0D
eencae 0:d563e74f0ae9 18 #define CMD_FS_HORIZONTAL_MODE 0x00
eencae 0:d563e74f0ae9 19 #define CMD_FS_VERTICAL_MODE 0x02
eencae 0:d563e74f0ae9 20 #define CMD_FS_BASIC_MODE 0x00
eencae 0:d563e74f0ae9 21 #define CMD_FS_EXTENDED_MODE 0x01
eencae 0:d563e74f0ae9 22 #define CMD_FS_ACTIVE_MODE 0x00
eencae 0:d563e74f0ae9 23 #define CMD_FS_POWER_DOWN_MODE 0x04
eencae 2:e93021cfb0a9 24 // H = 1 - Extended instructions
eencae 0:d563e74f0ae9 25 #define CMD_TC_TEMP_0 0x04
eencae 0:d563e74f0ae9 26 #define CMD_TC_TEMP_1 0x05
eencae 0:d563e74f0ae9 27 #define CMD_TC_TEMP_2 0x06
eencae 0:d563e74f0ae9 28 #define CMD_TC_TEMP_3 0x07
eencae 0:d563e74f0ae9 29 #define CMD_BI_MUX_24 0x15
eencae 0:d563e74f0ae9 30 #define CMD_BI_MUX_48 0x13
eencae 0:d563e74f0ae9 31 #define CMD_BI_MUX_100 0x10
eencae 0:d563e74f0ae9 32 #define CMD_VOP_6V06 0xB2
eencae 0:d563e74f0ae9 33 #define CMD_VOP_7V38 0xC8
eencae 0:d563e74f0ae9 34
eencae 17:780a542d5f8b 35 // number of pixels on display
eencae 13:908644099648 36 #define WIDTH 84
eencae 13:908644099648 37 #define HEIGHT 48
eencae 17:780a542d5f8b 38 #define BANKS 6
eencae 13:908644099648 39
eencae 0:d563e74f0ae9 40 #include "mbed.h"
eencae 0:d563e74f0ae9 41
eencae 17:780a542d5f8b 42 /**
eencae 16:b37a3a260598 43 @brief Library for interfacing with Nokia 5110 LCD display (https://www.sparkfun.com/products/10168) using the hardware SPI on the mbed.
eencae 5:6ea180eef702 44 @brief The display is powered from a GPIO pin meaning it can be controlled via software. The LED backlight is also software-controllable (via PWM pin).
eencae 17:780a542d5f8b 45 @brief Can print characters and strings to the display using the included 5x7 font.
eencae 5:6ea180eef702 46 @brief The library also implements a screen buffer so that individual pixels on the display (84 x 48) can be set, cleared and read.
eencae 17:780a542d5f8b 47 @brief The library can print primitive shapes (lines, circles, rectangles)
eencae 5:6ea180eef702 48 @brief Acknowledgements to Chris Yan's Nokia_5110 Library.
eencae 5:6ea180eef702 49
eencae 17:780a542d5f8b 50 @brief Revision 1.2
eencae 5:6ea180eef702 51
eencae 5:6ea180eef702 52 @author Craig A. Evans
eencae 17:780a542d5f8b 53 @date 17th March 2015
eencae 2:e93021cfb0a9 54 *
eencae 2:e93021cfb0a9 55 * Example:
eencae 2:e93021cfb0a9 56 * @code
eencae 17:780a542d5f8b 57
eencae 13:908644099648 58 #include "mbed.h"
eencae 13:908644099648 59 #include "N5110.h"
eencae 13:908644099648 60
eencae 13:908644099648 61 // VCC,SCE,RST,D/C,MOSI,SCLK,LED
eencae 13:908644099648 62 N5110 lcd(p7,p8,p9,p10,p11,p13,p21);
eencae 13:908644099648 63 // Can also power (VCC) directly from VOUT (3.3 V) -
eencae 17:780a542d5f8b 64 // Can give better performance due to current limitation from GPIO pin
eencae 13:908644099648 65
eencae 13:908644099648 66 int main()
eencae 13:908644099648 67 {
eencae 13:908644099648 68 // first need to initialise display
eencae 13:908644099648 69 lcd.init();
eencae 13:908644099648 70
eencae 13:908644099648 71 while(1) {
eencae 13:908644099648 72
eencae 13:908644099648 73 // these are default settings so not strictly needed
eencae 13:908644099648 74 lcd.normalMode(); // normal colour mode
eencae 17:780a542d5f8b 75 lcd.setBrightness(0.5); // put LED backlight on 50%
eencae 17:780a542d5f8b 76
eencae 13:908644099648 77 // can directly print strings at specified co-ordinates
eencae 13:908644099648 78 lcd.printString("Hello, World!",0,0);
eencae 13:908644099648 79
eencae 17:780a542d5f8b 80 char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
eencae 17:780a542d5f8b 81 // so can display a string of a maximum 14 characters in length
eencae 13:908644099648 82 // or create formatted strings - ensure they aren't more than 14 characters long
eencae 13:908644099648 83 int temperature = 27;
eencae 13:908644099648 84 int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer
eencae 13:908644099648 85 // it is important the format specifier ensures the length will fit in the buffer
eencae 13:908644099648 86 if (length <= 14) // if string will fit on display
eencae 13:908644099648 87 lcd.printString(buffer,0,1); // display on screen
eencae 17:780a542d5f8b 88
eencae 13:908644099648 89 float pressure = 1012.3; // same idea with floats
eencae 13:908644099648 90 length = sprintf(buffer,"P = %.2f mb",pressure);
eencae 13:908644099648 91 if (length <= 14)
eencae 13:908644099648 92 lcd.printString(buffer,0,2);
eencae 17:780a542d5f8b 93
eencae 17:780a542d5f8b 94 // can also print individual characters at specified place
eencae 13:908644099648 95 lcd.printChar('X',5,3);
eencae 17:780a542d5f8b 96
eencae 17:780a542d5f8b 97 // draw a line across the display at y = 40 pixels (origin top-left)
eencae 13:908644099648 98 for (int i = 0; i < WIDTH; i++) {
eencae 17:780a542d5f8b 99 lcd.setPixel(i,40);
eencae 13:908644099648 100 }
eencae 13:908644099648 101 // need to refresh display after setting pixels
eencae 17:780a542d5f8b 102 lcd.refresh();
eencae 17:780a542d5f8b 103
eencae 13:908644099648 104 // can also check status of pixels using getPixel(x,y)
eencae 17:780a542d5f8b 105
eencae 13:908644099648 106 wait(5.0);
eencae 13:908644099648 107 lcd.clear(); // clear display
eencae 13:908644099648 108 lcd.inverseMode(); // invert colours
eencae 13:908644099648 109 lcd.setBrightness(1.0); // put LED backlight on full
eencae 17:780a542d5f8b 110
eencae 13:908644099648 111 float array[84];
eencae 17:780a542d5f8b 112
eencae 13:908644099648 113 for (int i = 0; i < 84; i++) {
eencae 17:780a542d5f8b 114 array[i] = 0.5 + 0.5*sin(i*2*3.14/84);
eencae 13:908644099648 115 }
eencae 17:780a542d5f8b 116
eencae 13:908644099648 117 // can also plot graphs - 84 elements only
eencae 13:908644099648 118 // values must be in range 0.0 - 1.0
eencae 13:908644099648 119 lcd.plotArray(array);
eencae 17:780a542d5f8b 120 wait(5.0);
eencae 17:780a542d5f8b 121 lcd.clear();
eencae 17:780a542d5f8b 122 lcd.normalMode(); // normal colour mode back
eencae 17:780a542d5f8b 123 lcd.setBrightness(0.5); // put LED backlight on 50%
eencae 17:780a542d5f8b 124
eencae 17:780a542d5f8b 125 // example of drawing lines
eencae 17:780a542d5f8b 126 for (int x = 0; x < WIDTH ; x+=10) {
eencae 17:780a542d5f8b 127 // x0,y0,x1,y1,type 0-white,1-black,2-dotted
eencae 17:780a542d5f8b 128 lcd.drawLine(0,0,x,HEIGHT,2);
eencae 17:780a542d5f8b 129 }
eencae 17:780a542d5f8b 130
eencae 17:780a542d5f8b 131 wait(5.0);
eencae 17:780a542d5f8b 132 lcd.clear();
eencae 17:780a542d5f8b 133
eencae 17:780a542d5f8b 134 // example of how to draw circles
eencae 17:780a542d5f8b 135 lcd.drawCircle(WIDTH/2,HEIGHT/2,20,1); // x,y,radius,black fill
eencae 17:780a542d5f8b 136 lcd.drawCircle(WIDTH/2,HEIGHT/2,10,2); // x,y,radius,white fill
eencae 17:780a542d5f8b 137 lcd.drawCircle(WIDTH/2,HEIGHT/2,30,0); // x,y,radius,transparent with outline
eencae 17:780a542d5f8b 138
eencae 17:780a542d5f8b 139 wait(5.0);
eencae 17:780a542d5f8b 140 lcd.clear();
eencae 17:780a542d5f8b 141
eencae 17:780a542d5f8b 142 // example of how to draw rectangles
eencae 17:780a542d5f8b 143 // origin x,y,width,height,type
eencae 17:780a542d5f8b 144 lcd.drawRect(10,10,50,30,1); // filled black rectangle
eencae 17:780a542d5f8b 145 lcd.drawRect(15,15,20,10,2); // filled white rectange (no outline)
eencae 17:780a542d5f8b 146 lcd.drawRect(2,2,70,40,0); // transparent, just outline
eencae 17:780a542d5f8b 147
eencae 17:780a542d5f8b 148 wait(5.0);
eencae 17:780a542d5f8b 149 lcd.clear();
eencae 10:6f3abb40202b 150
eencae 13:908644099648 151 }
eencae 13:908644099648 152 }
eencae 13:908644099648 153
eencae 17:780a542d5f8b 154
eencae 2:e93021cfb0a9 155 * @endcode
eencae 2:e93021cfb0a9 156 */
eencae 1:df68f34cd32d 157 class N5110
eencae 1:df68f34cd32d 158 {
eencae 0:d563e74f0ae9 159
eencae 1:df68f34cd32d 160 public:
eencae 1:df68f34cd32d 161 /** Create a N5110 object connected to the specified pins
eencae 1:df68f34cd32d 162 *
eencae 1:df68f34cd32d 163 * @param pwr Pin connected to Vcc on the LCD display (pin 1)
eencae 1:df68f34cd32d 164 * @param sce Pin connected to chip enable (pin 3)
eencae 1:df68f34cd32d 165 * @param rst Pin connected to reset (pin 4)
eencae 1:df68f34cd32d 166 * @param dc Pin connected to data/command select (pin 5)
eencae 1:df68f34cd32d 167 * @param mosi Pin connected to data input (MOSI) (pin 6)
eencae 1:df68f34cd32d 168 * @param sclk Pin connected to serial clock (SCLK) (pin 7)
eencae 17:780a542d5f8b 169 * @param led Pin connected to LED backlight (must be PWM) (pin 8)
eencae 17:780a542d5f8b 170 *
eencae 1:df68f34cd32d 171 */
eencae 1:df68f34cd32d 172 N5110(PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin);
eencae 17:780a542d5f8b 173
eencae 1:df68f34cd32d 174 /** Initialise display
eencae 1:df68f34cd32d 175 *
eencae 1:df68f34cd32d 176 * Powers up the display and turns on backlight (50% brightness default).
eencae 1:df68f34cd32d 177 * Sets the display up in horizontal addressing mode and with normal video mode.
eencae 1:df68f34cd32d 178 */
eencae 1:df68f34cd32d 179 void init();
eencae 17:780a542d5f8b 180
eencae 1:df68f34cd32d 181 /** Turn off
eencae 1:df68f34cd32d 182 *
eencae 1:df68f34cd32d 183 * Powers down the display and turns of the backlight.
eencae 1:df68f34cd32d 184 * Needs to be reinitialised before being re-used.
eencae 1:df68f34cd32d 185 */
eencae 1:df68f34cd32d 186 void turnOff();
eencae 17:780a542d5f8b 187
eencae 1:df68f34cd32d 188 /** Clears
eencae 1:df68f34cd32d 189 *
eencae 1:df68f34cd32d 190 * Clears the screen.
eencae 1:df68f34cd32d 191 */
eencae 1:df68f34cd32d 192 void clear();
eencae 17:780a542d5f8b 193
eencae 1:df68f34cd32d 194 /** Turn on normal video mode (default)
eencae 1:df68f34cd32d 195 * Black on white
eencae 1:df68f34cd32d 196 */
eencae 1:df68f34cd32d 197 void normalMode();
eencae 17:780a542d5f8b 198
eencae 1:df68f34cd32d 199 /** Turn on inverse video mode (default)
eencae 1:df68f34cd32d 200 * White on black
eencae 1:df68f34cd32d 201 */
eencae 1:df68f34cd32d 202 void inverseMode();
eencae 17:780a542d5f8b 203
eencae 1:df68f34cd32d 204 /** Set Brightness
eencae 1:df68f34cd32d 205 *
eencae 1:df68f34cd32d 206 * Sets brightness of LED backlight.
eencae 1:df68f34cd32d 207 * @param brightness - float in range 0.0 to 1.0
eencae 1:df68f34cd32d 208 */
eencae 1:df68f34cd32d 209 void setBrightness(float brightness);
el14pjgn 18:d2140be00144 210
el14pjgn 18:d2140be00144 211 /** Set PWM frequency
el14pjgn 18:d2140be00144 212 * Sets PWM frequency of LED backlight
el14pjgn 18:d2140be00144 213 * @param freq - float in the range 0.1+
el14pjgn 18:d2140be00144 214 */
el14pjgn 18:d2140be00144 215 void setPwmFreq(float freq);
eencae 17:780a542d5f8b 216
eencae 2:e93021cfb0a9 217 /** Print String
eencae 2:e93021cfb0a9 218 *
eencae 17:780a542d5f8b 219 * Prints a string of characters to the display.
eencae 2:e93021cfb0a9 220 * @param x - the column number (0 to 83)
eencae 2:e93021cfb0a9 221 * @param y - the row number (0 to 5) - the display is split into 6 banks - each bank can be considered a row
eencae 2:e93021cfb0a9 222 */
eencae 1:df68f34cd32d 223 void printString(const char * str,int x,int y);
eencae 17:780a542d5f8b 224
eencae 1:df68f34cd32d 225 /** Print Character
eencae 1:df68f34cd32d 226 *
eencae 13:908644099648 227 * Sends a character to the display. Printed at the specified location
eencae 1:df68f34cd32d 228 * @param c - the character to print. Can print ASCII as so printChar('C').
eencae 13:908644099648 229 * @param x - the column number (0 to 83)
eencae 13:908644099648 230 * @param y - the row number (0 to 5) - the display is split into 6 banks - each bank can be considered a row
eencae 1:df68f34cd32d 231 */
eencae 13:908644099648 232 void printChar(char c,int x,int y);
el14pjgn 18:d2140be00144 233
el14pjgn 18:d2140be00144 234 /** Select Buffer
el14pjgn 18:d2140be00144 235 *
el14pjgn 18:d2140be00144 236 * Selects active buffer(s).
el14pjgn 18:d2140be00144 237 * @param type - switches between editable and displayed buffer edit;
el14pjgn 18:d2140be00144 238 * type = 1; selects visible buffer.
el14pjgn 18:d2140be00144 239 * type = 2; selects buffer to be written to.
el14pjgn 18:d2140be00144 240 * type = 3; switches both.
el14pjgn 18:d2140be00144 241 */
el14pjgn 18:d2140be00144 242 void selectBuffer(int type,int buffer);
eencae 17:780a542d5f8b 243
eencae 6:adb79338d40f 244 /** Set a Pixel
eencae 6:adb79338d40f 245 *
eencae 6:adb79338d40f 246 * This function sets a pixel in the display. A call to refresh() must be made
eencae 6:adb79338d40f 247 * to update the display to reflect the change in pixels.
eencae 6:adb79338d40f 248 * @param x - the x co-ordinate of the pixel (0 to 83)
eencae 17:780a542d5f8b 249 * @param y - the y co-ordinate of the pixel (0 to 47)
eencae 6:adb79338d40f 250 */
eencae 1:df68f34cd32d 251 void setPixel(int x, int y);
el14pjgn 18:d2140be00144 252
el14pjgn 18:d2140be00144 253 /** write to a pixel
el14pjgn 18:d2140be00144 254 *
el14pjgn 18:d2140be00144 255 * This function writes the value v to a pixel on the display. A call to refresh() must be made
el14pjgn 18:d2140be00144 256 * to update the display to reflect the change in pixels.
el14pjgn 18:d2140be00144 257 * @param x - the x co-ordinate of the pixel (0 to 83)
el14pjgn 18:d2140be00144 258 * @param y - the y co-ordinate of the pixel (0 to 47)
el14pjgn 18:d2140be00144 259 * @param v - the value to be written to the pixel (0 to 1)
el14pjgn 18:d2140be00144 260 */
el14pjgn 18:d2140be00144 261 void writePixel(int x, int y, int v);
eencae 17:780a542d5f8b 262
eencae 6:adb79338d40f 263 /** Clear a Pixel
eencae 6:adb79338d40f 264 *
eencae 6:adb79338d40f 265 * This function clears pixel in the display. A call to refresh() must be made
eencae 6:adb79338d40f 266 * to update the display to reflect the change in pixels.
eencae 6:adb79338d40f 267 * @param x - the x co-ordinate of the pixel (0 to 83)
eencae 17:780a542d5f8b 268 * @param y - the y co-ordinate of the pixel (0 to 47)
eencae 6:adb79338d40f 269 */
eencae 1:df68f34cd32d 270 void clearPixel(int x, int y);
eencae 17:780a542d5f8b 271
eencae 6:adb79338d40f 272 /** Get a Pixel
eencae 6:adb79338d40f 273 *
eencae 6:adb79338d40f 274 * This function gets the status of a pixel in the display.
eencae 6:adb79338d40f 275 * @param x - the x co-ordinate of the pixel (0 to 83)
eencae 17:780a542d5f8b 276 * @param y - the y co-ordinate of the pixel (0 to 47)
eencae 17:780a542d5f8b 277 * @returns
eencae 6:adb79338d40f 278 * 0 - pixel is clear
eencae 6:adb79338d40f 279 * non-zero - pixel is set
eencae 6:adb79338d40f 280 */
eencae 7:3010f24e0a81 281 int getPixel(int x, int y);
eencae 17:780a542d5f8b 282
eencae 6:adb79338d40f 283 /** Refresh display
eencae 6:adb79338d40f 284 *
eencae 6:adb79338d40f 285 * This functions refreshes the display to reflect the current data in the buffer.
eencae 17:780a542d5f8b 286 */
eencae 6:adb79338d40f 287 void refresh();
eencae 17:780a542d5f8b 288
eencae 6:adb79338d40f 289 /** Randomise buffer
eencae 6:adb79338d40f 290 *
eencae 17:780a542d5f8b 291 * This function fills the buffer with random data. Can be used to test the display.
eencae 6:adb79338d40f 292 * A call to refresh() must be made to update the display to reflect the change in pixels.
eencae 6:adb79338d40f 293 * The seed is not set and so the generated pattern will probably be the same each time.
eencae 6:adb79338d40f 294 * TODO: Randomise the seed - maybe using the noise on the AnalogIn pins.
eencae 6:adb79338d40f 295 */
eencae 1:df68f34cd32d 296 void randomiseBuffer();
el14pjgn 18:d2140be00144 297
el14pjgn 18:d2140be00144 298 /** Plot Array 2d
el14pjgn 18:d2140be00144 299 *
el14pjgn 18:d2140be00144 300 * This function plots a two-dimensional array on the display.
el14pjgn 18:d2140be00144 301 * @param array2d[][] - y values of the plot. Values should be normalised in the range 0.0 to 1.0. First 84 plotted.
el14pjgn 18:d2140be00144 302 */
el14pjgn 18:d2140be00144 303 void plotArray2d(bool array2d[][48]);
el14pjgn 18:d2140be00144 304
el14pjgn 18:d2140be00144 305 /** Plot Array 3d
el14pjgn 18:d2140be00144 306 *
el14pjgn 18:d2140be00144 307 * This function plots a two-dimensional array on the display.
el14pjgn 18:d2140be00144 308 * @param array2d[][] - y values of the plot. Values should be normalised in the range 0.0 to 1.0. First 84 plotted.
el14pjgn 18:d2140be00144 309 * Slightly over-specific to project
el14pjgn 18:d2140be00144 310 */
el14pjgn 18:d2140be00144 311 void plotArray3d(bool array3d[][50][2],int z,int off_x=0, int off_y=0);
eencae 17:780a542d5f8b 312
eencae 8:40abe5736eca 313 /** Plot Array
eencae 8:40abe5736eca 314 *
eencae 17:780a542d5f8b 315 * This function plots a one-dimensional array on the display.
eencae 17:780a542d5f8b 316 * @param array[] - y values of the plot. Values should be normalised in the range 0.0 to 1.0. First 84 plotted.
eencae 8:40abe5736eca 317 */
eencae 8:40abe5736eca 318 void plotArray(float array[]);
eencae 1:df68f34cd32d 319
eencae 17:780a542d5f8b 320 /** Draw Circle
eencae 17:780a542d5f8b 321 *
eencae 17:780a542d5f8b 322 * This function draws a circle at the specified origin with specified radius to the display.
eencae 17:780a542d5f8b 323 * Uses the midpoint circle algorithm.
eencae 17:780a542d5f8b 324 * @see http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
eencae 17:780a542d5f8b 325 * @param x0 - x-coordinate of centre
eencae 17:780a542d5f8b 326 * @param y0 - y-coordinate of centre
eencae 17:780a542d5f8b 327 * @param radius - radius of circle in pixels
eencae 17:780a542d5f8b 328 * @param fill - 0 transparent (w/outline), 1 filled black, 2 filled white (wo/outline)
eencae 17:780a542d5f8b 329 */
eencae 17:780a542d5f8b 330 void drawCircle(int x0,int y0,int radius,int fill);
eencae 17:780a542d5f8b 331
eencae 17:780a542d5f8b 332 /** Draw Line
eencae 17:780a542d5f8b 333 *
eencae 17:780a542d5f8b 334 * This function draws a line between the specified points using linear interpolation.
eencae 17:780a542d5f8b 335 * @param x0 - x-coordinate of first point
eencae 17:780a542d5f8b 336 * @param y0 - y-coordinate of first point
eencae 17:780a542d5f8b 337 * @param x1 - x-coordinate of last point
eencae 17:780a542d5f8b 338 * @param y1 - y-coordinate of last point
eencae 17:780a542d5f8b 339 * @param type - 0 white,1 black,2 dotted
eencae 17:780a542d5f8b 340 */
eencae 17:780a542d5f8b 341 void drawLine(int x0,int y0,int x1,int y1,int type);
eencae 17:780a542d5f8b 342
eencae 17:780a542d5f8b 343 /** Draw Rectangle
eencae 17:780a542d5f8b 344 *
eencae 17:780a542d5f8b 345 * This function draws a rectangle.
eencae 17:780a542d5f8b 346 * @param x0 - x-coordinate of origin (top-left)
eencae 17:780a542d5f8b 347 * @param y0 - y-coordinate of origin (top-left)
eencae 17:780a542d5f8b 348 * @param width - width of rectangle
eencae 17:780a542d5f8b 349 * @param height - height of rectangle
eencae 17:780a542d5f8b 350 * @param fill - 0 transparent (w/outline), 1 filled black, 2 filled white (wo/outline)
eencae 17:780a542d5f8b 351 */
eencae 17:780a542d5f8b 352 void drawRect(int x0,int y0,int width,int height,int fill);
eencae 17:780a542d5f8b 353
eencae 17:780a542d5f8b 354
eencae 1:df68f34cd32d 355 private:
eencae 13:908644099648 356
eencae 13:908644099648 357 void setXYAddress(int x, int y);
eencae 1:df68f34cd32d 358 void initSPI();
eencae 1:df68f34cd32d 359 void turnOn();
eencae 1:df68f34cd32d 360 void reset();
eencae 1:df68f34cd32d 361 void clearRAM();
eencae 6:adb79338d40f 362 void clearBuffer();
eencae 1:df68f34cd32d 363 void sendCommand(unsigned char command);
eencae 1:df68f34cd32d 364 void sendData(unsigned char data);
eencae 1:df68f34cd32d 365
eencae 1:df68f34cd32d 366 public:
el14pjgn 18:d2140be00144 367 unsigned char buffer[84][6][3]; // screen buffer - the 6 is for the banks - each one is 8 bits;
el14pjgn 18:d2140be00144 368 int bufferFrameEdit;
el14pjgn 18:d2140be00144 369 int bufferFrameDisplay;
eencae 1:df68f34cd32d 370
eencae 1:df68f34cd32d 371 private: // private variables
eencae 1:df68f34cd32d 372 SPI* spi;
eencae 1:df68f34cd32d 373 PwmOut* led;
eencae 1:df68f34cd32d 374 DigitalOut* pwr;
eencae 1:df68f34cd32d 375 DigitalOut* sce;
eencae 1:df68f34cd32d 376 DigitalOut* rst;
eencae 1:df68f34cd32d 377 DigitalOut* dc;
eencae 0:d563e74f0ae9 378
eencae 0:d563e74f0ae9 379 };
eencae 0:d563e74f0ae9 380
eencae 0:d563e74f0ae9 381 const unsigned char font5x7[480] = {
eencae 0:d563e74f0ae9 382 0x00, 0x00, 0x00, 0x00, 0x00,// (space)
eencae 0:d563e74f0ae9 383 0x00, 0x00, 0x5F, 0x00, 0x00,// !
eencae 0:d563e74f0ae9 384 0x00, 0x07, 0x00, 0x07, 0x00,// "
eencae 0:d563e74f0ae9 385 0x14, 0x7F, 0x14, 0x7F, 0x14,// #
eencae 0:d563e74f0ae9 386 0x24, 0x2A, 0x7F, 0x2A, 0x12,// $
eencae 0:d563e74f0ae9 387 0x23, 0x13, 0x08, 0x64, 0x62,// %
eencae 0:d563e74f0ae9 388 0x36, 0x49, 0x55, 0x22, 0x50,// &
eencae 0:d563e74f0ae9 389 0x00, 0x05, 0x03, 0x00, 0x00,// '
eencae 0:d563e74f0ae9 390 0x00, 0x1C, 0x22, 0x41, 0x00,// (
eencae 0:d563e74f0ae9 391 0x00, 0x41, 0x22, 0x1C, 0x00,// )
eencae 0:d563e74f0ae9 392 0x08, 0x2A, 0x1C, 0x2A, 0x08,// *
eencae 0:d563e74f0ae9 393 0x08, 0x08, 0x3E, 0x08, 0x08,// +
eencae 0:d563e74f0ae9 394 0x00, 0x50, 0x30, 0x00, 0x00,// ,
eencae 0:d563e74f0ae9 395 0x08, 0x08, 0x08, 0x08, 0x08,// -
eencae 0:d563e74f0ae9 396 0x00, 0x60, 0x60, 0x00, 0x00,// .
eencae 0:d563e74f0ae9 397 0x20, 0x10, 0x08, 0x04, 0x02,// /
eencae 0:d563e74f0ae9 398 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
eencae 0:d563e74f0ae9 399 0x00, 0x42, 0x7F, 0x40, 0x00,// 1
eencae 0:d563e74f0ae9 400 0x42, 0x61, 0x51, 0x49, 0x46,// 2
eencae 0:d563e74f0ae9 401 0x21, 0x41, 0x45, 0x4B, 0x31,// 3
eencae 0:d563e74f0ae9 402 0x18, 0x14, 0x12, 0x7F, 0x10,// 4
eencae 0:d563e74f0ae9 403 0x27, 0x45, 0x45, 0x45, 0x39,// 5
eencae 0:d563e74f0ae9 404 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
eencae 0:d563e74f0ae9 405 0x01, 0x71, 0x09, 0x05, 0x03,// 7
eencae 0:d563e74f0ae9 406 0x36, 0x49, 0x49, 0x49, 0x36,// 8
eencae 0:d563e74f0ae9 407 0x06, 0x49, 0x49, 0x29, 0x1E,// 9
eencae 0:d563e74f0ae9 408 0x00, 0x36, 0x36, 0x00, 0x00,// :
eencae 0:d563e74f0ae9 409 0x00, 0x56, 0x36, 0x00, 0x00,// ;
eencae 0:d563e74f0ae9 410 0x00, 0x08, 0x14, 0x22, 0x41,// <
eencae 0:d563e74f0ae9 411 0x14, 0x14, 0x14, 0x14, 0x14,// =
eencae 0:d563e74f0ae9 412 0x41, 0x22, 0x14, 0x08, 0x00,// >
eencae 0:d563e74f0ae9 413 0x02, 0x01, 0x51, 0x09, 0x06,// ?
eencae 0:d563e74f0ae9 414 0x32, 0x49, 0x79, 0x41, 0x3E,// @
eencae 0:d563e74f0ae9 415 0x7E, 0x11, 0x11, 0x11, 0x7E,// A
eencae 0:d563e74f0ae9 416 0x7F, 0x49, 0x49, 0x49, 0x36,// B
eencae 0:d563e74f0ae9 417 0x3E, 0x41, 0x41, 0x41, 0x22,// C
eencae 0:d563e74f0ae9 418 0x7F, 0x41, 0x41, 0x22, 0x1C,// D
eencae 0:d563e74f0ae9 419 0x7F, 0x49, 0x49, 0x49, 0x41,// E
eencae 0:d563e74f0ae9 420 0x7F, 0x09, 0x09, 0x01, 0x01,// F
eencae 0:d563e74f0ae9 421 0x3E, 0x41, 0x41, 0x51, 0x32,// G
eencae 0:d563e74f0ae9 422 0x7F, 0x08, 0x08, 0x08, 0x7F,// H
eencae 0:d563e74f0ae9 423 0x00, 0x41, 0x7F, 0x41, 0x00,// I
eencae 0:d563e74f0ae9 424 0x20, 0x40, 0x41, 0x3F, 0x01,// J
eencae 0:d563e74f0ae9 425 0x7F, 0x08, 0x14, 0x22, 0x41,// K
eencae 0:d563e74f0ae9 426 0x7F, 0x40, 0x40, 0x40, 0x40,// L
eencae 0:d563e74f0ae9 427 0x7F, 0x02, 0x04, 0x02, 0x7F,// M
eencae 0:d563e74f0ae9 428 0x7F, 0x04, 0x08, 0x10, 0x7F,// N
eencae 0:d563e74f0ae9 429 0x3E, 0x41, 0x41, 0x41, 0x3E,// O
eencae 0:d563e74f0ae9 430 0x7F, 0x09, 0x09, 0x09, 0x06,// P
eencae 0:d563e74f0ae9 431 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
eencae 0:d563e74f0ae9 432 0x7F, 0x09, 0x19, 0x29, 0x46,// R
eencae 0:d563e74f0ae9 433 0x46, 0x49, 0x49, 0x49, 0x31,// S
eencae 0:d563e74f0ae9 434 0x01, 0x01, 0x7F, 0x01, 0x01,// T
eencae 0:d563e74f0ae9 435 0x3F, 0x40, 0x40, 0x40, 0x3F,// U
eencae 0:d563e74f0ae9 436 0x1F, 0x20, 0x40, 0x20, 0x1F,// V
eencae 0:d563e74f0ae9 437 0x7F, 0x20, 0x18, 0x20, 0x7F,// W
eencae 0:d563e74f0ae9 438 0x63, 0x14, 0x08, 0x14, 0x63,// X
eencae 0:d563e74f0ae9 439 0x03, 0x04, 0x78, 0x04, 0x03,// Y
eencae 0:d563e74f0ae9 440 0x61, 0x51, 0x49, 0x45, 0x43,// Z
eencae 0:d563e74f0ae9 441 0x00, 0x00, 0x7F, 0x41, 0x41,// [
eencae 0:d563e74f0ae9 442 0x02, 0x04, 0x08, 0x10, 0x20,// "\"
eencae 0:d563e74f0ae9 443 0x41, 0x41, 0x7F, 0x00, 0x00,// ]
eencae 0:d563e74f0ae9 444 0x04, 0x02, 0x01, 0x02, 0x04,// ^
eencae 0:d563e74f0ae9 445 0x40, 0x40, 0x40, 0x40, 0x40,// _
eencae 0:d563e74f0ae9 446 0x00, 0x01, 0x02, 0x04, 0x00,// `
eencae 0:d563e74f0ae9 447 0x20, 0x54, 0x54, 0x54, 0x78,// a
eencae 0:d563e74f0ae9 448 0x7F, 0x48, 0x44, 0x44, 0x38,// b
eencae 0:d563e74f0ae9 449 0x38, 0x44, 0x44, 0x44, 0x20,// c
eencae 0:d563e74f0ae9 450 0x38, 0x44, 0x44, 0x48, 0x7F,// d
eencae 0:d563e74f0ae9 451 0x38, 0x54, 0x54, 0x54, 0x18,// e
eencae 0:d563e74f0ae9 452 0x08, 0x7E, 0x09, 0x01, 0x02,// f
eencae 0:d563e74f0ae9 453 0x08, 0x14, 0x54, 0x54, 0x3C,// g
eencae 0:d563e74f0ae9 454 0x7F, 0x08, 0x04, 0x04, 0x78,// h
eencae 0:d563e74f0ae9 455 0x00, 0x44, 0x7D, 0x40, 0x00,// i
eencae 0:d563e74f0ae9 456 0x20, 0x40, 0x44, 0x3D, 0x00,// j
eencae 0:d563e74f0ae9 457 0x00, 0x7F, 0x10, 0x28, 0x44,// k
eencae 0:d563e74f0ae9 458 0x00, 0x41, 0x7F, 0x40, 0x00,// l
eencae 0:d563e74f0ae9 459 0x7C, 0x04, 0x18, 0x04, 0x78,// m
eencae 0:d563e74f0ae9 460 0x7C, 0x08, 0x04, 0x04, 0x78,// n
eencae 0:d563e74f0ae9 461 0x38, 0x44, 0x44, 0x44, 0x38,// o
eencae 0:d563e74f0ae9 462 0x7C, 0x14, 0x14, 0x14, 0x08,// p
eencae 0:d563e74f0ae9 463 0x08, 0x14, 0x14, 0x18, 0x7C,// q
eencae 0:d563e74f0ae9 464 0x7C, 0x08, 0x04, 0x04, 0x08,// r
eencae 0:d563e74f0ae9 465 0x48, 0x54, 0x54, 0x54, 0x20,// s
eencae 0:d563e74f0ae9 466 0x04, 0x3F, 0x44, 0x40, 0x20,// t
eencae 0:d563e74f0ae9 467 0x3C, 0x40, 0x40, 0x20, 0x7C,// u
eencae 0:d563e74f0ae9 468 0x1C, 0x20, 0x40, 0x20, 0x1C,// v
eencae 0:d563e74f0ae9 469 0x3C, 0x40, 0x30, 0x40, 0x3C,// w
eencae 0:d563e74f0ae9 470 0x44, 0x28, 0x10, 0x28, 0x44,// x
eencae 0:d563e74f0ae9 471 0x0C, 0x50, 0x50, 0x50, 0x3C,// y
eencae 0:d563e74f0ae9 472 0x44, 0x64, 0x54, 0x4C, 0x44,// z
eencae 0:d563e74f0ae9 473 0x00, 0x08, 0x36, 0x41, 0x00,// {
eencae 0:d563e74f0ae9 474 0x00, 0x00, 0x7F, 0x00, 0x00,// |
eencae 0:d563e74f0ae9 475 0x00, 0x41, 0x36, 0x08, 0x00,// }
eencae 0:d563e74f0ae9 476 0x08, 0x08, 0x2A, 0x1C, 0x08,// ->
eencae 0:d563e74f0ae9 477 0x08, 0x1C, 0x2A, 0x08, 0x08 // <-
eencae 0:d563e74f0ae9 478 };
eencae 0:d563e74f0ae9 479
eencae 14:520a02fc12aa 480 #endif