Caiou
Dependents: LCD_Proj LCD_imagetest LCD_Proj_rtc
Fork of DmTftLibrary by
DmTouch.h@11:264e19992620, 2015-01-21 (annotated)
- Committer:
- displaymodule
- Date:
- Wed Jan 21 13:56:51 2015 +0000
- Revision:
- 11:264e19992620
- Parent:
- 10:d263094e666d
- Child:
- 14:2db7065edbec
add 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: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 | 11:264e19992620 | 29 | DM_TFT35_107 = 107, |
displaymodule | 11:264e19992620 | 30 | DM_TFT43_108 = 108, |
displaymodule | 11:264e19992620 | 31 | DM_TFT50_111 = 111 |
displaymodule | 7:6cd8c36cbdb3 | 32 | }; |
displaymodule | 7:6cd8c36cbdb3 | 33 | |
displaymodule | 7:6cd8c36cbdb3 | 34 | enum SpiMode { |
displaymodule | 7:6cd8c36cbdb3 | 35 | Auto, |
displaymodule | 7:6cd8c36cbdb3 | 36 | Software, |
displaymodule | 7:6cd8c36cbdb3 | 37 | Hardware |
displaymodule | 0:d6ff5fa503e8 | 38 | }; |
displaymodule | 11:264e19992620 | 39 | |
displaymodule | 11:264e19992620 | 40 | enum TouchId{ |
displaymodule | 11:264e19992620 | 41 | IC_8875 = 0x8875, |
displaymodule | 11:264e19992620 | 42 | IC_2046 = 0x2046 |
displaymodule | 11:264e19992620 | 43 | }; |
displaymodule | 0:d6ff5fa503e8 | 44 | |
displaymodule | 0:d6ff5fa503e8 | 45 | #if defined (DM_TOOLCHAIN_ARDUINO) |
displaymodule | 7:6cd8c36cbdb3 | 46 | DmTouch(Display disp, SpiMode spiMode=Auto, bool useIrq=true); |
displaymodule | 0:d6ff5fa503e8 | 47 | #elif defined (DM_TOOLCHAIN_MBED) |
displaymodule | 7:6cd8c36cbdb3 | 48 | DmTouch(Display disp, SpiMode spiMode=Hardware); |
displaymodule | 0:d6ff5fa503e8 | 49 | #endif |
displaymodule | 0:d6ff5fa503e8 | 50 | void init(); |
displaymodule | 0:d6ff5fa503e8 | 51 | void readTouchData(uint16_t& posX, uint16_t& posY, bool& touching); |
displaymodule | 7:6cd8c36cbdb3 | 52 | bool isTouched(); |
displaymodule | 7:6cd8c36cbdb3 | 53 | bool getMiddleXY(uint16_t &x, uint16_t &y); // Raw Touch Data, used for calibration |
displaymodule | 7:6cd8c36cbdb3 | 54 | void setCalibrationMatrix(CalibrationMatrix calibrationMatrix); |
displaymodule | 7:6cd8c36cbdb3 | 55 | void setPrecison(uint8_t samplesPerMeasurement); |
displaymodule | 7:6cd8c36cbdb3 | 56 | void waitForTouch(); |
displaymodule | 7:6cd8c36cbdb3 | 57 | void waitForTouchRelease(); |
displaymodule | 7:6cd8c36cbdb3 | 58 | uint32_t rescaleFactor() { return 1000000; }; |
displaymodule | 10:d263094e666d | 59 | Display getDisplay() { return _disp; }; |
displaymodule | 7:6cd8c36cbdb3 | 60 | |
displaymodule | 0:d6ff5fa503e8 | 61 | private: |
displaymodule | 0:d6ff5fa503e8 | 62 | void spiWrite(uint8_t data); |
displaymodule | 0:d6ff5fa503e8 | 63 | uint8_t spiRead(); |
displaymodule | 0:d6ff5fa503e8 | 64 | uint16_t readData12(uint8_t command); |
displaymodule | 0:d6ff5fa503e8 | 65 | void enableIrq(); |
displaymodule | 7:6cd8c36cbdb3 | 66 | void readRawData(uint16_t &x, uint16_t &y); |
displaymodule | 7:6cd8c36cbdb3 | 67 | void getAverageXY(uint16_t &x, uint16_t &y); |
displaymodule | 7:6cd8c36cbdb3 | 68 | uint16_t getDisplayCoordinateX(uint16_t x_touch, uint16_t y_touch); |
displaymodule | 7:6cd8c36cbdb3 | 69 | uint16_t getDisplayCoordinateY(uint16_t x_touch, uint16_t y_touch); |
displaymodule | 7:6cd8c36cbdb3 | 70 | uint16_t calculateMiddleValue(uint16_t values[], uint8_t count); |
displaymodule | 7:6cd8c36cbdb3 | 71 | bool isSampleValid(); |
displaymodule | 0:d6ff5fa503e8 | 72 | |
displaymodule | 10:d263094e666d | 73 | Display _disp; |
displaymodule | 10:d263094e666d | 74 | uint16_t _width, _height; |
displaymodule | 0:d6ff5fa503e8 | 75 | bool _hardwareSpi; |
displaymodule | 7:6cd8c36cbdb3 | 76 | uint8_t _samplesPerMeasurement; |
displaymodule | 7:6cd8c36cbdb3 | 77 | CalibrationMatrix _calibrationMatrix; |
displaymodule | 7:6cd8c36cbdb3 | 78 | uint8_t _cs, _clk, _mosi, _miso; |
displaymodule | 7:6cd8c36cbdb3 | 79 | int8_t _irq; |
displaymodule | 11:264e19992620 | 80 | uint16_t _touch_id; |
displaymodule | 0:d6ff5fa503e8 | 81 | |
displaymodule | 0:d6ff5fa503e8 | 82 | #if defined (DM_TOOLCHAIN_ARDUINO) |
displaymodule | 0:d6ff5fa503e8 | 83 | regtype *_pinDC, *_pinCS, *_pinCLK, *_pinMOSI, *_pinMISO, *_pinIrq; |
displaymodule | 0:d6ff5fa503e8 | 84 | regsize _bitmaskDC, _bitmaskCS, _bitmaskCLK, _bitmaskMOSI, _bitmaskMISO, _bitmaskIrq; |
displaymodule | 0:d6ff5fa503e8 | 85 | uint8_t _spiSettings; |
displaymodule | 0:d6ff5fa503e8 | 86 | #elif defined (DM_TOOLCHAIN_MBED) |
displaymodule | 3:02c19cbc707c | 87 | DigitalOut *_pinDC, *_pinCS, *_pinCLK, *_pinMOSI, *_led; |
displaymodule | 11:264e19992620 | 88 | DigitalIn *_pinMISO, *_pinIrq; |
displaymodule | 0:d6ff5fa503e8 | 89 | SPI *_spi; |
displaymodule | 0:d6ff5fa503e8 | 90 | #endif |
displaymodule | 0:d6ff5fa503e8 | 91 | |
displaymodule | 0:d6ff5fa503e8 | 92 | }; |
displaymodule | 0:d6ff5fa503e8 | 93 | #endif |