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

Touch.h (2209B)

      1  // Coded by Bodmer 10/2/18, see license in root directory.
      2  // This is part of the TFT_eSPI class and is associated with the Touch Screen handlers
      3 
      4  public:
      5            // Get raw x,y ADC values from touch controller
      6   uint8_t  getTouchRaw(uint16_t *x, uint16_t *y);
      7            // Get raw z (i.e. pressure) ADC value from touch controller
      8   uint16_t getTouchRawZ(void);
      9            // Convert raw x,y values to calibrated and correctly rotated screen coordinates
     10   void     convertRawXY(uint16_t *x, uint16_t *y);
     11            // Get the screen touch coordinates, returns true if screen has been touched
     12            // if the touch coordinates are off screen then x and y are not updated
     13            // The returned value can be treated as a bool type, false or 0 means touch not detected
     14            // In future the function may return an 8 "quality" (jitter) value.
     15   uint8_t  getTouch(uint16_t *x, uint16_t *y, uint16_t threshold = 600);
     16 
     17            // Run screen calibration and test, report calibration values to the serial port
     18   void     calibrateTouch(uint16_t *data, uint32_t color_fg, uint32_t color_bg, uint8_t size);
     19            // Set the screen calibration values
     20   void     setTouch(uint16_t *data);
     21 
     22  private:
     23            // Legacy support only - deprecated TODO: delete
     24   void     spi_begin_touch();
     25   void     spi_end_touch();
     26 
     27            // Handlers for the touch controller bus settings
     28   inline void begin_touch_read_write() __attribute__((always_inline));
     29   inline void end_touch_read_write()   __attribute__((always_inline));
     30 
     31            // Private function to validate a touch, allow settle time and reduce spurious coordinates
     32   uint8_t  validTouch(uint16_t *x, uint16_t *y, uint16_t threshold = 600);
     33 
     34            // Initialise with example calibration values so processor does not crash if setTouch() not called in setup()
     35   uint16_t touchCalibration_x0 = 300, touchCalibration_x1 = 3600, touchCalibration_y0 = 300, touchCalibration_y1 = 3600;
     36   uint8_t  touchCalibration_rotate = 1, touchCalibration_invert_x = 2, touchCalibration_invert_y = 0;
     37 
     38   uint32_t _pressTime;        // Press and hold time-out
     39   uint16_t _pressX, _pressY;  // For future use (last sampled calibrated coordinates)