tr

Committer:
valavanisalex
Date:
Thu Feb 16 15:32:05 2017 +0000
Revision:
29:5bc91bd44c77
Parent:
28:4091516537e4
Child:
31:8a0c21042f82
Add const safety to prevent unintentional modification of parameters, and set types to unsigned int where appropriate

Who changed what in which revision?

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