Shows how to use a display and the onboard SD Card. Requires a display module with an adapter

Dependencies:   DmTftLibrary SDFileSystem mbed

Committer:
displaymodule
Date:
Tue May 20 15:42:31 2014 +0000
Revision:
0:ee27d4c12433
Child:
1:64173e1ae223
First version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
displaymodule 0:ee27d4c12433 1 /**********************************************************************************************
displaymodule 0:ee27d4c12433 2 Copyright (c) 2014 DisplayModule. All rights reserved.
displaymodule 0:ee27d4c12433 3
displaymodule 0:ee27d4c12433 4 Redistribution and use of this source code, part of this source code or any compiled binary
displaymodule 0:ee27d4c12433 5 based on this source code is permitted as long as the above copyright notice and following
displaymodule 0:ee27d4c12433 6 disclaimer is retained.
displaymodule 0:ee27d4c12433 7
displaymodule 0:ee27d4c12433 8 DISCLAIMER:
displaymodule 0:ee27d4c12433 9 THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES
displaymodule 0:ee27d4c12433 10 NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE.
displaymodule 0:ee27d4c12433 11 ********************************************************************************************/
displaymodule 0:ee27d4c12433 12
displaymodule 0:ee27d4c12433 13 /******************************************************************************
displaymodule 0:ee27d4c12433 14 * Includes
displaymodule 0:ee27d4c12433 15 *****************************************************************************/
displaymodule 0:ee27d4c12433 16
displaymodule 0:ee27d4c12433 17 #include "mbed.h"
displaymodule 0:ee27d4c12433 18
displaymodule 0:ee27d4c12433 19 #include "DmTftHX8353C.h"
displaymodule 0:ee27d4c12433 20 #include "DmTftS6D0164.h"
displaymodule 0:ee27d4c12433 21 #include "DmTftIli9325.h"
displaymodule 0:ee27d4c12433 22 #include "DmTftSsd2119.h"
displaymodule 0:ee27d4c12433 23 #include "DmTouch.h"
displaymodule 0:ee27d4c12433 24
displaymodule 0:ee27d4c12433 25 #include "DmDrawBmpBase.h"
displaymodule 0:ee27d4c12433 26 #include "SDFileSystem.h"
displaymodule 0:ee27d4c12433 27
displaymodule 0:ee27d4c12433 28 /******************************************************************************
displaymodule 0:ee27d4c12433 29 * Typedefs and defines
displaymodule 0:ee27d4c12433 30 *****************************************************************************/
displaymodule 0:ee27d4c12433 31
displaymodule 0:ee27d4c12433 32 #define log(...) printf(__VA_ARGS__)
displaymodule 0:ee27d4c12433 33 //#define log(...)
displaymodule 0:ee27d4c12433 34
displaymodule 0:ee27d4c12433 35 #define DM_PIN_SPI_MOSI A0
displaymodule 0:ee27d4c12433 36 #define DM_PIN_SPI_MISO D9
displaymodule 0:ee27d4c12433 37 #define DM_PIN_SPI_SCLK A1
displaymodule 0:ee27d4c12433 38
displaymodule 0:ee27d4c12433 39 #define DM_PIN_CS_TOUCH D8
displaymodule 0:ee27d4c12433 40 #define DM_PIN_CS_TFT A3
displaymodule 0:ee27d4c12433 41 #define DM_PIN_CS_SDCARD D10
displaymodule 0:ee27d4c12433 42
displaymodule 0:ee27d4c12433 43 /******************************************************************************
displaymodule 0:ee27d4c12433 44 * Local variables
displaymodule 0:ee27d4c12433 45 *****************************************************************************/
displaymodule 0:ee27d4c12433 46
displaymodule 0:ee27d4c12433 47 DmTftHX8353C tft; /* DM_TFT18_101 */
displaymodule 0:ee27d4c12433 48 //DmTftS6D0164 tft; /* DM_TFT22_102 */
displaymodule 0:ee27d4c12433 49 //DmTftIli9325 tft; /* DM_TFT28_103 and DM_TFT24_104 */
displaymodule 0:ee27d4c12433 50 //DmTftSsd2119 tft; /* DM_TFT35_107 */
displaymodule 0:ee27d4c12433 51
displaymodule 0:ee27d4c12433 52 //DmTouch touch(DmTouch::DM_TFT28_103, false); /* For LPC4088 QuickStart Board */
displaymodule 0:ee27d4c12433 53 //DmTouch touch(DmTouch::DM_TFT28_103);
displaymodule 0:ee27d4c12433 54 //DmTouch touch(DmTouch::DM_TFT24_104);
displaymodule 0:ee27d4c12433 55 //DmTouch touch(DmTouch::DM_TFT24_104, false); /* For LPC4088 QuickStart Board */
displaymodule 0:ee27d4c12433 56 //DmTouch touch(DmTouch::DM_TFT35_107);
displaymodule 0:ee27d4c12433 57
displaymodule 0:ee27d4c12433 58 SDFileSystem sd(DM_PIN_SPI_MOSI, DM_PIN_SPI_MISO, DM_PIN_SPI_SCLK, DM_PIN_CS_SDCARD, "sd"); // mosi,miso,clk,cs
displaymodule 0:ee27d4c12433 59
displaymodule 0:ee27d4c12433 60 DigitalInOut csTouch(DM_PIN_CS_TOUCH, PIN_OUTPUT, PullUp, 1);
displaymodule 0:ee27d4c12433 61 DigitalInOut csDisplay(DM_PIN_CS_TFT, PIN_OUTPUT, PullUp, 1);
displaymodule 0:ee27d4c12433 62 DigitalInOut csSDCard(DM_PIN_CS_SDCARD, PIN_OUTPUT, PullUp, 1);
displaymodule 0:ee27d4c12433 63
displaymodule 0:ee27d4c12433 64
displaymodule 0:ee27d4c12433 65 /******************************************************************************
displaymodule 0:ee27d4c12433 66 * Global variables
displaymodule 0:ee27d4c12433 67 *****************************************************************************/
displaymodule 0:ee27d4c12433 68
displaymodule 0:ee27d4c12433 69 /******************************************************************************
displaymodule 0:ee27d4c12433 70 * Local functions
displaymodule 0:ee27d4c12433 71 *****************************************************************************/
displaymodule 0:ee27d4c12433 72
displaymodule 0:ee27d4c12433 73 static bool sdcardReader(uint32_t userData, uint8_t* data, int offset, int numBytes) {
displaymodule 0:ee27d4c12433 74 FILE* fp = (FILE*)userData;
displaymodule 0:ee27d4c12433 75 fseek(fp, offset, SEEK_SET);
displaymodule 0:ee27d4c12433 76 fread(data, 1, numBytes, fp);
displaymodule 0:ee27d4c12433 77 return true;
displaymodule 0:ee27d4c12433 78 }
displaymodule 0:ee27d4c12433 79
displaymodule 0:ee27d4c12433 80 /******************************************************************************
displaymodule 0:ee27d4c12433 81 * Main
displaymodule 0:ee27d4c12433 82 *****************************************************************************/
displaymodule 0:ee27d4c12433 83
displaymodule 0:ee27d4c12433 84 int main() {
displaymodule 0:ee27d4c12433 85 DmDrawBmpBase bmp;
displaymodule 0:ee27d4c12433 86 const char* fname = "/sd/logop565.bmp";
displaymodule 0:ee27d4c12433 87
displaymodule 0:ee27d4c12433 88 log("init tft \r\n");
displaymodule 0:ee27d4c12433 89 tft.init();
displaymodule 0:ee27d4c12433 90
displaymodule 0:ee27d4c12433 91 while (true) {
displaymodule 0:ee27d4c12433 92 log("Drawing from SD card (%s) ...\n", fname);
displaymodule 0:ee27d4c12433 93 FILE *fp = fopen(fname, "r");
displaymodule 0:ee27d4c12433 94 if (fp != NULL) {
displaymodule 0:ee27d4c12433 95 bmp.drawBitmap(tft, 0, 0, sdcardReader, (uint32_t)fp);
displaymodule 0:ee27d4c12433 96 fclose(fp);
displaymodule 0:ee27d4c12433 97 } else {
displaymodule 0:ee27d4c12433 98 log("failed to open file\n");
displaymodule 0:ee27d4c12433 99 log("Skipping SDCard reading as it is unsupported\n");
displaymodule 0:ee27d4c12433 100 tft.drawStringCentered(0, 0, tft.width(), tft.height(), "SD Card Unsupported!");
displaymodule 0:ee27d4c12433 101 }
displaymodule 0:ee27d4c12433 102
displaymodule 0:ee27d4c12433 103 wait_ms(3000);
displaymodule 0:ee27d4c12433 104 tft.clearScreen(RED);
displaymodule 0:ee27d4c12433 105 wait_ms(1000);
displaymodule 0:ee27d4c12433 106 }
displaymodule 0:ee27d4c12433 107 }