Josh Davy / Mbed 2 deprecated Flip

Dependencies:   mbed el17jd

Committer:
joshdavy
Date:
Tue Mar 12 12:38:34 2019 +0000
Revision:
0:4916a63a6cbf
initial commit

Who changed what in which revision?

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