Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: dm_bubbles dm_calc dm_paint dm_sdcard_with_adapter ... more
DmTouch.h@7:6cd8c36cbdb3, 2014-07-04 (annotated)
- Committer:
- displaymodule
- Date:
- Fri Jul 04 09:26:32 2014 +0000
- Revision:
- 7:6cd8c36cbdb3
- Parent:
- 3:02c19cbc707c
- Child:
- 8:b24f01d148c4
Improved handling of touch calibration
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| displaymodule | 0:d6ff5fa503e8 | 1 | /********************************************************************************************** | 
| displaymodule | 0:d6ff5fa503e8 | 2 | Copyright (c) 2014 DisplayModule. All rights reserved. | 
| displaymodule | 0:d6ff5fa503e8 | 3 | |
| displaymodule | 0:d6ff5fa503e8 | 4 | Redistribution and use of this source code, part of this source code or any compiled binary | 
| displaymodule | 0:d6ff5fa503e8 | 5 | based on this source code is permitted as long as the above copyright notice and following | 
| displaymodule | 0:d6ff5fa503e8 | 6 | disclaimer is retained. | 
| displaymodule | 0:d6ff5fa503e8 | 7 | |
| displaymodule | 0:d6ff5fa503e8 | 8 | DISCLAIMER: | 
| displaymodule | 0:d6ff5fa503e8 | 9 | THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES | 
| displaymodule | 0:d6ff5fa503e8 | 10 | NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. | 
| displaymodule | 0:d6ff5fa503e8 | 11 | ********************************************************************************************/ | 
| displaymodule | 0:d6ff5fa503e8 | 12 | |
| displaymodule | 0:d6ff5fa503e8 | 13 | #ifndef DM_TOUCH_h | 
| displaymodule | 0:d6ff5fa503e8 | 14 | #define DM_TOUCH_h | 
| displaymodule | 0:d6ff5fa503e8 | 15 | |
| displaymodule | 0:d6ff5fa503e8 | 16 | #include "dm_platform.h" | 
| displaymodule | 0:d6ff5fa503e8 | 17 | |
| displaymodule | 7:6cd8c36cbdb3 | 18 | typedef struct calibrationMatrix { | 
| displaymodule | 7:6cd8c36cbdb3 | 19 | int32_t a, b, c, d, e, f; | 
| displaymodule | 7:6cd8c36cbdb3 | 20 | } CalibrationMatrix; | 
| displaymodule | 7:6cd8c36cbdb3 | 21 | |
| displaymodule | 0:d6ff5fa503e8 | 22 | class DmTouch | 
| displaymodule | 0:d6ff5fa503e8 | 23 | { | 
| displaymodule | 0:d6ff5fa503e8 | 24 | public: | 
| displaymodule | 0:d6ff5fa503e8 | 25 | enum Display { | 
| displaymodule | 7:6cd8c36cbdb3 | 26 | DM_TFT28_103 = 103, | 
| displaymodule | 7:6cd8c36cbdb3 | 27 | DM_TFT24_104 = 104, | 
| displaymodule | 7:6cd8c36cbdb3 | 28 | DM_TFT28_105 = 105, | 
| displaymodule | 7:6cd8c36cbdb3 | 29 | DM_TFT35_107 = 107 | 
| displaymodule | 7:6cd8c36cbdb3 | 30 | }; | 
| displaymodule | 7:6cd8c36cbdb3 | 31 | |
| displaymodule | 7:6cd8c36cbdb3 | 32 | enum SpiMode { | 
| displaymodule | 7:6cd8c36cbdb3 | 33 | Auto, | 
| displaymodule | 7:6cd8c36cbdb3 | 34 | Software, | 
| displaymodule | 7:6cd8c36cbdb3 | 35 | Hardware | 
| displaymodule | 0:d6ff5fa503e8 | 36 | }; | 
| displaymodule | 0:d6ff5fa503e8 | 37 | |
| displaymodule | 0:d6ff5fa503e8 | 38 | #if defined (DM_TOOLCHAIN_ARDUINO) | 
| displaymodule | 7:6cd8c36cbdb3 | 39 | DmTouch(Display disp, SpiMode spiMode=Auto, bool useIrq=true); | 
| displaymodule | 0:d6ff5fa503e8 | 40 | #elif defined (DM_TOOLCHAIN_MBED) | 
| displaymodule | 7:6cd8c36cbdb3 | 41 | DmTouch(Display disp, SpiMode spiMode=Hardware); | 
| displaymodule | 0:d6ff5fa503e8 | 42 | #endif | 
| displaymodule | 0:d6ff5fa503e8 | 43 | void init(); | 
| displaymodule | 0:d6ff5fa503e8 | 44 | void readTouchData(uint16_t& posX, uint16_t& posY, bool& touching); | 
| displaymodule | 7:6cd8c36cbdb3 | 45 | bool isTouched(); | 
| displaymodule | 7:6cd8c36cbdb3 | 46 | bool getMiddleXY(uint16_t &x, uint16_t &y); // Raw Touch Data, used for calibration | 
| displaymodule | 7:6cd8c36cbdb3 | 47 | void setCalibrationMatrix(CalibrationMatrix calibrationMatrix); | 
| displaymodule | 7:6cd8c36cbdb3 | 48 | void setPrecison(uint8_t samplesPerMeasurement); | 
| displaymodule | 7:6cd8c36cbdb3 | 49 | void waitForTouch(); | 
| displaymodule | 7:6cd8c36cbdb3 | 50 | void waitForTouchRelease(); | 
| displaymodule | 7:6cd8c36cbdb3 | 51 | uint32_t rescaleFactor() { return 1000000; }; | 
| displaymodule | 7:6cd8c36cbdb3 | 52 | |
| displaymodule | 0:d6ff5fa503e8 | 53 | private: | 
| displaymodule | 0:d6ff5fa503e8 | 54 | void spiWrite(uint8_t data); | 
| displaymodule | 0:d6ff5fa503e8 | 55 | uint8_t spiRead(); | 
| displaymodule | 0:d6ff5fa503e8 | 56 | uint16_t readData12(uint8_t command); | 
| displaymodule | 0:d6ff5fa503e8 | 57 | void enableIrq(); | 
| displaymodule | 7:6cd8c36cbdb3 | 58 | void readRawData(uint16_t &x, uint16_t &y); | 
| displaymodule | 7:6cd8c36cbdb3 | 59 | void getAverageXY(uint16_t &x, uint16_t &y); | 
| displaymodule | 7:6cd8c36cbdb3 | 60 | uint16_t getDisplayCoordinateX(uint16_t x_touch, uint16_t y_touch); | 
| displaymodule | 7:6cd8c36cbdb3 | 61 | uint16_t getDisplayCoordinateY(uint16_t x_touch, uint16_t y_touch); | 
| displaymodule | 7:6cd8c36cbdb3 | 62 | uint16_t calculateMiddleValue(uint16_t values[], uint8_t count); | 
| displaymodule | 7:6cd8c36cbdb3 | 63 | bool isSampleValid(); | 
| displaymodule | 0:d6ff5fa503e8 | 64 | |
| displaymodule | 0:d6ff5fa503e8 | 65 | bool _hardwareSpi; | 
| displaymodule | 7:6cd8c36cbdb3 | 66 | uint8_t _samplesPerMeasurement; | 
| displaymodule | 7:6cd8c36cbdb3 | 67 | CalibrationMatrix _calibrationMatrix; | 
| displaymodule | 7:6cd8c36cbdb3 | 68 | uint8_t _cs, _clk, _mosi, _miso; | 
| displaymodule | 7:6cd8c36cbdb3 | 69 | int8_t _irq; | 
| displaymodule | 0:d6ff5fa503e8 | 70 | |
| displaymodule | 0:d6ff5fa503e8 | 71 | #if defined (DM_TOOLCHAIN_ARDUINO) | 
| displaymodule | 0:d6ff5fa503e8 | 72 | regtype *_pinDC, *_pinCS, *_pinCLK, *_pinMOSI, *_pinMISO, *_pinIrq; | 
| displaymodule | 0:d6ff5fa503e8 | 73 | regsize _bitmaskDC, _bitmaskCS, _bitmaskCLK, _bitmaskMOSI, _bitmaskMISO, _bitmaskIrq; | 
| displaymodule | 0:d6ff5fa503e8 | 74 | uint8_t _spiSettings; | 
| displaymodule | 0:d6ff5fa503e8 | 75 | #elif defined (DM_TOOLCHAIN_MBED) | 
| displaymodule | 3:02c19cbc707c | 76 | DigitalOut *_pinDC, *_pinCS, *_pinCLK, *_pinMOSI, *_led; | 
| displaymodule | 3:02c19cbc707c | 77 | DigitalIn *_pinIrq, *_pinMISO; | 
| displaymodule | 0:d6ff5fa503e8 | 78 | SPI *_spi; | 
| displaymodule | 0:d6ff5fa503e8 | 79 | #endif | 
| displaymodule | 0:d6ff5fa503e8 | 80 | |
| displaymodule | 0:d6ff5fa503e8 | 81 | }; | 
| displaymodule | 0:d6ff5fa503e8 | 82 | #endif | 
 DisplayModule 1.8" TFT with SPI Interface
            DisplayModule 1.8" TFT with SPI Interface
         DisplayModule 2.2" TFT with 8-bit interface
            DisplayModule 2.2" TFT with 8-bit interface
         DisplayModule 2.8" 240x320 Touch TFT with 8-bit Interface
            DisplayModule 2.8" 240x320 Touch TFT with 8-bit Interface
         DisplayModule 2.4" 240x320 Touch TFT with 8-bit Interface
            DisplayModule 2.4" 240x320 Touch TFT with 8-bit Interface
         DisplayModule 2.8" 240x320 TFT LCD With Resistive Touch - SPI, 4MB Flash
            DisplayModule 2.8" 240x320 TFT LCD With Resistive Touch - SPI, 4MB Flash
         DisplayModule 3.5" 320x240 TFT LCD With Resistive Touch - SPI, 4MB Flash
            DisplayModule 3.5" 320x240 TFT LCD With Resistive Touch - SPI, 4MB Flash
         DisplayModule 4.3" 480x272 Arduino TFT Shield With Touch And SPI Interface
            DisplayModule 4.3" 480x272 Arduino TFT Shield With Touch And SPI Interface
         DisplayModule 5.0" 800x480 Arduino TFT Shield With Touch And SPI Interface
            DisplayModule 5.0" 800x480 Arduino TFT Shield With Touch And SPI Interface
         DisplayModule 2.8" 240x320 TFT  With Capacitive Touch
            DisplayModule 2.8" 240x320 TFT  With Capacitive Touch