PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

76 Zeilen
2.5KB

  1. /* Touchscreen library for XPT2046 Touch Controller Chip
  2. * Copyright (c) 2015, Paul Stoffregen, paul@pjrc.com
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice, development funding notice, and this permission
  12. * notice shall be included in all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. * THE SOFTWARE.
  21. */
  22. #ifndef _XPT2046_Touchscreen_h_
  23. #define _XPT2046_Touchscreen_h_
  24. #include "Arduino.h"
  25. #include <SPI.h>
  26. #if ARDUINO < 10600
  27. #error "Arduino 1.6.0 or later (SPI library) is required"
  28. #endif
  29. class TS_Point {
  30. public:
  31. TS_Point(void) : x(0), y(0), z(0) {}
  32. TS_Point(int16_t x, int16_t y, int16_t z) : x(x), y(y), z(z) {}
  33. bool operator==(TS_Point p) { return ((p.x == x) && (p.y == y) && (p.z == z)); }
  34. bool operator!=(TS_Point p) { return ((p.x != x) || (p.y != y) || (p.z != z)); }
  35. int16_t x, y, z;
  36. };
  37. class XPT2046_Touchscreen {
  38. public:
  39. constexpr XPT2046_Touchscreen(uint8_t cspin, uint8_t tirq=255)
  40. : csPin(cspin), tirqPin(tirq) { }
  41. bool begin();
  42. TS_Point getPoint();
  43. bool tirqTouched();
  44. bool touched();
  45. void readData(uint16_t *x, uint16_t *y, uint8_t *z);
  46. bool bufferEmpty();
  47. uint8_t bufferSize() { return 1; }
  48. void setRotation(uint8_t n) { rotation = n % 4; }
  49. // protected:
  50. volatile bool isrWake=true;
  51. private:
  52. void update();
  53. uint8_t csPin, tirqPin, rotation=1;
  54. int16_t xraw=0, yraw=0, zraw=0;
  55. uint32_t msraw=0x80000000;
  56. };
  57. #ifndef ISR_PREFIX
  58. #if defined(ESP8266)
  59. #define ISR_PREFIX ICACHE_RAM_ATTR
  60. #elif defined(ESP32)
  61. // TODO: should this also be ICACHE_RAM_ATTR ??
  62. #define ISR_PREFIX IRAM_ATTR
  63. #else
  64. #define ISR_PREFIX
  65. #endif
  66. #endif
  67. #endif