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:
Mon Sep 01 11:06:18 2014 +0000
Revision:
6:592bba211e38
Parent:
2:bb52a280861b
Removed dependency on mbed-src for LPC1549

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 1:64173e1ae223 32 /* Note that there are restrictions on which platforms that can use printf
displaymodule 1:64173e1ae223 33 in combinations with the DmTftLibrary. Some platforms (e.g. LPC1549 LPCXpresso)
displaymodule 1:64173e1ae223 34 use the same pins for USBRX/USBTX and display control. Printing will
displaymodule 1:64173e1ae223 35 cause the display to not work. Read more about this on the display's notebook
displaymodule 1:64173e1ae223 36 page. */
displaymodule 1:64173e1ae223 37 //#define log(...) printf(__VA_ARGS__)
displaymodule 1:64173e1ae223 38 #define log(...)
displaymodule 0:ee27d4c12433 39
displaymodule 0:ee27d4c12433 40 #define DM_PIN_SPI_MOSI A0
displaymodule 0:ee27d4c12433 41 #define DM_PIN_SPI_MISO D9
displaymodule 0:ee27d4c12433 42 #define DM_PIN_SPI_SCLK A1
displaymodule 0:ee27d4c12433 43
displaymodule 1:64173e1ae223 44 #define DM_PIN_SD_SPI_MOSI D11
displaymodule 1:64173e1ae223 45 #define DM_PIN_SD_SPI_MISO D12
displaymodule 1:64173e1ae223 46 #define DM_PIN_SD_SPI_SCLK D13
displaymodule 1:64173e1ae223 47
displaymodule 0:ee27d4c12433 48 #define DM_PIN_CS_TOUCH D8
displaymodule 0:ee27d4c12433 49 #define DM_PIN_CS_TFT A3
displaymodule 0:ee27d4c12433 50 #define DM_PIN_CS_SDCARD D10
displaymodule 0:ee27d4c12433 51
displaymodule 0:ee27d4c12433 52 /******************************************************************************
displaymodule 0:ee27d4c12433 53 * Local variables
displaymodule 0:ee27d4c12433 54 *****************************************************************************/
displaymodule 0:ee27d4c12433 55
displaymodule 1:64173e1ae223 56 //DmTftHX8353C tft; /* DM_TFT18_101 */
displaymodule 1:64173e1ae223 57 DmTftS6D0164 tft; /* DM_TFT22_102 */
displaymodule 0:ee27d4c12433 58 //DmTftIli9325 tft; /* DM_TFT28_103 and DM_TFT24_104 */
displaymodule 0:ee27d4c12433 59
displaymodule 1:64173e1ae223 60 SDFileSystem sd(DM_PIN_SD_SPI_MOSI, DM_PIN_SD_SPI_MISO, DM_PIN_SD_SPI_SCLK, DM_PIN_CS_SDCARD, "sd"); // mosi,miso,clk,cs
displaymodule 0:ee27d4c12433 61
displaymodule 0:ee27d4c12433 62 DigitalInOut csTouch(DM_PIN_CS_TOUCH, PIN_OUTPUT, PullUp, 1);
displaymodule 0:ee27d4c12433 63 DigitalInOut csDisplay(DM_PIN_CS_TFT, PIN_OUTPUT, PullUp, 1);
displaymodule 0:ee27d4c12433 64 DigitalInOut csSDCard(DM_PIN_CS_SDCARD, PIN_OUTPUT, PullUp, 1);
displaymodule 0:ee27d4c12433 65
displaymodule 0:ee27d4c12433 66
displaymodule 0:ee27d4c12433 67 /******************************************************************************
displaymodule 0:ee27d4c12433 68 * Global variables
displaymodule 0:ee27d4c12433 69 *****************************************************************************/
displaymodule 0:ee27d4c12433 70
displaymodule 0:ee27d4c12433 71 /******************************************************************************
displaymodule 0:ee27d4c12433 72 * Local functions
displaymodule 0:ee27d4c12433 73 *****************************************************************************/
displaymodule 0:ee27d4c12433 74
displaymodule 0:ee27d4c12433 75 static bool sdcardReader(uint32_t userData, uint8_t* data, int offset, int numBytes) {
displaymodule 0:ee27d4c12433 76 FILE* fp = (FILE*)userData;
displaymodule 0:ee27d4c12433 77 fseek(fp, offset, SEEK_SET);
displaymodule 0:ee27d4c12433 78 fread(data, 1, numBytes, fp);
displaymodule 0:ee27d4c12433 79 return true;
displaymodule 0:ee27d4c12433 80 }
displaymodule 0:ee27d4c12433 81
displaymodule 0:ee27d4c12433 82 /******************************************************************************
displaymodule 0:ee27d4c12433 83 * Main
displaymodule 0:ee27d4c12433 84 *****************************************************************************/
displaymodule 0:ee27d4c12433 85
displaymodule 0:ee27d4c12433 86 int main() {
displaymodule 0:ee27d4c12433 87 DmDrawBmpBase bmp;
displaymodule 0:ee27d4c12433 88 const char* fname = "/sd/logop565.bmp";
displaymodule 0:ee27d4c12433 89
displaymodule 0:ee27d4c12433 90 log("init tft \r\n");
displaymodule 0:ee27d4c12433 91 tft.init();
displaymodule 0:ee27d4c12433 92
displaymodule 0:ee27d4c12433 93 while (true) {
displaymodule 0:ee27d4c12433 94 log("Drawing from SD card (%s) ...\n", fname);
displaymodule 0:ee27d4c12433 95 FILE *fp = fopen(fname, "r");
displaymodule 0:ee27d4c12433 96 if (fp != NULL) {
displaymodule 0:ee27d4c12433 97 bmp.drawBitmap(tft, 0, 0, sdcardReader, (uint32_t)fp);
displaymodule 0:ee27d4c12433 98 fclose(fp);
displaymodule 0:ee27d4c12433 99 } else {
displaymodule 0:ee27d4c12433 100 log("failed to open file\n");
displaymodule 0:ee27d4c12433 101 log("Skipping SDCard reading as it is unsupported\n");
displaymodule 0:ee27d4c12433 102 tft.drawStringCentered(0, 0, tft.width(), tft.height(), "SD Card Unsupported!");
displaymodule 0:ee27d4c12433 103 }
displaymodule 0:ee27d4c12433 104
displaymodule 0:ee27d4c12433 105 wait_ms(3000);
displaymodule 0:ee27d4c12433 106 tft.clearScreen(RED);
displaymodule 0:ee27d4c12433 107 wait_ms(1000);
displaymodule 0:ee27d4c12433 108 }
displaymodule 0:ee27d4c12433 109 }