acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
ModulesFT3267.tpp (4794B)
1 /** 2 * 3 * @license MIT License 4 * 5 * Copyright (c) 2022 micky 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy 8 * of this software and associated documentation files (the "Software"), to deal 9 * in the Software without restriction, including without limitation the rights 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 * copies of the Software, and to permit persons to whom the Software is 12 * furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included in all 15 * copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 * SOFTWARE. 24 * 25 * @file ModulesFT3267.tpp 26 * @author Micky (513673326@qq.com) 27 * @date 2022-12-14 28 * 29 */ 30 31 #if defined(ARDUINO) 32 #include <Arduino.h> 33 #endif 34 #include "REG/FT5x06Constants.h" 35 #include "TouchLibCommon.tpp" 36 #include "TouchLibInterface.hpp" 37 38 class TouchLibFT3267 : public TouchLibCommon<TouchLibFT3267>, public TouchLibInterface, public TouchLibGesture { 39 friend class TouchLibCommon<TouchLibFT3267>; 40 41 42 typedef enum { 43 ft3267_gesture_none = 0x00, 44 ft3267_gesture_move_up = 0x10, 45 ft3267_gesture_move_left = 0x14, 46 ft3267_gesture_move_down = 0x18, 47 ft3267_gesture_move_right = 0x1c, 48 ft3267_gesture_zoom_in = 0x48, 49 ft3267_gesture_zoom_out = 0x49, 50 } ft3267_gesture_t; 51 52 public: 53 #if defined(ARDUINO) 54 TouchLibFT3267(TwoWire &w, int sda = SDA, int scl = SCL, uint8_t addr = FT3267_SLAVE_ADDRESS, int rst = -1) { 55 __wire = &w; 56 __sda = sda; 57 __scl = scl; 58 __addr = addr; 59 __rst = rst; 60 } 61 #endif 62 63 TouchLibFT3267() { 64 #if defined(ARDUINO) 65 __wire = &Wire; 66 __sda = SDA; 67 __scl = SCL; 68 __rst = -1; 69 #endif 70 __addr = FT3267_SLAVE_ADDRESS; 71 } 72 73 ~TouchLibFT3267() { 74 log_i("~TouchLibFT3267"); 75 deinit(); 76 } 77 78 bool init() { 79 if (begin()) { 80 // Valid touching detect threshold 81 this->writeRegister(FT5x06_ID_G_THGROUP, 70); 82 83 // valid touching peak detect threshold 84 this->writeRegister(FT5x06_ID_G_THPEAK, 60); 85 86 // Touch focus threshold 87 this->writeRegister(FT5x06_ID_G_THCAL, 16); 88 89 // threshold when there is surface water 90 this->writeRegister(FT5x06_ID_G_THWATER, 60); 91 92 // threshold of temperature compensation 93 this->writeRegister(FT5x06_ID_G_THTEMP, 10); 94 95 // Touch difference threshold 96 this->writeRegister(FT5x06_ID_G_THDIFF, 20); 97 98 // Delay to enter 'Monitor' status (s) 99 this->writeRegister(FT5x06_ID_G_TIME_ENTER_MONITOR, 2); 100 101 // Period of 'Active' status (ms) 102 this->writeRegister(FT5x06_ID_G_PERIODACTIVE, 12); 103 104 // Timer to enter 'idle' when in 'Monitor' (ms) 105 this->writeRegister(FT5x06_ID_G_PERIODMONITOR, 40); 106 107 return 1; 108 } 109 return 0; 110 } 111 112 void deinit() { end(); } 113 114 bool enableSleep() { return 0; } 115 116 bool read() { 117 this->readRegister(FT5x06_TOUCH_POINTS, &raw_data, 1); 118 return (raw_data & 0x0f) > 0; 119 } 120 121 uint8_t getPointNum() { return raw_data & 0x0f; } 122 123 TP_Point getPoint(uint8_t n) { 124 TP_Point t; 125 uint8_t tmp[4] = {0}; 126 switch (n) { 127 case 0: 128 this->readRegister(FT5x06_TOUCH1_XH, tmp, sizeof(tmp)); 129 break; 130 case 1: 131 this->readRegister(FT5x06_TOUCH2_XH, tmp, sizeof(tmp)); 132 break; 133 case 2: 134 this->readRegister(FT5x06_TOUCH3_XH, tmp, sizeof(tmp)); 135 break; 136 case 3: 137 this->readRegister(FT5x06_TOUCH4_XH, tmp, sizeof(tmp)); 138 break; 139 case 4: 140 this->readRegister(FT5x06_TOUCH5_XH, tmp, sizeof(tmp)); 141 break; 142 default: 143 log_i("The parameter range of getPoint is between 0 and 4."); 144 break; 145 } 146 147 t.x = ((tmp[0] & 0x0f) << 8) + tmp[1]; 148 t.y = ((tmp[2] & 0x0f) << 8) + tmp[3]; 149 t.id = n; 150 151 if (rotation == 0) { 152 } else if (rotation == 1) { 153 uint16_t tmp = t.x; 154 t.x = t.y; 155 t.y = tmp; 156 } 157 return t; 158 } 159 160 void setRotation(uint8_t r) { rotation = r % 4; } 161 162 uint8_t getRotation() { return rotation; } 163 164 uint8_t getGesture(void) { 165 uint8_t tmp = 0; 166 this->readRegister(FT5x06_GESTURE_ID, &tmp, 1); 167 return tmp; 168 } 169 170 private: 171 bool isEnableGesture() { return 0; } 172 bool enableGesture() { return 0; } 173 bool disableGesture() { return 0; } 174 175 protected: 176 bool initImpl() { return true; } 177 uint8_t raw_data = 0; 178 uint8_t rotation = 0; 179 };