programme pour l'ecran TFT-ST7735

Dependencies:   mbed DmTftLibrary

Committer:
displaymodule
Date:
Fri Jul 04 10:34:20 2014 +0000
Revision:
1:4a281af0d8e6
Parent:
0:486bf9d63b80
Child:
2:14024c30df8d
Misc bugfixes

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