.
Fork of SPI_TFT_ILI9341_V2 by
Revision 15:cb16f37ef885, committed 2015-05-16
- Comitter:
- Sissors
- Date:
- Sat May 16 11:23:40 2015 +0000
- Parent:
- 14:70665f0a182f
- Commit message:
- Added BurstSPI support
Changed in this revision
diff -r 70665f0a182f -r cb16f37ef885 BurstSPI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BurstSPI.lib Sat May 16 11:23:40 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/BurstSPI/#bc069279eb37
diff -r 70665f0a182f -r cb16f37ef885 SPI_TFT_ILI9341.cpp --- a/SPI_TFT_ILI9341.cpp Tue Mar 24 01:33:24 2015 +0000 +++ b/SPI_TFT_ILI9341.cpp Sat May 16 11:23:40 2015 +0000 @@ -13,7 +13,7 @@ // 12.06.13 fork from SPI_TFT code because controller is different ... // 14.07.13 Test with real display and bugfix // 18.10.13 Better Circle function from Michael Ammann -// 22.10.13 Fixes for Kinetis Board - 8 bit spi +// 22.10.13 Fixes for Kinetis Board - 8 bit BurstSPI // 26.01.14 Change interface for BMP_16 to also use SD-cards // 23.06.14 switch back to old Version - fork for L152 // 24.06.14 Add compiler flag for optimized L152 version @@ -33,13 +33,13 @@ //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) - : GraphicsDisplay(name), SPI(mosi, miso, sclk,NC), _cs(cs), _reset(reset), _dc(dc) + : GraphicsDisplay(name), BurstSPI(mosi, miso, sclk), _cs(cs), _reset(reset), _dc(dc) { orientation = 0; char_x = 0; - SPI::format(8,3); // 8 bit spi mode 3 - SPI::frequency(10000000); // 10 Mhz SPI clock + BurstSPI::format(8,3); // 8 bit BurstSPI mode 3 + BurstSPI::frequency(10000000); // 10 Mhz BurstSPI clock tft_reset(); } @@ -63,16 +63,16 @@ wr_cmd(0x36); // MEMORY_ACCESS_CONTROL switch (orientation) { case 0: - SPI::write(0x48); + BurstSPI::write(0x48); break; case 1: - SPI::write(0x28); + BurstSPI::write(0x28); break; case 2: - SPI::write(0x88); + BurstSPI::write(0x88); break; case 3: - SPI::write(0xE8); + BurstSPI::write(0xE8); break; } _cs = 1; @@ -86,7 +86,7 @@ { _dc = 0; _cs = 0; - SPI::write(cmd); // mbed lib + BurstSPI::write(cmd); // mbed lib _dc = 1; } @@ -94,7 +94,7 @@ void SPI_TFT_ILI9341::wr_dat(unsigned char dat) { - SPI::write(dat); // mbed lib + BurstSPI::write(dat); // mbed lib } @@ -106,9 +106,9 @@ char r; _dc = 0; _cs = 0; - SPI::write(cmd); // mbed lib + BurstSPI::write(cmd); // mbed lib _cs = 1; - r = SPI::write(0xff); + r = BurstSPI::write(0xff); _cs = 1; return(r); } @@ -122,17 +122,17 @@ _cs = 0; d = cmd; d = d << 1; - SPI::format(9,3); // we have to add a dummy clock cycle - SPI::write(d); - SPI::format(8,3); + BurstSPI::format(9,3); // we have to add a dummy clock cycle + BurstSPI::write(d); + BurstSPI::format(8,3); _dc = 1; - r = SPI::write(0xff); + r = BurstSPI::write(0xff); d = r; - r = SPI::write(0xff); + r = BurstSPI::write(0xff); d = (d << 8) | r; - r = SPI::write(0xff); + r = BurstSPI::write(0xff); d = (d << 8) | r; - r = SPI::write(0xff); + r = BurstSPI::write(0xff); d = (d << 8) | r; _cs = 1; return(d); @@ -166,113 +166,113 @@ /* Start Initial Sequence ----------------------------------------------------*/ wr_cmd(0xCF); - SPI::write(0x00); - SPI::write(0x83); - SPI::write(0x30); + BurstSPI::write(0x00); + BurstSPI::write(0x83); + BurstSPI::write(0x30); _cs = 1; wr_cmd(0xED); - SPI::write(0x64); - SPI::write(0x03); - SPI::write(0x12); - SPI::write(0x81); + BurstSPI::write(0x64); + BurstSPI::write(0x03); + BurstSPI::write(0x12); + BurstSPI::write(0x81); _cs = 1; wr_cmd(0xE8); - SPI::write(0x85); - SPI::write(0x01); - SPI::write(0x79); + BurstSPI::write(0x85); + BurstSPI::write(0x01); + BurstSPI::write(0x79); _cs = 1; wr_cmd(0xCB); - SPI::write(0x39); - SPI::write(0x2C); - SPI::write(0x00); - SPI::write(0x34); - SPI::write(0x02); + BurstSPI::write(0x39); + BurstSPI::write(0x2C); + BurstSPI::write(0x00); + BurstSPI::write(0x34); + BurstSPI::write(0x02); _cs = 1; wr_cmd(0xF7); - SPI::write(0x20); + BurstSPI::write(0x20); _cs = 1; wr_cmd(0xEA); - SPI::write(0x00); - SPI::write(0x00); + BurstSPI::write(0x00); + BurstSPI::write(0x00); _cs = 1; wr_cmd(0xC0); // POWER_CONTROL_1 - SPI::write(0x26); + BurstSPI::write(0x26); _cs = 1; wr_cmd(0xC1); // POWER_CONTROL_2 - SPI::write(0x11); + BurstSPI::write(0x11); _cs = 1; wr_cmd(0xC5); // VCOM_CONTROL_1 - SPI::write(0x35); - SPI::write(0x3E); + BurstSPI::write(0x35); + BurstSPI::write(0x3E); _cs = 1; wr_cmd(0xC7); // VCOM_CONTROL_2 - SPI::write(0xBE); + BurstSPI::write(0xBE); _cs = 1; wr_cmd(0x36); // MEMORY_ACCESS_CONTROL - SPI::write(0x48); + BurstSPI::write(0x48); _cs = 1; wr_cmd(0x3A); // COLMOD_PIXEL_FORMAT_SET - SPI::write(0x55); // 16 bit pixel + BurstSPI::write(0x55); // 16 bit pixel _cs = 1; wr_cmd(0xB1); // Frame Rate - SPI::write(0x00); - SPI::write(0x1B); + BurstSPI::write(0x00); + BurstSPI::write(0x1B); _cs = 1; wr_cmd(0xF2); // Gamma Function Disable - SPI::write(0x08); + BurstSPI::write(0x08); _cs = 1; wr_cmd(0x26); - SPI::write(0x01); // gamma set for curve 01/2/04/08 + BurstSPI::write(0x01); // gamma set for curve 01/2/04/08 _cs = 1; wr_cmd(0xE0); // positive gamma correction - SPI::write(0x1F); - SPI::write(0x1A); - SPI::write(0x18); - SPI::write(0x0A); - SPI::write(0x0F); - SPI::write(0x06); - SPI::write(0x45); - SPI::write(0x87); - SPI::write(0x32); - SPI::write(0x0A); - SPI::write(0x07); - SPI::write(0x02); - SPI::write(0x07); - SPI::write(0x05); - SPI::write(0x00); + BurstSPI::write(0x1F); + BurstSPI::write(0x1A); + BurstSPI::write(0x18); + BurstSPI::write(0x0A); + BurstSPI::write(0x0F); + BurstSPI::write(0x06); + BurstSPI::write(0x45); + BurstSPI::write(0x87); + BurstSPI::write(0x32); + BurstSPI::write(0x0A); + BurstSPI::write(0x07); + BurstSPI::write(0x02); + BurstSPI::write(0x07); + BurstSPI::write(0x05); + BurstSPI::write(0x00); _cs = 1; wr_cmd(0xE1); // negativ gamma correction - SPI::write(0x00); - SPI::write(0x25); - SPI::write(0x27); - SPI::write(0x05); - SPI::write(0x10); - SPI::write(0x09); - SPI::write(0x3A); - SPI::write(0x78); - SPI::write(0x4D); - SPI::write(0x05); - SPI::write(0x18); - SPI::write(0x0D); - SPI::write(0x38); - SPI::write(0x3A); - SPI::write(0x1F); + BurstSPI::write(0x00); + BurstSPI::write(0x25); + BurstSPI::write(0x27); + BurstSPI::write(0x05); + BurstSPI::write(0x10); + BurstSPI::write(0x09); + BurstSPI::write(0x3A); + BurstSPI::write(0x78); + BurstSPI::write(0x4D); + BurstSPI::write(0x05); + BurstSPI::write(0x18); + BurstSPI::write(0x0D); + BurstSPI::write(0x38); + BurstSPI::write(0x3A); + BurstSPI::write(0x1F); _cs = 1; WindowMax (); @@ -284,14 +284,14 @@ //_cs = 1; wr_cmd(0xB7); // entry mode - SPI::write(0x07); + BurstSPI::write(0x07); _cs = 1; wr_cmd(0xB6); // display function control - SPI::write(0x0A); - SPI::write(0x82); - SPI::write(0x27); - SPI::write(0x00); + BurstSPI::write(0x0A); + BurstSPI::write(0x82); + BurstSPI::write(0x27); + BurstSPI::write(0x00); _cs = 1; wr_cmd(0x11); // sleep out @@ -310,21 +310,21 @@ void SPI_TFT_ILI9341::pixel(int x, int y, int color) { wr_cmd(0x2A); - SPI::write(x >> 8); - SPI::write(x); + BurstSPI::write(x >> 8); + BurstSPI::write(x); _cs = 1; wr_cmd(0x2B); - SPI::write(y >> 8); - SPI::write(y); + BurstSPI::write(y >> 8); + BurstSPI::write(y); _cs = 1; wr_cmd(0x2C); // send pixel - #if defined TARGET_KL25Z // 8 Bit SPI - SPI::write(color >> 8); - SPI::write(color & 0xff); + #if defined TARGET_KL25Z // 8 Bit BurstSPI + BurstSPI::write(color >> 8); + BurstSPI::write(color & 0xff); #else - SPI::format(16,3); // switch to 16 bit Mode 3 - SPI::write(color); // Write D0..D15 - SPI::format(8,3); + BurstSPI::format(16,3); // switch to 16 bit Mode 3 + BurstSPI::write(color); // Write D0..D15 + BurstSPI::format(8,3); #endif _cs = 1; } @@ -333,17 +333,17 @@ void SPI_TFT_ILI9341::window (unsigned int x, unsigned int y, unsigned int w, unsigned int h) { wr_cmd(0x2A); - SPI::write(x >> 8); - SPI::write(x); - SPI::write((x+w-1) >> 8); - SPI::write(x+w-1); + BurstSPI::write(x >> 8); + BurstSPI::write(x); + BurstSPI::write((x+w-1) >> 8); + BurstSPI::write(x+w-1); _cs = 1; wr_cmd(0x2B); - SPI::write(y >> 8); - SPI::write(y); - SPI::write((y+h-1) >> 8); - SPI::write(y+h-1); + BurstSPI::write(y >> 8); + BurstSPI::write(y); + BurstSPI::write((y+h-1) >> 8); + BurstSPI::write(y+h-1); _cs = 1; } @@ -380,7 +380,7 @@ } while (x <= 0); } - +/* void SPI_TFT_ILI9341::circleGFX(int x0, int y0, int r, int color) { int16_t f = 1 - r; @@ -416,7 +416,7 @@ pixel(x0 - y, y0 - x, color); } } - +*/ void SPI_TFT_ILI9341::fillcircle(int x0, int y0, int r, int color) { int x = -r, y = 0, err = 2-2*r, e2; @@ -439,20 +439,21 @@ w = x1 - x0 + 1; window(x0,y,w,1); wr_cmd(0x2C); // send pixel - #if defined TARGET_KL25Z // 8 Bit SPI + #if defined TARGET_KL25Z // 8 Bit BurstSPI int j; for (j=0; j<w; j++) { - SPI::write(color >> 8); - SPI::write(color & 0xff); + BurstSPI::write(color >> 8); + BurstSPI::write(color & 0xff); } #else - SPI::format(16,3); // switch to 16 bit Mode 3 + BurstSPI::format(16,3); // switch to 16 bit Mode 3 int j; for (j=0; j<w; j++) { - SPI::write(color); + BurstSPI::fastWrite(color); } - SPI::format(8,3); + BurstSPI::format(8,3); #endif + BurstSPI::clearRX(); _cs = 1; WindowMax(); return; @@ -464,18 +465,19 @@ h = y1 - y0 + 1; window(x,y0,1,h); wr_cmd(0x2C); // send pixel - #if defined TARGET_KL25Z // 8 Bit SPI + #if defined TARGET_KL25Z // 8 Bit BurstSPI for (int y=0; y<h; y++) { - SPI::write(color >> 8); - SPI::write(color & 0xff); + BurstSPI::write(color >> 8); + BurstSPI::write(color & 0xff); } #else - SPI::format(16,3); // switch to 16 bit Mode 3 + BurstSPI::format(16,3); // switch to 16 bit Mode 3 for (int y=0; y<h; y++) { - SPI::write(color); + BurstSPI::fastWrite(color); } - SPI::format(8,3); + BurstSPI::format(8,3); #endif + BurstSPI::clearRX(); _cs = 1; WindowMax(); return; @@ -583,18 +585,19 @@ int pixel = h * w; window(x0,y0,w,h); wr_cmd(0x2C); // send pixel - #if defined TARGET_KL25Z // 8 Bit SPI + #if defined TARGET_KL25Z // 8 Bit BurstSPI for (int p=0; p<pixel; p++) { - SPI::write(color >> 8); - SPI::write(color & 0xff); + BurstSPI::write(color >> 8); + BurstSPI::write(color & 0xff); } #else - SPI::format(16,3); // switch to 16 bit Mode 3 + BurstSPI::format(16,3); // switch to 16 bit Mode 3 for (int p=0; p<pixel; p++) { - SPI::write(color); + BurstSPI::fastWrite(color); } - SPI::format(8,3); + BurstSPI::format(8,3); #endif + BurstSPI::clearRX(); _cs = 1; WindowMax(); return; @@ -661,8 +664,8 @@ } window(char_x, char_y,hor,vert); // char box wr_cmd(0x2C); // send pixel - #ifndef TARGET_KL25Z // 16 Bit SPI - SPI::format(16,3); + #ifndef TARGET_KL25Z // 16 Bit BurstSPI + BurstSPI::format(16,3); #endif // switch to 16 bit Mode 3 zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap w = zeichen[0]; // width of actual char @@ -671,25 +674,25 @@ z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; b = 1 << (j & 0x07); if (( z & b ) == 0x00) { - #ifndef TARGET_KL25Z // 16 Bit SPI - SPI::write(_background); + #ifndef TARGET_KL25Z // 16 Bit BurstSPI + BurstSPI::write(_background); #else - SPI::write(_background >> 8); - SPI::write(_background & 0xff); + BurstSPI::write(_background >> 8); + BurstSPI::write(_background & 0xff); #endif } else { - #ifndef TARGET_KL25Z // 16 Bit SPI - SPI::write(_foreground); + #ifndef TARGET_KL25Z // 16 Bit BurstSPI + BurstSPI::write(_foreground); #else - SPI::write(_foreground >> 8); - SPI::write(_foreground & 0xff); + BurstSPI::write(_foreground >> 8); + BurstSPI::write(_foreground & 0xff); #endif } } } _cs = 1; - #ifndef TARGET_KL25Z // 16 Bit SPI - SPI::format(8,3); + #ifndef TARGET_KL25Z // 16 Bit BurstSPI + BurstSPI::format(8,3); #endif WindowMax(); if ((w + 2) < hor) { // x offset to next char @@ -710,7 +713,7 @@ unsigned int j; int padd; unsigned short *bitmap_ptr = (unsigned short *)bitmap; - #if defined TARGET_KL25Z // 8 Bit SPI + #if defined TARGET_KL25Z // 8 Bit BurstSPI unsigned short pix_temp; #endif @@ -724,27 +727,28 @@ window(x, y, w, h); bitmap_ptr += ((h - 1)* (w + padd)); wr_cmd(0x2C); // send pixel - #ifndef TARGET_KL25Z // 16 Bit SPI - SPI::format(16,3); + #ifndef TARGET_KL25Z // 16 Bit BurstSPI + BurstSPI::format(16,3); #endif // switch to 16 bit Mode 3 for (j = 0; j < h; j++) { //Lines for (i = 0; i < w; i++) { // one line - #if defined TARGET_KL25Z // 8 Bit SPI + #if defined TARGET_KL25Z // 8 Bit BurstSPI pix_temp = *bitmap_ptr; - SPI::write(pix_temp >> 8); - SPI::write(pix_temp); + BurstSPI::write(pix_temp >> 8); + BurstSPI::write(pix_temp); bitmap_ptr++; #else - SPI::write(*bitmap_ptr); // one line + BurstSPI::fastWrite(*bitmap_ptr); // one line bitmap_ptr++; #endif } bitmap_ptr -= 2*w; bitmap_ptr -= padd; } + BurstSPI::clearRX(); _cs = 1; - #ifndef TARGET_KL25Z // 16 Bit SPI - SPI::format(8,3); + #ifndef TARGET_KL25Z // 16 Bit BurstSPI + BurstSPI::format(8,3); #endif WindowMax(); } @@ -816,24 +820,25 @@ window(x, y,PixelWidth ,PixelHeigh); wr_cmd(0x2C); // send pixel - #ifndef TARGET_KL25Z // only 8 Bit SPI - SPI::format(16,3); + #ifndef TARGET_KL25Z // only 8 Bit BurstSPI + BurstSPI::format(16,3); #endif // switch to 16 bit Mode 3 for (j = PixelHeigh - 1; j >= 0; j--) { //Lines bottom up off = j * (PixelWidth * 2 + padd) + start_data; // start of line fseek(Image, off ,SEEK_SET); fread(line,1,PixelWidth * 2,Image); // read a line - slow for (i = 0; i < PixelWidth; i++) { // copy pixel data to TFT - #ifndef TARGET_KL25Z // only 8 Bit SPI - SPI::write(line[i]); // one 16 bit pixel + #ifndef TARGET_KL25Z // only 8 Bit BurstSPI + BurstSPI::fastWrite(line[i]); // one 16 bit pixel #else - SPI::write(line[i] >> 8); - SPI::write(line[i]); + BurstSPI::write(line[i] >> 8); + BurstSPI::write(line[i]); #endif } } + BurstSPI::clearRX(); _cs = 1; - SPI::format(8,3); + BurstSPI::format(8,3); free (line); fclose(Image); WindowMax();
diff -r 70665f0a182f -r cb16f37ef885 SPI_TFT_ILI9341.h --- a/SPI_TFT_ILI9341.h Tue Mar 24 01:33:24 2015 +0000 +++ b/SPI_TFT_ILI9341.h Sat May 16 11:23:40 2015 +0000 @@ -18,6 +18,7 @@ #include "mbed.h" #include "GraphicsDisplay.h" +#include "BurstSPI.h" #define RGB(r,g,b) (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue @@ -86,7 +87,7 @@ * } * @endcode */ - class SPI_TFT_ILI9341 : public GraphicsDisplay , public SPI { + class SPI_TFT_ILI9341 : public GraphicsDisplay , public BurstSPI { public: /** Create a SPI_TFT object connected to SPI and three pins