Test program for STMF103RB and LCD display supplied with an ADF4351

Dependencies:   UniGraphic mbed

Committer:
jluu
Date:
Wed Nov 23 17:45:34 2016 +0000
Revision:
2:167ceea448d2
Parent:
1:3f7462251f77
uncomment all display controler includes

Who changed what in which revision?

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