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