LPC1768 Mini-DK board with 2.8" SPI TFT and SPI touch
Dependencies: Mini-DK mbed SDFileSystem
WARNING: filetoflash (SD to CPU flash)
The SPI_TFT library called from Mini-DK.lib contains an option to copy an image from the SD card to the CPU flash memory. This allows you to use an image as background without speed loss when writing other text and graphics.
By default, this option is enabled.
It can be disabled by uncommenting the #define mentioned below in Mini_DK.h:
#define NO_FLASH_BUFFER
Since the flash memory has limited write endurance, DO NOT use this feature when you intend to read multiple images from the SD card (eg: when used as a photo frame).
Diff: main.cpp
- Revision:
- 2:d0acbd263ec7
- Parent:
- 1:557df792279c
- Child:
- 3:fb4d62b5ffb3
--- a/main.cpp Wed Dec 12 12:42:22 2012 +0000 +++ b/main.cpp Thu Jan 03 10:54:09 2013 +0000 @@ -1,165 +1,164 @@ -#include "stdio.h" -#include "mbed.h" -#include "SPI_TFT.h" -#include "string" -#include "Arial12x12.h" -#include "Arial24x23.h" -#include "Arial28x28.h" -#include "font_big.h" -#include "Touch.h" - -extern unsigned char p1[]; // the mbed logo -#define RGB565CONVERT(red, green, blue) (uint16_t)( (( red >> 3 ) << 11 ) | (( green >> 2 ) << 5 ) | ( blue >> 3 )) - -// ADS7843 -> mosi, miso, sclk, cs, irq - TFT -> mosi, miso, sclk, cs, reset -TouchScreenADS7843 TFT(p5 ,p6 ,p7 ,p8 ,P2_13 ,p11, p12, p13, p14, p15,"TFT"); - -// (To be modified) put these global vars back in Touch.cpp/Touch.h -Matrix matrix; -Coordinate display; -Coordinate screen; - -int main() -{ - unsigned char Ads7846_status; - unsigned short LCD_id; - TFT.claim(stdout); // send stdout to the TFT display - TFT.TP_Init(); - - TFT.background(Black); // set background to black - TFT.foreground(White); // set chars to white - - - // LCD demo - // first show the 4 directions - TFT.cls(); - TFT.set_font((unsigned char*) Arial12x12); - TFT.set_orientation(0); - TFT.locate(0,0); - printf(" Hello Mbed 0"); - TFT.set_orientation(1); - TFT.locate(0,0); - printf(" Hello Mbed 1"); - TFT.set_orientation(2); - TFT.locate(0,0); - printf(" Hello Mbed 2"); - TFT.set_orientation(3); - TFT.locate(0,0); - printf(" Hello Mbed 3"); - TFT.set_orientation(1); - TFT.set_font((unsigned char*) Arial24x23); - TFT.locate(50,100); - TFT.printf("TFT orientation"); - - wait(2); - - // draw some graphics - TFT.cls(); - TFT.set_orientation(1); - TFT.set_font((unsigned char*) Arial24x23); - TFT.locate(120,115); - TFT.printf("Graphic"); - TFT.line(0,0,100,200,Green); - TFT.rect(100,50,50,50,Red); - TFT.fillrect(180,25,40,45,Blue); - TFT.draw_ellipse(80, 150, 33, 33, White); - TFT.fill_ellipse(80, 50, 33, 33, White); - - wait(2); - - // bigger text - TFT.foreground(White); - TFT.background(Blue); - TFT.cls(); - TFT.set_font((unsigned char*) Arial24x23); - TFT.locate(0,0); - TFT.printf("Different Fonts :"); - - TFT.set_font((unsigned char*) Neu42x35); - TFT.locate(0,50); - TFT.printf("Hello"); - TFT.set_font((unsigned char*) Arial24x23); - TFT.locate(50,100); - TFT.printf("Hello"); - TFT.set_font((unsigned char*) Arial12x12); - TFT.locate(55,150); - TFT.printf("Hello"); - - TFT.set_orientation(2); - TFT.set_font((unsigned char*) Arial24x23); - TFT.locate(10,10); - TFT.printf("Hi mbed"); - wait(2); - - // mbed logo - TFT.set_orientation(1); - TFT.background(Black); - TFT.cls(); - TFT.Bitmap(90,90,172,55,p1); - - // Read LCD ID - TFT.set_orientation(0); - LCD_id = TFT.Read_ID(); - TFT.locate(10,10); - TFT.printf("LCD: ILI%04X", LCD_id); - wait(2); - - // RGB color wheel demo (cycle through all colors) - TFT.cls(); - TFT.foreground(Yellow); // set chars to yellow - TFT.set_font((unsigned char*) Arial12x12); - TFT.locate(10,10); - TFT.printf("RGB color wheel (5x)"); - - uint8_t r = 255, g = 0, b = 0, step = 5, i; - for (i=0;i<5;i++) - { - for(;g<255;g+=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));} // Cycle from FF0000 to FFFF00 : red to yellow - for(;r>0;r-=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));} // Cycle from FFFF00 to 00FF00 : yellow to green - for(;b<255;b+=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));} // Cycle from 00FF00 to 00FFFF : green to cyan - for(;g>0;g-=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));} // Cycle from 00FFFF to 0000FF : cyan to blue - for(;r<255;r+=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));} // Cycle from 0000FF to FF00FF : blue to purple - for(;b>0;b-=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));} // Cycle from FF00FF to FF0000 : purple to red - } - wait(2); - - - // Touchpanel demo - TFT.TouchPanel_Calibrate(&matrix); - TFT.set_font((unsigned char*) Arial12x12); - TFT.set_orientation(0); - TFT.cls(); - TFT.locate(0,0); - TFT.printf(" X:"); - TFT.locate(70,0); - TFT.printf(" Y:"); - - while (1) - { - if (!TFT._tp_irq) - { - Ads7846_status = TFT.Read_Ads7846(&screen); - if (Ads7846_status) - { - TFT.getDisplayPoint(&display, &screen, &matrix ) ; - TFT.TP_DrawPoint(display.x,display.y, Blue); -// TFT.rect(display.x,display.y,1,1,Red); - TFT.locate(25,0); - printf("%03d",display.x); - TFT.locate(95,0); - printf("%03d",display.y); - // Touchscreen area is larger than LCD area. - // We use the bottom area outside the LCD area to clear the screen (y value > 320). - if (display.y > 320) - { - TFT.cls(); - TFT.locate(0,0); - TFT.printf(" X:"); - TFT.locate(70,0); - TFT.printf(" Y:"); - - } - } - } - } -} +#include "stdio.h" +#include "mbed.h" +#include "Mini_DK.h" +//#include "string" + +extern unsigned char p1[]; // the mbed logo +#define RGB565CONVERT(red, green, blue) (uint16_t)( (( red >> 3 ) << 11 ) | (( green >> 2 ) << 5 ) | ( blue >> 3 )) + +DigitalOut led(DK_LED1); +// TFT -> mosi, miso, sclk, cs +SPI_TFT TFT(LCD_SDI, LCD_SDO, LCD_SCK, LCD_CS,"TFT"); +// ADS7843 -> mosi, miso, sclk, cs, irq +TouchScreenADS7843 TP(TP_SDI ,TP_SDO ,TP_SCK ,TP_CS ,TP_IRQ); + +// (To be modified) put these global vars back in Touch.cpp/Touch.h +//Matrix matrix; +//Coordinate display; +//Coordinate screen; + +int main() +{ + unsigned char Ads7846_status; + unsigned short LCD_id; + TFT.claim(stdout); // send stdout to the TFT display + + TFT.background(Black); // set background to black + TFT.foreground(White); // set chars to white + + + // LCD demo + // first show the 4 directions + TFT.cls(); + TFT.set_font((unsigned char*) Arial12x12); + TFT.set_orientation(0); + TFT.locate(0,0); + printf(" Hello Mbed 0"); + TFT.set_orientation(1); + TFT.locate(0,0); + printf(" Hello Mbed 1"); + TFT.set_orientation(2); + TFT.locate(0,0); + printf(" Hello Mbed 2"); + TFT.set_orientation(3); + TFT.locate(0,0); + printf(" Hello Mbed 3"); + TFT.set_orientation(1); + TFT.set_font((unsigned char*) Arial24x23); + TFT.locate(50,100); + TFT.printf("TFT orientation"); + + wait(2); + + // draw some graphics + TFT.cls(); + TFT.set_orientation(1); + TFT.set_font((unsigned char*) Arial24x23); + TFT.locate(120,115); + TFT.printf("Graphic"); + TFT.line(0,0,100,200,Green); + TFT.rect(100,50,50,50,Red); + TFT.fillrect(180,25,40,45,Blue); + TFT.draw_ellipse(80, 150, 33, 33, White); + TFT.fill_ellipse(80, 50, 33, 33, White); + wait(2); + TFT.cls(); + TFT.draw_ellipse(160, 120, 100, 50, Yellow); + TFT.draw_ellipse(160, 120, 100, 100, Blue); + TFT.fill_ellipse(160, 120, 80, 40, Green); + wait(2); + + // bigger text + TFT.foreground(White); + TFT.background(Blue); + TFT.cls(); + TFT.set_font((unsigned char*) Arial24x23); + TFT.locate(0,0); + TFT.printf("Different Fonts :"); + + TFT.set_font((unsigned char*) Neu42x35); + TFT.locate(0,50); + TFT.printf("Hello"); + TFT.set_font((unsigned char*) Arial24x23); + TFT.locate(50,100); + TFT.printf("Hello"); + TFT.set_font((unsigned char*) Arial12x12); + TFT.locate(55,150); + TFT.printf("Hello"); + + TFT.set_orientation(2); + TFT.set_font((unsigned char*) Arial24x23); + TFT.locate(10,10); + TFT.printf("Hi mbed"); + wait(2); + + // mbed logo + TFT.set_orientation(1); + TFT.background(Black); + TFT.cls(); + TFT.Bitmap(90,90,172,55,p1); + + // Read LCD ID + TFT.set_orientation(0); + LCD_id = TFT.Read_ID(); + TFT.locate(10,10); + TFT.printf("LCD: ILI%04X", LCD_id); + wait(2); + + // RGB color wheel demo (cycle through all colors) + TFT.cls(); + TFT.foreground(Yellow); // set chars to yellow + TFT.set_font((unsigned char*) Arial12x12); + TFT.locate(10,10); + TFT.printf("RGB color wheel (2x)"); + + uint8_t r = 255, g = 0, b = 0, step = 5, i; + for (i=0;i<2;i++) + { + for(;g<255;g+=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));} // Cycle from FF0000 to FFFF00 : red to yellow + for(;r>0;r-=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));} // Cycle from FFFF00 to 00FF00 : yellow to green + for(;b<255;b+=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));} // Cycle from 00FF00 to 00FFFF : green to cyan + for(;g>0;g-=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));} // Cycle from 00FFFF to 0000FF : cyan to blue + for(;r<255;r+=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));} // Cycle from 0000FF to FF00FF : blue to purple + for(;b>0;b-=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));} // Cycle from FF00FF to FF0000 : purple to red + } + wait(2); + + + // Touchpanel demo + TP.TouchPanel_Calibrate(); + TFT.set_font((unsigned char*) Arial12x12); + TFT.set_orientation(0); + TFT.cls(); + TFT.locate(0,0); + TFT.printf(" X:"); + TFT.locate(70,0); + TFT.printf(" Y:"); + while (1) + { + if (!TP._tp_irq) + { + Ads7846_status = TP.Read_Ads7846(&TP.screen); + if (Ads7846_status) + { + TP.getDisplayPoint() ; +// TP.TP_DrawPoint(display.x,display.y, Blue); + TFT.rect(TP.display.x,TP.display.y,1,1,Red); + TFT.locate(25,0); + printf("%03d",TP.display.x); + TFT.locate(95,0); + printf("%03d",TP.display.y); + // Touchscreen area is larger than LCD area. + // We use the bottom area outside the LCD area to clear the screen (y value > 320). + if (TP.display.y > 320) + { + TFT.cls(); + TFT.locate(0,0); + TFT.printf(" X:"); + TFT.locate(70,0); + TFT.printf(" Y:"); + } + } + } + } +}