Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DmTftLibrary mbed
Fork of dm_mainMod by
Diff: main.cpp
- Revision:
- 0:486bf9d63b80
- Child:
- 1:4a281af0d8e6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue May 20 15:37:27 2014 +0000
@@ -0,0 +1,195 @@
+/**********************************************************************************************
+ Copyright (c) 2014 DisplayModule. All rights reserved.
+
+ Redistribution and use of this source code, part of this source code or any compiled binary
+ based on this source code is permitted as long as the above copyright notice and following
+ disclaimer is retained.
+
+ DISCLAIMER:
+ THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES
+ NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE.
+ ********************************************************************************************/
+
+/******************************************************************************
+ * Includes
+ *****************************************************************************/
+
+#include "mbed.h"
+
+#include "DmTftHX8353C.h"
+#include "DmTftS6D0164.h"
+#include "DmTftIli9325.h"
+#include "DmTftIli9341.h"
+#include "DmTftSsd2119.h"
+
+/******************************************************************************
+ * Typedefs and defines
+ *****************************************************************************/
+
+//#define log(...) printf(__VA_ARGS__)
+#define log(...)
+
+/******************************************************************************
+ * Local variables
+ *****************************************************************************/
+
+//DmTftHX8353C tft; /* DM_TFT18_101 */
+//DmTftS6D0164 tft; /* DM_TFT22_102 */
+//DmTftIli9325 tft; /* DM_TFT28_103 and DM_TFT24_104 */
+DmTftIli9341 tft; /* DM_TFT28_105 */
+//DmTftSsd2119 tft; /* DM_TFT35_107 */
+
+int bmpWidth, bmpHeight;
+uint8_t bmpImageoffset;
+
+/******************************************************************************
+ * Global variables
+ *****************************************************************************/
+
+extern uint8_t dmlogo[];
+
+/******************************************************************************
+ * Local functions
+ *****************************************************************************/
+
+// LITTLE ENDIAN!
+uint16_t read16(uint8_t *src)
+{
+ uint16_t d;
+ uint8_t b;
+ b = *src;
+ d = *(src+1);
+ d <<= 8;
+ d |= b;
+ return d;
+}
+
+// LITTLE ENDIAN!
+uint32_t read32(uint8_t *src)
+{
+ uint32_t d;
+ uint16_t b;
+
+ b = read16(src);
+ d = read16(src+2);
+ d <<= 16;
+ d |= b;
+ return d;
+}
+
+void drawBmpFromFlash(int x, int y)
+{
+ uint16_t pos = bmpImageoffset;
+
+ uint16_t p; // pixel
+ uint8_t g, b;
+ int i, j; // line, column
+
+ for(i=bmpHeight; i>0; i--) {
+ for(j=0; j<bmpWidth; j++) {
+ b = *(dmlogo+pos++);
+ g = *(dmlogo+pos++);
+ p = *(dmlogo+pos++);
+
+ p >>= 3;
+ p <<= 6;
+
+ g >>= 2;
+ p |= g;
+ p <<= 5;
+
+ b >>= 3;
+ p |= b;
+
+ // write out the 16 bits of color
+ tft.setPixel(j, i+y, p);
+ }
+ }
+}
+
+
+int bmpReadHeader() {
+ uint32_t fileSize;
+ uint32_t headerSize;
+ uint16_t bmpDepth;
+ uint16_t pos = 0;
+ log("reading bmp header\r\n");
+ log("Magic byte is: %d \r\n", read16(dmlogo));
+
+ if (read16(dmlogo) !=0x4D42){ // read magic byte
+ log("Magic byte not found\r\n");
+ return false;
+ }
+ pos += 2;
+
+ // read file size
+ fileSize = read32(dmlogo+pos);
+ log("filesize is: %d \r\n", fileSize);
+ log("");
+ pos += 4;
+
+ pos += 4; // Skip creator bytes
+
+ bmpImageoffset = read32(dmlogo+pos);
+ pos += 4;
+
+ // read DIB header
+ headerSize = read32(dmlogo+pos);
+ pos +=4;
+ bmpWidth = read32(dmlogo+pos);
+ pos += 4;
+ bmpHeight = read32(dmlogo+pos);
+ pos += 4;
+
+ log("Image size: %d\r\n", fileSize);
+ log("Image offset: %d\r\n", bmpImageoffset);
+ log("Header size: %d\r\n", headerSize);
+ log("Image width: %d\r\n", bmpWidth );
+ log("Image height: %d\r\n", bmpHeight );
+
+ if (read16(dmlogo+pos) != 1){
+ // number of color planes must be 1
+ return false;
+ }
+ pos += 2;
+
+ bmpDepth = read16(dmlogo+pos);
+ pos +=2;
+ log("Bitdepth: %d\r\n", bmpDepth);
+
+ if (read16(dmlogo+pos) != 0) {
+ // compression not supported!
+ return false;
+ }
+ pos += 2; // Should really be 2??
+
+ return true;
+}
+
+/******************************************************************************
+ * Main
+ *****************************************************************************/
+
+int main() {
+ log("init tft \r\n");
+ tft.init();
+
+ tft.drawString(0,32,"www.");
+ tft.drawString(12,48,"displaymodule");
+ tft.drawString(88,64,".com");
+
+ tft.drawRectangle(20,85,40,105,GREEN);
+ tft.drawCircle(60,95,10,BLUE);
+ tft.drawTriangle(90,85, 80,105, 100,105, RED);
+
+ if (! bmpReadHeader()) {
+ log("bad bmp\r\n");
+ return -1;
+ }
+
+ drawBmpFromFlash(0, 0);
+ drawBmpFromFlash(0, 130);
+
+ while(1) {
+ }
+}
