Driver Library for our displays
Dependents: dm_bubbles dm_calc dm_paint dm_sdcard_with_adapter ... more
DmTouch.h
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 #ifndef DM_TOUCH_h 00014 #define DM_TOUCH_h 00015 00016 #include "dm_platform.h" 00017 00018 typedef struct calibrationMatrix { 00019 int32_t a, b, c, d, e, f; 00020 } CalibrationMatrix; 00021 00022 class DmTouch 00023 { 00024 public: 00025 enum Display { 00026 DM_TFT28_103 = 103, 00027 DM_TFT24_104 = 104, 00028 DM_TFT28_105 = 105, 00029 DM_TFT35_107 = 107, 00030 DM_TFT43_108 = 108, 00031 DM_TFT50_111 = 111 00032 }; 00033 00034 enum SpiMode { 00035 Auto, 00036 Software, 00037 Hardware 00038 }; 00039 00040 enum TouchId{ 00041 IC_8875 = 0x8875, 00042 IC_2046 = 0x2046 00043 }; 00044 00045 #if defined (DM_TOOLCHAIN_ARDUINO) 00046 DmTouch(Display disp, SpiMode spiMode=Auto, bool useIrq=true); 00047 #elif defined (DM_TOOLCHAIN_MBED) 00048 DmTouch(Display disp, PinName mosi=D11, PinName miso=D12, PinName clk=D13); 00049 #endif 00050 void init(); 00051 void readTouchData(uint16_t& posX, uint16_t& posY, bool& touching); 00052 bool isTouched(); 00053 bool getMiddleXY(uint16_t &x, uint16_t &y); // Raw Touch Data, used for calibration 00054 void setCalibrationMatrix(CalibrationMatrix calibrationMatrix); 00055 void setPrecison(uint8_t samplesPerMeasurement); 00056 void waitForTouch(); 00057 void waitForTouchRelease(); 00058 uint32_t rescaleFactor() { return 1000000; }; 00059 Display getDisplay() { return _disp; }; 00060 00061 private: 00062 void spiWrite(uint8_t data); 00063 uint8_t spiRead(); 00064 uint16_t readData12(uint8_t command); 00065 void enableIrq(); 00066 void readRawData(uint16_t &x, uint16_t &y); 00067 void getAverageXY(uint16_t &x, uint16_t &y); 00068 uint16_t getDisplayCoordinateX(uint16_t x_touch, uint16_t y_touch); 00069 uint16_t getDisplayCoordinateY(uint16_t x_touch, uint16_t y_touch); 00070 uint16_t calculateMiddleValue(uint16_t values[], uint8_t count); 00071 bool isSampleValid(); 00072 00073 Display _disp; 00074 uint16_t _width, _height; 00075 bool _hardwareSpi; 00076 uint8_t _samplesPerMeasurement; 00077 CalibrationMatrix _calibrationMatrix; 00078 uint16_t _touch_id; 00079 00080 #if defined (DM_TOOLCHAIN_ARDUINO) 00081 uint8_t _cs, _clk, _mosi, _miso,_irq;; 00082 regtype *_pinDC, *_pinCS, *_pinCLK, *_pinMOSI, *_pinMISO, *_pinIrq; 00083 regsize _bitmaskDC, _bitmaskCS, _bitmaskCLK, _bitmaskMOSI, _bitmaskMISO, _bitmaskIrq; 00084 uint8_t _spiSettings; 00085 #elif defined (DM_TOOLCHAIN_MBED) 00086 PinName _cs, _clk, _mosi, _miso, _irq; 00087 DigitalOut *_pinDC, *_pinCS, *_pinCLK, *_pinMOSI, *_led; 00088 DigitalIn *_pinMISO, *_pinIrq; 00089 SPI *_spi; 00090 #endif 00091 00092 }; 00093 #endif
Generated on Wed Jul 13 2022 04:21:40 by 1.7.2