bird

Dependencies:   mbed

Committer:
1013373474
Date:
Fri May 03 17:51:38 2019 +0000
Revision:
0:3887ebee1b37
fly bird

Who changed what in which revision?

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