Ryan Tseng
/
DisplayTest
KS0108/KS0108.h@0:87b78725a6dd, 2012-03-05 (annotated)
- Committer:
- kagelump
- Date:
- Mon Mar 05 06:00:16 2012 +0000
- Revision:
- 0:87b78725a6dd
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kagelump | 0:87b78725a6dd | 1 | #ifndef KS0108_H |
kagelump | 0:87b78725a6dd | 2 | #define KS0108_H |
kagelump | 0:87b78725a6dd | 3 | |
kagelump | 0:87b78725a6dd | 4 | #define VERSION 2.0 |
kagelump | 0:87b78725a6dd | 5 | |
kagelump | 0:87b78725a6dd | 6 | #include <mbed.h> |
kagelump | 0:87b78725a6dd | 7 | #include "SystemFont5x7.h" |
kagelump | 0:87b78725a6dd | 8 | |
kagelump | 0:87b78725a6dd | 9 | /************************************************************************************/ |
kagelump | 0:87b78725a6dd | 10 | // Commands |
kagelump | 0:87b78725a6dd | 11 | #define LCD_ON 0x3F |
kagelump | 0:87b78725a6dd | 12 | #define LCD_OFF 0x3E |
kagelump | 0:87b78725a6dd | 13 | #define LCD_SET_ADD 0x40 |
kagelump | 0:87b78725a6dd | 14 | #define LCD_SET_PAGE 0xB8 |
kagelump | 0:87b78725a6dd | 15 | #define LCD_DISP_START 0xC0 |
kagelump | 0:87b78725a6dd | 16 | |
kagelump | 0:87b78725a6dd | 17 | //Controller directives |
kagelump | 0:87b78725a6dd | 18 | #define LEFT 0 |
kagelump | 0:87b78725a6dd | 19 | #define RIGHT 1 |
kagelump | 0:87b78725a6dd | 20 | #define BOTH 3 |
kagelump | 0:87b78725a6dd | 21 | #define NONE 4 |
kagelump | 0:87b78725a6dd | 22 | |
kagelump | 0:87b78725a6dd | 23 | // Colors |
kagelump | 0:87b78725a6dd | 24 | #define BLACK 0xFF |
kagelump | 0:87b78725a6dd | 25 | #define WHITE 0x00 |
kagelump | 0:87b78725a6dd | 26 | |
kagelump | 0:87b78725a6dd | 27 | //Screen dimensions |
kagelump | 0:87b78725a6dd | 28 | #define SCREEN_HEIGHT 64 |
kagelump | 0:87b78725a6dd | 29 | #define SCREEN_WIDTH 128 |
kagelump | 0:87b78725a6dd | 30 | #define CHIP_WIDTH 64 |
kagelump | 0:87b78725a6dd | 31 | |
kagelump | 0:87b78725a6dd | 32 | /***********************************************************************************/ |
kagelump | 0:87b78725a6dd | 33 | //helper functions |
kagelump | 0:87b78725a6dd | 34 | |
kagelump | 0:87b78725a6dd | 35 | #define absDiff(x,y) ((x>y) ? (x-y) : (y-x)) |
kagelump | 0:87b78725a6dd | 36 | #define swap(a,b) \ |
kagelump | 0:87b78725a6dd | 37 | do\ |
kagelump | 0:87b78725a6dd | 38 | {\ |
kagelump | 0:87b78725a6dd | 39 | uint8_t t;\ |
kagelump | 0:87b78725a6dd | 40 | t=a;\ |
kagelump | 0:87b78725a6dd | 41 | a=b;\ |
kagelump | 0:87b78725a6dd | 42 | b=t;\ |
kagelump | 0:87b78725a6dd | 43 | } while(0) |
kagelump | 0:87b78725a6dd | 44 | |
kagelump | 0:87b78725a6dd | 45 | /**************************************************************************************/ |
kagelump | 0:87b78725a6dd | 46 | |
kagelump | 0:87b78725a6dd | 47 | // Font Indices |
kagelump | 0:87b78725a6dd | 48 | #define FONT_LENGTH 0 |
kagelump | 0:87b78725a6dd | 49 | #define FONT_FIXED_WIDTH 2 |
kagelump | 0:87b78725a6dd | 50 | #define FONT_HEIGHT 3 |
kagelump | 0:87b78725a6dd | 51 | #define FONT_FIRST_CHAR 4 |
kagelump | 0:87b78725a6dd | 52 | #define FONT_CHAR_COUNT 5 |
kagelump | 0:87b78725a6dd | 53 | #define FONT_WIDTH_TABLE 6 |
kagelump | 0:87b78725a6dd | 54 | |
kagelump | 0:87b78725a6dd | 55 | |
kagelump | 0:87b78725a6dd | 56 | /*************************Callback function definietion for fonts *********************/ |
kagelump | 0:87b78725a6dd | 57 | typedef unsigned int (*FontCallback)(unsigned int*); |
kagelump | 0:87b78725a6dd | 58 | |
kagelump | 0:87b78725a6dd | 59 | /*************************Callback function for reading font array*********************/ |
kagelump | 0:87b78725a6dd | 60 | static unsigned int ReadData(unsigned int* ptr) { |
kagelump | 0:87b78725a6dd | 61 | return *ptr; |
kagelump | 0:87b78725a6dd | 62 | } |
kagelump | 0:87b78725a6dd | 63 | |
kagelump | 0:87b78725a6dd | 64 | /*************************************************************************************/ |
kagelump | 0:87b78725a6dd | 65 | #define MAX_IMG_SIZE 128*64 |
kagelump | 0:87b78725a6dd | 66 | |
kagelump | 0:87b78725a6dd | 67 | typedef struct { |
kagelump | 0:87b78725a6dd | 68 | unsigned int imgWidth; |
kagelump | 0:87b78725a6dd | 69 | unsigned int imgHeight; |
kagelump | 0:87b78725a6dd | 70 | unsigned char imgarray[MAX_IMG_SIZE]; |
kagelump | 0:87b78725a6dd | 71 | }Image; |
kagelump | 0:87b78725a6dd | 72 | |
kagelump | 0:87b78725a6dd | 73 | |
kagelump | 0:87b78725a6dd | 74 | typedef struct { |
kagelump | 0:87b78725a6dd | 75 | unsigned int x; |
kagelump | 0:87b78725a6dd | 76 | unsigned int y; |
kagelump | 0:87b78725a6dd | 77 | unsigned int page; |
kagelump | 0:87b78725a6dd | 78 | } LCDCoord; |
kagelump | 0:87b78725a6dd | 79 | |
kagelump | 0:87b78725a6dd | 80 | |
kagelump | 0:87b78725a6dd | 81 | /****************************************************************************************/ |
kagelump | 0:87b78725a6dd | 82 | |
kagelump | 0:87b78725a6dd | 83 | |
kagelump | 0:87b78725a6dd | 84 | |
kagelump | 0:87b78725a6dd | 85 | class KS0108 { |
kagelump | 0:87b78725a6dd | 86 | public: |
kagelump | 0:87b78725a6dd | 87 | |
kagelump | 0:87b78725a6dd | 88 | /** |
kagelump | 0:87b78725a6dd | 89 | *@brief Constructor, initializes the lcd on the respective pins. |
kagelump | 0:87b78725a6dd | 90 | *@param control pins RST,DI,RW,E,CS2,CS1 |
kagelump | 0:87b78725a6dd | 91 | *@param databus DB0-DB7 data pins |
kagelump | 0:87b78725a6dd | 92 | *@return none |
kagelump | 0:87b78725a6dd | 93 | */ |
kagelump | 0:87b78725a6dd | 94 | |
kagelump | 0:87b78725a6dd | 95 | KS0108 (PinName _RST,PinName _DI, PinName _RW, PinName _E, PinName _CS1, PinName _CS2, PinName DB0, PinName DB1, PinName DB2, PinName DB3, PinName DB4, PinName DB5, PinName DB6, PinName DB7); |
kagelump | 0:87b78725a6dd | 96 | |
kagelump | 0:87b78725a6dd | 97 | /** |
kagelump | 0:87b78725a6dd | 98 | *@brief Write instruction to the specific controller. |
kagelump | 0:87b78725a6dd | 99 | *@param Command command to send to the controller |
kagelump | 0:87b78725a6dd | 100 | *@param side controller side can be LEFT or RIGHT |
kagelump | 0:87b78725a6dd | 101 | *@return none |
kagelump | 0:87b78725a6dd | 102 | * |
kagelump | 0:87b78725a6dd | 103 | */ |
kagelump | 0:87b78725a6dd | 104 | void WriteInstruction(unsigned int Command,unsigned int side); |
kagelump | 0:87b78725a6dd | 105 | |
kagelump | 0:87b78725a6dd | 106 | /** |
kagelump | 0:87b78725a6dd | 107 | *@brief Write data byte to the controller. |
kagelump | 0:87b78725a6dd | 108 | *@param data data send to the controller chip |
kagelump | 0:87b78725a6dd | 109 | *@param side selected controller can be LEFT or RIGHT |
kagelump | 0:87b78725a6dd | 110 | *@return none |
kagelump | 0:87b78725a6dd | 111 | * |
kagelump | 0:87b78725a6dd | 112 | */ |
kagelump | 0:87b78725a6dd | 113 | void WriteData(unsigned int data ,unsigned char side); |
kagelump | 0:87b78725a6dd | 114 | |
kagelump | 0:87b78725a6dd | 115 | |
kagelump | 0:87b78725a6dd | 116 | /** |
kagelump | 0:87b78725a6dd | 117 | *@brief Write data byte to the controller (overloaded function). |
kagelump | 0:87b78725a6dd | 118 | * |
kagelump | 0:87b78725a6dd | 119 | *@param data data send to the controller chip |
kagelump | 0:87b78725a6dd | 120 | *@return none |
kagelump | 0:87b78725a6dd | 121 | */ |
kagelump | 0:87b78725a6dd | 122 | void WriteData(unsigned int data); |
kagelump | 0:87b78725a6dd | 123 | |
kagelump | 0:87b78725a6dd | 124 | /** |
kagelump | 0:87b78725a6dd | 125 | *@brief Write data byte to the screen on specific page and column |
kagelump | 0:87b78725a6dd | 126 | *@param page page varies from 0-7 for each side |
kagelump | 0:87b78725a6dd | 127 | *@param col col varies from 0-64 for each side |
kagelump | 0:87b78725a6dd | 128 | *@param data info to be written on given coordinates |
kagelump | 0:87b78725a6dd | 129 | *@return none |
kagelump | 0:87b78725a6dd | 130 | * |
kagelump | 0:87b78725a6dd | 131 | */ |
kagelump | 0:87b78725a6dd | 132 | void WriteDataColPag(unsigned int page, unsigned int col, unsigned int data); |
kagelump | 0:87b78725a6dd | 133 | |
kagelump | 0:87b78725a6dd | 134 | /** |
kagelump | 0:87b78725a6dd | 135 | *@brief Read data from display |
kagelump | 0:87b78725a6dd | 136 | *@param none |
kagelump | 0:87b78725a6dd | 137 | *@return none |
kagelump | 0:87b78725a6dd | 138 | * |
kagelump | 0:87b78725a6dd | 139 | */ |
kagelump | 0:87b78725a6dd | 140 | unsigned int ReadData(); |
kagelump | 0:87b78725a6dd | 141 | |
kagelump | 0:87b78725a6dd | 142 | /** |
kagelump | 0:87b78725a6dd | 143 | *@brief Read status of display , and check if it's busy |
kagelump | 0:87b78725a6dd | 144 | *@param none |
kagelump | 0:87b78725a6dd | 145 | *@return status status of display |
kagelump | 0:87b78725a6dd | 146 | * |
kagelump | 0:87b78725a6dd | 147 | */ |
kagelump | 0:87b78725a6dd | 148 | unsigned int ReadStatus(); |
kagelump | 0:87b78725a6dd | 149 | |
kagelump | 0:87b78725a6dd | 150 | /** |
kagelump | 0:87b78725a6dd | 151 | *@brief Select controller chip |
kagelump | 0:87b78725a6dd | 152 | * |
kagelump | 0:87b78725a6dd | 153 | *@param side controller side can be LEFT or RIGHT |
kagelump | 0:87b78725a6dd | 154 | *@return none |
kagelump | 0:87b78725a6dd | 155 | * |
kagelump | 0:87b78725a6dd | 156 | */ |
kagelump | 0:87b78725a6dd | 157 | void SelectSide(unsigned char side); |
kagelump | 0:87b78725a6dd | 158 | |
kagelump | 0:87b78725a6dd | 159 | |
kagelump | 0:87b78725a6dd | 160 | /** |
kagelump | 0:87b78725a6dd | 161 | *@brief Set cursor to specified coordinates |
kagelump | 0:87b78725a6dd | 162 | * |
kagelump | 0:87b78725a6dd | 163 | *@param x row |
kagelump | 0:87b78725a6dd | 164 | *@param y column |
kagelump | 0:87b78725a6dd | 165 | *@return none |
kagelump | 0:87b78725a6dd | 166 | */ |
kagelump | 0:87b78725a6dd | 167 | void GotoXY(unsigned int x, unsigned int y); |
kagelump | 0:87b78725a6dd | 168 | |
kagelump | 0:87b78725a6dd | 169 | |
kagelump | 0:87b78725a6dd | 170 | /** |
kagelump | 0:87b78725a6dd | 171 | *@brief Clears display |
kagelump | 0:87b78725a6dd | 172 | * |
kagelump | 0:87b78725a6dd | 173 | *@param none |
kagelump | 0:87b78725a6dd | 174 | *@return none |
kagelump | 0:87b78725a6dd | 175 | * |
kagelump | 0:87b78725a6dd | 176 | */ |
kagelump | 0:87b78725a6dd | 177 | void ClearScreen(); |
kagelump | 0:87b78725a6dd | 178 | |
kagelump | 0:87b78725a6dd | 179 | |
kagelump | 0:87b78725a6dd | 180 | /** |
kagelump | 0:87b78725a6dd | 181 | *@brief Turn on display |
kagelump | 0:87b78725a6dd | 182 | * |
kagelump | 0:87b78725a6dd | 183 | *@param none |
kagelump | 0:87b78725a6dd | 184 | *@return none |
kagelump | 0:87b78725a6dd | 185 | * |
kagelump | 0:87b78725a6dd | 186 | */ |
kagelump | 0:87b78725a6dd | 187 | void TurnOn(); |
kagelump | 0:87b78725a6dd | 188 | |
kagelump | 0:87b78725a6dd | 189 | |
kagelump | 0:87b78725a6dd | 190 | /** |
kagelump | 0:87b78725a6dd | 191 | *@brief Turn Off display |
kagelump | 0:87b78725a6dd | 192 | * |
kagelump | 0:87b78725a6dd | 193 | *@param none |
kagelump | 0:87b78725a6dd | 194 | *@return none |
kagelump | 0:87b78725a6dd | 195 | * |
kagelump | 0:87b78725a6dd | 196 | */ |
kagelump | 0:87b78725a6dd | 197 | void TurnOff(); |
kagelump | 0:87b78725a6dd | 198 | |
kagelump | 0:87b78725a6dd | 199 | /*******************************Graphic functions************************************************/ |
kagelump | 0:87b78725a6dd | 200 | |
kagelump | 0:87b78725a6dd | 201 | /** |
kagelump | 0:87b78725a6dd | 202 | *@brief Set pixel to specific location on the screen. |
kagelump | 0:87b78725a6dd | 203 | *@param x coordinate varies from 0-128 |
kagelump | 0:87b78725a6dd | 204 | *@param y col varies from 0-64 |
kagelump | 0:87b78725a6dd | 205 | *@param color color of pixel, can be BLACK or WHITE |
kagelump | 0:87b78725a6dd | 206 | *@return none |
kagelump | 0:87b78725a6dd | 207 | * |
kagelump | 0:87b78725a6dd | 208 | */ |
kagelump | 0:87b78725a6dd | 209 | void SetPixel( unsigned int x, unsigned int y, unsigned int color); |
kagelump | 0:87b78725a6dd | 210 | |
kagelump | 0:87b78725a6dd | 211 | |
kagelump | 0:87b78725a6dd | 212 | /** |
kagelump | 0:87b78725a6dd | 213 | *@brief Draws a line from x1,y1 to x2,y1 |
kagelump | 0:87b78725a6dd | 214 | *@param Xaxis1 x coordinate of one side |
kagelump | 0:87b78725a6dd | 215 | *@param Xaxis2 x coordinate of one side |
kagelump | 0:87b78725a6dd | 216 | *@param Yaxis y coordinate both points |
kagelump | 0:87b78725a6dd | 217 | *@param color can be BLACK or WHITE |
kagelump | 0:87b78725a6dd | 218 | *@return none |
kagelump | 0:87b78725a6dd | 219 | * |
kagelump | 0:87b78725a6dd | 220 | */ |
kagelump | 0:87b78725a6dd | 221 | void HLine(unsigned int Xaxis1, unsigned int Xaxis2 ,unsigned int Yaxis,unsigned int color); |
kagelump | 0:87b78725a6dd | 222 | |
kagelump | 0:87b78725a6dd | 223 | /** |
kagelump | 0:87b78725a6dd | 224 | *@brief Draw a horizontal line |
kagelump | 0:87b78725a6dd | 225 | *@param Xaxis1 |
kagelump | 0:87b78725a6dd | 226 | *@param Xaxis2 |
kagelump | 0:87b78725a6dd | 227 | *@param width |
kagelump | 0:87b78725a6dd | 228 | *@param color can be BLACK or WHITE |
kagelump | 0:87b78725a6dd | 229 | *@return none |
kagelump | 0:87b78725a6dd | 230 | * |
kagelump | 0:87b78725a6dd | 231 | */ |
kagelump | 0:87b78725a6dd | 232 | void HLineShort(unsigned int Xaxis, unsigned int Yaxis,unsigned int width ,unsigned int color); |
kagelump | 0:87b78725a6dd | 233 | |
kagelump | 0:87b78725a6dd | 234 | /** |
kagelump | 0:87b78725a6dd | 235 | *@brief Draws a vertical line |
kagelump | 0:87b78725a6dd | 236 | *@param Xaxis |
kagelump | 0:87b78725a6dd | 237 | *@param Yaxis1 |
kagelump | 0:87b78725a6dd | 238 | *@param Yaxis2 |
kagelump | 0:87b78725a6dd | 239 | *@param color can be BLACK or WHITE |
kagelump | 0:87b78725a6dd | 240 | *@return none |
kagelump | 0:87b78725a6dd | 241 | * |
kagelump | 0:87b78725a6dd | 242 | */ |
kagelump | 0:87b78725a6dd | 243 | void VLine(unsigned int Xaxis, unsigned int Yaxis1 ,unsigned int Yaxis2,unsigned int color); |
kagelump | 0:87b78725a6dd | 244 | |
kagelump | 0:87b78725a6dd | 245 | /** |
kagelump | 0:87b78725a6dd | 246 | *@brief Draw a vertical line of a given width starting from X, Y |
kagelump | 0:87b78725a6dd | 247 | *@param Xaxis |
kagelump | 0:87b78725a6dd | 248 | *@param Yaxis |
kagelump | 0:87b78725a6dd | 249 | *@param height Height of line |
kagelump | 0:87b78725a6dd | 250 | *@param color can be BLACK or WHITE |
kagelump | 0:87b78725a6dd | 251 | *@return none |
kagelump | 0:87b78725a6dd | 252 | * |
kagelump | 0:87b78725a6dd | 253 | */ |
kagelump | 0:87b78725a6dd | 254 | void VLineShort(unsigned int Xaxis,unsigned int Yaxis, unsigned int height ,unsigned int color); |
kagelump | 0:87b78725a6dd | 255 | |
kagelump | 0:87b78725a6dd | 256 | |
kagelump | 0:87b78725a6dd | 257 | /** |
kagelump | 0:87b78725a6dd | 258 | *@brief Draws a line from x1,y1 to x2,y2. |
kagelump | 0:87b78725a6dd | 259 | *@param x1 x coordinate of one side |
kagelump | 0:87b78725a6dd | 260 | *@param y1 y coordinate of one side |
kagelump | 0:87b78725a6dd | 261 | *@param x2 x coordinate of other side |
kagelump | 0:87b78725a6dd | 262 | *@param y2 y coordinate of other side |
kagelump | 0:87b78725a6dd | 263 | *@param color can be BLACK or WHITE |
kagelump | 0:87b78725a6dd | 264 | *@return none |
kagelump | 0:87b78725a6dd | 265 | * |
kagelump | 0:87b78725a6dd | 266 | */ |
kagelump | 0:87b78725a6dd | 267 | void Line(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2, unsigned int color); |
kagelump | 0:87b78725a6dd | 268 | |
kagelump | 0:87b78725a6dd | 269 | |
kagelump | 0:87b78725a6dd | 270 | /** |
kagelump | 0:87b78725a6dd | 271 | *@brief Draws a slanty line from x1,y1 to x2,y2 |
kagelump | 0:87b78725a6dd | 272 | *@param lX1 x coordinate of one side |
kagelump | 0:87b78725a6dd | 273 | *@param lY1 y coordinate of one side |
kagelump | 0:87b78725a6dd | 274 | *@param lX2 x coordinate of other side |
kagelump | 0:87b78725a6dd | 275 | *@param lY2 y coordinate of other side |
kagelump | 0:87b78725a6dd | 276 | *@param color can be BLACK or WHITE |
kagelump | 0:87b78725a6dd | 277 | *@return none |
kagelump | 0:87b78725a6dd | 278 | * |
kagelump | 0:87b78725a6dd | 279 | */ |
kagelump | 0:87b78725a6dd | 280 | void SlantyLine(unsigned int lX1, unsigned int lY1, unsigned int lX2,unsigned int lY2,unsigned int color); |
kagelump | 0:87b78725a6dd | 281 | |
kagelump | 0:87b78725a6dd | 282 | /** |
kagelump | 0:87b78725a6dd | 283 | *@brief Draws a line from x,y at given degree from inner_radius to outer_radius. |
kagelump | 0:87b78725a6dd | 284 | *@param x |
kagelump | 0:87b78725a6dd | 285 | *@param y |
kagelump | 0:87b78725a6dd | 286 | *@param inner_radius |
kagelump | 0:87b78725a6dd | 287 | *@param outer_radius |
kagelump | 0:87b78725a6dd | 288 | *@param color can be BLACK or WHITE |
kagelump | 0:87b78725a6dd | 289 | *@return none |
kagelump | 0:87b78725a6dd | 290 | * |
kagelump | 0:87b78725a6dd | 291 | */ |
kagelump | 0:87b78725a6dd | 292 | void DegreeLine(unsigned int x, int y,unsigned int degree,unsigned int inner_radius,unsigned int outer_radius, unsigned int color); |
kagelump | 0:87b78725a6dd | 293 | |
kagelump | 0:87b78725a6dd | 294 | /** |
kagelump | 0:87b78725a6dd | 295 | *@brief Draw a filled reactangle |
kagelump | 0:87b78725a6dd | 296 | * |
kagelump | 0:87b78725a6dd | 297 | *@param Xaxis1 |
kagelump | 0:87b78725a6dd | 298 | *@param Yaxis1 |
kagelump | 0:87b78725a6dd | 299 | *@param Xaxis2 |
kagelump | 0:87b78725a6dd | 300 | *@param Yaxis2 |
kagelump | 0:87b78725a6dd | 301 | *@param color can be BLACK or WHITE |
kagelump | 0:87b78725a6dd | 302 | *@return none |
kagelump | 0:87b78725a6dd | 303 | * |
kagelump | 0:87b78725a6dd | 304 | */ |
kagelump | 0:87b78725a6dd | 305 | void FullRectangle(unsigned int Xaxis1, unsigned int Yaxis1, unsigned int Xaxis2 ,unsigned int Yaxis2,unsigned int color); |
kagelump | 0:87b78725a6dd | 306 | |
kagelump | 0:87b78725a6dd | 307 | /** |
kagelump | 0:87b78725a6dd | 308 | *@brief Draw an empty rectangle |
kagelump | 0:87b78725a6dd | 309 | *@param Xaxis1 |
kagelump | 0:87b78725a6dd | 310 | *@param Yaxis1 |
kagelump | 0:87b78725a6dd | 311 | *@param Xaxis2 |
kagelump | 0:87b78725a6dd | 312 | *@param Yaxis2 |
kagelump | 0:87b78725a6dd | 313 | *@param color can be BLACK or WHITE |
kagelump | 0:87b78725a6dd | 314 | *@return none |
kagelump | 0:87b78725a6dd | 315 | * |
kagelump | 0:87b78725a6dd | 316 | */ |
kagelump | 0:87b78725a6dd | 317 | void EmptyRectangle(unsigned int Xaxis1,unsigned int Yaxis1, unsigned int Xaxis2,unsigned int Yaxis2,unsigned int color); |
kagelump | 0:87b78725a6dd | 318 | |
kagelump | 0:87b78725a6dd | 319 | |
kagelump | 0:87b78725a6dd | 320 | /** |
kagelump | 0:87b78725a6dd | 321 | *@brief Draw a rectangle with round corners |
kagelump | 0:87b78725a6dd | 322 | *@param Xaxis1 x-coordinate of the top left point |
kagelump | 0:87b78725a6dd | 323 | *@param Yaxis1 y-coordinate of the top left point |
kagelump | 0:87b78725a6dd | 324 | *@param width rectangle width |
kagelump | 0:87b78725a6dd | 325 | *@param height rectangle height |
kagelump | 0:87b78725a6dd | 326 | *@param radius radius of the edges |
kagelump | 0:87b78725a6dd | 327 | *@param color can be BLACK or WHITE |
kagelump | 0:87b78725a6dd | 328 | *@return none |
kagelump | 0:87b78725a6dd | 329 | * |
kagelump | 0:87b78725a6dd | 330 | */ |
kagelump | 0:87b78725a6dd | 331 | void RoundRectangle(unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned int radius, unsigned int color); |
kagelump | 0:87b78725a6dd | 332 | |
kagelump | 0:87b78725a6dd | 333 | |
kagelump | 0:87b78725a6dd | 334 | /** |
kagelump | 0:87b78725a6dd | 335 | *Draws a triangle . |
kagelump | 0:87b78725a6dd | 336 | *@param |
kagelump | 0:87b78725a6dd | 337 | *@param |
kagelump | 0:87b78725a6dd | 338 | *@param |
kagelump | 0:87b78725a6dd | 339 | *@param |
kagelump | 0:87b78725a6dd | 340 | *@return none |
kagelump | 0:87b78725a6dd | 341 | * |
kagelump | 0:87b78725a6dd | 342 | */ |
kagelump | 0:87b78725a6dd | 343 | |
kagelump | 0:87b78725a6dd | 344 | void Triangle ( int topx, int topy, int rightx, int righty); |
kagelump | 0:87b78725a6dd | 345 | |
kagelump | 0:87b78725a6dd | 346 | |
kagelump | 0:87b78725a6dd | 347 | /** |
kagelump | 0:87b78725a6dd | 348 | *Draws a right angle triangle . |
kagelump | 0:87b78725a6dd | 349 | *@param |
kagelump | 0:87b78725a6dd | 350 | *@param |
kagelump | 0:87b78725a6dd | 351 | *@param |
kagelump | 0:87b78725a6dd | 352 | *@param |
kagelump | 0:87b78725a6dd | 353 | *@return none |
kagelump | 0:87b78725a6dd | 354 | * |
kagelump | 0:87b78725a6dd | 355 | */ |
kagelump | 0:87b78725a6dd | 356 | void RightTriangle ( int topx, int topy, int rightx, int righty); |
kagelump | 0:87b78725a6dd | 357 | |
kagelump | 0:87b78725a6dd | 358 | |
kagelump | 0:87b78725a6dd | 359 | /** |
kagelump | 0:87b78725a6dd | 360 | *Draws an empty circle centered a x,y with radius R and specific color. |
kagelump | 0:87b78725a6dd | 361 | *@param CenterX center x coordinate |
kagelump | 0:87b78725a6dd | 362 | *@param CenterY center y coordinate |
kagelump | 0:87b78725a6dd | 363 | *@param Radius circle radius |
kagelump | 0:87b78725a6dd | 364 | *@param color Color can be BLACK or WHITE |
kagelump | 0:87b78725a6dd | 365 | *@return none |
kagelump | 0:87b78725a6dd | 366 | * |
kagelump | 0:87b78725a6dd | 367 | */ |
kagelump | 0:87b78725a6dd | 368 | void EmptyCircle(unsigned int CenterX, unsigned int CenterY, unsigned int Radius,unsigned int color); |
kagelump | 0:87b78725a6dd | 369 | |
kagelump | 0:87b78725a6dd | 370 | /** |
kagelump | 0:87b78725a6dd | 371 | * Circle fill Code is merely a modification of the midpoint |
kagelump | 0:87b78725a6dd | 372 | * circle algorithem which is an adaption of Bresenham's line algorithm |
kagelump | 0:87b78725a6dd | 373 | * http://en.wikipedia.org/wiki/Midpoint_circle_algorithm |
kagelump | 0:87b78725a6dd | 374 | * http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm |
kagelump | 0:87b78725a6dd | 375 | * Adapted from arduino lib |
kagelump | 0:87b78725a6dd | 376 | * |
kagelump | 0:87b78725a6dd | 377 | *@param CenterX center x coordinate |
kagelump | 0:87b78725a6dd | 378 | *@param CenterY center y coordinate |
kagelump | 0:87b78725a6dd | 379 | *@param Radius circle radius |
kagelump | 0:87b78725a6dd | 380 | *@param color Color can be BLACK or WHITE |
kagelump | 0:87b78725a6dd | 381 | */ |
kagelump | 0:87b78725a6dd | 382 | void FullCircle(unsigned int CenterX, unsigned int CenterY, unsigned int Radius,unsigned int color); |
kagelump | 0:87b78725a6dd | 383 | |
kagelump | 0:87b78725a6dd | 384 | /** |
kagelump | 0:87b78725a6dd | 385 | *Draws an ellipse. |
kagelump | 0:87b78725a6dd | 386 | *@param CX x coordinate of one side |
kagelump | 0:87b78725a6dd | 387 | *@param CY y coordinate of one side |
kagelump | 0:87b78725a6dd | 388 | *@param XRadius x coordinate of other side |
kagelump | 0:87b78725a6dd | 389 | *@param YRadius y coordinate of other side |
kagelump | 0:87b78725a6dd | 390 | *@param color can be BLACK or WHITE |
kagelump | 0:87b78725a6dd | 391 | *@return none |
kagelump | 0:87b78725a6dd | 392 | * |
kagelump | 0:87b78725a6dd | 393 | * Ported the algorithm found at http://homepage.smc.edu/kennedy_john/belipse.pdf |
kagelump | 0:87b78725a6dd | 394 | * |
kagelump | 0:87b78725a6dd | 395 | */ |
kagelump | 0:87b78725a6dd | 396 | void PlotEllipse(long CX, long CY, long XRadius,long YRadius, int color); |
kagelump | 0:87b78725a6dd | 397 | void Plot4EllipsePoints(long CX,long CY, long X, long Y, int color); |
kagelump | 0:87b78725a6dd | 398 | |
kagelump | 0:87b78725a6dd | 399 | |
kagelump | 0:87b78725a6dd | 400 | /** |
kagelump | 0:87b78725a6dd | 401 | *@brief Round a double |
kagelump | 0:87b78725a6dd | 402 | *@param double |
kagelump | 0:87b78725a6dd | 403 | *@return value |
kagelump | 0:87b78725a6dd | 404 | * |
kagelump | 0:87b78725a6dd | 405 | */ |
kagelump | 0:87b78725a6dd | 406 | double dfloor( double value ); |
kagelump | 0:87b78725a6dd | 407 | |
kagelump | 0:87b78725a6dd | 408 | |
kagelump | 0:87b78725a6dd | 409 | /*****************************Bitmaps *****************************************************************/ |
kagelump | 0:87b78725a6dd | 410 | |
kagelump | 0:87b78725a6dd | 411 | /** |
kagelump | 0:87b78725a6dd | 412 | *@brief Draws an image on screen. |
kagelump | 0:87b78725a6dd | 413 | *@param PictureData 128x64 image array |
kagelump | 0:87b78725a6dd | 414 | *@return none |
kagelump | 0:87b78725a6dd | 415 | * |
kagelump | 0:87b78725a6dd | 416 | * |
kagelump | 0:87b78725a6dd | 417 | */ |
kagelump | 0:87b78725a6dd | 418 | void FullScreenBMP (unsigned char *ImageData); |
kagelump | 0:87b78725a6dd | 419 | |
kagelump | 0:87b78725a6dd | 420 | /** |
kagelump | 0:87b78725a6dd | 421 | *@brief Draw a 1-bit bitmap |
kagelump | 0:87b78725a6dd | 422 | * |
kagelump | 0:87b78725a6dd | 423 | *@param image struct containing img size and array |
kagelump | 0:87b78725a6dd | 424 | *@param x x-coordinate |
kagelump | 0:87b78725a6dd | 425 | *@param y y-coordinate |
kagelump | 0:87b78725a6dd | 426 | *@param color can be BLACK or WHITE |
kagelump | 0:87b78725a6dd | 427 | *@return none |
kagelump | 0:87b78725a6dd | 428 | */ |
kagelump | 0:87b78725a6dd | 429 | void DrawBitmap(const unsigned int * bitmap, unsigned int x, unsigned int y, unsigned int color); |
kagelump | 0:87b78725a6dd | 430 | |
kagelump | 0:87b78725a6dd | 431 | /** |
kagelump | 0:87b78725a6dd | 432 | *@brief Static function , mplemented to read an array |
kagelump | 0:87b78725a6dd | 433 | *@param ptr data array |
kagelump | 0:87b78725a6dd | 434 | *@return none |
kagelump | 0:87b78725a6dd | 435 | */ |
kagelump | 0:87b78725a6dd | 436 | unsigned int ReadArrayData(const unsigned int* ptr); |
kagelump | 0:87b78725a6dd | 437 | |
kagelump | 0:87b78725a6dd | 438 | |
kagelump | 0:87b78725a6dd | 439 | /*************************************Font functions **************************************/ |
kagelump | 0:87b78725a6dd | 440 | |
kagelump | 0:87b78725a6dd | 441 | /** |
kagelump | 0:87b78725a6dd | 442 | *@brief Print a character on specified coordinates |
kagelump | 0:87b78725a6dd | 443 | * |
kagelump | 0:87b78725a6dd | 444 | *@param page row |
kagelump | 0:87b78725a6dd | 445 | *@param col column |
kagelump | 0:87b78725a6dd | 446 | *@param c integer value |
kagelump | 0:87b78725a6dd | 447 | *@return none |
kagelump | 0:87b78725a6dd | 448 | */ |
kagelump | 0:87b78725a6dd | 449 | void Putchar (int page, int col,unsigned char c); |
kagelump | 0:87b78725a6dd | 450 | |
kagelump | 0:87b78725a6dd | 451 | /** |
kagelump | 0:87b78725a6dd | 452 | *@brief Print a string on specified coordinates |
kagelump | 0:87b78725a6dd | 453 | * |
kagelump | 0:87b78725a6dd | 454 | *@param str char array |
kagelump | 0:87b78725a6dd | 455 | *@param x row |
kagelump | 0:87b78725a6dd | 456 | *@param y column |
kagelump | 0:87b78725a6dd | 457 | *@return none |
kagelump | 0:87b78725a6dd | 458 | */ |
kagelump | 0:87b78725a6dd | 459 | void PutString(unsigned int x, unsigned int y,char* str); |
kagelump | 0:87b78725a6dd | 460 | |
kagelump | 0:87b78725a6dd | 461 | /** |
kagelump | 0:87b78725a6dd | 462 | *@brief Print a float on specified coordinates |
kagelump | 0:87b78725a6dd | 463 | * |
kagelump | 0:87b78725a6dd | 464 | *@param val float value |
kagelump | 0:87b78725a6dd | 465 | *@param x row |
kagelump | 0:87b78725a6dd | 466 | *@param y column |
kagelump | 0:87b78725a6dd | 467 | *@return none |
kagelump | 0:87b78725a6dd | 468 | */ |
kagelump | 0:87b78725a6dd | 469 | void PrintFloat(float val, unsigned int x,unsigned int y); |
kagelump | 0:87b78725a6dd | 470 | |
kagelump | 0:87b78725a6dd | 471 | /** |
kagelump | 0:87b78725a6dd | 472 | *@brief Print an integer on specified coordinates |
kagelump | 0:87b78725a6dd | 473 | * |
kagelump | 0:87b78725a6dd | 474 | *@param val integer value |
kagelump | 0:87b78725a6dd | 475 | *@param x row |
kagelump | 0:87b78725a6dd | 476 | *@param y column |
kagelump | 0:87b78725a6dd | 477 | *@return none |
kagelump | 0:87b78725a6dd | 478 | */ |
kagelump | 0:87b78725a6dd | 479 | void PrintInteger(int val,unsigned int x,unsigned int y); |
kagelump | 0:87b78725a6dd | 480 | |
kagelump | 0:87b78725a6dd | 481 | |
kagelump | 0:87b78725a6dd | 482 | /** |
kagelump | 0:87b78725a6dd | 483 | *@brief Select a specific font |
kagelump | 0:87b78725a6dd | 484 | * |
kagelump | 0:87b78725a6dd | 485 | *@param font font array |
kagelump | 0:87b78725a6dd | 486 | *@param color font color , can be BLACK or WHITE |
kagelump | 0:87b78725a6dd | 487 | *@param callback function pointer to load font |
kagelump | 0:87b78725a6dd | 488 | *@return none |
kagelump | 0:87b78725a6dd | 489 | */ |
kagelump | 0:87b78725a6dd | 490 | void SelectFont(unsigned int* font,unsigned int color, FontCallback callback); |
kagelump | 0:87b78725a6dd | 491 | |
kagelump | 0:87b78725a6dd | 492 | |
kagelump | 0:87b78725a6dd | 493 | /** |
kagelump | 0:87b78725a6dd | 494 | *@brief Print a character |
kagelump | 0:87b78725a6dd | 495 | * |
kagelump | 0:87b78725a6dd | 496 | *@param c char |
kagelump | 0:87b78725a6dd | 497 | *@return none |
kagelump | 0:87b78725a6dd | 498 | */ |
kagelump | 0:87b78725a6dd | 499 | int PrintChar(char c); |
kagelump | 0:87b78725a6dd | 500 | |
kagelump | 0:87b78725a6dd | 501 | |
kagelump | 0:87b78725a6dd | 502 | /** |
kagelump | 0:87b78725a6dd | 503 | *@brief Print a character string |
kagelump | 0:87b78725a6dd | 504 | * |
kagelump | 0:87b78725a6dd | 505 | *@param str char string |
kagelump | 0:87b78725a6dd | 506 | *@return none |
kagelump | 0:87b78725a6dd | 507 | */ |
kagelump | 0:87b78725a6dd | 508 | void PrintString(char* str); |
kagelump | 0:87b78725a6dd | 509 | |
kagelump | 0:87b78725a6dd | 510 | |
kagelump | 0:87b78725a6dd | 511 | /** |
kagelump | 0:87b78725a6dd | 512 | *@brief Print a number |
kagelump | 0:87b78725a6dd | 513 | * |
kagelump | 0:87b78725a6dd | 514 | *@param n number |
kagelump | 0:87b78725a6dd | 515 | *@return none |
kagelump | 0:87b78725a6dd | 516 | */ |
kagelump | 0:87b78725a6dd | 517 | void PrintNumber(long n); |
kagelump | 0:87b78725a6dd | 518 | |
kagelump | 0:87b78725a6dd | 519 | |
kagelump | 0:87b78725a6dd | 520 | private: |
kagelump | 0:87b78725a6dd | 521 | BusInOut DB; |
kagelump | 0:87b78725a6dd | 522 | DigitalOut RST; |
kagelump | 0:87b78725a6dd | 523 | DigitalOut DI; |
kagelump | 0:87b78725a6dd | 524 | DigitalOut RW; |
kagelump | 0:87b78725a6dd | 525 | DigitalOut E; |
kagelump | 0:87b78725a6dd | 526 | DigitalInOut CS2; |
kagelump | 0:87b78725a6dd | 527 | DigitalInOut CS1; |
kagelump | 0:87b78725a6dd | 528 | bool Inverted; |
kagelump | 0:87b78725a6dd | 529 | |
kagelump | 0:87b78725a6dd | 530 | LCDCoord Coord; |
kagelump | 0:87b78725a6dd | 531 | FontCallback FontRead ; |
kagelump | 0:87b78725a6dd | 532 | unsigned int FontColor; |
kagelump | 0:87b78725a6dd | 533 | unsigned int* Font; |
kagelump | 0:87b78725a6dd | 534 | unsigned int color; |
kagelump | 0:87b78725a6dd | 535 | |
kagelump | 0:87b78725a6dd | 536 | |
kagelump | 0:87b78725a6dd | 537 | }; |
kagelump | 0:87b78725a6dd | 538 | |
kagelump | 0:87b78725a6dd | 539 | |
kagelump | 0:87b78725a6dd | 540 | #endif |