Embed:
(wiki syntax)
Show/hide line numbers
SPI_TFT.h
00001 #ifndef MBED_SPI_TFT_H 00002 #define MBED_SPI_TFT_H 00003 00004 00005 #include "mbed.h" 00006 #include "GraphicsDisplay.h" 00007 00008 extern "C" void mbed_reset(); 00009 00010 #define RGB(r,g,b) (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue 00011 00012 #define SPI_START (0x70) /* Start byte for SPI transfer */ 00013 #define SPI_RD (0x01) /* WR bit 1 within start */ 00014 #define SPI_WR (0x00) /* WR bit 0 within start */ 00015 #define SPI_DATA (0x02) /* RS bit 1 within start byte */ 00016 #define SPI_INDEX (0x00) /* RS bit 0 within start byte */ 00017 00018 00019 /* some RGB color definitions 00020 # Define RGB565CONVERT NEGRO ( 0 , 0 , 0 ) 00021 # Define RGB565CONVERT BRIGHTBLUE ( 0 , 0 , 255 ) 00022 # Define RGB565CONVERT BRIGHTGREEN ( 0 , 255 , 0 ) 00023 # Define RGB565CONVERT BRIGHTCYAN ( 0 , 255 , 255 ) 00024 # Define RGB565CONVERT BRIGHTRED ( 255 , 0 , 0 ) 00025 # Define RGB565CONVERT BRIGHTMAGENTA ( 255 , 0 , 255 ) 00026 # Define RGB565CONVERT BRIGHTYELLOW ( 255 , 255 , 0 ) 00027 # Define RGB565CONVERT AZUL ( 0 , 0 , 128 ) 00028 # Define RGB565CONVERT VERDE ( 0 , 128 , 0 ) 00029 # Define RGB565CONVERT CIAN ( 0 , 128 , 128 ) 00030 # Define RGB565CONVERT ROJO ( 128 , 0 , 0 ) 00031 # Define MAGENTA RGB565CONVERT ( 128 , 0 , 128 ) 00032 # Define RGB565CONVERT BROWN ( 255 , 128 , 0 ) 00033 # Define RGB565CONVERT gris_claro ( 128 , 128 , 128 ) 00034 # Define RGB565CONVERT gris_oscuro ( 64 , 64 , 64 ) 00035 # Define RGB565CONVERT lightblue ( 128 , 128 , 255 ) 00036 # Define RGB565CONVERT verde claro ( 128 , 255 , 128 ) 00037 # Define RGB565CONVERT LIGHTCYAN ( 128 , 255 , 255 ) 00038 # Define RGB565CONVERT LIGHTRED ( 255 , 128 , 128 ) 00039 # Define RGB565CONVERT LIGHTMAGENTA ( 255 , 128 , 255 ) 00040 # Define RGB565CONVERT AMARILLO ( 255 , 255 , 128 ) 00041 # Define RGB565CONVERT BLANCO ( 255 , 255 , 255 ) 00042 00043 # Define GRAY0 RGB565CONVERT ( 224 , 224 , 224 ) 00044 # Define GRAY1 RGB565CONVERT ( 192 , 192 , 192 ) 00045 # Define GRAY2 RGB565CONVERT ( 160 , 160 , 160 ) 00046 # Define GRAY3 RGB565CONVERT ( 128 , 128 , 128 ) 00047 # Define GRAY4 RGB565CONVERT ( 96 , 96 , 96 ) 00048 # Define GRAY5 RGB565CONVERT ( 64 , 64 , 64 ) 00049 # Define GRAY6 RGB565CONVERT ( 32 , 32 , 32 ) 00050 00051 #define GRAY20 RGB565CONVERT(51, 51, 51) 00052 #define GRAY40 RGB565CONVERT(102, 102, 102) 00053 #define GRAY80 RGB565CONVERT(204, 204, 204) 00054 #define GRAY90 RGB565CONVERT(229, 229, 229) 00055 #define GRAY95 RGB565CONVERT(242, 242, 242) 00056 #define RED4 RGB565CONVERT(139, 0, 0) 00057 #define FIREBRICK1 RGB565CONVERT(255, 48, 48) 00058 #define DARKGREEN RGB565CONVERT(0, 100, 0) 00059 #define PALEGREEN RGB565CONVERT(152, 251, 152) 00060 #define LIGHTYELLOW RGB565CONVERT(238, 221, 130) 00061 #define GOLD RGB565CONVERT(255, 215, 0) 00062 #define DARKORANGE RGB565CONVERT(255, 140, 0) 00063 */ 00064 #define Black 0x0000 /* 0, 0, 0 */ 00065 #define Navy 0x000F /* 0, 0, 128 */ 00066 #define DarkGreen 0x03E0 /* 0, 128, 0 */ 00067 #define DarkCyan 0x03EF /* 0, 128, 128 */ 00068 #define Maroon 0x7800 /* 128, 0, 0 */ 00069 #define Purple 0x780F /* 128, 0, 128 */ 00070 #define Olive 0x7BE0 /* 128, 128, 0 */ 00071 #define LightGrey 0xC618 /* 192, 192, 192 */ 00072 #define DarkGrey 0x7BEF /* 128, 128, 128 */ 00073 #define Blue 0x001F /* 0, 0, 255 */////////////////////////// 32 00074 #define Green 0x07E0 /* 0, 255, 0 */////////////////////////// 2016 00075 #define Cyan 0x07FF /* 0, 255, 255 */ 00076 #define Red 0xF800 /* 255, 0, 0 */////////////////////////// 63488 00077 #define Magenta 0xF81F /* 255, 0, 255 */ 00078 #define Yellow 0xFFE0 /* 255, 255, 0 */ 00079 #define White 0xFFFF /* 255, 255, 255 */ 00080 #define Orange 0xFD20 /* 255, 165, 0 */ 00081 #define GreenYellow 0xAFE5 /* 173, 255, 47 */ 00082 00083 00084 /** Display control class, based on GraphicsDisplay and TextDisplay 00085 * 00086 * Example: 00087 * @code 00088 * #include "stdio.h" 00089 * #include "mbed.h" 00090 * #include "SPI_TFT.h" 00091 * #include "string" 00092 * #include "Arial12x12.h" 00093 * #include "Arial24x23.h" 00094 * 00095 * 00096 * 00097 * // the TFT is connected to SPI pin 5-7 00098 * SPI_TFT TFT(p5, p6, p7, p8, p15,"TFT"); // mosi, miso, sclk, cs, reset 00099 * 00100 * int main() { 00101 * TFT.claim(stdout); // send stdout to the TFT display 00102 * //TFT.claim(stderr); // send stderr to the TFT display 00103 * 00104 * TFT.background(Black); // set background to black 00105 * TFT.foreground(White); // set chars to white 00106 * TFT.cls(); // clear the screen 00107 * TFT.set_font((unsigned char*) Arial12x12); // select the font 00108 * 00109 * TFT.set_orientation(0); 00110 * TFT.locate(0,0); 00111 * printf(" Hello Mbed 0"); 00112 * TFT.set_font((unsigned char*) Arial24x23); // select font 2 00113 * TFT.locate(48,115); 00114 * TFT.printf("Bigger Font"); 00115 * } 00116 * @endcode 00117 */ 00118 class SPI_TFT : public GraphicsDisplay { 00119 public: 00120 00121 /** Create a SPI_TFT object connected to SPI and two pins 00122 * 00123 * @param mosi,miso,sclk SPI 00124 * @param cs pin connected to CS of display 00125 * @param reset pin connected to RESET of display 00126 * 00127 */ 00128 SPI_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName bk,const char* name ="TFT"); 00129 00130 /** Get the width of the screen in pixel 00131 * 00132 * @param 00133 * @returns width of screen in pixel 00134 * 00135 */ 00136 virtual int width(); 00137 00138 /** Get the height of the screen in pixel 00139 * 00140 * @returns height of screen in pixel 00141 * 00142 */ 00143 virtual int height(); 00144 00145 /** Draw a pixel at x,y with color 00146 * 00147 * @param x horizontal position 00148 * @param y vertical position 00149 * @param color 16 bit pixel color 00150 */ 00151 virtual void pixel(int x, int y, int colour); 00152 00153 /** draw a circle 00154 * 00155 * @param x0,y0 center 00156 * @param r radius 00157 * @param color 16 bit color * 00158 * 00159 */ 00160 void circle(int x, int y, int r, int colour); 00161 00162 /** draw a filled circle 00163 * 00164 * @param x0,y0 center 00165 * @param r radius 00166 * @param color 16 bit color * 00167 * 00168 * use circle with different radius, 00169 * can miss some pixel 00170 */ 00171 void fillcircle(int x, int y, int r, int colour); 00172 00173 00174 00175 /** draw a 1 pixel line 00176 * 00177 * @param x0,y0 start point 00178 * @param x1,y1 stop point 00179 * @param color 16 bit color 00180 * 00181 */ 00182 void line(int x0, int y0, int x1, int y1, int colour); 00183 00184 /** draw a rect 00185 * 00186 * @param x0,y0 top left corner 00187 * @param x1,y1 down right corner 00188 * @param color 16 bit color 00189 * * 00190 */ 00191 void rect(int x0, int y0, int x1, int y1, int colour); 00192 00193 /** draw a filled rect 00194 * 00195 * @param x0,y0 top left corner 00196 * @param x1,y1 down right corner 00197 * @param color 16 bit color 00198 * 00199 */ 00200 void fillrect(int x0, int y0, int x1, int y1, int colour); 00201 00202 /** setup cursor position 00203 * 00204 * @param x x-position (top left) 00205 * @param y y-position 00206 */ 00207 00208 virtual void locate(int x, int y); 00209 00210 /** Fill the screen with _backgroun color 00211 * 00212 */ 00213 00214 virtual void cls (void); 00215 00216 /** calculate the max number of char in a line 00217 * 00218 * @returns max columns 00219 * depends on actual font size 00220 * 00221 */ 00222 00223 virtual int columns(void); 00224 00225 /** calculate the max number of columns 00226 * 00227 * @returns max column 00228 * depends on actual font size 00229 * 00230 */ 00231 00232 virtual int rows(void); 00233 00234 /** put a char on the screen 00235 * 00236 * @param value char to print 00237 * @returns printed char 00238 * 00239 */ 00240 00241 virtual int _putc(int value); 00242 00243 /** draw a character on given position out of the active font to the TFT 00244 * 00245 * @param x x-position of char (top left) 00246 * @param y y-position 00247 * @param c char to print 00248 * 00249 */ 00250 00251 virtual void character(int x, int y, int c); 00252 00253 /** paint a bitmap on the TFT 00254 * 00255 * @param x,y : upper left corner 00256 * @param w width of bitmap 00257 * @param h high of bitmap 00258 * @param *bitmap pointer to the bitmap data 00259 * 00260 * bitmap format: 16 bit R5 G6 B5 00261 * 00262 * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 00263 * use winhex to load this file and mark data stating at offset 0x46 to end 00264 * use edit -> copy block -> C Source to export C array 00265 * paste this array into your program 00266 * 00267 * define the array as static const unsigned char to put it into flash memory 00268 * cast the pointer to (unsigned char *) : 00269 * tft.Bitmap(10,40,309,50,(unsigned char *)scala); 00270 */ 00271 00272 void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap); 00273 00274 00275 /** paint a 16 bit BMP from local filesytem on the TFT (slow) 00276 * 00277 * @param x,y : upper left corner 00278 * @param *Name_BMP name of the BMP file 00279 * @returns 1 if bmp file was found and painted 00280 * @returns -1 if bmp file was found not found 00281 * @returns -2 if bmp file is not 16bit 00282 * @returns -3 if bmp file is to big for screen 00283 * @returns -4 if buffer malloc go wrong 00284 * 00285 * bitmap format: 16 bit R5 G6 B5 00286 * 00287 * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 00288 * copy to internal file system 00289 * 00290 */ 00291 00292 int BMP_16(unsigned int x, unsigned int y, const char *Name_BMP); 00293 00294 00295 /** paint a 16 bit BMP from memory uSD Card on the TFT (slow) 00296 * 00297 * @param x,y : upper left corner 00298 * @param *Name_BMP name of the BMP file 00299 * @returns 1 if bmp file was found and painted 00300 * @returns -1 if bmp file was found not found 00301 * @returns -2 if bmp file is not 16bit 00302 * @returns -3 if bmp file is to big for screen 00303 * @returns -4 if buffer malloc go wrong 00304 * 00305 * bitmap format: 16 bit R5 G6 B5 00306 * 00307 * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 00308 * copy to internal file system 00309 * 00310 */ 00311 00312 int BMP_SD(unsigned int x_sd, unsigned int y_sd, const char *Name_BMP_SD); 00313 00314 00315 /** select the font to use 00316 * 00317 * @param f pointer to font array 00318 * 00319 * font array can created with GLCD Font Creator from http://www.mikroe.com 00320 * you have to add 4 parameter at the beginning of the font array to use: 00321 * - the number of byte / char 00322 * - the vertial size in pixel 00323 * - the horizontal size in pixel 00324 * - the number of byte per vertical line 00325 * you also have to change the array to char[] 00326 * 00327 */ 00328 00329 void set_font(unsigned char* f); 00330 00331 /** Set the orientation of the screen 00332 * x,y: 0,0 is always top left 00333 * 00334 * @param o direction to use the screen (0-3) 90� Steps 00335 * 00336 */ 00337 00338 void set_orientation(unsigned int o); 00339 00340 SPI _spi; 00341 DigitalOut _cs; 00342 DigitalOut _reset; 00343 PwmOut _bk; 00344 unsigned char* font; 00345 00346 /**Resetea mediante hardware el LFCD TFT a travez del pin RESET 00347 */ 00348 00349 void tft_rst_hw(); 00350 00351 /**Enciende el Backligth del LCD TFT a travez de un pin PWM 00352 */ 00353 00354 void backlight(float intensity); 00355 00356 /**Modula el Backligth del LCD TFT a travez de un pin PWM 00357 * minimo 0.01; maximo 1.0 ; paso para FOR 0.01, retardo 0.01 00358 */ 00359 00360 void contraste_pos(float min, float max, float steep, float delay); 00361 00362 /**Modula el Backligth del LCD TFT a travez de un pin PWM 00363 * minimo 0.01; maximo 1.0 ; paso para FOR 0.01, retardo 0.01 00364 */ 00365 00366 void contraste_neg(float max, float min, float steep, float delay); 00367 00368 /* Genera una barra de carga para animar la congiguracion de un programa 00369 * mientras este lee un archivo *.cfg de la raiz del sistema y configura las 00370 * operaciones generales del programa segun indique el estado de su 00371 * configuracion guardado la anterior vez en su memoria 00372 */ 00373 void charge(int x0, int y0, int x1, int y1, int color_max, int color_min, float speed); 00374 00375 /* Animacion controlada por PWM para parpadeos de la pantalla, estipular el numero de parpadeos 00376 * el maximo de intensidad, el minimo, la cantidad de incremento en steep, el retardo por cada uno 00377 * el tiempo de parada entre cada uno y el brillo final que mantendra la LCD TFT al terminar la animacion 00378 */ 00379 00380 void parpadeo(int parpadeos, float max, float min, float steep, float delay,float stop, float brigthness); 00381 00382 /* 00383 * 00384 */ 00385 void Init_Kernel_Up (float brillo, int color, int orientation, unsigned char* letra,int x,int y,int delay); 00386 00387 /* 00388 * 00389 */ 00390 void Init_Kernel_Down(float brillo, int color, int orientation, unsigned char* letra,int x,int y,int delay); 00391 00392 /* 00393 * 00394 */ 00395 00396 void init_tasking(float brillo, int color, int orientation, unsigned char* letra,int x,int y,int delay); 00397 00398 /* 00399 * 00400 */ 00401 void strcmp(float brillo, int color, int orientation, unsigned char* letra,int x,int y,int delay); 00402 00403 /* 00404 * 00405 */ 00406 void Loading(float bkt,int fondo, int color, unsigned char* letra,const char *titulo1,int x,int y,int fondo2, int color2,unsigned char* sam, const char *titulo2, int z,int w, int delay,int a,int b, int c, int d, int max, int min, float alfa_cromatic); 00407 00408 00409 /*trae el codigo del LCD TFT para identificarlo mediante el registro 0x00h 00410 * 00411 */ 00412 int ID(); 00413 00414 void binary_init(int a, int b, int c, int d, int delay); 00415 00416 /*permite definir el espacio maximo de desplazamiento para la pantalla 00417 * top es TFA Top Fixed Area, button es BFA, button fixed area, y height es Height de Vertical Scroll Area 00418 * top = 0, button= 0, height = 320, definen la pantalla maxima, top es el inicio y button es el resto, la suma de 00419 * t+b+h = 320, si esto no se cumple el sroll no estaria bien definido. 00420 * p es el puntero incremental o decremental que posicionara la imagen 00421 * si pointer = 30, aparecera desplazado 30 pixeles 00422 * speed es la velocidad a la que la imagen se desplaza 00423 */ 00424 void sharepoint(unsigned int top, unsigned int button, unsigned int height, unsigned int pointer, unsigned int speed, unsigned repetitions); 00425 void icon_ball(int x, int y, int state); 00426 00427 /*****************************************************************************************************/ 00428 00429 00430 00431 //protected: 00432 /** Init the HX8347D controller 00433 * 00434 */ 00435 00436 00437 void tft_init(); 00438 00439 /** Set draw window region to whole screen 00440 * 00441 */ 00442 00443 void WindowMax (void); 00444 00445 00446 /** draw a horizontal line 00447 * 00448 * @param x0 horizontal start 00449 * @param x1 horizontal stop 00450 * @param y vertical position 00451 * @param color 16 bit color 00452 * 00453 */ 00454 00455 void hline(int x0, int x1, int y, int colour); 00456 00457 /** draw a vertical line 00458 * 00459 * @param x horizontal position 00460 * @param y0 vertical start 00461 * @param y1 vertical stop 00462 * @param color 16 bit color 00463 */ 00464 00465 void vline(int y0, int y1, int x, int colour); 00466 00467 /** Set draw window region 00468 * 00469 * @param x horizontal position 00470 * @param y vertical position 00471 * @param w window width in pixel 00472 * @param h window height in pixels 00473 */ 00474 00475 virtual void windows (unsigned int x, unsigned int y, unsigned int w, unsigned int h); 00476 00477 00478 00479 00480 00481 /** Write data to the LCD controller 00482 * 00483 * @param dat data written to LCD controller 00484 * 00485 */ 00486 00487 void wr_dat(int value); 00488 00489 /** Write a command the LCD controller 00490 * 00491 * @param cmd: command to be written 00492 * 00493 */ 00494 00495 void wr_cmd(int value); 00496 00497 /** Start data sequence to the LCD controller 00498 * 00499 */ 00500 00501 void wr_dat_start(); 00502 00503 /** Stop of data writing to the LCD controller 00504 * 00505 */ 00506 00507 void wr_dat_stop(); 00508 00509 /** write data to the LCD controller 00510 * 00511 * @param data to be written 00512 * * 00513 */ 00514 00515 void wr_dat_only(unsigned short dat); 00516 00517 /** Read data from the LCD controller 00518 * 00519 * @returns data from LCD controller 00520 * 00521 */ 00522 00523 unsigned short rd_dat(void); 00524 00525 /** Write a value to the to a LCD register 00526 * 00527 * @param reg register to be written 00528 * @param val data to be written 00529 */ 00530 00531 void wr_reg (unsigned char reg, unsigned short val); 00532 00533 /** Read a LCD register 00534 * 00535 * @param reg register to be read 00536 * @returns value of the register 00537 */ 00538 00539 unsigned short rd_reg (unsigned char reg); 00540 00541 unsigned int orientation; 00542 unsigned int char_x; 00543 unsigned int char_y; 00544 00545 protected: 00546 00547 00548 }; 00549 00550 #endif
Generated on Sat Jul 16 2022 01:38:08 by 1.7.2