![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
UniGraphic demo for TFT and LCD, par or spi
main.cpp@6:851dbb62def7, 2022-01-25 (annotated)
- Committer:
- Geremia
- Date:
- Tue Jan 25 18:00:21 2022 +0000
- Revision:
- 6:851dbb62def7
- Parent:
- 5:c69049e461b7
updated to OS6 baremetal, got bored about online compiler, mbed studio, platformIO and all this shitty kiddy stuff
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Geremia | 6:851dbb62def7 | 1 | //#include "stdio.h" |
Geremia | 0:2ccd65a72ab8 | 2 | #include "mbed.h" |
Geremia | 6:851dbb62def7 | 3 | //#include "string" |
Geremia | 0:2ccd65a72ab8 | 4 | #include "Arial12x12.h" |
Geremia | 0:2ccd65a72ab8 | 5 | #include "Arial24x23.h" |
Geremia | 0:2ccd65a72ab8 | 6 | //#include "Terminal6x8.h" |
Geremia | 0:2ccd65a72ab8 | 7 | #include "Arial43x48_numb.h" |
Geremia | 0:2ccd65a72ab8 | 8 | #include "pict.h" |
Geremia | 4:818956c30cae | 9 | #include "pavement_48x34.h" |
Geremia | 0:2ccd65a72ab8 | 10 | |
Geremia | 1:083257298075 | 11 | //#include "IST3020.h" |
Geremia | 0:2ccd65a72ab8 | 12 | //#include "UC1608.h" |
Geremia | 5:c69049e461b7 | 13 | //#include "ST7565.h" |
Geremia | 6:851dbb62def7 | 14 | //#include "ILI932x.h" |
Geremia | 6:851dbb62def7 | 15 | #include "ILI9341.h" |
Geremia | 2:2b781c215ac0 | 16 | //#include "ILI9486.h" |
Geremia | 2:2b781c215ac0 | 17 | //#include "TFT_MIPI.h" |
Geremia | 4:818956c30cae | 18 | //#include "SSD1306.h" |
Geremia | 0:2ccd65a72ab8 | 19 | |
Geremia | 6:851dbb62def7 | 20 | |
Geremia | 6:851dbb62def7 | 21 | BufferedSerial serial_port(USBTX, USBRX, 115200); |
Geremia | 6:851dbb62def7 | 22 | FileHandle *mbed::mbed_override_console(int fd) |
Geremia | 6:851dbb62def7 | 23 | { |
Geremia | 6:851dbb62def7 | 24 | return &serial_port; |
Geremia | 6:851dbb62def7 | 25 | } |
Geremia | 6:851dbb62def7 | 26 | |
Geremia | 0:2ccd65a72ab8 | 27 | |
Geremia | 4:818956c30cae | 28 | //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 |
Geremia | 4:818956c30cae | 29 | //UC1608 myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9, D8,"myLCD", 240, 120); // Spi 16bit, 10MHz, mosi, miso, sclk, cs, reset, dc |
Geremia | 5:c69049e461b7 | 30 | //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 |
Geremia | 6:851dbb62def7 | 31 | //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 |
Geremia | 5:c69049e461b7 | 32 | //ILI932x myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset |
Geremia | 6:851dbb62def7 | 33 | ILI9341 myLCD(SPI_16, 12000000, D11, D12, D13, D10, D9, D8,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset, dc |
Geremia | 5:c69049e461b7 | 34 | //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 |
Geremia | 5:c69049e461b7 | 35 | //ILI9486 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 |
Geremia | 5:c69049e461b7 | 36 | //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 |
Geremia | 4:818956c30cae | 37 | //SSD1306 myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9, D8,"myLCD", 240, 120); // Spi 16bit, 10MHz, mosi, miso, sclk, cs, reset, dc |
Geremia | 5:c69049e461b7 | 38 | //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 |
Geremia | 5:c69049e461b7 | 39 | //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 |
Geremia | 0:2ccd65a72ab8 | 40 | |
Geremia | 0:2ccd65a72ab8 | 41 | Timer t; |
Geremia | 0:2ccd65a72ab8 | 42 | |
Geremia | 5:c69049e461b7 | 43 | //unsigned short backgroundcolor=White; |
Geremia | 5:c69049e461b7 | 44 | //unsigned short foregroundcolor=Black; |
Geremia | 0:2ccd65a72ab8 | 45 | unsigned short backgroundcolor=Black; |
Geremia | 0:2ccd65a72ab8 | 46 | unsigned short foregroundcolor=White; |
Geremia | 0:2ccd65a72ab8 | 47 | |
Geremia | 0:2ccd65a72ab8 | 48 | char orient=1; |
Geremia | 0:2ccd65a72ab8 | 49 | int main() |
Geremia | 0:2ccd65a72ab8 | 50 | { |
Geremia | 4:818956c30cae | 51 | // myLCD.set_contrast(26);//for uc1608 |
Geremia | 4:818956c30cae | 52 | // myLCD.set_contrast(46);//for ist3020 |
Geremia | 4:818956c30cae | 53 | myLCD.set_orientation(orient); |
Geremia | 3:65af1a9fedda | 54 | int time, time2; |
Geremia | 6:851dbb62def7 | 55 | // serial_port.set_baud (115200); |
Geremia | 6:851dbb62def7 | 56 | printf("\n\nSystem Core Clock = %.3f MHZ\r\n",(float)SystemCoreClock/1000000); |
Geremia | 0:2ccd65a72ab8 | 57 | t.start(); |
Geremia | 5:c69049e461b7 | 58 | // myLCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 4:818956c30cae | 59 | // myLCD.claim(stdout); // send stdout to the LCD display |
Geremia | 4:818956c30cae | 60 | //myLCD.claim(stderr); // send stderr to the LCD display |
Geremia | 4:818956c30cae | 61 | myLCD.background(backgroundcolor); // set background to black |
Geremia | 4:818956c30cae | 62 | myLCD.foreground(foregroundcolor); // set chars to white |
Geremia | 5:c69049e461b7 | 63 | |
Geremia | 5:c69049e461b7 | 64 | while(1) |
Geremia | 5:c69049e461b7 | 65 | { |
Geremia | 5:c69049e461b7 | 66 | myLCD.set_orientation((orient++)%4); |
Geremia | 5:c69049e461b7 | 67 | // myLCD.set_orientation(2); |
Geremia | 4:818956c30cae | 68 | myLCD.cls(); // clear the screen |
Geremia | 4:818956c30cae | 69 | myLCD.locate(0,30); |
Geremia | 4:818956c30cae | 70 | myLCD.printf("Display ID: %.8X\r\n", myLCD.tftID); |
Geremia | 6:851dbb62def7 | 71 | printf("Display ID: %.8X\r\n", myLCD.tftID); |
Geremia | 0:2ccd65a72ab8 | 72 | // mem write/read test |
Geremia | 0:2ccd65a72ab8 | 73 | unsigned short readback; |
Geremia | 4:818956c30cae | 74 | unsigned short colorstep = (0x10000/myLCD.width()); |
Geremia | 4:818956c30cae | 75 | for(unsigned short i=0; i<myLCD.width(); i++) |
Geremia | 1:083257298075 | 76 | { |
Geremia | 4:818956c30cae | 77 | myLCD.pixel(i,0,i*colorstep); // write line |
Geremia | 1:083257298075 | 78 | } |
Geremia | 1:083257298075 | 79 | bool readerror=false; |
Geremia | 4:818956c30cae | 80 | for(unsigned short i=0; i<myLCD.width(); i++) // verify line |
Geremia | 0:2ccd65a72ab8 | 81 | { |
Geremia | 4:818956c30cae | 82 | readback = myLCD.pixelread(i,0); |
Geremia | 1:083257298075 | 83 | if(readback!=i*colorstep) |
Geremia | 1:083257298075 | 84 | { |
Geremia | 1:083257298075 | 85 | readerror=true; |
Geremia | 6:851dbb62def7 | 86 | printf("pix %.4X readback %.4X\r\n", i*colorstep, readback); |
Geremia | 1:083257298075 | 87 | } |
Geremia | 0:2ccd65a72ab8 | 88 | } |
Geremia | 4:818956c30cae | 89 | myLCD.locate(0,10); |
Geremia | 4:818956c30cae | 90 | myLCD.printf("pixelread test %s\r\n", readerror ? "FAIL":"PASS"); |
Geremia | 6:851dbb62def7 | 91 | thread_sleep_for(2000); |
Geremia | 0:2ccd65a72ab8 | 92 | |
Geremia | 4:818956c30cae | 93 | myLCD.cls(); |
Geremia | 4:818956c30cae | 94 | myLCD.set_font((unsigned char*) Terminal6x8,32,127,false); //variable width disabled |
Geremia | 4:818956c30cae | 95 | myLCD.locate(0,0); |
Geremia | 5:c69049e461b7 | 96 | myLCD.printf("Display Test\r\nSome text just to see if auto carriage return works correctly"); |
Geremia | 4:818956c30cae | 97 | myLCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 4:818956c30cae | 98 | // myLCD.locate(0,0); |
Geremia | 5:c69049e461b7 | 99 | myLCD.printf("\r\nDisplay Test\r\nSome text just to see if auto carriage return works correctly"); |
Geremia | 6:851dbb62def7 | 100 | printf(" Display Test \r\n"); |
Geremia | 6:851dbb62def7 | 101 | thread_sleep_for(3000); |
Geremia | 0:2ccd65a72ab8 | 102 | t.reset(); |
Geremia | 4:818956c30cae | 103 | myLCD.cls(); |
Geremia | 6:851dbb62def7 | 104 | time=t.read_us(); // time=t.elapsed_time().count(); |
Geremia | 4:818956c30cae | 105 | myLCD.locate(2,55); |
Geremia | 4:818956c30cae | 106 | myLCD.printf("cls: %.3fms", (float)time/1000); |
Geremia | 6:851dbb62def7 | 107 | printf("cls: %.3fms\r\n", (float)time/1000); |
Geremia | 6:851dbb62def7 | 108 | thread_sleep_for(3000); |
Geremia | 4:818956c30cae | 109 | |
Geremia | 4:818956c30cae | 110 | myLCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 111 | t.reset(); |
Geremia | 0:2ccd65a72ab8 | 112 | // draw some graphics |
Geremia | 4:818956c30cae | 113 | //myLCD.cls(); |
Geremia | 4:818956c30cae | 114 | myLCD.set_font((unsigned char*) Arial24x23); |
Geremia | 4:818956c30cae | 115 | myLCD.locate(10,10); |
Geremia | 4:818956c30cae | 116 | myLCD.printf("Test"); |
Geremia | 0:2ccd65a72ab8 | 117 | |
Geremia | 4:818956c30cae | 118 | myLCD.line(0,0,myLCD.width()-1,0,foregroundcolor); |
Geremia | 4:818956c30cae | 119 | myLCD.line(0,0,0,myLCD.height()-1,foregroundcolor); |
Geremia | 4:818956c30cae | 120 | myLCD.line(0,0,myLCD.width()-1,myLCD.height()-1,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 121 | |
Geremia | 4:818956c30cae | 122 | myLCD.rect(10,30,50,40,foregroundcolor); |
Geremia | 4:818956c30cae | 123 | myLCD.fillrect(60,30,100,40,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 124 | |
Geremia | 4:818956c30cae | 125 | myLCD.circle(150,32,30,foregroundcolor); |
Geremia | 4:818956c30cae | 126 | myLCD.fillcircle(140,20,10,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 127 | |
Geremia | 0:2ccd65a72ab8 | 128 | double s; |
Geremia | 0:2ccd65a72ab8 | 129 | |
Geremia | 4:818956c30cae | 130 | for (unsigned short i=0; i<myLCD.width(); i++) |
Geremia | 0:2ccd65a72ab8 | 131 | { |
Geremia | 0:2ccd65a72ab8 | 132 | s =10 * sin((long double) i / 10 ); |
Geremia | 4:818956c30cae | 133 | myLCD.pixel(i,40 + (int)s ,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 134 | } |
Geremia | 0:2ccd65a72ab8 | 135 | |
Geremia | 0:2ccd65a72ab8 | 136 | |
Geremia | 0:2ccd65a72ab8 | 137 | time=t.read_us(); |
Geremia | 4:818956c30cae | 138 | myLCD.locate(2,55); |
Geremia | 4:818956c30cae | 139 | myLCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 4:818956c30cae | 140 | myLCD.printf("plot: %.3fms", (float)time/1000); |
Geremia | 6:851dbb62def7 | 141 | printf("plot: %.3fms\r\n", (float)time/1000); |
Geremia | 6:851dbb62def7 | 142 | thread_sleep_for(3000); |
Geremia | 4:818956c30cae | 143 | myLCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 144 | t.reset(); |
Geremia | 0:2ccd65a72ab8 | 145 | Bitmap_s pic = { |
Geremia | 0:2ccd65a72ab8 | 146 | 64, // XSize |
Geremia | 0:2ccd65a72ab8 | 147 | 64, // YSize |
Geremia | 0:2ccd65a72ab8 | 148 | 8, // Bytes in Line |
Geremia | 0:2ccd65a72ab8 | 149 | burp, // Pointer to picture data |
Geremia | 0:2ccd65a72ab8 | 150 | }; |
Geremia | 4:818956c30cae | 151 | myLCD.Bitmap_BW(pic,myLCD.width()-64,0); |
Geremia | 0:2ccd65a72ab8 | 152 | time=t.read_us(); |
Geremia | 4:818956c30cae | 153 | myLCD.locate(2,55); |
Geremia | 4:818956c30cae | 154 | myLCD.printf("bmp: %.3fms", (float)time/1000); |
Geremia | 6:851dbb62def7 | 155 | printf("bmp: %.3fms\r\n", (float)time/1000); |
Geremia | 6:851dbb62def7 | 156 | thread_sleep_for(3000); |
Geremia | 4:818956c30cae | 157 | myLCD.cls(); |
Geremia | 4:818956c30cae | 158 | myLCD.set_font((unsigned char*) Arial43x48_numb, 46, 58, false); //only numbers, variable-width disabled |
Geremia | 0:2ccd65a72ab8 | 159 | t.reset(); |
Geremia | 4:818956c30cae | 160 | myLCD.locate(0,0); |
Geremia | 4:818956c30cae | 161 | myLCD.printf("%d", 12345); |
Geremia | 0:2ccd65a72ab8 | 162 | time=t.read_us(); |
Geremia | 4:818956c30cae | 163 | myLCD.locate(2,55); |
Geremia | 4:818956c30cae | 164 | myLCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 5:c69049e461b7 | 165 | myLCD.printf("Big Font: %.3fms", (float)time/1000); |
Geremia | 6:851dbb62def7 | 166 | printf("Big Font: %.3fms\r\n", (float)time/1000); |
Geremia | 6:851dbb62def7 | 167 | thread_sleep_for(3000); |
Geremia | 3:65af1a9fedda | 168 | // sparse pixels test |
Geremia | 4:818956c30cae | 169 | myLCD.cls(); |
Geremia | 4:818956c30cae | 170 | myLCD.FastWindow(true); |
Geremia | 3:65af1a9fedda | 171 | t.reset(); |
Geremia | 3:65af1a9fedda | 172 | for(unsigned int i=0; i<20000; i++) |
Geremia | 3:65af1a9fedda | 173 | { |
Geremia | 4:818956c30cae | 174 | myLCD.pixel((i+(i*89)%myLCD.width()), (i+(i*61)%myLCD.height()), White); |
Geremia | 3:65af1a9fedda | 175 | } |
Geremia | 4:818956c30cae | 176 | myLCD.copy_to_lcd(); |
Geremia | 3:65af1a9fedda | 177 | time=t.read_us(); |
Geremia | 4:818956c30cae | 178 | myLCD.cls(); |
Geremia | 4:818956c30cae | 179 | myLCD.FastWindow(false); |
Geremia | 3:65af1a9fedda | 180 | t.reset(); |
Geremia | 3:65af1a9fedda | 181 | for(unsigned int i=0; i<20000; i++) |
Geremia | 3:65af1a9fedda | 182 | { |
Geremia | 4:818956c30cae | 183 | myLCD.pixel((i+(i*89)%myLCD.width()), (i+(i*61)%myLCD.height()), White); |
Geremia | 3:65af1a9fedda | 184 | } |
Geremia | 4:818956c30cae | 185 | myLCD.copy_to_lcd(); |
Geremia | 3:65af1a9fedda | 186 | time2=t.read_us(); |
Geremia | 4:818956c30cae | 187 | myLCD.locate(2,55); |
Geremia | 5:c69049e461b7 | 188 | myLCD.printf("std:%.3fms fastw:%.3fms", (float)time2/1000, (float)time/1000); |
Geremia | 6:851dbb62def7 | 189 | printf("std: %.3fms fastw: %.3fms\r\n", (float)time2/1000, (float)time/1000); |
Geremia | 6:851dbb62def7 | 190 | thread_sleep_for(3000); |
Geremia | 2:2b781c215ac0 | 191 | // scroll test, only for TFT |
Geremia | 4:818956c30cae | 192 | myLCD.cls(); |
Geremia | 4:818956c30cae | 193 | myLCD.set_font((unsigned char*) Arial24x23); |
Geremia | 5:c69049e461b7 | 194 | myLCD.locate(2,10); |
Geremia | 4:818956c30cae | 195 | myLCD.printf("Scrolling"); |
Geremia | 4:818956c30cae | 196 | myLCD.rect(0,0,myLCD.width()-1,myLCD.height()-1,White); |
Geremia | 4:818956c30cae | 197 | myLCD.rect(1,1,myLCD.width()-2,myLCD.height()-2,Blue); |
Geremia | 4:818956c30cae | 198 | myLCD.setscrollarea(0,myLCD.sizeY()); |
Geremia | 6:851dbb62def7 | 199 | thread_sleep_for(1000); |
Geremia | 4:818956c30cae | 200 | myLCD.scroll(1); //up 1 |
Geremia | 6:851dbb62def7 | 201 | thread_sleep_for(1000); |
Geremia | 4:818956c30cae | 202 | myLCD.scroll(0); //center |
Geremia | 6:851dbb62def7 | 203 | thread_sleep_for(1000); |
Geremia | 4:818956c30cae | 204 | myLCD.scroll(myLCD.sizeY()-1); //down 1 |
Geremia | 6:851dbb62def7 | 205 | thread_sleep_for(1000); |
Geremia | 4:818956c30cae | 206 | myLCD.scroll(myLCD.sizeY()); // same as 0, center |
Geremia | 6:851dbb62def7 | 207 | thread_sleep_for(1000); |
Geremia | 4:818956c30cae | 208 | myLCD.scroll(myLCD.sizeY()>>1); // half screen |
Geremia | 6:851dbb62def7 | 209 | thread_sleep_for(1000); |
Geremia | 4:818956c30cae | 210 | myLCD.scrollreset(); // center |
Geremia | 6:851dbb62def7 | 211 | thread_sleep_for(1000); |
Geremia | 4:818956c30cae | 212 | for(unsigned short i=1; i<=myLCD.sizeY(); i++) |
Geremia | 2:2b781c215ac0 | 213 | { |
Geremia | 4:818956c30cae | 214 | myLCD.scroll(i); |
Geremia | 6:851dbb62def7 | 215 | thread_sleep_for(2); |
Geremia | 2:2b781c215ac0 | 216 | } |
Geremia | 6:851dbb62def7 | 217 | thread_sleep_for(2000); |
Geremia | 2:2b781c215ac0 | 218 | // color inversion |
Geremia | 2:2b781c215ac0 | 219 | for(unsigned short i=0; i<=8; i++) |
Geremia | 2:2b781c215ac0 | 220 | { |
Geremia | 4:818956c30cae | 221 | myLCD.invert(i&1); |
Geremia | 6:851dbb62def7 | 222 | thread_sleep_for(200); |
Geremia | 2:2b781c215ac0 | 223 | } |
Geremia | 6:851dbb62def7 | 224 | thread_sleep_for(2000); |
Geremia | 4:818956c30cae | 225 | // bmp 16bit test |
Geremia | 4:818956c30cae | 226 | myLCD.cls(); |
Geremia | 4:818956c30cae | 227 | t.reset(); |
Geremia | 4:818956c30cae | 228 | for(int y=0; y<myLCD.height(); y+=34) |
Geremia | 4:818956c30cae | 229 | { |
Geremia | 4:818956c30cae | 230 | for(int x=0; x<myLCD.width(); x+=48) myLCD.Bitmap(x,y,48,34,(unsigned char *)pavement_48x34); |
Geremia | 4:818956c30cae | 231 | } |
Geremia | 4:818956c30cae | 232 | time=t.read_us(); |
Geremia | 4:818956c30cae | 233 | myLCD.locate(2,55); |
Geremia | 4:818956c30cae | 234 | myLCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 4:818956c30cae | 235 | myLCD.printf("Bmp speed: %.3fms", (float)time/1000); |
Geremia | 6:851dbb62def7 | 236 | printf("Bmp speed: %.3fms\r\n", (float)time/1000); |
Geremia | 6:851dbb62def7 | 237 | thread_sleep_for(2000); |
Geremia | 0:2ccd65a72ab8 | 238 | } |
Geremia | 0:2ccd65a72ab8 | 239 | } |