PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

157 líneas
4.0KB

  1. /***************************************************
  2. This is a library for the Adafruit STMPE610 Resistive
  3. touch screen controller breakout
  4. ----> http://www.adafruit.com/products/1571
  5. Check out the links above for our tutorials and wiring diagrams
  6. These breakouts use SPI or I2C to communicate
  7. Adafruit invests time and resources providing this open source code,
  8. please support Adafruit and open-source hardware by purchasing
  9. products from Adafruit!
  10. Written by Limor Fried/Ladyada for Adafruit Industries.
  11. MIT license, all text above must be included in any redistribution
  12. ****************************************************/
  13. #ifndef _ADAFRUIT_STMPE610H_
  14. #define _ADAFRUIT_STMPE610H_
  15. #if ARDUINO >= 100
  16. #include "Arduino.h"
  17. #else
  18. #include "WProgram.h"
  19. #endif
  20. #include <Wire.h>
  21. #define STMPE_ADDR 0x41
  22. #define STMPE_SYS_CTRL1 0x03
  23. #define STMPE_SYS_CTRL1_RESET 0x02
  24. #define STMPE_SYS_CTRL2 0x04
  25. #define STMPE_TSC_CTRL 0x40
  26. #define STMPE_TSC_CTRL_EN 0x01
  27. #define STMPE_TSC_CTRL_XYZ 0x00
  28. #define STMPE_TSC_CTRL_XY 0x02
  29. #define STMPE_INT_CTRL 0x09
  30. #define STMPE_INT_CTRL_POL_HIGH 0x04
  31. #define STMPE_INT_CTRL_POL_LOW 0x00
  32. #define STMPE_INT_CTRL_EDGE 0x02
  33. #define STMPE_INT_CTRL_LEVEL 0x00
  34. #define STMPE_INT_CTRL_ENABLE 0x01
  35. #define STMPE_INT_CTRL_DISABLE 0x00
  36. #define STMPE_INT_EN 0x0A
  37. #define STMPE_INT_EN_TOUCHDET 0x01
  38. #define STMPE_INT_EN_FIFOTH 0x02
  39. #define STMPE_INT_EN_FIFOOF 0x04
  40. #define STMPE_INT_EN_FIFOFULL 0x08
  41. #define STMPE_INT_EN_FIFOEMPTY 0x10
  42. #define STMPE_INT_EN_ADC 0x40
  43. #define STMPE_INT_EN_GPIO 0x80
  44. #define STMPE_INT_STA 0x0B
  45. #define STMPE_INT_STA_TOUCHDET 0x01
  46. #define STMPE_ADC_CTRL1 0x20
  47. #define STMPE_ADC_CTRL1_12BIT 0x08
  48. #define STMPE_ADC_CTRL1_10BIT 0x00
  49. #define STMPE_ADC_CTRL2 0x21
  50. #define STMPE_ADC_CTRL2_1_625MHZ 0x00
  51. #define STMPE_ADC_CTRL2_3_25MHZ 0x01
  52. #define STMPE_ADC_CTRL2_6_5MHZ 0x02
  53. #define STMPE_TSC_CFG 0x41
  54. #define STMPE_TSC_CFG_1SAMPLE 0x00
  55. #define STMPE_TSC_CFG_2SAMPLE 0x40
  56. #define STMPE_TSC_CFG_4SAMPLE 0x80
  57. #define STMPE_TSC_CFG_8SAMPLE 0xC0
  58. #define STMPE_TSC_CFG_DELAY_10US 0x00
  59. #define STMPE_TSC_CFG_DELAY_50US 0x08
  60. #define STMPE_TSC_CFG_DELAY_100US 0x10
  61. #define STMPE_TSC_CFG_DELAY_500US 0x18
  62. #define STMPE_TSC_CFG_DELAY_1MS 0x20
  63. #define STMPE_TSC_CFG_DELAY_5MS 0x28
  64. #define STMPE_TSC_CFG_DELAY_10MS 0x30
  65. #define STMPE_TSC_CFG_DELAY_50MS 0x38
  66. #define STMPE_TSC_CFG_SETTLE_10US 0x00
  67. #define STMPE_TSC_CFG_SETTLE_100US 0x01
  68. #define STMPE_TSC_CFG_SETTLE_500US 0x02
  69. #define STMPE_TSC_CFG_SETTLE_1MS 0x03
  70. #define STMPE_TSC_CFG_SETTLE_5MS 0x04
  71. #define STMPE_TSC_CFG_SETTLE_10MS 0x05
  72. #define STMPE_TSC_CFG_SETTLE_50MS 0x06
  73. #define STMPE_TSC_CFG_SETTLE_100MS 0x07
  74. #define STMPE_FIFO_TH 0x4A
  75. #define STMPE_FIFO_SIZE 0x4C
  76. #define STMPE_FIFO_STA 0x4B
  77. #define STMPE_FIFO_STA_RESET 0x01
  78. #define STMPE_FIFO_STA_OFLOW 0x80
  79. #define STMPE_FIFO_STA_FULL 0x40
  80. #define STMPE_FIFO_STA_EMPTY 0x20
  81. #define STMPE_FIFO_STA_THTRIG 0x10
  82. #define STMPE_TSC_I_DRIVE 0x58
  83. #define STMPE_TSC_I_DRIVE_20MA 0x00
  84. #define STMPE_TSC_I_DRIVE_50MA 0x01
  85. #define STMPE_TSC_DATA_X 0x4D
  86. #define STMPE_TSC_DATA_Y 0x4F
  87. #define STMPE_TSC_FRACTION_Z 0x56
  88. #define STMPE_GPIO_SET_PIN 0x10
  89. #define STMPE_GPIO_CLR_PIN 0x11
  90. #define STMPE_GPIO_DIR 0x13
  91. #define STMPE_GPIO_ALT_FUNCT 0x17
  92. class TS_Point {
  93. public:
  94. TS_Point(void);
  95. TS_Point(int16_t x, int16_t y, int16_t z);
  96. bool operator==(TS_Point);
  97. bool operator!=(TS_Point);
  98. int16_t x, y, z;
  99. };
  100. class Adafruit_STMPE610{
  101. public:
  102. Adafruit_STMPE610(uint8_t cspin, uint8_t mosipin, uint8_t misopin, uint8_t clkpin);
  103. Adafruit_STMPE610(uint8_t cs);
  104. Adafruit_STMPE610(void);
  105. boolean begin(uint8_t i2caddr = STMPE_ADDR);
  106. void writeRegister8(uint8_t reg, uint8_t val);
  107. uint16_t readRegister16(uint8_t reg);
  108. uint8_t readRegister8(uint8_t reg);
  109. void readData(uint16_t *x, uint16_t *y, uint8_t *z);
  110. uint16_t getVersion();
  111. boolean touched(void);
  112. boolean bufferEmpty(void);
  113. uint8_t bufferSize(void);
  114. TS_Point getPoint(void);
  115. private:
  116. uint8_t spiIn();
  117. void spiOut(uint8_t x);
  118. int8_t _CS, _MOSI, _MISO, _CLK;
  119. uint8_t _i2caddr;
  120. int m_spiMode;
  121. };
  122. #endif