programme pour l'ecran TFT-ST7735

Dependencies:   mbed DmTftLibrary

Committer:
displaymodule
Date:
Thu Jan 22 03:06:58 2015 +0000
Revision:
4:d58fe9f48040
Parent:
2:14024c30df8d
Child:
5:47192882d9d0
Add DM_TFT43_108, DM_TFT50_111 based on new lib drv: DmTftRa8875

Who changed what in which revision?

UserRevisionLine numberNew contents of line
displaymodule 0:486bf9d63b80 1 /**********************************************************************************************
displaymodule 0:486bf9d63b80 2 Copyright (c) 2014 DisplayModule. All rights reserved.
displaymodule 0:486bf9d63b80 3
displaymodule 0:486bf9d63b80 4 Redistribution and use of this source code, part of this source code or any compiled binary
displaymodule 0:486bf9d63b80 5 based on this source code is permitted as long as the above copyright notice and following
displaymodule 0:486bf9d63b80 6 disclaimer is retained.
displaymodule 0:486bf9d63b80 7
displaymodule 0:486bf9d63b80 8 DISCLAIMER:
displaymodule 0:486bf9d63b80 9 THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES
displaymodule 0:486bf9d63b80 10 NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE.
displaymodule 0:486bf9d63b80 11 ********************************************************************************************/
displaymodule 0:486bf9d63b80 12
displaymodule 0:486bf9d63b80 13 /******************************************************************************
displaymodule 0:486bf9d63b80 14 * Includes
displaymodule 0:486bf9d63b80 15 *****************************************************************************/
displaymodule 0:486bf9d63b80 16
displaymodule 0:486bf9d63b80 17 #include "mbed.h"
displaymodule 0:486bf9d63b80 18
displaymodule 0:486bf9d63b80 19 #include "DmTftHX8353C.h"
displaymodule 0:486bf9d63b80 20 #include "DmTftS6D0164.h"
displaymodule 0:486bf9d63b80 21 #include "DmTftIli9325.h"
displaymodule 0:486bf9d63b80 22 #include "DmTftIli9341.h"
displaymodule 0:486bf9d63b80 23 #include "DmTftSsd2119.h"
displaymodule 4:d58fe9f48040 24 #include "DmTftRa8875.h"
displaymodule 0:486bf9d63b80 25
displaymodule 0:486bf9d63b80 26 /******************************************************************************
displaymodule 0:486bf9d63b80 27 * Typedefs and defines
displaymodule 0:486bf9d63b80 28 *****************************************************************************/
displaymodule 0:486bf9d63b80 29
displaymodule 1:4a281af0d8e6 30 /* Note that there are restrictions on which platforms that can use printf
displaymodule 1:4a281af0d8e6 31 in combinations with the DmTftLibrary. Some platforms (e.g. LPC1549 LPCXpresso)
displaymodule 1:4a281af0d8e6 32 use the same pins for USBRX/USBTX and display control. Printing will
displaymodule 1:4a281af0d8e6 33 cause the display to not work. Read more about this on the display's notebook
displaymodule 1:4a281af0d8e6 34 page. */
displaymodule 0:486bf9d63b80 35 //#define log(...) printf(__VA_ARGS__)
displaymodule 0:486bf9d63b80 36 #define log(...)
displaymodule 0:486bf9d63b80 37
displaymodule 0:486bf9d63b80 38 /******************************************************************************
displaymodule 0:486bf9d63b80 39 * Local variables
displaymodule 0:486bf9d63b80 40 *****************************************************************************/
displaymodule 0:486bf9d63b80 41
displaymodule 4:d58fe9f48040 42 //DmTftHX8353C tft; /* DM_TFT18_101 */
displaymodule 0:486bf9d63b80 43 //DmTftS6D0164 tft; /* DM_TFT22_102 */
displaymodule 0:486bf9d63b80 44 //DmTftIli9325 tft; /* DM_TFT28_103 and DM_TFT24_104 */
displaymodule 1:4a281af0d8e6 45 //DmTftIli9341 tft; /* DM_TFT28_105 */
displaymodule 4:d58fe9f48040 46 //DmTftSsd2119 tft; /* DM_TFT35_107 */
displaymodule 4:d58fe9f48040 47 DmTftRa8875 tft; /* 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 48
displaymodule 0:486bf9d63b80 49 int bmpWidth, bmpHeight;
displaymodule 0:486bf9d63b80 50 uint8_t bmpImageoffset;
displaymodule 0:486bf9d63b80 51
displaymodule 0:486bf9d63b80 52 /******************************************************************************
displaymodule 0:486bf9d63b80 53 * Global variables
displaymodule 0:486bf9d63b80 54 *****************************************************************************/
displaymodule 0:486bf9d63b80 55
displaymodule 0:486bf9d63b80 56 extern uint8_t dmlogo[];
displaymodule 0:486bf9d63b80 57
displaymodule 0:486bf9d63b80 58 /******************************************************************************
displaymodule 0:486bf9d63b80 59 * Local functions
displaymodule 0:486bf9d63b80 60 *****************************************************************************/
displaymodule 0:486bf9d63b80 61
displaymodule 0:486bf9d63b80 62 // LITTLE ENDIAN!
displaymodule 0:486bf9d63b80 63 uint16_t read16(uint8_t *src)
displaymodule 0:486bf9d63b80 64 {
displaymodule 0:486bf9d63b80 65 uint16_t d;
displaymodule 0:486bf9d63b80 66 uint8_t b;
displaymodule 0:486bf9d63b80 67 b = *src;
displaymodule 0:486bf9d63b80 68 d = *(src+1);
displaymodule 0:486bf9d63b80 69 d <<= 8;
displaymodule 0:486bf9d63b80 70 d |= b;
displaymodule 0:486bf9d63b80 71 return d;
displaymodule 0:486bf9d63b80 72 }
displaymodule 0:486bf9d63b80 73
displaymodule 0:486bf9d63b80 74 // LITTLE ENDIAN!
displaymodule 0:486bf9d63b80 75 uint32_t read32(uint8_t *src)
displaymodule 0:486bf9d63b80 76 {
displaymodule 0:486bf9d63b80 77 uint32_t d;
displaymodule 0:486bf9d63b80 78 uint16_t b;
displaymodule 0:486bf9d63b80 79
displaymodule 0:486bf9d63b80 80 b = read16(src);
displaymodule 0:486bf9d63b80 81 d = read16(src+2);
displaymodule 0:486bf9d63b80 82 d <<= 16;
displaymodule 0:486bf9d63b80 83 d |= b;
displaymodule 0:486bf9d63b80 84 return d;
displaymodule 0:486bf9d63b80 85 }
displaymodule 0:486bf9d63b80 86
displaymodule 0:486bf9d63b80 87 void drawBmpFromFlash(int x, int y)
displaymodule 0:486bf9d63b80 88 {
displaymodule 0:486bf9d63b80 89 uint16_t pos = bmpImageoffset;
displaymodule 0:486bf9d63b80 90
displaymodule 0:486bf9d63b80 91 uint16_t p; // pixel
displaymodule 0:486bf9d63b80 92 uint8_t g, b;
displaymodule 0:486bf9d63b80 93 int i, j; // line, column
displaymodule 0:486bf9d63b80 94
displaymodule 0:486bf9d63b80 95 for(i=bmpHeight; i>0; i--) {
displaymodule 0:486bf9d63b80 96 for(j=0; j<bmpWidth; j++) {
displaymodule 0:486bf9d63b80 97 b = *(dmlogo+pos++);
displaymodule 0:486bf9d63b80 98 g = *(dmlogo+pos++);
displaymodule 0:486bf9d63b80 99 p = *(dmlogo+pos++);
displaymodule 0:486bf9d63b80 100
displaymodule 0:486bf9d63b80 101 p >>= 3;
displaymodule 0:486bf9d63b80 102 p <<= 6;
displaymodule 0:486bf9d63b80 103
displaymodule 0:486bf9d63b80 104 g >>= 2;
displaymodule 0:486bf9d63b80 105 p |= g;
displaymodule 0:486bf9d63b80 106 p <<= 5;
displaymodule 0:486bf9d63b80 107
displaymodule 0:486bf9d63b80 108 b >>= 3;
displaymodule 0:486bf9d63b80 109 p |= b;
displaymodule 0:486bf9d63b80 110
displaymodule 0:486bf9d63b80 111 // write out the 16 bits of color
displaymodule 0:486bf9d63b80 112 tft.setPixel(j, i+y, p);
displaymodule 0:486bf9d63b80 113 }
displaymodule 0:486bf9d63b80 114 }
displaymodule 0:486bf9d63b80 115 }
displaymodule 0:486bf9d63b80 116
displaymodule 0:486bf9d63b80 117
displaymodule 0:486bf9d63b80 118 int bmpReadHeader() {
displaymodule 0:486bf9d63b80 119 uint32_t fileSize;
displaymodule 0:486bf9d63b80 120 uint32_t headerSize;
displaymodule 0:486bf9d63b80 121 uint16_t bmpDepth;
displaymodule 0:486bf9d63b80 122 uint16_t pos = 0;
displaymodule 0:486bf9d63b80 123 log("reading bmp header\r\n");
displaymodule 0:486bf9d63b80 124 log("Magic byte is: %d \r\n", read16(dmlogo));
displaymodule 0:486bf9d63b80 125
displaymodule 0:486bf9d63b80 126 if (read16(dmlogo) !=0x4D42){ // read magic byte
displaymodule 0:486bf9d63b80 127 log("Magic byte not found\r\n");
displaymodule 0:486bf9d63b80 128 return false;
displaymodule 0:486bf9d63b80 129 }
displaymodule 0:486bf9d63b80 130 pos += 2;
displaymodule 0:486bf9d63b80 131
displaymodule 0:486bf9d63b80 132 // read file size
displaymodule 0:486bf9d63b80 133 fileSize = read32(dmlogo+pos);
displaymodule 0:486bf9d63b80 134 log("filesize is: %d \r\n", fileSize);
displaymodule 0:486bf9d63b80 135 log("");
displaymodule 0:486bf9d63b80 136 pos += 4;
displaymodule 0:486bf9d63b80 137
displaymodule 0:486bf9d63b80 138 pos += 4; // Skip creator bytes
displaymodule 0:486bf9d63b80 139
displaymodule 0:486bf9d63b80 140 bmpImageoffset = read32(dmlogo+pos);
displaymodule 0:486bf9d63b80 141 pos += 4;
displaymodule 0:486bf9d63b80 142
displaymodule 0:486bf9d63b80 143 // read DIB header
displaymodule 0:486bf9d63b80 144 headerSize = read32(dmlogo+pos);
displaymodule 0:486bf9d63b80 145 pos +=4;
displaymodule 0:486bf9d63b80 146 bmpWidth = read32(dmlogo+pos);
displaymodule 0:486bf9d63b80 147 pos += 4;
displaymodule 0:486bf9d63b80 148 bmpHeight = read32(dmlogo+pos);
displaymodule 0:486bf9d63b80 149 pos += 4;
displaymodule 0:486bf9d63b80 150
displaymodule 0:486bf9d63b80 151 log("Image size: %d\r\n", fileSize);
displaymodule 0:486bf9d63b80 152 log("Image offset: %d\r\n", bmpImageoffset);
displaymodule 0:486bf9d63b80 153 log("Header size: %d\r\n", headerSize);
displaymodule 0:486bf9d63b80 154 log("Image width: %d\r\n", bmpWidth );
displaymodule 0:486bf9d63b80 155 log("Image height: %d\r\n", bmpHeight );
displaymodule 0:486bf9d63b80 156
displaymodule 0:486bf9d63b80 157 if (read16(dmlogo+pos) != 1){
displaymodule 0:486bf9d63b80 158 // number of color planes must be 1
displaymodule 0:486bf9d63b80 159 return false;
displaymodule 0:486bf9d63b80 160 }
displaymodule 0:486bf9d63b80 161 pos += 2;
displaymodule 0:486bf9d63b80 162
displaymodule 0:486bf9d63b80 163 bmpDepth = read16(dmlogo+pos);
displaymodule 0:486bf9d63b80 164 pos +=2;
displaymodule 0:486bf9d63b80 165 log("Bitdepth: %d\r\n", bmpDepth);
displaymodule 0:486bf9d63b80 166
displaymodule 0:486bf9d63b80 167 if (read16(dmlogo+pos) != 0) {
displaymodule 0:486bf9d63b80 168 // compression not supported!
displaymodule 0:486bf9d63b80 169 return false;
displaymodule 0:486bf9d63b80 170 }
displaymodule 0:486bf9d63b80 171 pos += 2; // Should really be 2??
displaymodule 0:486bf9d63b80 172
displaymodule 0:486bf9d63b80 173 return true;
displaymodule 0:486bf9d63b80 174 }
displaymodule 0:486bf9d63b80 175
displaymodule 0:486bf9d63b80 176 /******************************************************************************
displaymodule 0:486bf9d63b80 177 * Main
displaymodule 0:486bf9d63b80 178 *****************************************************************************/
displaymodule 0:486bf9d63b80 179
displaymodule 0:486bf9d63b80 180 int main() {
displaymodule 0:486bf9d63b80 181 log("init tft \r\n");
displaymodule 0:486bf9d63b80 182 tft.init();
displaymodule 0:486bf9d63b80 183
displaymodule 0:486bf9d63b80 184 tft.drawString(0,32,"www.");
displaymodule 0:486bf9d63b80 185 tft.drawString(12,48,"displaymodule");
displaymodule 0:486bf9d63b80 186 tft.drawString(88,64,".com");
displaymodule 0:486bf9d63b80 187
displaymodule 0:486bf9d63b80 188 tft.drawRectangle(20,85,40,105,GREEN);
displaymodule 0:486bf9d63b80 189 tft.drawCircle(60,95,10,BLUE);
displaymodule 0:486bf9d63b80 190 tft.drawTriangle(90,85, 80,105, 100,105, RED);
displaymodule 0:486bf9d63b80 191
displaymodule 0:486bf9d63b80 192 if (! bmpReadHeader()) {
displaymodule 0:486bf9d63b80 193 log("bad bmp\r\n");
displaymodule 0:486bf9d63b80 194 return -1;
displaymodule 0:486bf9d63b80 195 }
displaymodule 0:486bf9d63b80 196
displaymodule 0:486bf9d63b80 197 drawBmpFromFlash(0, 0);
displaymodule 0:486bf9d63b80 198 drawBmpFromFlash(0, 130);
displaymodule 0:486bf9d63b80 199
displaymodule 0:486bf9d63b80 200 while(1) {
displaymodule 0:486bf9d63b80 201 }
displaymodule 0:486bf9d63b80 202 }