mmm
Dependencies: PinDetect TFT_fonts TouchADS7843 mbed
Fork of SPI_TFT_ILI9341 by
Revision 6:fe07ae8329f7, committed 2014-01-26
- Comitter:
- dreschpe
- Date:
- Sun Jan 26 16:58:45 2014 +0000
- Parent:
- 5:55aed13f2630
- Child:
- 7:4c30bea883bc
- Commit message:
- Change the bmp16 interface to also use SD-cards to load pictures.
Changed in this revision
SPI_TFT_ILI9341.cpp | Show annotated file Show diff for this revision Revisions of this file |
SPI_TFT_ILI9341.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SPI_TFT_ILI9341.cpp Tue Oct 22 20:55:39 2013 +0000 +++ b/SPI_TFT_ILI9341.cpp Sun Jan 26 16:58:45 2014 +0000 @@ -14,19 +14,20 @@ // 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 +// 26.01.14 Change interface for BMP_16 to also use SD-cards #include "SPI_TFT_ILI9341.h" #include "mbed.h" #define BPP 16 // Bits per pixel - - + //extern Serial pc; //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) : _spi(mosi, miso, sclk), _cs(cs), _reset(reset), _dc(dc), GraphicsDisplay(name) { + clk = sclk; orientation = 0; char_x = 0; tft_reset(); @@ -88,18 +89,53 @@ -// the ILI9341 can read - has to be implemented later -// A read will return 0 at the moment +// the ILI9341 can read + +char SPI_TFT_ILI9341::rd_byte(unsigned char cmd) +{ + char r; + _dc = 0; + _cs = 0; + _spi.write(cmd); // mbed lib + _cs = 1; + r = _spi.write(0xff); + _cs = 1; + return(r); +} -//unsigned short SPI_TFT_ILI9341::rd_dat (void) -//{ -// unsigned short val = 0; +// read 32 bit +int SPI_TFT_ILI9341::rd_32(unsigned char cmd) +{ + int d; + char r; + _dc = 0; + _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); + _dc = 1; + r = _spi.write(0xff); + d = r; + r = _spi.write(0xff); + d = (d << 8) | r; + r = _spi.write(0xff); + d = (d << 8) | r; + r = _spi.write(0xff); + d = (d << 8) | r; + _cs = 1; + return(d); +} - //val = _spi.write(0x73ff); /* Dummy read 1 */ - //val = _spi.write(0x0000); /* Read D8..D15 */ -// return (val); -//} - +int SPI_TFT_ILI9341::Read_ID(void){ + int r; + r = rd_byte(0x0A); + r = rd_byte(0x0A); + r = rd_byte(0x0A); + r = rd_byte(0x0A); + return(r); +} // Init code based on MI0283QT datasheet @@ -107,7 +143,7 @@ void SPI_TFT_ILI9341::tft_reset() { _spi.format(8,3); // 8 bit spi mode 3 - _spi.frequency(10000000); // 10 Mhz SPI clock + _spi.frequency(20000000); // 10 Mhz SPI clock _cs = 1; // cs high _dc = 1; // dc high _reset = 0; // display reset @@ -686,8 +722,7 @@ } -// local filesystem is not implemented in kinetis board -#ifndef TARGET_KL25Z +// local filesystem is not implemented in kinetis board , but you can add a SD card int SPI_TFT_ILI9341::BMP_16(unsigned int x, unsigned int y, const char *Name_BMP) { @@ -707,15 +742,12 @@ unsigned short *line; // get the filename - LocalFileSystem local("local"); - sprintf(&filename[0],"/local/"); - i=7; + i=0; while (*Name_BMP!='\0') { filename[i++]=*Name_BMP++; } - - fprintf(stderr, "filename : %s \n\r",filename); - + filename[i] = 0; + FILE *Image = fopen((const char *)&filename[0], "rb"); // open the bmp file if (!Image) { return(0); // error file not found ! @@ -754,17 +786,22 @@ padd ++; } while ((PixelWidth * 2 + padd)%4 != 0); - -//fseek(Image, 70 ,SEEK_SET); window(x, y,PixelWidth ,PixelHeigh); - wr_cmd(0x2C); // send pixel - _spi.format(16,3); // switch to 16 bit Mode 3 + wr_cmd(0x2C); // send pixel + #ifndef TARGET_KL25Z // only 8 Bit SPI + _spi.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 ! + 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 + #else + _spi.write(line[i] >> 8); + _spi.write(line[i]); + #endif } } _cs = 1; @@ -774,4 +811,3 @@ WindowMax(); return(1); } -#endif \ No newline at end of file
--- a/SPI_TFT_ILI9341.h Tue Oct 22 20:55:39 2013 +0000 +++ b/SPI_TFT_ILI9341.h Sun Jan 26 16:58:45 2014 +0000 @@ -95,7 +95,6 @@ /** Get the width of the screen in pixel * - * @param * @returns width of screen in pixel * */ @@ -130,12 +129,8 @@ * @param x0,y0 center * @param r radius * @param color 16 bit color * - * - * use circle with different radius, - * can miss some pixel */ void fillcircle(int x, int y, int r, int colour); - /** draw a 1 pixel line @@ -231,21 +226,22 @@ void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap); - /** paint a 16 bit BMP from local filesytem on the TFT (slow) + /** paint a 16 bit BMP from filesytem on the TFT (slow) + * + * @param x,y : position of upper left corner + * @param *Name_BMP name of the BMP file with drive: "/local/test.bmp" * - * @param x,y : upper left corner - * @param *Name_BMP name of the BMP file * @returns 1 if bmp file was found and painted - * @returns -1 if bmp file was found not found - * @returns -2 if bmp file is not 16bit + * @returns 0 if bmp file was found not found + * @returns -1 if file is no bmp + * @returns -2 if bmp file is no 16 bit bmp * @returns -3 if bmp file is to big for screen * @returns -4 if buffer malloc go wrong * * bitmap format: 16 bit R5 G6 B5 * * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 - * copy to internal file system - * + * copy to internal file system or SD card */ int BMP_16(unsigned int x, unsigned int y, const char *Name_BMP); @@ -274,6 +270,15 @@ * */ void set_orientation(unsigned int o); + + + /** read out the manufacturer ID of the LCD + * can used for checking the connection to the display + * @returns ID + */ + int Read_ID(void); + + SPI _spi; DigitalOut _cs; @@ -322,7 +327,7 @@ - /** Init the HX8347D controller + /** Init the ILI9341 controller * */ void tft_reset(); @@ -359,12 +364,17 @@ */ //void wr_dat_only(unsigned short dat); - /** Read data from the LCD controller + /** Read byte from the LCD controller * + * @param cmd comand to controller * @returns data from LCD controller * */ - //unsigned short rd_dat(void); + char rd_byte(unsigned char cmd); + + + int rd_32(unsigned char cmd); + /** Write a value to the to a LCD register * @@ -384,6 +394,7 @@ unsigned int orientation; unsigned int char_x; unsigned int char_y; + PinName clk; };