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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /**********************************************************************************************
00002  Copyright (c) 2014 DisplayModule. All rights reserved.
00003 
00004  Redistribution and use of this source code, part of this source code or any compiled binary
00005  based on this source code is permitted as long as the above copyright notice and following
00006  disclaimer is retained.
00007 
00008  DISCLAIMER:
00009  THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES
00010  NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE.
00011  ********************************************************************************************/
00012 
00013 /******************************************************************************
00014  * Tested on NUCLEO-F401RE, LPCXpresso11U68, LPCXpresso824-MAX platform.
00015  *****************************************************************************/
00016 
00017 #include "mbed.h"
00018 
00019 #include "DmTftHX8353C.h"
00020 #include "DmTftS6D0164.h"
00021 #include "DmTftIli9325.h"
00022 #include "DmTftIli9341.h"
00023 #include "DmTftSsd2119.h"
00024 #include "DmTftRa8875.h"
00025 #include "DmTouch.h"
00026 #include "DmTpFt6x06.h"
00027 
00028 /******************************************************************************
00029  * Typedefs and defines
00030  *****************************************************************************/
00031 
00032 /* Note that there are restrictions on which platforms that can use printf
00033    in combinations with the DmTftLibrary. Some platforms (e.g. LPC1549 LPCXpresso)
00034    use the same pins for USBRX/USBTX and display control. Printing will
00035    cause the display to not work. Read more about this on the display's notebook
00036    page. */
00037 //#define log(...) printf(__VA_ARGS__)
00038 #define log(...)
00039 
00040 #if 1
00041   /* Displays without adapter */
00042   #define DM_PIN_SPI_MOSI   D11
00043   #define DM_PIN_SPI_MISO   D12
00044   #define DM_PIN_SPI_SCLK   D13
00045   #define DM_PIN_CS_TOUCH   D4
00046   #define DM_PIN_CS_TFT     D10
00047   #define DM_PIN_CS_SDCARD  D8
00048   #define DM_PIN_CS_FLASH   D6
00049 #else
00050   /* Displays with adapter */
00051   #define DM_PIN_SPI_MOSI   A0
00052   #define DM_PIN_SPI_MISO   D9
00053   #define DM_PIN_SPI_SCLK   A1
00054   #define DM_PIN_CS_TOUCH   D8
00055   #define DM_PIN_CS_TFT     A3
00056   #define DM_PIN_CS_SDCARD  D10
00057 #endif
00058 
00059 /******************************************************************************
00060  * Local variables
00061  *****************************************************************************/
00062  
00063 /*********  TFT DISPLAY INIT *********/
00064 //DmTftIli9325 tft(A4, A3, A5, A2);  /* DmTftIli9325(PinName wr, PinName cs, PinName dc, PinName rst) DM_TFT28_103 and DM_TFT24_104 */
00065 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*/
00066 //DmTftSsd2119 tft(D10, D9, D11, D12, D13);  /* DmTftSsd2119(PinName cs, PinName dc, PinName mosi, PinName miso, PinName clk) DM_TFT35_107 */
00067 //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. */
00068 
00069  /*********   TOUCH PANEL INIT  *********/
00070 //DmTouch touch(DmTouch::DM_TFT28_103);
00071 //DmTouch touch(DmTouch::DM_TFT24_104);
00072 DmTouch touch(DmTouch::DM_TFT28_105, D11, D12, D13);
00073 /* DM-TFT28-116  */
00074 //I2C i2c(D14, D15);  
00075 //DmTpFt6x06 touch(DmTpFt6x06::DM_TFT28_116, i2c); 
00076 //DmTouch touch(DmTouch::DM_TFT35_107, D11, D12, D13);
00077 //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.
00078 //DmTouch touch(DmTouch::DM_TFT50_111);
00079 
00080 
00081 DigitalInOut csTouch(DM_PIN_CS_TOUCH, PIN_OUTPUT, PullUp, 1);
00082 DigitalInOut csDisplay(DM_PIN_CS_TFT, PIN_OUTPUT, PullUp, 1);
00083 DigitalInOut csSDCard(DM_PIN_CS_SDCARD, PIN_OUTPUT, PullUp, 1);
00084 #ifdef DM_PIN_CS_FLASH
00085   DigitalInOut csFlash(DM_PIN_CS_FLASH, PIN_OUTPUT, PullUp, 1);
00086 #endif
00087 
00088 /******************************************************************************
00089  * Global variables
00090  *****************************************************************************/
00091 
00092 /******************************************************************************
00093  * Local functions
00094  *****************************************************************************/
00095 
00096 
00097 /******************************************************************************
00098  * Main
00099  *****************************************************************************/
00100 
00101 int main() {
00102   log("init tft \r\n");
00103   tft.init();
00104   
00105   uint16_t x = 0;
00106   uint16_t y = 0;
00107   uint16_t w = tft.width();
00108   uint16_t h = tft.height();
00109   
00110   bool down = false;
00111   bool lastDown = false;
00112   
00113   tft.drawString(20, 20, "x:");
00114   tft.drawString(100, 20, "y:");
00115 
00116   touch.init();
00117   while (1) {
00118    touch.readTouchData(x, y, down);
00119     if (down) {
00120       tft.drawNumber(40, 20, x, 5, false);
00121       tft.drawNumber(120, 20, y, 5, false);
00122       tft.drawPoint(x, y, 1);
00123     } else if (lastDown) {
00124       // no longer pressed, clean text
00125       tft.drawString(40, 20, "     ");
00126       tft.drawString(120, 20, "     ");
00127     }
00128     wait(0.040);
00129     lastDown = down;
00130   }
00131 
00132 }