programme pour l'ecran TFT-ST7735

Dependencies:   mbed DmTftLibrary

Committer:
lolo2
Date:
Wed Apr 03 12:31:48 2019 +0000
Revision:
7:3da729e3e2c6
Parent:
6:6acbe3629822
e

Who changed what in which revision?

UserRevisionLine numberNew contents of line
displaymodule 0:486bf9d63b80 1 #include "mbed.h"
displaymodule 0:486bf9d63b80 2
displaymodule 0:486bf9d63b80 3 #include "DmTftHX8353C.h"
displaymodule 0:486bf9d63b80 4 #include "DmTftS6D0164.h"
displaymodule 0:486bf9d63b80 5 #include "DmTftIli9325.h"
displaymodule 0:486bf9d63b80 6 #include "DmTftIli9341.h"
displaymodule 0:486bf9d63b80 7 #include "DmTftSsd2119.h"
displaymodule 4:d58fe9f48040 8 #include "DmTftRa8875.h"
displaymodule 0:486bf9d63b80 9
displaymodule 0:486bf9d63b80 10 /******************************************************************************
displaymodule 0:486bf9d63b80 11 * Typedefs and defines
displaymodule 0:486bf9d63b80 12 *****************************************************************************/
displaymodule 0:486bf9d63b80 13
displaymodule 1:4a281af0d8e6 14 /* Note that there are restrictions on which platforms that can use printf
displaymodule 1:4a281af0d8e6 15 in combinations with the DmTftLibrary. Some platforms (e.g. LPC1549 LPCXpresso)
displaymodule 1:4a281af0d8e6 16 use the same pins for USBRX/USBTX and display control. Printing will
displaymodule 1:4a281af0d8e6 17 cause the display to not work. Read more about this on the display's notebook
displaymodule 1:4a281af0d8e6 18 page. */
displaymodule 5:47192882d9d0 19 #define log(...) printf(__VA_ARGS__)
displaymodule 5:47192882d9d0 20 //#define log(...)
displaymodule 0:486bf9d63b80 21
displaymodule 0:486bf9d63b80 22 /******************************************************************************
displaymodule 0:486bf9d63b80 23 * Local variables
displaymodule 0:486bf9d63b80 24 *****************************************************************************/
displaymodule 0:486bf9d63b80 25
displaymodule 5:47192882d9d0 26 //DmTftHX8353C tft(D2, D3, D4, D5, D6); /* DmTftHX8353C(PinName mosi, PinName clk, PinName cs, PinName dc, PinName rst) DM_TFT18_101 */
displaymodule 5:47192882d9d0 27 //DmTftS6D0164 tft(A4, A3, A5, A2); /* DmTftS6D0164(PinName wr, PinName cs, PinName dc, PinName rst) DM_TFT22_102 */
displaymodule 5:47192882d9d0 28 //DmTftIli9325 tft(A4, A3, A5, A2); /* DmTftIli9325(PinName wr, PinName cs, PinName dc, PinName rst) DM_TFT28_103 and DM_TFT24_104 */
lolo2 7:3da729e3e2c6 29 DmTftIli9341 tft(D10, D12, D11, D12, D13); /* DmTftIli9341(PinName cs, PinName dc, PinName mosi, PinName miso, PinName clk) DM_TFT28_105 */
displaymodule 5:47192882d9d0 30 //DmTftSsd2119 tft(D10, D9, D11, D12, D13); /* DmTftSsd2119(PinName cs, PinName dc, PinName mosi, PinName miso, PinName clk) DM_TFT35_107 */
displaymodule 5:47192882d9d0 31 //DmTftRa8875 tft(D10, D9, D11, D12, D13); /* DmTftRa8875(PinName cs, PinName sel, PinName mosi, PinName miso, PinName clk) DM_TFT43_108 and DM_TFT50_111 For DmTftRa8875 driver, The panel resolution should be config in DmTftRa8875::init() function on the DmTftRa8875.cpp file. */
displaymodule 0:486bf9d63b80 32
displaymodule 0:486bf9d63b80 33 int bmpWidth, bmpHeight;
displaymodule 0:486bf9d63b80 34 uint8_t bmpImageoffset;
displaymodule 0:486bf9d63b80 35
displaymodule 0:486bf9d63b80 36 /******************************************************************************
displaymodule 0:486bf9d63b80 37 * Global variables
displaymodule 0:486bf9d63b80 38 *****************************************************************************/
displaymodule 0:486bf9d63b80 39
displaymodule 0:486bf9d63b80 40 extern uint8_t dmlogo[];
displaymodule 0:486bf9d63b80 41
displaymodule 0:486bf9d63b80 42 /******************************************************************************
displaymodule 0:486bf9d63b80 43 * Local functions
displaymodule 0:486bf9d63b80 44 *****************************************************************************/
displaymodule 0:486bf9d63b80 45
displaymodule 0:486bf9d63b80 46 // LITTLE ENDIAN!
displaymodule 0:486bf9d63b80 47 uint16_t read16(uint8_t *src)
displaymodule 0:486bf9d63b80 48 {
displaymodule 0:486bf9d63b80 49 uint16_t d;
displaymodule 0:486bf9d63b80 50 uint8_t b;
displaymodule 0:486bf9d63b80 51 b = *src;
displaymodule 0:486bf9d63b80 52 d = *(src+1);
displaymodule 0:486bf9d63b80 53 d <<= 8;
displaymodule 0:486bf9d63b80 54 d |= b;
displaymodule 0:486bf9d63b80 55 return d;
displaymodule 0:486bf9d63b80 56 }
displaymodule 0:486bf9d63b80 57
displaymodule 0:486bf9d63b80 58 // LITTLE ENDIAN!
displaymodule 0:486bf9d63b80 59 uint32_t read32(uint8_t *src)
displaymodule 0:486bf9d63b80 60 {
displaymodule 0:486bf9d63b80 61 uint32_t d;
displaymodule 0:486bf9d63b80 62 uint16_t b;
displaymodule 0:486bf9d63b80 63
displaymodule 0:486bf9d63b80 64 b = read16(src);
displaymodule 0:486bf9d63b80 65 d = read16(src+2);
displaymodule 0:486bf9d63b80 66 d <<= 16;
displaymodule 0:486bf9d63b80 67 d |= b;
displaymodule 0:486bf9d63b80 68 return d;
displaymodule 0:486bf9d63b80 69 }
displaymodule 0:486bf9d63b80 70
displaymodule 0:486bf9d63b80 71 void drawBmpFromFlash(int x, int y)
displaymodule 0:486bf9d63b80 72 {
displaymodule 0:486bf9d63b80 73 uint16_t pos = bmpImageoffset;
displaymodule 0:486bf9d63b80 74
displaymodule 0:486bf9d63b80 75 uint16_t p; // pixel
displaymodule 0:486bf9d63b80 76 uint8_t g, b;
displaymodule 0:486bf9d63b80 77 int i, j; // line, column
displaymodule 0:486bf9d63b80 78
displaymodule 0:486bf9d63b80 79 for(i=bmpHeight; i>0; i--) {
displaymodule 0:486bf9d63b80 80 for(j=0; j<bmpWidth; j++) {
displaymodule 0:486bf9d63b80 81 b = *(dmlogo+pos++);
displaymodule 0:486bf9d63b80 82 g = *(dmlogo+pos++);
displaymodule 0:486bf9d63b80 83 p = *(dmlogo+pos++);
displaymodule 0:486bf9d63b80 84
displaymodule 0:486bf9d63b80 85 p >>= 3;
displaymodule 0:486bf9d63b80 86 p <<= 6;
displaymodule 0:486bf9d63b80 87
displaymodule 0:486bf9d63b80 88 g >>= 2;
displaymodule 0:486bf9d63b80 89 p |= g;
displaymodule 0:486bf9d63b80 90 p <<= 5;
displaymodule 0:486bf9d63b80 91
displaymodule 0:486bf9d63b80 92 b >>= 3;
displaymodule 0:486bf9d63b80 93 p |= b;
displaymodule 0:486bf9d63b80 94
displaymodule 0:486bf9d63b80 95 // write out the 16 bits of color
displaymodule 0:486bf9d63b80 96 tft.setPixel(j, i+y, p);
displaymodule 0:486bf9d63b80 97 }
displaymodule 0:486bf9d63b80 98 }
displaymodule 0:486bf9d63b80 99 }
displaymodule 0:486bf9d63b80 100
displaymodule 0:486bf9d63b80 101
displaymodule 0:486bf9d63b80 102 int bmpReadHeader() {
displaymodule 0:486bf9d63b80 103 uint32_t fileSize;
displaymodule 0:486bf9d63b80 104 uint32_t headerSize;
displaymodule 0:486bf9d63b80 105 uint16_t bmpDepth;
displaymodule 0:486bf9d63b80 106 uint16_t pos = 0;
displaymodule 0:486bf9d63b80 107 log("reading bmp header\r\n");
displaymodule 0:486bf9d63b80 108 log("Magic byte is: %d \r\n", read16(dmlogo));
displaymodule 0:486bf9d63b80 109
displaymodule 0:486bf9d63b80 110 if (read16(dmlogo) !=0x4D42){ // read magic byte
displaymodule 0:486bf9d63b80 111 log("Magic byte not found\r\n");
displaymodule 0:486bf9d63b80 112 return false;
displaymodule 0:486bf9d63b80 113 }
displaymodule 0:486bf9d63b80 114 pos += 2;
displaymodule 0:486bf9d63b80 115
displaymodule 0:486bf9d63b80 116 // read file size
displaymodule 0:486bf9d63b80 117 fileSize = read32(dmlogo+pos);
displaymodule 0:486bf9d63b80 118 log("filesize is: %d \r\n", fileSize);
displaymodule 0:486bf9d63b80 119 log("");
displaymodule 0:486bf9d63b80 120 pos += 4;
displaymodule 0:486bf9d63b80 121
displaymodule 0:486bf9d63b80 122 pos += 4; // Skip creator bytes
displaymodule 0:486bf9d63b80 123
displaymodule 0:486bf9d63b80 124 bmpImageoffset = read32(dmlogo+pos);
displaymodule 0:486bf9d63b80 125 pos += 4;
displaymodule 0:486bf9d63b80 126
displaymodule 0:486bf9d63b80 127 // read DIB header
displaymodule 0:486bf9d63b80 128 headerSize = read32(dmlogo+pos);
displaymodule 0:486bf9d63b80 129 pos +=4;
displaymodule 0:486bf9d63b80 130 bmpWidth = read32(dmlogo+pos);
displaymodule 0:486bf9d63b80 131 pos += 4;
displaymodule 0:486bf9d63b80 132 bmpHeight = read32(dmlogo+pos);
displaymodule 0:486bf9d63b80 133 pos += 4;
displaymodule 0:486bf9d63b80 134
displaymodule 0:486bf9d63b80 135 log("Image size: %d\r\n", fileSize);
displaymodule 0:486bf9d63b80 136 log("Image offset: %d\r\n", bmpImageoffset);
displaymodule 0:486bf9d63b80 137 log("Header size: %d\r\n", headerSize);
displaymodule 0:486bf9d63b80 138 log("Image width: %d\r\n", bmpWidth );
displaymodule 0:486bf9d63b80 139 log("Image height: %d\r\n", bmpHeight );
displaymodule 0:486bf9d63b80 140
displaymodule 0:486bf9d63b80 141 if (read16(dmlogo+pos) != 1){
displaymodule 0:486bf9d63b80 142 // number of color planes must be 1
displaymodule 0:486bf9d63b80 143 return false;
displaymodule 0:486bf9d63b80 144 }
displaymodule 0:486bf9d63b80 145 pos += 2;
displaymodule 0:486bf9d63b80 146
displaymodule 0:486bf9d63b80 147 bmpDepth = read16(dmlogo+pos);
displaymodule 0:486bf9d63b80 148 pos +=2;
displaymodule 0:486bf9d63b80 149 log("Bitdepth: %d\r\n", bmpDepth);
displaymodule 0:486bf9d63b80 150
displaymodule 0:486bf9d63b80 151 if (read16(dmlogo+pos) != 0) {
displaymodule 0:486bf9d63b80 152 // compression not supported!
displaymodule 0:486bf9d63b80 153 return false;
displaymodule 0:486bf9d63b80 154 }
displaymodule 0:486bf9d63b80 155 pos += 2; // Should really be 2??
displaymodule 0:486bf9d63b80 156
displaymodule 0:486bf9d63b80 157 return true;
displaymodule 0:486bf9d63b80 158 }
displaymodule 0:486bf9d63b80 159
displaymodule 0:486bf9d63b80 160 /******************************************************************************
displaymodule 0:486bf9d63b80 161 * Main
displaymodule 0:486bf9d63b80 162 *****************************************************************************/
displaymodule 0:486bf9d63b80 163
displaymodule 0:486bf9d63b80 164 int main() {
displaymodule 0:486bf9d63b80 165 log("init tft \r\n");
displaymodule 0:486bf9d63b80 166 tft.init();
displaymodule 0:486bf9d63b80 167
lolo2 7:3da729e3e2c6 168 tft.drawString(0,00," ");
lolo2 7:3da729e3e2c6 169 tft.drawString(0,16," ");
lolo2 7:3da729e3e2c6 170 tft.drawString(0,32,"Bonjour, ");
lolo2 7:3da729e3e2c6 171 tft.drawString(0,48,"je suis cubya! ");
lolo2 7:3da729e3e2c6 172 tft.drawString(0,64,"Que faites vous?");
lolo2 7:3da729e3e2c6 173 tft.drawString(0,80,"Je suis la pour ");
lolo2 7:3da729e3e2c6 174 tft.drawString(0,96,"vous aider. ");
lolo2 7:3da729e3e2c6 175 tft.drawString(0,112,"Comment ");
lolo2 7:3da729e3e2c6 176 tft.drawString(0,128,"allez-vous ? ");
lolo2 7:3da729e3e2c6 177 tft.drawString(0,144," ");
displaymodule 0:486bf9d63b80 178
displaymodule 0:486bf9d63b80 179
displaymodule 0:486bf9d63b80 180 if (! bmpReadHeader()) {
displaymodule 0:486bf9d63b80 181 log("bad bmp\r\n");
displaymodule 0:486bf9d63b80 182 return -1;
displaymodule 0:486bf9d63b80 183 }
displaymodule 0:486bf9d63b80 184
lolo2 6:6acbe3629822 185
displaymodule 0:486bf9d63b80 186
displaymodule 0:486bf9d63b80 187 while(1) {
displaymodule 0:486bf9d63b80 188 }
lolo2 6:6acbe3629822 189 }