This application makes it possible to calibrate the touch screen. Note that the calibration data is not persistently saved. Either do the calibration on every startup or modify the default values in DmTouchCalibration.
Dependencies: DmTftLibrary mbed
main.cpp@4:6bcad4fe23d6, 2015-01-22 (annotated)
- Committer:
- displaymodule
- Date:
- Thu Jan 22 01:10:00 2015 +0000
- Revision:
- 4:6bcad4fe23d6
- Parent:
- 0:aba2ac5dd09d
Add new Producets: DM_TFT43_108, DM_TFT50_111 based on new lib drv: DmTftRa8875
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
displaymodule | 0:aba2ac5dd09d | 1 | /********************************************************************************************** |
displaymodule | 0:aba2ac5dd09d | 2 | Copyright (c) 2014 DisplayModule. All rights reserved. |
displaymodule | 0:aba2ac5dd09d | 3 | |
displaymodule | 0:aba2ac5dd09d | 4 | Redistribution and use of this source code, part of this source code or any compiled binary |
displaymodule | 0:aba2ac5dd09d | 5 | based on this source code is permitted as long as the above copyright notice and following |
displaymodule | 0:aba2ac5dd09d | 6 | disclaimer is retained. |
displaymodule | 0:aba2ac5dd09d | 7 | |
displaymodule | 0:aba2ac5dd09d | 8 | DISCLAIMER: |
displaymodule | 0:aba2ac5dd09d | 9 | THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES |
displaymodule | 0:aba2ac5dd09d | 10 | NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. |
displaymodule | 0:aba2ac5dd09d | 11 | ********************************************************************************************/ |
displaymodule | 0:aba2ac5dd09d | 12 | |
displaymodule | 0:aba2ac5dd09d | 13 | /****************************************************************************** |
displaymodule | 0:aba2ac5dd09d | 14 | * Includes |
displaymodule | 0:aba2ac5dd09d | 15 | *****************************************************************************/ |
displaymodule | 0:aba2ac5dd09d | 16 | |
displaymodule | 0:aba2ac5dd09d | 17 | #include "mbed.h" |
displaymodule | 0:aba2ac5dd09d | 18 | |
displaymodule | 0:aba2ac5dd09d | 19 | #include "DmTftHX8353C.h" |
displaymodule | 0:aba2ac5dd09d | 20 | #include "DmTftS6D0164.h" |
displaymodule | 0:aba2ac5dd09d | 21 | #include "DmTftIli9325.h" |
displaymodule | 0:aba2ac5dd09d | 22 | #include "DmTftIli9341.h" |
displaymodule | 0:aba2ac5dd09d | 23 | #include "DmTftSsd2119.h" |
displaymodule | 4:6bcad4fe23d6 | 24 | #include "DmTftRa8875.h" |
displaymodule | 0:aba2ac5dd09d | 25 | #include "DmTouch.h" |
displaymodule | 0:aba2ac5dd09d | 26 | #include "DmTouchCalibration.h" |
displaymodule | 0:aba2ac5dd09d | 27 | |
displaymodule | 0:aba2ac5dd09d | 28 | /****************************************************************************** |
displaymodule | 0:aba2ac5dd09d | 29 | * Typedefs and defines |
displaymodule | 0:aba2ac5dd09d | 30 | *****************************************************************************/ |
displaymodule | 0:aba2ac5dd09d | 31 | |
displaymodule | 0:aba2ac5dd09d | 32 | /* Note that there are restrictions on which platforms that can use printf |
displaymodule | 0:aba2ac5dd09d | 33 | in combinations with the DmTftLibrary. Some platforms (e.g. LPC1549 LPCXpresso) |
displaymodule | 0:aba2ac5dd09d | 34 | use the same pins for USBRX/USBTX and display control. Printing will |
displaymodule | 0:aba2ac5dd09d | 35 | cause the display to not work. Read more about this on the display's notebook |
displaymodule | 0:aba2ac5dd09d | 36 | page. */ |
displaymodule | 0:aba2ac5dd09d | 37 | //#define log(...) printf(__VA_ARGS__) |
displaymodule | 0:aba2ac5dd09d | 38 | #define log(...) |
displaymodule | 0:aba2ac5dd09d | 39 | |
displaymodule | 0:aba2ac5dd09d | 40 | #if 1 |
displaymodule | 0:aba2ac5dd09d | 41 | /* Displays without adapter */ |
displaymodule | 0:aba2ac5dd09d | 42 | #define DM_PIN_SPI_MOSI D11 |
displaymodule | 0:aba2ac5dd09d | 43 | #define DM_PIN_SPI_MISO D12 |
displaymodule | 0:aba2ac5dd09d | 44 | #define DM_PIN_SPI_SCLK D13 |
displaymodule | 0:aba2ac5dd09d | 45 | #define DM_PIN_CS_TOUCH D4 |
displaymodule | 0:aba2ac5dd09d | 46 | #define DM_PIN_CS_TFT D10 |
displaymodule | 0:aba2ac5dd09d | 47 | #define DM_PIN_CS_SDCARD D8 |
displaymodule | 0:aba2ac5dd09d | 48 | #define DM_PIN_CS_FLASH D6 |
displaymodule | 0:aba2ac5dd09d | 49 | #else |
displaymodule | 0:aba2ac5dd09d | 50 | /* Displays with adapter */ |
displaymodule | 0:aba2ac5dd09d | 51 | #define DM_PIN_SPI_MOSI A0 |
displaymodule | 0:aba2ac5dd09d | 52 | #define DM_PIN_SPI_MISO D9 |
displaymodule | 0:aba2ac5dd09d | 53 | #define DM_PIN_SPI_SCLK A1 |
displaymodule | 0:aba2ac5dd09d | 54 | #define DM_PIN_CS_TOUCH D8 |
displaymodule | 0:aba2ac5dd09d | 55 | #define DM_PIN_CS_TFT A3 |
displaymodule | 0:aba2ac5dd09d | 56 | #define DM_PIN_CS_SDCARD D10 |
displaymodule | 0:aba2ac5dd09d | 57 | #endif |
displaymodule | 0:aba2ac5dd09d | 58 | |
displaymodule | 0:aba2ac5dd09d | 59 | /****************************************************************************** |
displaymodule | 0:aba2ac5dd09d | 60 | * Local variables |
displaymodule | 0:aba2ac5dd09d | 61 | *****************************************************************************/ |
displaymodule | 0:aba2ac5dd09d | 62 | |
displaymodule | 0:aba2ac5dd09d | 63 | //DmTftIli9325 tft; /* DM_TFT28_103 and DM_TFT24_104 */ |
displaymodule | 0:aba2ac5dd09d | 64 | //DmTftIli9341 tft; /* DM_TFT28_105 */ |
displaymodule | 4:6bcad4fe23d6 | 65 | //DmTftSsd2119 tft; /* DM_TFT35_107 */ |
displaymodule | 4:6bcad4fe23d6 | 66 | DmTftRa8875 tft; /* DM_TFT43_108 and DM_TFT50_111 */ |
displaymodule | 0:aba2ac5dd09d | 67 | |
displaymodule | 0:aba2ac5dd09d | 68 | //DmTouch touch(DmTouch::DM_TFT28_103, DmTouch::Software); /* For LPC4088 QuickStart Board */ |
displaymodule | 0:aba2ac5dd09d | 69 | //DmTouch touch(DmTouch::DM_TFT28_103); |
displaymodule | 0:aba2ac5dd09d | 70 | //DmTouch touch(DmTouch::DM_TFT24_104, DmTouch::Software); /* For LPC4088 QuickStart Board */ |
displaymodule | 0:aba2ac5dd09d | 71 | //DmTouch touch(DmTouch::DM_TFT24_104); |
displaymodule | 0:aba2ac5dd09d | 72 | //DmTouch touch(DmTouch::DM_TFT28_105); |
displaymodule | 4:6bcad4fe23d6 | 73 | //DmTouch touch(DmTouch::DM_TFT35_107); |
displaymodule | 4:6bcad4fe23d6 | 74 | //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 | 4:6bcad4fe23d6 | 75 | DmTouch touch(DmTouch::DM_TFT50_111); |
displaymodule | 0:aba2ac5dd09d | 76 | |
displaymodule | 0:aba2ac5dd09d | 77 | DmTouchCalibration calibration = DmTouchCalibration(&tft, &touch); |
displaymodule | 0:aba2ac5dd09d | 78 | |
displaymodule | 0:aba2ac5dd09d | 79 | DigitalInOut csTouch(DM_PIN_CS_TOUCH, PIN_OUTPUT, PullUp, 1); |
displaymodule | 0:aba2ac5dd09d | 80 | DigitalInOut csDisplay(DM_PIN_CS_TFT, PIN_OUTPUT, PullUp, 1); |
displaymodule | 0:aba2ac5dd09d | 81 | DigitalInOut csSDCard(DM_PIN_CS_SDCARD, PIN_OUTPUT, PullUp, 1); |
displaymodule | 0:aba2ac5dd09d | 82 | #ifdef DM_PIN_CS_FLASH |
displaymodule | 0:aba2ac5dd09d | 83 | DigitalInOut csFlash(DM_PIN_CS_FLASH, PIN_OUTPUT, PullUp, 1); |
displaymodule | 0:aba2ac5dd09d | 84 | #endif |
displaymodule | 0:aba2ac5dd09d | 85 | |
displaymodule | 0:aba2ac5dd09d | 86 | bool calibrated = false; |
displaymodule | 0:aba2ac5dd09d | 87 | |
displaymodule | 0:aba2ac5dd09d | 88 | /****************************************************************************** |
displaymodule | 0:aba2ac5dd09d | 89 | * Global variables |
displaymodule | 0:aba2ac5dd09d | 90 | *****************************************************************************/ |
displaymodule | 0:aba2ac5dd09d | 91 | |
displaymodule | 0:aba2ac5dd09d | 92 | /****************************************************************************** |
displaymodule | 0:aba2ac5dd09d | 93 | * Local functions |
displaymodule | 0:aba2ac5dd09d | 94 | *****************************************************************************/ |
displaymodule | 0:aba2ac5dd09d | 95 | |
displaymodule | 0:aba2ac5dd09d | 96 | static void loop() { |
displaymodule | 0:aba2ac5dd09d | 97 | uint16_t x, y = 0; |
displaymodule | 0:aba2ac5dd09d | 98 | bool touched = false; |
displaymodule | 0:aba2ac5dd09d | 99 | |
displaymodule | 0:aba2ac5dd09d | 100 | if (!calibrated) { |
displaymodule | 0:aba2ac5dd09d | 101 | tft.drawString(5, 5, "Press and hold on cross"); |
displaymodule | 0:aba2ac5dd09d | 102 | tft.drawString(5, 25, "until it turns green. "); |
displaymodule | 4:6bcad4fe23d6 | 103 | |
displaymodule | 0:aba2ac5dd09d | 104 | Point displayRefPoint[5]; |
displaymodule | 0:aba2ac5dd09d | 105 | Point touchRefPoint[5]; |
displaymodule | 0:aba2ac5dd09d | 106 | if (calibration.getTouchReferencePoints(displayRefPoint, touchRefPoint, tft.width(), tft.height())) { |
displaymodule | 0:aba2ac5dd09d | 107 | CalibrationMatrix calibrationMatrix = calibration.calculateCalibrationMatrix(displayRefPoint, touchRefPoint); |
displaymodule | 0:aba2ac5dd09d | 108 | touch.setCalibrationMatrix(calibrationMatrix); |
displaymodule | 0:aba2ac5dd09d | 109 | tft.clearScreen(); |
displaymodule | 0:aba2ac5dd09d | 110 | calibration.drawCalibPoint(displayRefPoint[0].x, displayRefPoint[0].y); |
displaymodule | 0:aba2ac5dd09d | 111 | calibration.drawCalibPoint(displayRefPoint[1].x, displayRefPoint[1].y); |
displaymodule | 0:aba2ac5dd09d | 112 | calibration.drawCalibPoint(displayRefPoint[2].x, displayRefPoint[2].y); |
displaymodule | 0:aba2ac5dd09d | 113 | calibration.drawCalibPoint(displayRefPoint[3].x, displayRefPoint[3].y); |
displaymodule | 0:aba2ac5dd09d | 114 | calibration.drawCalibPoint(displayRefPoint[4].x, displayRefPoint[4].y); |
displaymodule | 0:aba2ac5dd09d | 115 | calibration.drawCalibration(calibrationMatrix); |
displaymodule | 0:aba2ac5dd09d | 116 | calibrated = true; |
displaymodule | 0:aba2ac5dd09d | 117 | } else { |
displaymodule | 0:aba2ac5dd09d | 118 | tft.clearScreen(); |
displaymodule | 0:aba2ac5dd09d | 119 | tft.drawString(5, 5, "Calibration failed"); |
displaymodule | 0:aba2ac5dd09d | 120 | tft.drawString(5, 25, "Please try again."); |
displaymodule | 0:aba2ac5dd09d | 121 | delay(2000); |
displaymodule | 0:aba2ac5dd09d | 122 | tft.clearScreen(); |
displaymodule | 0:aba2ac5dd09d | 123 | return; |
displaymodule | 0:aba2ac5dd09d | 124 | } |
displaymodule | 0:aba2ac5dd09d | 125 | } |
displaymodule | 0:aba2ac5dd09d | 126 | |
displaymodule | 0:aba2ac5dd09d | 127 | if (touch.isTouched()) { |
displaymodule | 0:aba2ac5dd09d | 128 | touch.readTouchData(x,y,touched); |
displaymodule | 0:aba2ac5dd09d | 129 | calibration.drawCalibPoint(x, y); |
displaymodule | 0:aba2ac5dd09d | 130 | } |
displaymodule | 0:aba2ac5dd09d | 131 | } |
displaymodule | 0:aba2ac5dd09d | 132 | |
displaymodule | 0:aba2ac5dd09d | 133 | /****************************************************************************** |
displaymodule | 0:aba2ac5dd09d | 134 | * Main |
displaymodule | 0:aba2ac5dd09d | 135 | *****************************************************************************/ |
displaymodule | 0:aba2ac5dd09d | 136 | |
displaymodule | 0:aba2ac5dd09d | 137 | int main() { |
displaymodule | 0:aba2ac5dd09d | 138 | tft.init(); |
displaymodule | 0:aba2ac5dd09d | 139 | touch.init(); |
displaymodule | 0:aba2ac5dd09d | 140 | while (1) { |
displaymodule | 0:aba2ac5dd09d | 141 | loop(); |
displaymodule | 0:aba2ac5dd09d | 142 | } |
displaymodule | 0:aba2ac5dd09d | 143 | } |
displaymodule | 0:aba2ac5dd09d | 144 |