Gustavo D. Serafim / Mbed 2 deprecated mbed_ili9486

Dependencies:   mbed UniGraphicILI9486GraphicsTest

Committer:
guhserafs
Date:
Wed May 20 12:59:29 2020 +0000
Revision:
0:f8ddaff1eba6
Nothing special.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
guhserafs 0:f8ddaff1eba6 1 #include "stdio.h"
guhserafs 0:f8ddaff1eba6 2 #include "mbed.h"
guhserafs 0:f8ddaff1eba6 3 #include "string"
guhserafs 0:f8ddaff1eba6 4 #include "Arial12x12.h"
guhserafs 0:f8ddaff1eba6 5 #include "Arial24x23.h"
guhserafs 0:f8ddaff1eba6 6 //#include "Terminal6x8.h"
guhserafs 0:f8ddaff1eba6 7 #include "Arial43x48_numb.h"
guhserafs 0:f8ddaff1eba6 8 #include "pict.h"
guhserafs 0:f8ddaff1eba6 9 #include "pavement_48x34.h"
guhserafs 0:f8ddaff1eba6 10
guhserafs 0:f8ddaff1eba6 11 //#include "IST3020.h"
guhserafs 0:f8ddaff1eba6 12 //#include "UC1608.h"
guhserafs 0:f8ddaff1eba6 13 //#include "ST7565.h"
guhserafs 0:f8ddaff1eba6 14 //#include "ILI932x.h"
guhserafs 0:f8ddaff1eba6 15 //#include "ILI9341.h"
guhserafs 0:f8ddaff1eba6 16 #include "ILI9486.h"
guhserafs 0:f8ddaff1eba6 17 //#include "TFT_MIPI.h"
guhserafs 0:f8ddaff1eba6 18 //#include "SSD1306.h"
guhserafs 0:f8ddaff1eba6 19
guhserafs 0:f8ddaff1eba6 20 Serial pc(USBTX, USBRX);
guhserafs 0:f8ddaff1eba6 21
guhserafs 0:f8ddaff1eba6 22 PinName dataBus[8]={D8,D9,D2,D3,D4,D5,D6,D7};
guhserafs 0:f8ddaff1eba6 23
guhserafs 0:f8ddaff1eba6 24 //IST3020 myLCD(PAR_8, PortC, PC_8, PC_9, PA_0, PA_1, PA_4,"myLCD", 192, 64); // Parallel 8bit, Port, CS, reset, A0, WR, RD for F302
guhserafs 0:f8ddaff1eba6 25 //UC1608 myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9, D8,"myLCD", 240, 120); // Spi 16bit, 10MHz, mosi, miso, sclk, cs, reset, dc
guhserafs 0:f8ddaff1eba6 26 //ST7565 myLCD(PAR_8, PortC, PC_8, PC_9, PA_0, PA_1, PA_4,"myLCD", 128, 64); // Parallel 8bit, Port, CS, reset, A0, WR, RD
guhserafs 0:f8ddaff1eba6 27 //ILI932x myLCD(PAR_8, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 8bit, Port, CS, reset, RS, WR, RD for F401
guhserafs 0:f8ddaff1eba6 28 //ILI932x myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset
guhserafs 0:f8ddaff1eba6 29 //ILI9341 myLCD(SPI_16, 12000000, D11, D12, D13, D10, D9, D8,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset, dc
guhserafs 0:f8ddaff1eba6 30 //ILI9341 myLCD(PAR_16, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 16bit, Port, CS, reset, DC, WR, RD for F401
guhserafs 0:f8ddaff1eba6 31 ILI9486 myLCD(BUS_8, dataBus, A3, A4, A2, A1, A0,"myLCD"); // Parallel 16bit, Port, CS, reset, DC, WR, RD for F401
guhserafs 0:f8ddaff1eba6 32 //TFT_MIPI myLCD(PAR_16, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 16bit, Port, CS, reset, DC, WR, RD for F401
guhserafs 0:f8ddaff1eba6 33 //SSD1306 myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9, D8,"myLCD", 240, 120); // Spi 16bit, 10MHz, mosi, miso, sclk, cs, reset, dc
guhserafs 0:f8ddaff1eba6 34 //ILI9486 myLCD(SPI_8, 12000000, PA_7, PA_6, PA_5, PB_6, PA_8, PA_9,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset, dc for minimaple
guhserafs 0:f8ddaff1eba6 35 //ILI9341 myLCD(SPI_8, 12000000, PA_7, PA_6, PA_5, PB_6, PA_8, PA_9,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset, dc for minimaple
guhserafs 0:f8ddaff1eba6 36
guhserafs 0:f8ddaff1eba6 37 Timer t;
guhserafs 0:f8ddaff1eba6 38
guhserafs 0:f8ddaff1eba6 39 //unsigned short backgroundcolor=White;
guhserafs 0:f8ddaff1eba6 40 //unsigned short foregroundcolor=Black;
guhserafs 0:f8ddaff1eba6 41 unsigned short backgroundcolor=Black;
guhserafs 0:f8ddaff1eba6 42 unsigned short foregroundcolor=White;
guhserafs 0:f8ddaff1eba6 43
guhserafs 0:f8ddaff1eba6 44 char orient=1;
guhserafs 0:f8ddaff1eba6 45 int main()
guhserafs 0:f8ddaff1eba6 46 {
guhserafs 0:f8ddaff1eba6 47 // myLCD.set_contrast(26);//for uc1608
guhserafs 0:f8ddaff1eba6 48 // myLCD.set_contrast(46);//for ist3020
guhserafs 0:f8ddaff1eba6 49 myLCD.set_orientation(orient);
guhserafs 0:f8ddaff1eba6 50 int time, time2;
guhserafs 0:f8ddaff1eba6 51 pc.baud (115200);
guhserafs 0:f8ddaff1eba6 52 pc.printf("\n\nSystem Core Clock = %.3f MHZ\r\n",(float)SystemCoreClock/1000000);
guhserafs 0:f8ddaff1eba6 53 t.start();
guhserafs 0:f8ddaff1eba6 54 // myLCD.set_font((unsigned char*) Terminal6x8);
guhserafs 0:f8ddaff1eba6 55 // myLCD.claim(stdout); // send stdout to the LCD display
guhserafs 0:f8ddaff1eba6 56 //myLCD.claim(stderr); // send stderr to the LCD display
guhserafs 0:f8ddaff1eba6 57 myLCD.background(backgroundcolor); // set background to black
guhserafs 0:f8ddaff1eba6 58 myLCD.foreground(foregroundcolor); // set chars to white
guhserafs 0:f8ddaff1eba6 59
guhserafs 0:f8ddaff1eba6 60 while(1)
guhserafs 0:f8ddaff1eba6 61 {
guhserafs 0:f8ddaff1eba6 62 myLCD.set_orientation((orient++)%4);
guhserafs 0:f8ddaff1eba6 63 // myLCD.set_orientation(2);
guhserafs 0:f8ddaff1eba6 64 myLCD.cls(); // clear the screen
guhserafs 0:f8ddaff1eba6 65 myLCD.locate(0,30);
guhserafs 0:f8ddaff1eba6 66 myLCD.printf("Display ID: %.8X\r\n", myLCD.tftID);
guhserafs 0:f8ddaff1eba6 67 pc.printf("Display ID: %.8X\r\n", myLCD.tftID);
guhserafs 0:f8ddaff1eba6 68 // mem write/read test
guhserafs 0:f8ddaff1eba6 69 unsigned short readback;
guhserafs 0:f8ddaff1eba6 70 unsigned short colorstep = (0x10000/myLCD.width());
guhserafs 0:f8ddaff1eba6 71 for(unsigned short i=0; i<myLCD.width(); i++)
guhserafs 0:f8ddaff1eba6 72 {
guhserafs 0:f8ddaff1eba6 73 myLCD.pixel(i,0,i*colorstep); // write line
guhserafs 0:f8ddaff1eba6 74 }
guhserafs 0:f8ddaff1eba6 75 bool readerror=false;
guhserafs 0:f8ddaff1eba6 76 for(unsigned short i=0; i<myLCD.width(); i++) // verify line
guhserafs 0:f8ddaff1eba6 77 {
guhserafs 0:f8ddaff1eba6 78 readback = myLCD.pixelread(i,0);
guhserafs 0:f8ddaff1eba6 79 if(readback!=i*colorstep)
guhserafs 0:f8ddaff1eba6 80 {
guhserafs 0:f8ddaff1eba6 81 readerror=true;
guhserafs 0:f8ddaff1eba6 82 pc.printf("pix %.4X readback %.4X\r\n", i*colorstep, readback);
guhserafs 0:f8ddaff1eba6 83 }
guhserafs 0:f8ddaff1eba6 84 }
guhserafs 0:f8ddaff1eba6 85 myLCD.locate(0,10);
guhserafs 0:f8ddaff1eba6 86 myLCD.printf("pixelread test %s\r\n", readerror ? "FAIL":"PASS");
guhserafs 0:f8ddaff1eba6 87 wait(2);
guhserafs 0:f8ddaff1eba6 88
guhserafs 0:f8ddaff1eba6 89 myLCD.cls();
guhserafs 0:f8ddaff1eba6 90 myLCD.set_font((unsigned char*) Terminal6x8,32,127,false); //variable width disabled
guhserafs 0:f8ddaff1eba6 91 myLCD.locate(0,0);
guhserafs 0:f8ddaff1eba6 92 myLCD.printf("Display Test\r\nSome text just to see if auto carriage return works correctly");
guhserafs 0:f8ddaff1eba6 93 myLCD.set_font((unsigned char*) Terminal6x8);
guhserafs 0:f8ddaff1eba6 94 // myLCD.locate(0,0);
guhserafs 0:f8ddaff1eba6 95 myLCD.printf("\r\nDisplay Test\r\nSome text just to see if auto carriage return works correctly");
guhserafs 0:f8ddaff1eba6 96 pc.printf(" Display Test \r\n");
guhserafs 0:f8ddaff1eba6 97 wait(3);
guhserafs 0:f8ddaff1eba6 98 t.reset();
guhserafs 0:f8ddaff1eba6 99 myLCD.cls();
guhserafs 0:f8ddaff1eba6 100 time=t.read_us();
guhserafs 0:f8ddaff1eba6 101 myLCD.locate(2,55);
guhserafs 0:f8ddaff1eba6 102 myLCD.printf("cls: %.3fms", (float)time/1000);
guhserafs 0:f8ddaff1eba6 103 pc.printf("cls: %.3fms\r\n", (float)time/1000);
guhserafs 0:f8ddaff1eba6 104 wait(3);
guhserafs 0:f8ddaff1eba6 105
guhserafs 0:f8ddaff1eba6 106 myLCD.cls();
guhserafs 0:f8ddaff1eba6 107 t.reset();
guhserafs 0:f8ddaff1eba6 108 // draw some graphics
guhserafs 0:f8ddaff1eba6 109 //myLCD.cls();
guhserafs 0:f8ddaff1eba6 110 myLCD.set_font((unsigned char*) Arial24x23);
guhserafs 0:f8ddaff1eba6 111 myLCD.locate(10,10);
guhserafs 0:f8ddaff1eba6 112 myLCD.printf("Test");
guhserafs 0:f8ddaff1eba6 113
guhserafs 0:f8ddaff1eba6 114 myLCD.line(0,0,myLCD.width()-1,0,foregroundcolor);
guhserafs 0:f8ddaff1eba6 115 myLCD.line(0,0,0,myLCD.height()-1,foregroundcolor);
guhserafs 0:f8ddaff1eba6 116 myLCD.line(0,0,myLCD.width()-1,myLCD.height()-1,foregroundcolor);
guhserafs 0:f8ddaff1eba6 117
guhserafs 0:f8ddaff1eba6 118 myLCD.rect(10,30,50,40,foregroundcolor);
guhserafs 0:f8ddaff1eba6 119 myLCD.fillrect(60,30,100,40,foregroundcolor);
guhserafs 0:f8ddaff1eba6 120
guhserafs 0:f8ddaff1eba6 121 myLCD.circle(150,32,30,foregroundcolor);
guhserafs 0:f8ddaff1eba6 122 myLCD.fillcircle(140,20,10,foregroundcolor);
guhserafs 0:f8ddaff1eba6 123
guhserafs 0:f8ddaff1eba6 124 double s;
guhserafs 0:f8ddaff1eba6 125
guhserafs 0:f8ddaff1eba6 126 for (unsigned short i=0; i<myLCD.width(); i++)
guhserafs 0:f8ddaff1eba6 127 {
guhserafs 0:f8ddaff1eba6 128 s =10 * sin((long double) i / 10 );
guhserafs 0:f8ddaff1eba6 129 myLCD.pixel(i,40 + (int)s ,foregroundcolor);
guhserafs 0:f8ddaff1eba6 130 }
guhserafs 0:f8ddaff1eba6 131
guhserafs 0:f8ddaff1eba6 132
guhserafs 0:f8ddaff1eba6 133 time=t.read_us();
guhserafs 0:f8ddaff1eba6 134 myLCD.locate(2,55);
guhserafs 0:f8ddaff1eba6 135 myLCD.set_font((unsigned char*) Terminal6x8);
guhserafs 0:f8ddaff1eba6 136 myLCD.printf("plot: %.3fms", (float)time/1000);
guhserafs 0:f8ddaff1eba6 137 pc.printf("plot: %.3fms\r\n", (float)time/1000);
guhserafs 0:f8ddaff1eba6 138 wait(3);
guhserafs 0:f8ddaff1eba6 139 myLCD.cls();
guhserafs 0:f8ddaff1eba6 140 t.reset();
guhserafs 0:f8ddaff1eba6 141 Bitmap_s pic = {
guhserafs 0:f8ddaff1eba6 142 64, // XSize
guhserafs 0:f8ddaff1eba6 143 64, // YSize
guhserafs 0:f8ddaff1eba6 144 8, // Bytes in Line
guhserafs 0:f8ddaff1eba6 145 burp, // Pointer to picture data
guhserafs 0:f8ddaff1eba6 146 };
guhserafs 0:f8ddaff1eba6 147 myLCD.Bitmap_BW(pic,myLCD.width()-64,0);
guhserafs 0:f8ddaff1eba6 148 time=t.read_us();
guhserafs 0:f8ddaff1eba6 149 myLCD.locate(2,55);
guhserafs 0:f8ddaff1eba6 150 myLCD.printf("bmp: %.3fms", (float)time/1000);
guhserafs 0:f8ddaff1eba6 151 pc.printf("bmp: %.3fms\r\n", (float)time/1000);
guhserafs 0:f8ddaff1eba6 152 wait(3);
guhserafs 0:f8ddaff1eba6 153 myLCD.cls();
guhserafs 0:f8ddaff1eba6 154 myLCD.set_font((unsigned char*) Arial43x48_numb, 46, 58, false); //only numbers, variable-width disabled
guhserafs 0:f8ddaff1eba6 155 t.reset();
guhserafs 0:f8ddaff1eba6 156 myLCD.locate(0,0);
guhserafs 0:f8ddaff1eba6 157 myLCD.printf("%d", 12345);
guhserafs 0:f8ddaff1eba6 158 time=t.read_us();
guhserafs 0:f8ddaff1eba6 159 myLCD.locate(2,55);
guhserafs 0:f8ddaff1eba6 160 myLCD.set_font((unsigned char*) Terminal6x8);
guhserafs 0:f8ddaff1eba6 161 myLCD.printf("Big Font: %.3fms", (float)time/1000);
guhserafs 0:f8ddaff1eba6 162 pc.printf("Big Font: %.3fms\r\n", (float)time/1000);
guhserafs 0:f8ddaff1eba6 163 wait(3);
guhserafs 0:f8ddaff1eba6 164 // sparse pixels test
guhserafs 0:f8ddaff1eba6 165 myLCD.cls();
guhserafs 0:f8ddaff1eba6 166 myLCD.FastWindow(true);
guhserafs 0:f8ddaff1eba6 167 t.reset();
guhserafs 0:f8ddaff1eba6 168 for(unsigned int i=0; i<20000; i++)
guhserafs 0:f8ddaff1eba6 169 {
guhserafs 0:f8ddaff1eba6 170 myLCD.pixel((i+(i*89)%myLCD.width()), (i+(i*61)%myLCD.height()), White);
guhserafs 0:f8ddaff1eba6 171 }
guhserafs 0:f8ddaff1eba6 172 myLCD.copy_to_lcd();
guhserafs 0:f8ddaff1eba6 173 time=t.read_us();
guhserafs 0:f8ddaff1eba6 174 myLCD.cls();
guhserafs 0:f8ddaff1eba6 175 myLCD.FastWindow(false);
guhserafs 0:f8ddaff1eba6 176 t.reset();
guhserafs 0:f8ddaff1eba6 177 for(unsigned int i=0; i<20000; i++)
guhserafs 0:f8ddaff1eba6 178 {
guhserafs 0:f8ddaff1eba6 179 myLCD.pixel((i+(i*89)%myLCD.width()), (i+(i*61)%myLCD.height()), White);
guhserafs 0:f8ddaff1eba6 180 }
guhserafs 0:f8ddaff1eba6 181 myLCD.copy_to_lcd();
guhserafs 0:f8ddaff1eba6 182 time2=t.read_us();
guhserafs 0:f8ddaff1eba6 183 myLCD.locate(2,55);
guhserafs 0:f8ddaff1eba6 184 myLCD.printf("std:%.3fms fastw:%.3fms", (float)time2/1000, (float)time/1000);
guhserafs 0:f8ddaff1eba6 185 pc.printf("std: %.3fms fastw: %.3fms\r\n", (float)time2/1000, (float)time/1000);
guhserafs 0:f8ddaff1eba6 186 wait(3);
guhserafs 0:f8ddaff1eba6 187 // scroll test, only for TFT
guhserafs 0:f8ddaff1eba6 188 myLCD.cls();
guhserafs 0:f8ddaff1eba6 189 myLCD.set_font((unsigned char*) Arial24x23);
guhserafs 0:f8ddaff1eba6 190 myLCD.locate(2,10);
guhserafs 0:f8ddaff1eba6 191 myLCD.printf("Scrolling");
guhserafs 0:f8ddaff1eba6 192 myLCD.rect(0,0,myLCD.width()-1,myLCD.height()-1,White);
guhserafs 0:f8ddaff1eba6 193 myLCD.rect(1,1,myLCD.width()-2,myLCD.height()-2,Blue);
guhserafs 0:f8ddaff1eba6 194 myLCD.setscrollarea(0,myLCD.sizeY());
guhserafs 0:f8ddaff1eba6 195 wait(1);
guhserafs 0:f8ddaff1eba6 196 myLCD.scroll(1); //up 1
guhserafs 0:f8ddaff1eba6 197 wait(1);
guhserafs 0:f8ddaff1eba6 198 myLCD.scroll(0); //center
guhserafs 0:f8ddaff1eba6 199 wait(1);
guhserafs 0:f8ddaff1eba6 200 myLCD.scroll(myLCD.sizeY()-1); //down 1
guhserafs 0:f8ddaff1eba6 201 wait(1);
guhserafs 0:f8ddaff1eba6 202 myLCD.scroll(myLCD.sizeY()); // same as 0, center
guhserafs 0:f8ddaff1eba6 203 wait(1);
guhserafs 0:f8ddaff1eba6 204 myLCD.scroll(myLCD.sizeY()>>1); // half screen
guhserafs 0:f8ddaff1eba6 205 wait(1);
guhserafs 0:f8ddaff1eba6 206 myLCD.scrollreset(); // center
guhserafs 0:f8ddaff1eba6 207 wait(1);
guhserafs 0:f8ddaff1eba6 208 for(unsigned short i=1; i<=myLCD.sizeY(); i++)
guhserafs 0:f8ddaff1eba6 209 {
guhserafs 0:f8ddaff1eba6 210 myLCD.scroll(i);
guhserafs 0:f8ddaff1eba6 211 wait_ms(2);
guhserafs 0:f8ddaff1eba6 212 }
guhserafs 0:f8ddaff1eba6 213 wait(2);
guhserafs 0:f8ddaff1eba6 214 // color inversion
guhserafs 0:f8ddaff1eba6 215 for(unsigned short i=0; i<=8; i++)
guhserafs 0:f8ddaff1eba6 216 {
guhserafs 0:f8ddaff1eba6 217 myLCD.invert(i&1);
guhserafs 0:f8ddaff1eba6 218 wait_ms(200);
guhserafs 0:f8ddaff1eba6 219 }
guhserafs 0:f8ddaff1eba6 220 wait(2);
guhserafs 0:f8ddaff1eba6 221 // bmp 16bit test
guhserafs 0:f8ddaff1eba6 222 myLCD.cls();
guhserafs 0:f8ddaff1eba6 223 t.reset();
guhserafs 0:f8ddaff1eba6 224 for(int y=0; y<myLCD.height(); y+=34)
guhserafs 0:f8ddaff1eba6 225 {
guhserafs 0:f8ddaff1eba6 226 for(int x=0; x<myLCD.width(); x+=48) myLCD.Bitmap(x,y,48,34,(unsigned char *)pavement_48x34);
guhserafs 0:f8ddaff1eba6 227 }
guhserafs 0:f8ddaff1eba6 228 time=t.read_us();
guhserafs 0:f8ddaff1eba6 229 myLCD.locate(2,55);
guhserafs 0:f8ddaff1eba6 230 myLCD.set_font((unsigned char*) Terminal6x8);
guhserafs 0:f8ddaff1eba6 231 myLCD.printf("Bmp speed: %.3fms", (float)time/1000);
guhserafs 0:f8ddaff1eba6 232 pc.printf("Bmp speed: %.3fms\r\n", (float)time/1000);
guhserafs 0:f8ddaff1eba6 233 wait(2);
guhserafs 0:f8ddaff1eba6 234 }
guhserafs 0:f8ddaff1eba6 235 }