Shows how to use the display. Draws a bitmap from internal flash, some geometric shapes and some text
Dependencies: DmTftLibrary mbed
main.cpp
00001 /********************************************************************************************** 00002 Copyright (c) 2014 DisplayModule. All rights reserved. 00003 00004 Redistribution and use of this source code, part of this source code or any compiled binary 00005 based on this source code is permitted as long as the above copyright notice and following 00006 disclaimer is retained. 00007 00008 DISCLAIMER: 00009 THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES 00010 NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. 00011 ********************************************************************************************/ 00012 00013 /****************************************************************************** 00014 * Includes 00015 *****************************************************************************/ 00016 00017 #include "mbed.h" 00018 00019 #include "DmTftHX8353C.h" 00020 #include "DmTftS6D0164.h" 00021 #include "DmTftIli9325.h" 00022 #include "DmTftIli9341.h" 00023 #include "DmTftSsd2119.h" 00024 #include "DmTftRa8875.h" 00025 00026 /****************************************************************************** 00027 * Typedefs and defines 00028 *****************************************************************************/ 00029 00030 /* Note that there are restrictions on which platforms that can use printf 00031 in combinations with the DmTftLibrary. Some platforms (e.g. LPC1549 LPCXpresso) 00032 use the same pins for USBRX/USBTX and display control. Printing will 00033 cause the display to not work. Read more about this on the display's notebook 00034 page. */ 00035 #define log(...) printf(__VA_ARGS__) 00036 //#define log(...) 00037 00038 /****************************************************************************** 00039 * Local variables 00040 *****************************************************************************/ 00041 00042 //DmTftHX8353C tft(D2, D3, D4, D5, D6); /* DmTftHX8353C(PinName mosi, PinName clk, PinName cs, PinName dc, PinName rst) DM_TFT18_101 */ 00043 //DmTftS6D0164 tft(A4, A3, A5, A2); /* DmTftS6D0164(PinName wr, PinName cs, PinName dc, PinName rst) DM_TFT22_102 */ 00044 //DmTftIli9325 tft(A4, A3, A5, A2); /* DmTftIli9325(PinName wr, PinName cs, PinName dc, PinName rst) DM_TFT28_103 and DM_TFT24_104 */ 00045 DmTftIli9341 tft(D10, D9, D11, D12, D13); /* DmTftIli9341(PinName cs, PinName dc, PinName mosi, PinName miso, PinName clk) DM_TFT28_105 */ 00046 //DmTftSsd2119 tft(D10, D9, D11, D12, D13); /* DmTftSsd2119(PinName cs, PinName dc, PinName mosi, PinName miso, PinName clk) DM_TFT35_107 */ 00047 //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. */ 00048 00049 int bmpWidth, bmpHeight; 00050 uint8_t bmpImageoffset; 00051 00052 /****************************************************************************** 00053 * Global variables 00054 *****************************************************************************/ 00055 00056 extern uint8_t dmlogo[]; 00057 00058 /****************************************************************************** 00059 * Local functions 00060 *****************************************************************************/ 00061 00062 // LITTLE ENDIAN! 00063 uint16_t read16(uint8_t *src) 00064 { 00065 uint16_t d; 00066 uint8_t b; 00067 b = *src; 00068 d = *(src+1); 00069 d <<= 8; 00070 d |= b; 00071 return d; 00072 } 00073 00074 // LITTLE ENDIAN! 00075 uint32_t read32(uint8_t *src) 00076 { 00077 uint32_t d; 00078 uint16_t b; 00079 00080 b = read16(src); 00081 d = read16(src+2); 00082 d <<= 16; 00083 d |= b; 00084 return d; 00085 } 00086 00087 void drawBmpFromFlash(int x, int y) 00088 { 00089 uint16_t pos = bmpImageoffset; 00090 00091 uint16_t p; // pixel 00092 uint8_t g, b; 00093 int i, j; // line, column 00094 00095 for(i=bmpHeight; i>0; i--) { 00096 for(j=0; j<bmpWidth; j++) { 00097 b = *(dmlogo+pos++); 00098 g = *(dmlogo+pos++); 00099 p = *(dmlogo+pos++); 00100 00101 p >>= 3; 00102 p <<= 6; 00103 00104 g >>= 2; 00105 p |= g; 00106 p <<= 5; 00107 00108 b >>= 3; 00109 p |= b; 00110 00111 // write out the 16 bits of color 00112 tft.setPixel(j, i+y, p); 00113 } 00114 } 00115 } 00116 00117 00118 int bmpReadHeader() { 00119 uint32_t fileSize; 00120 uint32_t headerSize; 00121 uint16_t bmpDepth; 00122 uint16_t pos = 0; 00123 log("reading bmp header\r\n"); 00124 log("Magic byte is: %d \r\n", read16(dmlogo)); 00125 00126 if (read16(dmlogo) !=0x4D42){ // read magic byte 00127 log("Magic byte not found\r\n"); 00128 return false; 00129 } 00130 pos += 2; 00131 00132 // read file size 00133 fileSize = read32(dmlogo+pos); 00134 log("filesize is: %d \r\n", fileSize); 00135 log(""); 00136 pos += 4; 00137 00138 pos += 4; // Skip creator bytes 00139 00140 bmpImageoffset = read32(dmlogo+pos); 00141 pos += 4; 00142 00143 // read DIB header 00144 headerSize = read32(dmlogo+pos); 00145 pos +=4; 00146 bmpWidth = read32(dmlogo+pos); 00147 pos += 4; 00148 bmpHeight = read32(dmlogo+pos); 00149 pos += 4; 00150 00151 log("Image size: %d\r\n", fileSize); 00152 log("Image offset: %d\r\n", bmpImageoffset); 00153 log("Header size: %d\r\n", headerSize); 00154 log("Image width: %d\r\n", bmpWidth ); 00155 log("Image height: %d\r\n", bmpHeight ); 00156 00157 if (read16(dmlogo+pos) != 1){ 00158 // number of color planes must be 1 00159 return false; 00160 } 00161 pos += 2; 00162 00163 bmpDepth = read16(dmlogo+pos); 00164 pos +=2; 00165 log("Bitdepth: %d\r\n", bmpDepth); 00166 00167 if (read16(dmlogo+pos) != 0) { 00168 // compression not supported! 00169 return false; 00170 } 00171 pos += 2; // Should really be 2?? 00172 00173 return true; 00174 } 00175 00176 /****************************************************************************** 00177 * Main 00178 *****************************************************************************/ 00179 00180 int main() { 00181 log("init tft \r\n"); 00182 tft.init(); 00183 00184 tft.drawString(0,32,"www."); 00185 tft.drawString(12,48,"displaymodule"); 00186 tft.drawString(88,64,".com"); 00187 00188 tft.drawRectangle(20,85,40,105,GREEN); 00189 tft.drawCircle(60,95,10,BLUE); 00190 tft.drawTriangle(90,85, 80,105, 100,105, RED); 00191 00192 if (! bmpReadHeader()) { 00193 log("bad bmp\r\n"); 00194 return -1; 00195 } 00196 00197 drawBmpFromFlash(0, 0); 00198 drawBmpFromFlash(0, 130); 00199 00200 while(1) { 00201 } 00202 }
Generated on Fri Jul 15 2022 21:41:14 by 1.7.2