Erik -
/
Mini_DK_clk
Simple clock program for LPC1768 Mini-DK
Embed:
(wiki syntax)
Show/hide line numbers
SPI_TFT.h
00001 // mbed library for 240*320 pixel display TFT 00002 00003 #ifndef MBED_SPI_TFT_H 00004 #define MBED_SPI_TFT_H 00005 00006 00007 #include "GraphicsDisplay.h" 00008 #include "mbed.h" 00009 00010 #define incx() x++, dxt += d2xt, t += dxt 00011 #define incy() y--, dyt += d2yt, t += dyt 00012 00013 #define SPI_F_LO 10000000 00014 #define SPI_F_HI 48000000 00015 00016 /* some RGB565 color definitions */ 00017 #define Black 0x0000 /* 0, 0, 0 */ 00018 #define Navy 0x000F /* 0, 0, 128 */ 00019 #define DarkGreen 0x03E0 /* 0, 128, 0 */ 00020 #define DarkCyan 0x03EF /* 0, 128, 128 */ 00021 #define Maroon 0x7800 /* 128, 0, 0 */ 00022 #define Purple 0x780F /* 128, 0, 128 */ 00023 #define Olive 0x7BE0 /* 128, 128, 0 */ 00024 #define LightGrey 0xC618 /* 192, 192, 192 */ 00025 #define DarkGrey 0x7BEF /* 128, 128, 128 */ 00026 #define Blue 0x001F /* 0, 0, 255 */ 00027 #define Green 0x07E0 /* 0, 255, 0 */ 00028 #define Cyan 0x07FF /* 0, 255, 255 */ 00029 #define Red 0xF800 /* 255, 0, 0 */ 00030 #define Magenta 0xF81F /* 255, 0, 255 */ 00031 #define Yellow 0xFFE0 /* 255, 255, 0 */ 00032 #define White 0xFFFF /* 255, 255, 255 */ 00033 #define Orange 0xFD20 /* 255, 165, 0 */ 00034 #define GreenYellow 0xAFE5 /* 173, 255, 47 */ 00035 00036 class SPI_TFT : public GraphicsDisplay { 00037 public: 00038 00039 /** Create a SPI_TFT object connected to SPI and two pins 00040 * 00041 * @param mosi,miso,sclk SPI 00042 * @param cs pin connected to CS of display 00043 * @param reset pin connected to RESET of display 00044 * 00045 */ 00046 SPI_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset,const char* name ="TFT"); 00047 00048 /** Get the width of the screen in pixel 00049 * 00050 * @param 00051 * @returns width of screen in pixel 00052 * 00053 */ 00054 virtual int width(); 00055 00056 /** Get the height of the screen in pixel 00057 * 00058 * @returns height of screen in pixel 00059 * 00060 */ 00061 virtual int height(); 00062 00063 /** Draw a pixel at x,y with color 00064 * 00065 * @param x horizontal position 00066 * @param y vertical position 00067 * @param color 16 bit pixel color 00068 */ 00069 virtual void pixel(int x, int y,int colour); 00070 00071 /** draw a 1 pixel line 00072 * 00073 * @param x0,y0 start point 00074 * @param x1,y1 stop point 00075 * @param color 16 bit color 00076 * 00077 */ 00078 void line(int x0, int y0, int x1, int y1, int colour); 00079 00080 /** draw a rect 00081 * 00082 * @param x0,y0 top left corner 00083 * @param w,h width and height 00084 * @param color 16 bit color 00085 * * 00086 */ 00087 void rect(int x0, int y0, int w, int h, int colour); 00088 00089 /** draw a filled rect 00090 * 00091 * @param x0,y0 top left corner 00092 * @param w,h width and height 00093 * @param color 16 bit color 00094 * 00095 */ 00096 void fillrect(int x0, int y0, int w, int h, int colour); 00097 00098 /** draw an ellipse - source : http://enchantia.com/graphapp/doc/tech/ellipses.html 00099 * 00100 * @param xc,yc center point 00101 * @param a,b semi-major axis and semi-minor axis 00102 * @param color 16 bit color 00103 * 00104 */ 00105 void draw_ellipse(int xc, int yc, int a, int b, unsigned int color); 00106 00107 /** draw a filled ellipse - source : http://enchantia.com/graphapp/doc/tech/ellipses.html 00108 * 00109 * @param xc,yc center point 00110 * @param a,b semi-major axis and semi-minor axis 00111 * @param color 16 bit color 00112 * 00113 */ 00114 void fill_ellipse(int xc, int yc, int a, int b, unsigned int color); 00115 00116 /** setup cursor position 00117 * 00118 * @param x x-position (top left) 00119 * @param y y-position 00120 */ 00121 virtual void locate(int x, int y); 00122 00123 /** Fill the screen with _backgroun color 00124 * 00125 */ 00126 virtual void cls (void); 00127 00128 /** Read ILI9320 ID 00129 * 00130 * @returns LCD ID code 00131 * 00132 */ 00133 unsigned short Read_ID(void); 00134 00135 /** calculate the max number of char in a line 00136 * 00137 * @returns max columns 00138 * depends on actual font size 00139 * 00140 */ 00141 virtual int columns(void); 00142 00143 /** calculate the max number of columns 00144 * 00145 * @returns max column 00146 * depends on actual font size 00147 * 00148 */ 00149 virtual int rows(void); 00150 00151 /** put a char on the screen 00152 * 00153 * @param value char to print 00154 * @returns printed char 00155 * 00156 */ 00157 virtual int _putc(int value); 00158 00159 /** draw a character on given position out of the active font to the TFT 00160 * 00161 * @param x x-position of char (top left) 00162 * @param y y-position 00163 * @param c char to print 00164 * 00165 */ 00166 virtual void character(int x, int y, int c); 00167 00168 /** paint a bitmap on the TFT 00169 * 00170 * @param x,y : upper left corner 00171 * @param w width of bitmap 00172 * @param h high of bitmap 00173 * @param *bitmap pointer to the bitmap data 00174 * 00175 * bitmap format: 16 bit R5 G6 B5 00176 * 00177 * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 00178 * use winhex to load this file and mark data stating at offset 0x46 to end 00179 * use edit -> copy block -> C Source to export C array 00180 * paste this array into your program 00181 * 00182 * define the array as static const unsigned char to put it into flash memory 00183 * cast the pointer to (unsigned char *) : 00184 * tft.Bitmap(10,40,309,50,(unsigned char *)scala); 00185 */ 00186 void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap); 00187 00188 00189 /** paint a 16 bit BMP from local filesytem on the TFT (slow) 00190 * 00191 * @param x,y : upper left corner 00192 * @param *Name_BMP name of the BMP file 00193 * @returns 1 if bmp file was found and painted 00194 * @returns -1 if bmp file was not found 00195 * @returns -2 if bmp file is not 16bit 00196 * @returns -3 if bmp file is to big for screen 00197 * @returns -4 if buffer malloc go wrong 00198 * 00199 * bitmap format: 16 bit R5 G6 B5 00200 * 00201 * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 00202 * copy to internal file system 00203 * 00204 */ 00205 00206 int BMP_16(unsigned int x, unsigned int y, const char *Name_BMP); 00207 00208 00209 00210 /** select the font to use 00211 * 00212 * @param f pointer to font array 00213 * 00214 * font array can created with GLCD Font Creator from http://www.mikroe.com 00215 * you have to add 4 parameter at the beginning of the font array to use: 00216 * - the number of byte / char 00217 * - the vertial size in pixel 00218 * - the horizontal size in pixel 00219 * - the number of byte per vertical line 00220 * you also have to change the array to char[] 00221 * 00222 */ 00223 void set_font(unsigned char* f); 00224 00225 /** Set the orientation of the screen 00226 * x,y: 0,0 is always top left 00227 * 00228 * @param o direction to use the screen (0-3) 90� Steps 00229 * 00230 */ 00231 void set_orientation(unsigned int o); 00232 void mod_orientation(void); 00233 SPI _spi; 00234 DigitalOut _cs; 00235 DigitalOut _reset; 00236 unsigned char* font; 00237 00238 00239 00240 // ------------------ PROTECTED PART ------------------ 00241 protected: 00242 00243 /** Set draw window region to whole screen 00244 * 00245 */ 00246 void WindowMax (void); 00247 00248 00249 /** draw a horizontal line 00250 * 00251 * @param x0 horizontal start 00252 * @param x1 horizontal stop 00253 * @param y vertical position 00254 * @param color 16 bit color 00255 * 00256 */ 00257 void hline(int x0, int x1, int y, int colour); 00258 00259 /** draw a vertical line 00260 * 00261 * @param x horizontal position 00262 * @param y0 vertical start 00263 * @param y1 vertical stop 00264 * @param color 16 bit color 00265 */ 00266 void vline(int y0, int y1, int x, int colour); 00267 00268 /** Set draw window region 00269 * 00270 * @param x horizontal position 00271 * @param y vertical position 00272 * @param w window width in pixel 00273 * @param h window height in pixels 00274 */ 00275 virtual void window(int x, int y, int w, int h); 00276 00277 00278 /** Init the ILI9320 controller 00279 * 00280 */ 00281 void tft_reset(); 00282 00283 /** Write data to the LCD controller 00284 * 00285 * @param dat data written to LCD controller 00286 * 00287 */ 00288 void wr_dat(unsigned short value); 00289 00290 /** Start data sequence to the LCD controller 00291 * 00292 */ 00293 //void wr_dat_start(); 00294 void wr_dat_start(void); 00295 00296 /** write data only to the LCD controller 00297 * 00298 * @param data to be written 00299 * * 00300 */ 00301 void wr_dat_only (unsigned short dat); 00302 00303 /** Write a command the LCD controller 00304 * 00305 * @param cmd: command to be written 00306 * 00307 */ 00308 void wr_cmd(unsigned char value); 00309 00310 /** Read data from the LCD controller 00311 * 00312 * @returns data from LCD controller 00313 * 00314 */ 00315 unsigned short rd_dat(void); 00316 00317 /** Write a value to the to a LCD register 00318 * 00319 * @param reg register to be written 00320 * @param val data to be written 00321 */ 00322 void wr_reg (unsigned char reg, unsigned short val); 00323 00324 /** Read a LCD register 00325 * 00326 * @param reg register to be read 00327 * @returns value of the register 00328 */ 00329 unsigned short rd_reg (unsigned char reg); 00330 00331 void SetCursor( unsigned short Xpos, unsigned short Ypos ); 00332 00333 unsigned int orientation; 00334 unsigned int char_x; 00335 unsigned int char_y; 00336 00337 }; 00338 00339 #endif
Generated on Tue Jul 12 2022 17:26:32 by 1.7.2