Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SPI_TFT_ILI9341 by
Revision 11:7aabc3810093, committed 2014-04-22
- Comitter:
- wim
- Date:
- Tue Apr 22 19:10:47 2014 +0000
- Parent:
- 10:2d505d14b7eb
- Commit message:
- Added methods and features
Changed in this revision
--- a/GraphicsDisplay.cpp Sat Apr 12 20:33:24 2014 +0000 +++ b/GraphicsDisplay.cpp Tue Apr 22 19:10:47 2014 +0000 @@ -103,6 +103,7 @@ 0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // } 0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~ 0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}; // DEL + GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) { foreground(0xFFFF);
--- a/SPI_TFT_ILI9341.cpp Sat Apr 12 20:33:24 2014 +0000 +++ b/SPI_TFT_ILI9341.cpp Tue Apr 22 19:10:47 2014 +0000 @@ -24,7 +24,6 @@ //extern DigitalOut xx; // debug !! SPI_TFT_ILI9341::SPI_TFT_ILI9341(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName dc, const char *name) -//WH : _spi(mosi, miso, sclk), _cs(cs), _reset(reset), _dc(dc), GraphicsDisplay(name) : GraphicsDisplay(name), _spi(mosi, miso, sclk), _cs(cs), _dc(dc) { @@ -187,7 +186,10 @@ _cs = 0; d = cmd; d = d << 1; + +//Note WH: the 9bit format is not supported for most mbed devices...This wont work. _spi.format(9,0); // we have to add a dummy clock cycle + _spi.write(d); _spi.format(8,0); _dc = 1; @@ -218,7 +220,7 @@ void SPI_TFT_ILI9341::tft_reset() { //WH _spi.format(8,3); // 8 bit spi Mode 3 - _spi.format(8,0); // 8 bit spi mode 0 + _spi.format(8,0); // 8 bit spi, mode 0 // _spi.frequency(4000000); // 4 Mhz SPI clock // _spi.frequency(8000000); // 8 Mhz SPI clock @@ -229,22 +231,18 @@ _hwreset(); // HW reset -//WH wr_cmd(0x01); // SW reset wr_cmd(ILI9341_DISPLAY_RST); // SW reset wait_ms(5); -//WH wr_cmd(0x28); // display off wr_cmd(ILI9341_DISPLAY_OFF); // display off /* Start Initial Sequence ----------------------------------------------------*/ -// wr_cmd(0xCF); wr_cmd(ILI9341_POWERB); /* Power control B register */ _spi.write(0x00); _spi.write(0x83); _spi.write(0x30); _cs = 1; -// wr_cmd(0xED); wr_cmd(ILI9341_POWER_SEQ); /* Power on sequence register */ _spi.write(0x64); _spi.write(0x03); @@ -252,14 +250,12 @@ _spi.write(0x81); _cs = 1; -// wr_cmd(0xE8); wr_cmd(ILI9341_DTCA); /* Driver timing control A */ _spi.write(0x85); _spi.write(0x01); _spi.write(0x79); _cs = 1; -// wr_cmd(0xCB); wr_cmd(ILI9341_POWERA); /* Power control A register */ _spi.write(0x39); _spi.write(0x2C); @@ -268,65 +264,53 @@ _spi.write(0x02); _cs = 1; -// wr_cmd(0xF7); wr_cmd(ILI9341_PRC); /* Pump ratio control register */ _spi.write(0x20); _cs = 1; -// wr_cmd(0xEA); wr_cmd(ILI9341_DTCB); /* Driver timing control B */ _spi.write(0x00); _spi.write(0x00); _cs = 1; -// wr_cmd(0xC0); // POWER_CONTROL_1 wr_cmd(ILI9341_POWER1); // POWER_CONTROL_1 _spi.write(0x26); _cs = 1; -// wr_cmd(0xC1); // POWER_CONTROL_2 wr_cmd(ILI9341_POWER2); // POWER_CONTROL_2 _spi.write(0x11); _cs = 1; -// wr_cmd(0xC5); // VCOM_CONTROL_1 wr_cmd(ILI9341_VCOM1); // VCOM_CONTROL_1 _spi.write(0x35); _spi.write(0x3E); _cs = 1; -// wr_cmd(0xC7); // VCOM_CONTROL_2 wr_cmd(ILI9341_VCOM2); // VCOM_CONTROL_2 _spi.write(0xBE); _cs = 1; -// wr_cmd(0x36); // MEMORY_ACCESS_CONTROL wr_cmd(ILI9341_MAC); // MEMORY_ACCESS_CONTROL _spi.write(0x48); // my,mx,mv,ml,BGR,mh,0,0 _cs = 1; -// wr_cmd(0x3A); // COLMOD_PIXEL_FORMAT_SET wr_cmd(ILI9341_PIXEL_FORMAT); /* Pixel Format register */ _spi.write(0x55); // 16 bit pixel _cs = 1; -// wr_cmd(0xB1); // Frame Rate wr_cmd(ILI9341_FRC); /* Frame Rate Control register */ _spi.write(0x00); _spi.write(0x1B); _cs = 1; -// wr_cmd(0xF2); // Gamma Function Disable wr_cmd(ILI9341_3GAMMA_EN); /* 3 Gamma enable register */ _spi.write(0x08); // Gamma Function Disable _cs = 1; -// wr_cmd(0x26); wr_cmd(ILI9341_GAMMA); /* Gamma register */ _spi.write(0x01); // gamma set for curve 01/2/04/08 _cs = 1; -// wr_cmd(0xE0); // positive gamma correction wr_cmd(ILI9341_PGAMMA); /* Positive Gamma Correction register*/ _spi.write(0x1F); _spi.write(0x1A); @@ -345,7 +329,6 @@ _spi.write(0x00); _cs = 1; -// wr_cmd(0xE1); // negativ gamma correction wr_cmd(ILI9341_NGAMMA); /* Negative Gamma Correction register*/ _spi.write(0x00); _spi.write(0x25); @@ -372,12 +355,10 @@ //wr_cmd(ILI9341_TEAR_ON); // tearing effect on //_cs = 1; -//WH wr_cmd(0xB7); // entry mode wr_cmd(ILI9341_ENTRY_MODE); // entry mode _spi.write(0x07); _cs = 1; -// wr_cmd(0xB6); // display function control wr_cmd(ILI9341_DFC); /* Display Function Control register*/ _spi.write(0x0A); _spi.write(0x82); @@ -385,13 +366,11 @@ _spi.write(0x00); _cs = 1; -// wr_cmd(0x11); // sleep out wr_cmd(ILI9341_SLEEP_OUT); // sleep out _cs = 1; wait_ms(100); -// wr_cmd(0x29); // display on wr_cmd(ILI9341_DISPLAY_ON); _cs = 1; @@ -413,7 +392,6 @@ void SPI_TFT_ILI9341::pixel(int x, int y, int color) { -// wr_cmd(0x2A); wr_cmd(ILI9341_COLUMN_ADDR); _spi.write(x >> 8); _spi.write(x); @@ -422,7 +400,6 @@ _cs = 1; -// wr_cmd(0x2B); wr_cmd(ILI9341_PAGE_ADDR); _spi.write(y >> 8); _spi.write(y); @@ -431,21 +408,8 @@ _cs = 1; -// wr_cmd(0x2C); // send pixel wr_cmd(ILI9341_GRAM); // send pixel -//WH -#if(0) - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(color >> 8); - _spi.write(color & 0xff); - #else - _spi.format(16,0); // switch to 16 bit Mode 0 - _spi.write(color); // Write D0..D15 - _spi.format(8,0); - #endif -#endif - // #if (SPI_16 == 1) #if(0) // dont bother switching for only one pixel // 16 Bit SPI @@ -465,7 +429,6 @@ void SPI_TFT_ILI9341::window (unsigned int x, unsigned int y, unsigned int w, unsigned int h) { -// wr_cmd(0x2A); wr_cmd(ILI9341_COLUMN_ADDR); _spi.write(x >> 8); _spi.write(x); @@ -473,7 +436,6 @@ _spi.write(x+w-1); _cs = 1; -// wr_cmd(0x2B); wr_cmd(ILI9341_PAGE_ADDR); _spi.write(y >> 8); _spi.write(y); @@ -489,30 +451,6 @@ } -//WH -#if(0) -void SPI_TFT_ILI9341::cls (void) -{ - int pixel = ( width() * height()); - window_max(); - wr_cmd(0x2C); // send pixel - #if defined TARGET_KL25Z // 8 Bit SPI - unsigned int i; - for (i = 0; i < ( width() * height()); i++){ - _spi.write(_background >> 8); - _spi.write(_background & 0xff); - } - - #else - _spi.format(16,0); // switch to 16 bit Mode 0 - unsigned int i; - for (i = 0; i < ( width() * height()); i++) - _spi.write(_background); - _spi.format(8,0); - #endif - _cs = 1; -} -#else /** Fill the screen with _background color * @param none @@ -522,11 +460,9 @@ { fillrect(0, 0, width()-1, height()-1, _background); } - -#endif - +//WH test void SPI_TFT_ILI9341::newcls (void) { int pixels = height() * width(); @@ -737,34 +673,6 @@ } /* End filloval */ - -//WH -#if(0) -void SPI_TFT_ILI9341::hline(int x0, int x1, int y, int color) -{ - int w; - w = x1 - x0 + 1; - window(x0,y,w,1); - wr_cmd(0x2C); // send pixel - #if defined TARGET_KL25Z // 8 Bit SPI - int j; - for (j=0; j<w; j++) { - _spi.write(color >> 8); - _spi.write(color & 0xff); - } - #else - _spi.format(16,0); // switch to 16 bit Mode 0 - int j; - for (j=0; j<w; j++) { - _spi.write(color); - } - _spi.format(8,0); - #endif - _cs = 1; - window_max(); - return; -} -#else void SPI_TFT_ILI9341::hline(int x0, int x1, int y, int color) { int i, w; @@ -795,35 +703,9 @@ _cs = 1; window_max(); } -#endif -//WH -#if(0) -void SPI_TFT_ILI9341::vline(int x, int y0, int y1, int color) -{ - int h; - h = y1 - y0 + 1; - window(x,y0,1,h); - wr_cmd(0x2C); // send pixel - #if defined TARGET_KL25Z // 8 Bit SPI - for (int y=0; y<h; y++) { - _spi.write(color >> 8); - _spi.write(color & 0xff); - } - #else - _spi.format(16,0); // switch to 16 bit Mode 0 - for (int y=0; y<h; y++) { - _spi.write(color); - } - _spi.format(8,0); - #endif - _cs = 1; - window_max(); - return; -} -#else void SPI_TFT_ILI9341::vline(int x, int y0, int y1, int color) { int i, h; @@ -855,7 +737,6 @@ _cs = 1; window_max(); } -#endif void SPI_TFT_ILI9341::line(int x0, int y0, int x1, int y1, int color) { @@ -948,34 +829,6 @@ } -//WH -#if(0) -void SPI_TFT_ILI9341::fillrect(int x0, int y0, int x1, int y1, int color) -{ - int h = y1 - y0 + 1; - int w = x1 - x0 + 1; - int pixel = h * w; - window(x0,y0,w,h); - wr_cmd(0x2C); // send pixel - #if defined TARGET_KL25Z // 8 Bit SPI - for (int p=0; p<pixel; p++) { - _spi.write(color >> 8); - _spi.write(color & 0xff); - } - #else - _spi.format(16,0); // switch to 16 bit Mode 0 - for (int p=0; p<pixel; p++) { - _spi.write(color); - } - _spi.format(8,0); - #endif - _cs = 1; - window_max(); - return; -} - -#else - void SPI_TFT_ILI9341::fillrect(int x0, int y0, int x1, int y1, int color) { //sanity check @@ -1014,7 +867,7 @@ _cs = 1; } -#endif + void SPI_TFT_ILI9341::roundrect( int x1, int y1, int x2, int y2, int color ) { @@ -1298,8 +1151,6 @@ } #endif - - #endif
--- a/SPI_TFT_ILI9341.h Sat Apr 12 20:33:24 2014 +0000 +++ b/SPI_TFT_ILI9341.h Tue Apr 22 19:10:47 2014 +0000 @@ -25,8 +25,10 @@ //Always disable for KL25Z since it does not support 16 bit SPI. #define SPI_16 0 #else -//Disable anyhow since 16 bit SPI does not really seem to improve performance.. +//Disable anyhow //#define SPI_16 0 + +//Enable 16 bit SPI. Does improve performance for fill operations. #define SPI_16 1 #endif @@ -334,9 +336,9 @@ */ virtual int columns(void); - /** calculate the max number of columns + /** calculate the max number of rows * - * @returns max column + * @returns max row * depends on actual font size * */ @@ -435,20 +437,28 @@ * */ //WH void set_orientation(unsigned int o); + + + /** Set the origin of the screen + * x,y: 0,0 is always top left + * + * @param origin top left corner of the screen + * @return None + */ void set_origin(Origin origin); - /** Set background transparancy for characters + /** Set background transparancy for characters, meaning that background pixels remain unchanged * * @param state transparancy on/off - * + * @return None */ void set_transparancy(bool state); /** Enable the ILI9341 display * * @param on: display On/Off - * + * @return None */ void tft_on(bool on); @@ -466,8 +476,8 @@ * @param x0 horizontal start * @param x1 horizontal stop * @param y vertical position - * @param color 16 bit color - * + * @param color 16 bit color + * @return None */ void hline(int x0, int x1, int y, int colour); @@ -477,6 +487,7 @@ * @param y0 vertical start * @param y1 vertical stop * @param color 16 bit color + * @return None */ void vline(int x, int y0, int y1, int colour); @@ -486,22 +497,26 @@ * @param y vertical position * @param w window width in pixel * @param h window height in pixels + * @return None */ virtual void window (unsigned int x,unsigned int y, unsigned int w, unsigned int h); /** Set draw window region to whole screen * + * @return None */ void window_max (void); /** Init the ILI9341 controller * + * @return None */ void tft_reset(); /** HW Reset to ILI9341 controller + * @return None */ void _hwreset(); @@ -509,7 +524,7 @@ /** Write data to the LCD controller * * @param dat data written to LCD controller - * + * @return None */ //void wr_dat(unsigned int value); void wr_dat(unsigned char value); @@ -517,32 +532,14 @@ /** Write a command the LCD controller * * @param cmd: command to be written - * + * @return None */ void wr_cmd(unsigned char value); - /** Start data sequence to the LCD controller - * - */ - //void wr_dat_start(); - - /** Stop of data writing to the LCD controller - * - */ - //void wr_dat_stop(); - - /** write data to the LCD controller - * - * @param data to be written - * * - */ - //void wr_dat_only(unsigned short dat); - /** Read byte from the LCD controller * * @param cmd command to controller * @returns data from LCD controller - * */ char rd_byte(unsigned char cmd); @@ -551,7 +548,6 @@ * * @param cmd command to controller * @returns data from LCD controller - * */ int rd_32(unsigned char cmd); @@ -560,6 +556,7 @@ * * @param reg register to be written * @param val data to be written + * @return None */ //void wr_reg (unsigned char reg, unsigned char val); @@ -581,7 +578,7 @@ unsigned int _char_y; bool _transparancy; - //WHunsigned int orientation; + //WH unsigned int orientation; Origin _origin; };