![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
test st7735 on lpc1768 with mbed v5. bug with spi frequency...
main.cpp@1:121b61eeffe7, 2020-04-08 (annotated)
- Committer:
- skydarc
- Date:
- Wed Apr 08 14:52:09 2020 +0000
- Revision:
- 1:121b61eeffe7
- Parent:
- 0:309c546f048d
my own version of the library with multi optimisation. giflib (not enough memory with lpc1768) etc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
skydarc | 1:121b61eeffe7 | 1 | #include "mbed.h" |
skydarc | 1:121b61eeffe7 | 2 | #include "math.h" |
skydarc | 1:121b61eeffe7 | 3 | #include "SDBlockDevice.h" |
skydarc | 1:121b61eeffe7 | 4 | #include "FATFileSystem.h" |
skydarc | 1:121b61eeffe7 | 5 | |
smultron1977 | 0:309c546f048d | 6 | |
skydarc | 1:121b61eeffe7 | 7 | SDBlockDevice sd(p5, p6, p7, p8); |
skydarc | 1:121b61eeffe7 | 8 | FATFileSystem fs("sd"); |
smultron1977 | 0:309c546f048d | 9 | |
skydarc | 1:121b61eeffe7 | 10 | #include "tar.h" |
skydarc | 1:121b61eeffe7 | 11 | |
skydarc | 1:121b61eeffe7 | 12 | |
smultron1977 | 0:309c546f048d | 13 | |
smultron1977 | 0:309c546f048d | 14 | |
skydarc | 1:121b61eeffe7 | 15 | #include "ST7735.h" |
skydarc | 1:121b61eeffe7 | 16 | |
skydarc | 1:121b61eeffe7 | 17 | ST7735 TFT(p5, p6, p7, p9, p10, p11); |
skydarc | 1:121b61eeffe7 | 18 | //ST7735 TFT(p11, p12, p13, p15, p16, p17); |
skydarc | 1:121b61eeffe7 | 19 | PwmOut TFT_BackLight(p25); |
skydarc | 1:121b61eeffe7 | 20 | |
skydarc | 1:121b61eeffe7 | 21 | DigitalOut myled(LED1); |
skydarc | 1:121b61eeffe7 | 22 | DigitalOut myled2(LED2); |
skydarc | 1:121b61eeffe7 | 23 | DigitalOut myled4(LED4); |
skydarc | 1:121b61eeffe7 | 24 | |
skydarc | 1:121b61eeffe7 | 25 | float p = 3.1415926; |
skydarc | 1:121b61eeffe7 | 26 | |
skydarc | 1:121b61eeffe7 | 27 | Timer t; |
skydarc | 1:121b61eeffe7 | 28 | |
skydarc | 1:121b61eeffe7 | 29 | extern int confSaber[]; |
skydarc | 1:121b61eeffe7 | 30 | extern int theme[]; |
skydarc | 1:121b61eeffe7 | 31 | extern int confSaber_mini[]; |
skydarc | 1:121b61eeffe7 | 32 | extern int theme_mini[]; |
skydarc | 1:121b61eeffe7 | 33 | |
skydarc | 1:121b61eeffe7 | 34 | FILE * fp; |
skydarc | 1:121b61eeffe7 | 35 | |
skydarc | 1:121b61eeffe7 | 36 | int main() |
smultron1977 | 0:309c546f048d | 37 | { |
skydarc | 1:121b61eeffe7 | 38 | sd.init(); |
skydarc | 1:121b61eeffe7 | 39 | fs.mount(&sd); |
skydarc | 1:121b61eeffe7 | 40 | |
skydarc | 1:121b61eeffe7 | 41 | myled2 = 1; |
skydarc | 1:121b61eeffe7 | 42 | |
skydarc | 1:121b61eeffe7 | 43 | TFT_BackLight = 0; |
skydarc | 1:121b61eeffe7 | 44 | |
skydarc | 1:121b61eeffe7 | 45 | TFT.initR(INITR_MINI160x80_RS); // INITR_MINI160x80 |
skydarc | 1:121b61eeffe7 | 46 | |
skydarc | 1:121b61eeffe7 | 47 | TFT.setRotation(2); |
skydarc | 1:121b61eeffe7 | 48 | TFT.fillScreen(ST7735_BLACK); |
skydarc | 1:121b61eeffe7 | 49 | TFT_BackLight = 1; |
skydarc | 1:121b61eeffe7 | 50 | |
skydarc | 1:121b61eeffe7 | 51 | //fp = fopenTar("/sd/mydir/config.thm", "config.bmp"); |
skydarc | 1:121b61eeffe7 | 52 | //TFT.DrawBMP(0, 0, fp); |
skydarc | 1:121b61eeffe7 | 53 | //fclose(fp); |
skydarc | 1:121b61eeffe7 | 54 | |
skydarc | 1:121b61eeffe7 | 55 | |
skydarc | 1:121b61eeffe7 | 56 | int i = 1; |
skydarc | 1:121b61eeffe7 | 57 | while(0) { |
skydarc | 1:121b61eeffe7 | 58 | fp = fopen("/sd/mydir/cat.ani", "r"); |
skydarc | 1:121b61eeffe7 | 59 | TFT.DrawANI(0, 30, fp, i); |
skydarc | 1:121b61eeffe7 | 60 | fclose(fp); |
skydarc | 1:121b61eeffe7 | 61 | wait_ms(20); |
skydarc | 1:121b61eeffe7 | 62 | i++; |
skydarc | 1:121b61eeffe7 | 63 | if(i == 9) i = 1; |
skydarc | 1:121b61eeffe7 | 64 | } |
skydarc | 1:121b61eeffe7 | 65 | |
smultron1977 | 0:309c546f048d | 66 | |
skydarc | 1:121b61eeffe7 | 67 | /* |
skydarc | 1:121b61eeffe7 | 68 | fp = fopen("/sd/mydir/test1_16.gif", "r"); |
skydarc | 1:121b61eeffe7 | 69 | TFT.DrawGIF(0, 0, fp); |
skydarc | 1:121b61eeffe7 | 70 | fclose(fp); |
skydarc | 1:121b61eeffe7 | 71 | |
skydarc | 1:121b61eeffe7 | 72 | fp = fopen("/sd/mydir/test1_ff.gif", "r"); |
skydarc | 1:121b61eeffe7 | 73 | TFT.DrawGIF(40, 0, fp); |
skydarc | 1:121b61eeffe7 | 74 | fclose(fp); |
skydarc | 1:121b61eeffe7 | 75 | |
skydarc | 1:121b61eeffe7 | 76 | fp = fopen("/sd/mydir/test2_4.gif", "r"); |
skydarc | 1:121b61eeffe7 | 77 | TFT.DrawGIF(0, 80, fp); |
skydarc | 1:121b61eeffe7 | 78 | fclose(fp); |
skydarc | 1:121b61eeffe7 | 79 | |
skydarc | 1:121b61eeffe7 | 80 | fp = fopen("/sd/mydir/test2_16.gif", "r"); |
skydarc | 1:121b61eeffe7 | 81 | TFT.DrawGIF(40, 80, fp); |
skydarc | 1:121b61eeffe7 | 82 | fclose(fp); |
skydarc | 1:121b61eeffe7 | 83 | |
skydarc | 1:121b61eeffe7 | 84 | fp = fopenTar("/sd/mydir/config.thm", "test1_16.gif"); |
skydarc | 1:121b61eeffe7 | 85 | TFT.DrawGIF(20, 0, fp); |
skydarc | 1:121b61eeffe7 | 86 | fclose(fp);*/ |
skydarc | 1:121b61eeffe7 | 87 | |
skydarc | 1:121b61eeffe7 | 88 | |
skydarc | 1:121b61eeffe7 | 89 | TFT.fillCircle(10, 10, 5, ST7735_RED); |
skydarc | 1:121b61eeffe7 | 90 | TFT.fillCircle(150, 10, 5, ST7735_GREEN); |
skydarc | 1:121b61eeffe7 | 91 | TFT.fillCircle(150, 70, 5, ST7735_BLUE); |
skydarc | 1:121b61eeffe7 | 92 | TFT.fillCircle(10, 70, 5, ST7735_WHITE); |
skydarc | 1:121b61eeffe7 | 93 | |
skydarc | 1:121b61eeffe7 | 94 | |
skydarc | 1:121b61eeffe7 | 95 | for ( int i=0; i<360; i+=10 ) { |
skydarc | 1:121b61eeffe7 | 96 | TFT_BackLight = cos( i*2.0*3.14/360 ) * 0.5 + 0.5; |
skydarc | 1:121b61eeffe7 | 97 | wait(0.1); |
skydarc | 1:121b61eeffe7 | 98 | } |
skydarc | 1:121b61eeffe7 | 99 | |
skydarc | 1:121b61eeffe7 | 100 | TFT.setCursor(0, 0); |
skydarc | 1:121b61eeffe7 | 101 | TFT.setTextColor(ST7735_WHITE); |
skydarc | 1:121b61eeffe7 | 102 | TFT.setTextWrap(true); |
skydarc | 1:121b61eeffe7 | 103 | TFT.write("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", 0xffff); |
skydarc | 1:121b61eeffe7 | 104 | |
skydarc | 1:121b61eeffe7 | 105 | //wait(1); |
skydarc | 1:121b61eeffe7 | 106 | |
skydarc | 1:121b61eeffe7 | 107 | //tftPrintTest(); |
skydarc | 1:121b61eeffe7 | 108 | |
skydarc | 1:121b61eeffe7 | 109 | /* |
skydarc | 1:121b61eeffe7 | 110 | t.start(); |
skydarc | 1:121b61eeffe7 | 111 | fp = fopenTar("/sd/mydir/config.thm", "config.bmp"); |
skydarc | 1:121b61eeffe7 | 112 | TFT.DrawBMP(0, 0, fp); |
skydarc | 1:121b61eeffe7 | 113 | t.stop(); |
skydarc | 1:121b61eeffe7 | 114 | fclose(fp); |
skydarc | 1:121b61eeffe7 | 115 | printf("config TAR : %f seconds sur SD\n", t.read()); |
skydarc | 1:121b61eeffe7 | 116 | t.reset(); |
skydarc | 1:121b61eeffe7 | 117 | |
skydarc | 1:121b61eeffe7 | 118 | |
skydarc | 1:121b61eeffe7 | 119 | t.start(); |
skydarc | 1:121b61eeffe7 | 120 | fp = fopenTar("/sd/mydir/config.thm", "main.bmp"); |
skydarc | 1:121b61eeffe7 | 121 | TFT.DrawBMP(0, 80, fp); |
skydarc | 1:121b61eeffe7 | 122 | t.stop(); |
skydarc | 1:121b61eeffe7 | 123 | fclose(fp); |
skydarc | 1:121b61eeffe7 | 124 | printf("config TAR : %f seconds sur SD\n", t.read()); |
skydarc | 1:121b61eeffe7 | 125 | t.reset(); |
skydarc | 1:121b61eeffe7 | 126 | */ |
skydarc | 1:121b61eeffe7 | 127 | |
skydarc | 1:121b61eeffe7 | 128 | /* |
skydarc | 1:121b61eeffe7 | 129 | wait(1); |
skydarc | 1:121b61eeffe7 | 130 | t.start(); |
skydarc | 1:121b61eeffe7 | 131 | fp = fopen("/sd/mydir/tour.bmp", "r"); |
skydarc | 1:121b61eeffe7 | 132 | TFT_BackLight = 0; |
skydarc | 1:121b61eeffe7 | 133 | TFT.DrawBMP(0, 0, fp); |
skydarc | 1:121b61eeffe7 | 134 | TFT_BackLight = 1; |
skydarc | 1:121b61eeffe7 | 135 | t.stop(); |
skydarc | 1:121b61eeffe7 | 136 | fclose(fp); |
skydarc | 1:121b61eeffe7 | 137 | printf("Tour : %f seconds sur SD\n", t.read()); |
skydarc | 1:121b61eeffe7 | 138 | t.reset(); |
skydarc | 1:121b61eeffe7 | 139 | |
skydarc | 1:121b61eeffe7 | 140 | t.start(); |
skydarc | 1:121b61eeffe7 | 141 | fp = fopen("/sd/mydir/test2.bmp", "r"); |
skydarc | 1:121b61eeffe7 | 142 | TFT.DrawBMP(0, 0, fp); |
skydarc | 1:121b61eeffe7 | 143 | t.stop(); |
skydarc | 1:121b61eeffe7 | 144 | fclose(fp); |
skydarc | 1:121b61eeffe7 | 145 | printf("coeur : %f seconds sur SD\n", t.read()); |
skydarc | 1:121b61eeffe7 | 146 | t.reset(); |
skydarc | 1:121b61eeffe7 | 147 | */ |
skydarc | 1:121b61eeffe7 | 148 | |
skydarc | 1:121b61eeffe7 | 149 | |
skydarc | 1:121b61eeffe7 | 150 | //wait(1); |
skydarc | 1:121b61eeffe7 | 151 | //TFT.fillScreen(ST7735_BLACK); |
skydarc | 1:121b61eeffe7 | 152 | //TFT.DrawStarfield(80, 40, 1, 0, 300, 4); |
skydarc | 1:121b61eeffe7 | 153 | //TFT.fillScreen(ST7735_BLACK); |
skydarc | 1:121b61eeffe7 | 154 | |
skydarc | 1:121b61eeffe7 | 155 | wait(1); |
skydarc | 1:121b61eeffe7 | 156 | TFT.DrawRam(11, 52, 57, 57, confSaber); |
skydarc | 1:121b61eeffe7 | 157 | TFT.drawFastHLine(0, 0, 80, ST7735_GREEN); |
skydarc | 1:121b61eeffe7 | 158 | wait(1); |
skydarc | 1:121b61eeffe7 | 159 | TFT.scrollBmp(0, 0, BOTTOM_TO_TOP, theme); |
skydarc | 1:121b61eeffe7 | 160 | wait(1); |
skydarc | 1:121b61eeffe7 | 161 | TFT.scrollBmp(0, 0, TOP_TO_BOTTOM, confSaber); |
skydarc | 1:121b61eeffe7 | 162 | |
skydarc | 1:121b61eeffe7 | 163 | |
skydarc | 1:121b61eeffe7 | 164 | /* |
skydarc | 1:121b61eeffe7 | 165 | wait(1); |
skydarc | 1:121b61eeffe7 | 166 | TFT.drawFastHLine(0, 14, 80, 0x2104); |
skydarc | 1:121b61eeffe7 | 167 | TFT.DrawRam(1, 1, 11, 11, confSaber_mini); |
skydarc | 1:121b61eeffe7 | 168 | wait(1); |
skydarc | 1:121b61eeffe7 | 169 | TFT.scrollBmp(15, 0, BOTTOM_TO_TOP, theme); |
skydarc | 1:121b61eeffe7 | 170 | wait(1); |
skydarc | 1:121b61eeffe7 | 171 | TFT.scrollBmp(15, 0, TOP_TO_BOTTOM, confSaber); |
skydarc | 1:121b61eeffe7 | 172 | TFT.drawFastHLine(0, 146, 80, 0x2104); |
skydarc | 1:121b61eeffe7 | 173 | TFT.DrawRam(1, 148, 11, 11, theme_mini); |
skydarc | 1:121b61eeffe7 | 174 | wait(1); |
skydarc | 1:121b61eeffe7 | 175 | TFT.scrollBmp(15, 15, BOTTOM_TO_TOP, theme); |
skydarc | 1:121b61eeffe7 | 176 | wait(1); |
skydarc | 1:121b61eeffe7 | 177 | TFT.scrollBmp(15, 15, TOP_TO_BOTTOM, confSaber); |
skydarc | 1:121b61eeffe7 | 178 | */ |
skydarc | 1:121b61eeffe7 | 179 | |
skydarc | 1:121b61eeffe7 | 180 | while(1) { |
skydarc | 1:121b61eeffe7 | 181 | myled = 1; |
skydarc | 1:121b61eeffe7 | 182 | wait(1); |
skydarc | 1:121b61eeffe7 | 183 | myled = 0; |
skydarc | 1:121b61eeffe7 | 184 | wait(1); |
smultron1977 | 0:309c546f048d | 185 | } |
smultron1977 | 0:309c546f048d | 186 | } |