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:
Mon Oct 12 08:58:55 2015 +0000
Revision:
7:5cc7d70faa97
Parent:
6:d28b8be6e90a
Compatible with the new DmTftLibrary and mbed library, more platform support. Recommended updates.

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 7:5cc7d70faa97 14 * Tested on NUCLEO-F401RE, LPCXpresso11U68, LPCXpresso824-MAX platform.
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 6:d28b8be6e90a 26 #include "DmTpFt6x06.h"
displaymodule 0:144e2312d558 27
displaymodule 0:144e2312d558 28 /******************************************************************************
displaymodule 0:144e2312d558 29 * Typedefs and defines
displaymodule 0:144e2312d558 30 *****************************************************************************/
displaymodule 0:144e2312d558 31
displaymodule 1:63e25ac12708 32 /* Note that there are restrictions on which platforms that can use printf
displaymodule 1:63e25ac12708 33 in combinations with the DmTftLibrary. Some platforms (e.g. LPC1549 LPCXpresso)
displaymodule 1:63e25ac12708 34 use the same pins for USBRX/USBTX and display control. Printing will
displaymodule 1:63e25ac12708 35 cause the display to not work. Read more about this on the display's notebook
displaymodule 1:63e25ac12708 36 page. */
displaymodule 0:144e2312d558 37 //#define log(...) printf(__VA_ARGS__)
displaymodule 0:144e2312d558 38 #define log(...)
displaymodule 0:144e2312d558 39
displaymodule 1:63e25ac12708 40 #if 1
displaymodule 1:63e25ac12708 41 /* Displays without adapter */
displaymodule 1:63e25ac12708 42 #define DM_PIN_SPI_MOSI D11
displaymodule 1:63e25ac12708 43 #define DM_PIN_SPI_MISO D12
displaymodule 1:63e25ac12708 44 #define DM_PIN_SPI_SCLK D13
displaymodule 1:63e25ac12708 45 #define DM_PIN_CS_TOUCH D4
displaymodule 1:63e25ac12708 46 #define DM_PIN_CS_TFT D10
displaymodule 1:63e25ac12708 47 #define DM_PIN_CS_SDCARD D8
displaymodule 1:63e25ac12708 48 #define DM_PIN_CS_FLASH D6
displaymodule 1:63e25ac12708 49 #else
displaymodule 1:63e25ac12708 50 /* Displays with adapter */
displaymodule 1:63e25ac12708 51 #define DM_PIN_SPI_MOSI A0
displaymodule 1:63e25ac12708 52 #define DM_PIN_SPI_MISO D9
displaymodule 1:63e25ac12708 53 #define DM_PIN_SPI_SCLK A1
displaymodule 1:63e25ac12708 54 #define DM_PIN_CS_TOUCH D8
displaymodule 1:63e25ac12708 55 #define DM_PIN_CS_TFT A3
displaymodule 1:63e25ac12708 56 #define DM_PIN_CS_SDCARD D10
displaymodule 0:144e2312d558 57 #endif
displaymodule 0:144e2312d558 58
displaymodule 0:144e2312d558 59 /******************************************************************************
displaymodule 0:144e2312d558 60 * Local variables
displaymodule 0:144e2312d558 61 *****************************************************************************/
displaymodule 7:5cc7d70faa97 62
displaymodule 7:5cc7d70faa97 63 /********* TFT DISPLAY INIT *********/
displaymodule 7:5cc7d70faa97 64 //DmTftIli9325 tft(A4, A3, A5, A2); /* DmTftIli9325(PinName wr, PinName cs, PinName dc, PinName rst) DM_TFT28_103 and DM_TFT24_104 */
displaymodule 7:5cc7d70faa97 65 DmTftIli9341 tft(D10, D9, D11, D12, D13); /* DmTftIli9341(PinName cs, PinName dc, PinName mosi, PinName miso, PinName clk) DM_TFT28_105 and DM_TFT28_116*/
displaymodule 7:5cc7d70faa97 66 //DmTftSsd2119 tft(D10, D9, D11, D12, D13); /* DmTftSsd2119(PinName cs, PinName dc, PinName mosi, PinName miso, PinName clk) DM_TFT35_107 */
displaymodule 7:5cc7d70faa97 67 //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. */
displaymodule 0:144e2312d558 68
displaymodule 7:5cc7d70faa97 69 /********* TOUCH PANEL INIT *********/
displaymodule 0:144e2312d558 70 //DmTouch touch(DmTouch::DM_TFT28_103);
displaymodule 1:63e25ac12708 71 //DmTouch touch(DmTouch::DM_TFT24_104);
displaymodule 7:5cc7d70faa97 72 DmTouch touch(DmTouch::DM_TFT28_105, D11, D12, D13);
displaymodule 7:5cc7d70faa97 73 /* DM-TFT28-116 */
displaymodule 7:5cc7d70faa97 74 //I2C i2c(D14, D15);
displaymodule 7:5cc7d70faa97 75 //DmTpFt6x06 touch(DmTpFt6x06::DM_TFT28_116, i2c);
displaymodule 7:5cc7d70faa97 76 //DmTouch touch(DmTouch::DM_TFT35_107, D11, D12, D13);
displaymodule 7:5cc7d70faa97 77 //DmTouch touch(DmTouch::DM_TFT43_108, D11, D12, D13); // For DmTftRa8875 driver, The panel resolution should be config in DmTftRa8875::init() function on the DmTftRa8875.cpp file.
displaymodule 6:d28b8be6e90a 78 //DmTouch touch(DmTouch::DM_TFT50_111);
displaymodule 6:d28b8be6e90a 79
displaymodule 0:144e2312d558 80
displaymodule 0:144e2312d558 81 DigitalInOut csTouch(DM_PIN_CS_TOUCH, PIN_OUTPUT, PullUp, 1);
displaymodule 0:144e2312d558 82 DigitalInOut csDisplay(DM_PIN_CS_TFT, PIN_OUTPUT, PullUp, 1);
displaymodule 0:144e2312d558 83 DigitalInOut csSDCard(DM_PIN_CS_SDCARD, PIN_OUTPUT, PullUp, 1);
displaymodule 0:144e2312d558 84 #ifdef DM_PIN_CS_FLASH
displaymodule 0:144e2312d558 85 DigitalInOut csFlash(DM_PIN_CS_FLASH, PIN_OUTPUT, PullUp, 1);
displaymodule 0:144e2312d558 86 #endif
displaymodule 0:144e2312d558 87
displaymodule 0:144e2312d558 88 /******************************************************************************
displaymodule 0:144e2312d558 89 * Global variables
displaymodule 0:144e2312d558 90 *****************************************************************************/
displaymodule 0:144e2312d558 91
displaymodule 0:144e2312d558 92 /******************************************************************************
displaymodule 0:144e2312d558 93 * Local functions
displaymodule 0:144e2312d558 94 *****************************************************************************/
displaymodule 0:144e2312d558 95
displaymodule 0:144e2312d558 96
displaymodule 0:144e2312d558 97 /******************************************************************************
displaymodule 0:144e2312d558 98 * Main
displaymodule 0:144e2312d558 99 *****************************************************************************/
displaymodule 0:144e2312d558 100
displaymodule 0:144e2312d558 101 int main() {
displaymodule 0:144e2312d558 102 log("init tft \r\n");
displaymodule 0:144e2312d558 103 tft.init();
displaymodule 5:cf0097e3a18c 104
displaymodule 0:144e2312d558 105 uint16_t x = 0;
displaymodule 0:144e2312d558 106 uint16_t y = 0;
displaymodule 0:144e2312d558 107 uint16_t w = tft.width();
displaymodule 0:144e2312d558 108 uint16_t h = tft.height();
displaymodule 0:144e2312d558 109
displaymodule 0:144e2312d558 110 bool down = false;
displaymodule 0:144e2312d558 111 bool lastDown = false;
displaymodule 0:144e2312d558 112
displaymodule 0:144e2312d558 113 tft.drawString(20, 20, "x:");
displaymodule 0:144e2312d558 114 tft.drawString(100, 20, "y:");
displaymodule 7:5cc7d70faa97 115
displaymodule 0:144e2312d558 116 touch.init();
displaymodule 0:144e2312d558 117 while (1) {
displaymodule 7:5cc7d70faa97 118 touch.readTouchData(x, y, down);
displaymodule 0:144e2312d558 119 if (down) {
displaymodule 0:144e2312d558 120 tft.drawNumber(40, 20, x, 5, false);
displaymodule 0:144e2312d558 121 tft.drawNumber(120, 20, y, 5, false);
displaymodule 7:5cc7d70faa97 122 tft.drawPoint(x, y, 1);
displaymodule 0:144e2312d558 123 } else if (lastDown) {
displaymodule 0:144e2312d558 124 // no longer pressed, clean text
displaymodule 0:144e2312d558 125 tft.drawString(40, 20, " ");
displaymodule 0:144e2312d558 126 tft.drawString(120, 20, " ");
displaymodule 0:144e2312d558 127 }
displaymodule 0:144e2312d558 128 wait(0.040);
displaymodule 0:144e2312d558 129 lastDown = down;
displaymodule 0:144e2312d558 130 }
displaymodule 7:5cc7d70faa97 131
displaymodule 0:144e2312d558 132 }