ELEC2645 (2018/19) / Mbed 2 deprecated el18w2w1

Dependencies:   mbed

Committer:
wuweilong
Date:
Wed May 08 20:08:17 2019 +0000
Revision:
10:ae5f62a1e40e
version1

Who changed what in which revision?

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