Shows how to use a display and the touch controller. Will display the X and Y coordinates of the current touch event.

Dependencies:   DmTftLibrary mbed

Committer:
displaymodule
Date:
Wed Jan 21 13:57:06 2015 +0000
Revision:
5:cf0097e3a18c
Parent:
2:c8e477ca4276
Child:
6:d28b8be6e90a
add DM_TFT43_108, DM_TFT50_111 based on new lib drv: DmTftRa8875

Who changed what in which revision?

UserRevisionLine numberNew contents of line
displaymodule 0:144e2312d558 1 /**********************************************************************************************
displaymodule 0:144e2312d558 2 Copyright (c) 2014 DisplayModule. All rights reserved.
displaymodule 0:144e2312d558 3
displaymodule 0:144e2312d558 4 Redistribution and use of this source code, part of this source code or any compiled binary
displaymodule 0:144e2312d558 5 based on this source code is permitted as long as the above copyright notice and following
displaymodule 0:144e2312d558 6 disclaimer is retained.
displaymodule 0:144e2312d558 7
displaymodule 0:144e2312d558 8 DISCLAIMER:
displaymodule 0:144e2312d558 9 THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES
displaymodule 0:144e2312d558 10 NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE.
displaymodule 0:144e2312d558 11 ********************************************************************************************/
displaymodule 0:144e2312d558 12
displaymodule 0:144e2312d558 13 /******************************************************************************
displaymodule 0:144e2312d558 14 * Includes
displaymodule 0:144e2312d558 15 *****************************************************************************/
displaymodule 0:144e2312d558 16
displaymodule 0:144e2312d558 17 #include "mbed.h"
displaymodule 0:144e2312d558 18
displaymodule 0:144e2312d558 19 #include "DmTftHX8353C.h"
displaymodule 0:144e2312d558 20 #include "DmTftS6D0164.h"
displaymodule 0:144e2312d558 21 #include "DmTftIli9325.h"
displaymodule 0:144e2312d558 22 #include "DmTftIli9341.h"
displaymodule 0:144e2312d558 23 #include "DmTftSsd2119.h"
displaymodule 5:cf0097e3a18c 24 #include "DmTftRa8875.h"
displaymodule 0:144e2312d558 25 #include "DmTouch.h"
displaymodule 0:144e2312d558 26
displaymodule 0:144e2312d558 27 /******************************************************************************
displaymodule 0:144e2312d558 28 * Typedefs and defines
displaymodule 0:144e2312d558 29 *****************************************************************************/
displaymodule 0:144e2312d558 30
displaymodule 1:63e25ac12708 31 /* Note that there are restrictions on which platforms that can use printf
displaymodule 1:63e25ac12708 32 in combinations with the DmTftLibrary. Some platforms (e.g. LPC1549 LPCXpresso)
displaymodule 1:63e25ac12708 33 use the same pins for USBRX/USBTX and display control. Printing will
displaymodule 1:63e25ac12708 34 cause the display to not work. Read more about this on the display's notebook
displaymodule 1:63e25ac12708 35 page. */
displaymodule 0:144e2312d558 36 //#define log(...) printf(__VA_ARGS__)
displaymodule 0:144e2312d558 37 #define log(...)
displaymodule 0:144e2312d558 38
displaymodule 1:63e25ac12708 39 #if 1
displaymodule 1:63e25ac12708 40 /* Displays without adapter */
displaymodule 1:63e25ac12708 41 #define DM_PIN_SPI_MOSI D11
displaymodule 1:63e25ac12708 42 #define DM_PIN_SPI_MISO D12
displaymodule 1:63e25ac12708 43 #define DM_PIN_SPI_SCLK D13
displaymodule 1:63e25ac12708 44 #define DM_PIN_CS_TOUCH D4
displaymodule 1:63e25ac12708 45 #define DM_PIN_CS_TFT D10
displaymodule 1:63e25ac12708 46 #define DM_PIN_CS_SDCARD D8
displaymodule 1:63e25ac12708 47 #define DM_PIN_CS_FLASH D6
displaymodule 1:63e25ac12708 48 #else
displaymodule 1:63e25ac12708 49 /* Displays with adapter */
displaymodule 1:63e25ac12708 50 #define DM_PIN_SPI_MOSI A0
displaymodule 1:63e25ac12708 51 #define DM_PIN_SPI_MISO D9
displaymodule 1:63e25ac12708 52 #define DM_PIN_SPI_SCLK A1
displaymodule 1:63e25ac12708 53 #define DM_PIN_CS_TOUCH D8
displaymodule 1:63e25ac12708 54 #define DM_PIN_CS_TFT A3
displaymodule 1:63e25ac12708 55 #define DM_PIN_CS_SDCARD D10
displaymodule 0:144e2312d558 56 #endif
displaymodule 0:144e2312d558 57
displaymodule 0:144e2312d558 58 /******************************************************************************
displaymodule 0:144e2312d558 59 * Local variables
displaymodule 0:144e2312d558 60 *****************************************************************************/
displaymodule 0:144e2312d558 61
displaymodule 1:63e25ac12708 62 //DmTftIli9325 tft; /* DM_TFT28_103 and DM_TFT24_104 */
displaymodule 0:144e2312d558 63 //DmTftIli9341 tft; /* DM_TFT28_105 */
displaymodule 5:cf0097e3a18c 64 //DmTftSsd2119 tft; /* DM_TFT35_107 */
displaymodule 5:cf0097e3a18c 65 DmTftRa8875 tft; /* DM_TFT43_108 and DM_TFT50_111 */
displaymodule 0:144e2312d558 66
displaymodule 1:63e25ac12708 67 //DmTouch touch(DmTouch::DM_TFT28_103, DmTouch::Software); /* For LPC4088 QuickStart Board */
displaymodule 0:144e2312d558 68 //DmTouch touch(DmTouch::DM_TFT28_103);
displaymodule 1:63e25ac12708 69 //DmTouch touch(DmTouch::DM_TFT24_104, DmTouch::Software); /* For LPC4088 QuickStart Board */
displaymodule 1:63e25ac12708 70 //DmTouch touch(DmTouch::DM_TFT24_104);
displaymodule 0:144e2312d558 71 //DmTouch touch(DmTouch::DM_TFT28_105);
displaymodule 5:cf0097e3a18c 72 //DmTouch touch(DmTouch::DM_TFT35_107);
displaymodule 5:cf0097e3a18c 73 //DmTouch touch(DmTouch::DM_TFT43_108); // For DmTftRa8875 driver, The panel resolution should be config in DmTftRa8875::init() function on the DmTftRa8875.cpp file.
displaymodule 5:cf0097e3a18c 74 DmTouch touch(DmTouch::DM_TFT50_111);
displaymodule 0:144e2312d558 75
displaymodule 0:144e2312d558 76 DigitalInOut csTouch(DM_PIN_CS_TOUCH, PIN_OUTPUT, PullUp, 1);
displaymodule 0:144e2312d558 77 DigitalInOut csDisplay(DM_PIN_CS_TFT, PIN_OUTPUT, PullUp, 1);
displaymodule 0:144e2312d558 78 DigitalInOut csSDCard(DM_PIN_CS_SDCARD, PIN_OUTPUT, PullUp, 1);
displaymodule 0:144e2312d558 79 #ifdef DM_PIN_CS_FLASH
displaymodule 0:144e2312d558 80 DigitalInOut csFlash(DM_PIN_CS_FLASH, PIN_OUTPUT, PullUp, 1);
displaymodule 0:144e2312d558 81 #endif
displaymodule 0:144e2312d558 82
displaymodule 0:144e2312d558 83 /******************************************************************************
displaymodule 0:144e2312d558 84 * Global variables
displaymodule 0:144e2312d558 85 *****************************************************************************/
displaymodule 0:144e2312d558 86
displaymodule 0:144e2312d558 87 /******************************************************************************
displaymodule 0:144e2312d558 88 * Local functions
displaymodule 0:144e2312d558 89 *****************************************************************************/
displaymodule 0:144e2312d558 90
displaymodule 0:144e2312d558 91
displaymodule 0:144e2312d558 92 /******************************************************************************
displaymodule 0:144e2312d558 93 * Main
displaymodule 0:144e2312d558 94 *****************************************************************************/
displaymodule 0:144e2312d558 95
displaymodule 0:144e2312d558 96 int main() {
displaymodule 0:144e2312d558 97 log("init tft \r\n");
displaymodule 0:144e2312d558 98 tft.init();
displaymodule 5:cf0097e3a18c 99
displaymodule 0:144e2312d558 100 uint16_t x = 0;
displaymodule 0:144e2312d558 101 uint16_t y = 0;
displaymodule 0:144e2312d558 102 uint16_t w = tft.width();
displaymodule 0:144e2312d558 103 uint16_t h = tft.height();
displaymodule 0:144e2312d558 104
displaymodule 0:144e2312d558 105 bool down = false;
displaymodule 0:144e2312d558 106 bool lastDown = false;
displaymodule 0:144e2312d558 107
displaymodule 0:144e2312d558 108 tft.drawString(20, 20, "x:");
displaymodule 0:144e2312d558 109 tft.drawString(100, 20, "y:");
displaymodule 0:144e2312d558 110
displaymodule 0:144e2312d558 111 touch.init();
displaymodule 0:144e2312d558 112 while (1) {
displaymodule 0:144e2312d558 113 touch.readTouchData(x, y, down);
displaymodule 0:144e2312d558 114 if (down) {
displaymodule 0:144e2312d558 115 tft.drawNumber(40, 20, x, 5, false);
displaymodule 0:144e2312d558 116 tft.drawNumber(120, 20, y, 5, false);
displaymodule 0:144e2312d558 117 } else if (lastDown) {
displaymodule 0:144e2312d558 118 // no longer pressed, clean text
displaymodule 0:144e2312d558 119 tft.drawString(40, 20, " ");
displaymodule 0:144e2312d558 120 tft.drawString(120, 20, " ");
displaymodule 0:144e2312d558 121 }
displaymodule 0:144e2312d558 122 wait(0.040);
displaymodule 0:144e2312d558 123 lastDown = down;
displaymodule 0:144e2312d558 124 }
displaymodule 0:144e2312d558 125 }