First Commit
This commit is contained in:
388
libraries/Adafruit_STMPE610/Adafruit_STMPE610.cpp
Normal file
388
libraries/Adafruit_STMPE610/Adafruit_STMPE610.cpp
Normal file
@@ -0,0 +1,388 @@
|
||||
/*!
|
||||
*
|
||||
* @file Adafruit_STMPE610.cpp
|
||||
*
|
||||
* @mainpage Adafruit STMPE610 Resistive Touch Screen Controller
|
||||
*
|
||||
* @section intro_sec Introduction
|
||||
*
|
||||
* This is a library for the Adafruit STMPE610 Resistive
|
||||
* touch screen controller breakout
|
||||
* ----> http://www.adafruit.com/products/1571
|
||||
*
|
||||
* Check out the links above for our tutorials and wiring diagrams
|
||||
* These breakouts use SPI or I2C to communicate
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* @section author Author
|
||||
*
|
||||
* Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
*
|
||||
* @section license License
|
||||
*
|
||||
* MIT license, all text above must be included in any redistribution
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
|
||||
#include "Adafruit_STMPE610.h"
|
||||
|
||||
static SPISettings mySPISettings;
|
||||
|
||||
/*!
|
||||
* @brief Instantiates a new STMPE610 class using bitbang SPI
|
||||
* @param cspin
|
||||
* CS pin
|
||||
* @param mosipin
|
||||
* MOSI pin
|
||||
* @param misopin
|
||||
* MISO pin
|
||||
* @param clkpin
|
||||
* CLK pin
|
||||
*/
|
||||
Adafruit_STMPE610::Adafruit_STMPE610(uint8_t cspin, uint8_t mosipin,
|
||||
uint8_t misopin, uint8_t clkpin) {
|
||||
_CS = cspin;
|
||||
_MOSI = mosipin;
|
||||
_MISO = misopin;
|
||||
_CLK = clkpin;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Instantiates a new STMPE610 using provided SPI
|
||||
* @param cspin
|
||||
* CS pin
|
||||
* @param *theSPI
|
||||
* spi object
|
||||
*/
|
||||
Adafruit_STMPE610::Adafruit_STMPE610(uint8_t cspin, SPIClass *theSPI) {
|
||||
_CS = cspin;
|
||||
_MOSI = _MISO = _CLK = -1;
|
||||
_spi = theSPI;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Instantiates a new STMPE610 using provided Wire
|
||||
* @param *theWire
|
||||
* wire object
|
||||
*/
|
||||
Adafruit_STMPE610::Adafruit_STMPE610(TwoWire *theWire) {
|
||||
_CS = _MISO = _MOSI = _CLK = -1;
|
||||
_wire = theWire;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Setups the HW
|
||||
* @param i2caddr
|
||||
* I2C address (defaults to STMPE_ADDR)
|
||||
* @return True if process is successful
|
||||
*/
|
||||
boolean Adafruit_STMPE610::begin(uint8_t i2caddr) {
|
||||
if (_CS != -1 && _CLK == -1) {
|
||||
// hardware SPI
|
||||
pinMode(_CS, OUTPUT);
|
||||
digitalWrite(_CS, HIGH);
|
||||
|
||||
_spi->begin();
|
||||
mySPISettings = SPISettings(1000000, MSBFIRST, SPI_MODE0);
|
||||
m_spiMode = SPI_MODE0;
|
||||
} else if (_CS != -1) {
|
||||
// software SPI
|
||||
pinMode(_CLK, OUTPUT);
|
||||
pinMode(_CS, OUTPUT);
|
||||
pinMode(_MOSI, OUTPUT);
|
||||
pinMode(_MISO, INPUT);
|
||||
} else {
|
||||
_wire->begin();
|
||||
_i2caddr = i2caddr;
|
||||
}
|
||||
|
||||
// try mode0
|
||||
if (getVersion() != 0x811) {
|
||||
if (_CS != -1 && _CLK == -1) {
|
||||
// Serial.println("try MODE1");
|
||||
mySPISettings = SPISettings(1000000, MSBFIRST, SPI_MODE1);
|
||||
m_spiMode = SPI_MODE1;
|
||||
|
||||
if (getVersion() != 0x811) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
writeRegister8(STMPE_SYS_CTRL1, STMPE_SYS_CTRL1_RESET);
|
||||
delay(10);
|
||||
|
||||
for (uint8_t i = 0; i < 65; i++) {
|
||||
readRegister8(i);
|
||||
}
|
||||
|
||||
writeRegister8(STMPE_SYS_CTRL2, 0x0); // turn on clocks!
|
||||
writeRegister8(STMPE_TSC_CTRL,
|
||||
STMPE_TSC_CTRL_XYZ | STMPE_TSC_CTRL_EN); // XYZ and enable!
|
||||
// Serial.println(readRegister8(STMPE_TSC_CTRL), HEX);
|
||||
writeRegister8(STMPE_INT_EN, STMPE_INT_EN_TOUCHDET);
|
||||
writeRegister8(STMPE_ADC_CTRL1, STMPE_ADC_CTRL1_10BIT |
|
||||
(0x6 << 4)); // 96 clocks per conversion
|
||||
writeRegister8(STMPE_ADC_CTRL2, STMPE_ADC_CTRL2_6_5MHZ);
|
||||
writeRegister8(STMPE_TSC_CFG, STMPE_TSC_CFG_4SAMPLE |
|
||||
STMPE_TSC_CFG_DELAY_1MS |
|
||||
STMPE_TSC_CFG_SETTLE_5MS);
|
||||
writeRegister8(STMPE_TSC_FRACTION_Z, 0x6);
|
||||
writeRegister8(STMPE_FIFO_TH, 1);
|
||||
writeRegister8(STMPE_FIFO_STA, STMPE_FIFO_STA_RESET);
|
||||
writeRegister8(STMPE_FIFO_STA, 0); // unreset
|
||||
writeRegister8(STMPE_TSC_I_DRIVE, STMPE_TSC_I_DRIVE_50MA);
|
||||
writeRegister8(STMPE_INT_STA, 0xFF); // reset all ints
|
||||
writeRegister8(STMPE_INT_CTRL,
|
||||
STMPE_INT_CTRL_POL_HIGH | STMPE_INT_CTRL_ENABLE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Returns true if touched, false otherwise
|
||||
* @return True if if touched, false otherwise
|
||||
*/
|
||||
boolean Adafruit_STMPE610::touched() {
|
||||
return (readRegister8(STMPE_TSC_CTRL) & 0x80);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Checks if buffer is empty
|
||||
* @return True if empty, false otherwise
|
||||
*/
|
||||
boolean Adafruit_STMPE610::bufferEmpty() {
|
||||
return (readRegister8(STMPE_FIFO_STA) & STMPE_FIFO_STA_EMPTY);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Returns the FIFO buffer size
|
||||
* @return The FIFO buffer size
|
||||
*/
|
||||
uint8_t Adafruit_STMPE610::bufferSize() {
|
||||
return readRegister8(STMPE_FIFO_SIZE);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Returns the STMPE610 version number
|
||||
* @return The STMPE610 version number
|
||||
*/
|
||||
uint16_t Adafruit_STMPE610::getVersion() {
|
||||
uint16_t v;
|
||||
// Serial.print("get version");
|
||||
v = readRegister8(0);
|
||||
v <<= 8;
|
||||
v |= readRegister8(1);
|
||||
// Serial.print("Version: 0x"); Serial.println(v, HEX);
|
||||
return v;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Reads touchscreen data
|
||||
* @param *x
|
||||
* The x coordinate
|
||||
* @param *y
|
||||
* The y coordinate
|
||||
* @param *z
|
||||
* The z coordinate
|
||||
*/
|
||||
void Adafruit_STMPE610::readData(uint16_t *x, uint16_t *y, uint8_t *z) {
|
||||
uint8_t data[4];
|
||||
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
data[i] = readRegister8(0xD7); // _spi->transfer(0x00);
|
||||
// Serial.print("0x"); Serial.print(data[i], HEX); Serial.print(" / ");
|
||||
}
|
||||
*x = data[0];
|
||||
*x <<= 4;
|
||||
*x |= (data[1] >> 4);
|
||||
*y = data[1] & 0x0F;
|
||||
*y <<= 8;
|
||||
*y |= data[2];
|
||||
*z = data[3];
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Returns point for touchscreen data
|
||||
* @return The touch point using TS_Point
|
||||
*/
|
||||
TS_Point Adafruit_STMPE610::getPoint() {
|
||||
uint16_t x = 0, y = 0;
|
||||
uint8_t z;
|
||||
|
||||
/* Making sure that we are reading all data before leaving */
|
||||
while (!bufferEmpty()) {
|
||||
readData(&x, &y, &z);
|
||||
}
|
||||
|
||||
if (bufferEmpty())
|
||||
writeRegister8(STMPE_INT_STA, 0xFF); // reset all ints
|
||||
|
||||
return TS_Point(x, y, z);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Reads SPI data
|
||||
*/
|
||||
uint8_t Adafruit_STMPE610::spiIn() {
|
||||
if (_CLK == -1) {
|
||||
uint8_t d = _spi->transfer(0);
|
||||
return d;
|
||||
} else
|
||||
return shiftIn(_MISO, _CLK, MSBFIRST);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Sends data through SPI
|
||||
* @param x
|
||||
* Data to send (one byte)
|
||||
*/
|
||||
void Adafruit_STMPE610::spiOut(uint8_t x) {
|
||||
if (_CLK == -1) {
|
||||
_spi->transfer(x);
|
||||
} else
|
||||
shiftOut(_MOSI, _CLK, MSBFIRST, x);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Reads 8bit of data from specified register
|
||||
* @param reg
|
||||
* The register
|
||||
* @return Data in the register
|
||||
*/
|
||||
uint8_t Adafruit_STMPE610::readRegister8(uint8_t reg) {
|
||||
uint8_t x;
|
||||
if (_CS == -1) {
|
||||
// use i2c
|
||||
_wire->beginTransmission(_i2caddr);
|
||||
_wire->write((byte)reg);
|
||||
_wire->endTransmission();
|
||||
_wire->requestFrom(_i2caddr, (byte)1);
|
||||
x = _wire->read();
|
||||
|
||||
// Serial.print("$"); Serial.print(reg, HEX);
|
||||
// Serial.print(": 0x"); Serial.println(x, HEX);
|
||||
} else {
|
||||
if (_CLK == -1)
|
||||
_spi->beginTransaction(mySPISettings);
|
||||
|
||||
digitalWrite(_CS, LOW);
|
||||
spiOut(0x80 | reg);
|
||||
spiOut(0x00);
|
||||
x = spiIn();
|
||||
digitalWrite(_CS, HIGH);
|
||||
|
||||
if (_CLK == -1)
|
||||
_spi->endTransaction();
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Reads 16 bits of data from specified register
|
||||
* @param reg
|
||||
* The register
|
||||
* @return Data in the register
|
||||
*/
|
||||
uint16_t Adafruit_STMPE610::readRegister16(uint8_t reg) {
|
||||
uint16_t x = 0;
|
||||
if (_CS == -1) {
|
||||
// use i2c
|
||||
_wire->beginTransmission(_i2caddr);
|
||||
_wire->write((byte)reg);
|
||||
_wire->endTransmission();
|
||||
_wire->requestFrom(_i2caddr, (byte)2);
|
||||
x = _wire->read();
|
||||
x <<= 8;
|
||||
x |= _wire->read();
|
||||
}
|
||||
if (_CLK == -1) {
|
||||
// hardware SPI
|
||||
if (_CLK == -1)
|
||||
_spi->beginTransaction(mySPISettings);
|
||||
digitalWrite(_CS, LOW);
|
||||
spiOut(0x80 | reg);
|
||||
spiOut(0x00);
|
||||
x = spiIn();
|
||||
x <<= 8;
|
||||
x |= spiIn();
|
||||
digitalWrite(_CS, HIGH);
|
||||
if (_CLK == -1)
|
||||
_spi->endTransaction();
|
||||
}
|
||||
|
||||
// Serial.print("$"); Serial.print(reg, HEX);
|
||||
// Serial.print(": 0x"); Serial.println(x, HEX);
|
||||
return x;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Writes 8 bit of data to specified register
|
||||
* @param reg
|
||||
* The register
|
||||
* @param val
|
||||
* Value to write
|
||||
*/
|
||||
void Adafruit_STMPE610::writeRegister8(uint8_t reg, uint8_t val) {
|
||||
if (_CS == -1) {
|
||||
// use i2c
|
||||
_wire->beginTransmission(_i2caddr);
|
||||
_wire->write((byte)reg);
|
||||
_wire->write(val);
|
||||
_wire->endTransmission();
|
||||
} else {
|
||||
if (_CLK == -1)
|
||||
_spi->beginTransaction(mySPISettings);
|
||||
digitalWrite(_CS, LOW);
|
||||
spiOut(reg);
|
||||
spiOut(val);
|
||||
digitalWrite(_CS, HIGH);
|
||||
if (_CLK == -1)
|
||||
_spi->endTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief TS_Point constructor
|
||||
*/
|
||||
TS_Point::TS_Point() { x = y = 0; }
|
||||
|
||||
/*!
|
||||
* @brief TS_Point constructor
|
||||
* @param x0
|
||||
* Initial x
|
||||
* @param y0
|
||||
* Initial y
|
||||
* @param z0
|
||||
* Initial z
|
||||
*/
|
||||
TS_Point::TS_Point(int16_t x0, int16_t y0, int16_t z0) {
|
||||
x = x0;
|
||||
y = y0;
|
||||
z = z0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Equality operator for TS_Point
|
||||
* @return True if points are equal
|
||||
*/
|
||||
bool TS_Point::operator==(TS_Point p1) {
|
||||
return ((p1.x == x) && (p1.y == y) && (p1.z == z));
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Non-equality operator for TS_Point
|
||||
* @return True if points are not equal
|
||||
*/
|
||||
bool TS_Point::operator!=(TS_Point p1) {
|
||||
return ((p1.x != x) || (p1.y != y) || (p1.z != z));
|
||||
}
|
||||
183
libraries/Adafruit_STMPE610/Adafruit_STMPE610.h
Normal file
183
libraries/Adafruit_STMPE610/Adafruit_STMPE610.h
Normal file
@@ -0,0 +1,183 @@
|
||||
/*!
|
||||
*
|
||||
* @file Adafruit_STMPE610.cpp
|
||||
*
|
||||
* This is a library for the Adafruit STMPE610 Resistive
|
||||
* touch screen controller breakout
|
||||
* ----> http://www.adafruit.com/products/1571
|
||||
*
|
||||
* Check out the links above for our tutorials and wiring diagrams
|
||||
* These breakouts use SPI or I2C to communicate
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
*
|
||||
* MIT license, all text above must be included in any redistribution
|
||||
*/
|
||||
|
||||
#ifndef _ADAFRUIT_STMPE610H_
|
||||
#define _ADAFRUIT_STMPE610H_
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
|
||||
/** STMPE610 Address **/
|
||||
#define STMPE_ADDR 0x41
|
||||
|
||||
/** Reset Control **/
|
||||
#define STMPE_SYS_CTRL1 0x03
|
||||
#define STMPE_SYS_CTRL1_RESET 0x02
|
||||
|
||||
/** Clock Contrl **/
|
||||
#define STMPE_SYS_CTRL2 0x04
|
||||
|
||||
/** Touchscreen controller setup **/
|
||||
#define STMPE_TSC_CTRL 0x40
|
||||
#define STMPE_TSC_CTRL_EN 0x01
|
||||
#define STMPE_TSC_CTRL_XYZ 0x00
|
||||
#define STMPE_TSC_CTRL_XY 0x02
|
||||
|
||||
/** Interrupt control **/
|
||||
#define STMPE_INT_CTRL 0x09
|
||||
#define STMPE_INT_CTRL_POL_HIGH 0x04
|
||||
#define STMPE_INT_CTRL_POL_LOW 0x00
|
||||
#define STMPE_INT_CTRL_EDGE 0x02
|
||||
#define STMPE_INT_CTRL_LEVEL 0x00
|
||||
#define STMPE_INT_CTRL_ENABLE 0x01
|
||||
#define STMPE_INT_CTRL_DISABLE 0x00
|
||||
|
||||
/** Interrupt enable **/
|
||||
#define STMPE_INT_EN 0x0A
|
||||
#define STMPE_INT_EN_TOUCHDET 0x01
|
||||
#define STMPE_INT_EN_FIFOTH 0x02
|
||||
#define STMPE_INT_EN_FIFOOF 0x04
|
||||
#define STMPE_INT_EN_FIFOFULL 0x08
|
||||
#define STMPE_INT_EN_FIFOEMPTY 0x10
|
||||
#define STMPE_INT_EN_ADC 0x40
|
||||
#define STMPE_INT_EN_GPIO 0x80
|
||||
|
||||
/** Interrupt status **/
|
||||
#define STMPE_INT_STA 0x0B
|
||||
#define STMPE_INT_STA_TOUCHDET 0x01
|
||||
|
||||
/** ADC control **/
|
||||
#define STMPE_ADC_CTRL1 0x20
|
||||
#define STMPE_ADC_CTRL1_12BIT 0x08
|
||||
#define STMPE_ADC_CTRL1_10BIT 0x00
|
||||
|
||||
/** ADC control **/
|
||||
#define STMPE_ADC_CTRL2 0x21
|
||||
#define STMPE_ADC_CTRL2_1_625MHZ 0x00
|
||||
#define STMPE_ADC_CTRL2_3_25MHZ 0x01
|
||||
#define STMPE_ADC_CTRL2_6_5MHZ 0x02
|
||||
|
||||
/** Touchscreen controller configuration **/
|
||||
#define STMPE_TSC_CFG 0x41
|
||||
#define STMPE_TSC_CFG_1SAMPLE 0x00
|
||||
#define STMPE_TSC_CFG_2SAMPLE 0x40
|
||||
#define STMPE_TSC_CFG_4SAMPLE 0x80
|
||||
#define STMPE_TSC_CFG_8SAMPLE 0xC0
|
||||
#define STMPE_TSC_CFG_DELAY_10US 0x00
|
||||
#define STMPE_TSC_CFG_DELAY_50US 0x08
|
||||
#define STMPE_TSC_CFG_DELAY_100US 0x10
|
||||
#define STMPE_TSC_CFG_DELAY_500US 0x18
|
||||
#define STMPE_TSC_CFG_DELAY_1MS 0x20
|
||||
#define STMPE_TSC_CFG_DELAY_5MS 0x28
|
||||
#define STMPE_TSC_CFG_DELAY_10MS 0x30
|
||||
#define STMPE_TSC_CFG_DELAY_50MS 0x38
|
||||
#define STMPE_TSC_CFG_SETTLE_10US 0x00
|
||||
#define STMPE_TSC_CFG_SETTLE_100US 0x01
|
||||
#define STMPE_TSC_CFG_SETTLE_500US 0x02
|
||||
#define STMPE_TSC_CFG_SETTLE_1MS 0x03
|
||||
#define STMPE_TSC_CFG_SETTLE_5MS 0x04
|
||||
#define STMPE_TSC_CFG_SETTLE_10MS 0x05
|
||||
#define STMPE_TSC_CFG_SETTLE_50MS 0x06
|
||||
#define STMPE_TSC_CFG_SETTLE_100MS 0x07
|
||||
|
||||
/** FIFO level to generate interrupt **/
|
||||
#define STMPE_FIFO_TH 0x4A
|
||||
|
||||
/** Current filled level of FIFO **/
|
||||
#define STMPE_FIFO_SIZE 0x4C
|
||||
|
||||
/** Current status of FIFO **/
|
||||
#define STMPE_FIFO_STA 0x4B
|
||||
#define STMPE_FIFO_STA_RESET 0x01
|
||||
#define STMPE_FIFO_STA_OFLOW 0x80
|
||||
#define STMPE_FIFO_STA_FULL 0x40
|
||||
#define STMPE_FIFO_STA_EMPTY 0x20
|
||||
#define STMPE_FIFO_STA_THTRIG 0x10
|
||||
|
||||
/** Touchscreen controller drive I **/
|
||||
#define STMPE_TSC_I_DRIVE 0x58
|
||||
#define STMPE_TSC_I_DRIVE_20MA 0x00
|
||||
#define STMPE_TSC_I_DRIVE_50MA 0x01
|
||||
|
||||
/** Data port for TSC data address **/
|
||||
#define STMPE_TSC_DATA_X 0x4D
|
||||
#define STMPE_TSC_DATA_Y 0x4F
|
||||
#define STMPE_TSC_FRACTION_Z 0x56
|
||||
|
||||
/** GPIO **/
|
||||
#define STMPE_GPIO_SET_PIN 0x10
|
||||
#define STMPE_GPIO_CLR_PIN 0x11
|
||||
#define STMPE_GPIO_DIR 0x13
|
||||
#define STMPE_GPIO_ALT_FUNCT 0x17
|
||||
|
||||
/*!
|
||||
* @brief Class for working with points
|
||||
*/
|
||||
class TS_Point {
|
||||
public:
|
||||
TS_Point();
|
||||
TS_Point(int16_t x, int16_t y, int16_t z);
|
||||
|
||||
bool operator==(TS_Point);
|
||||
bool operator!=(TS_Point);
|
||||
|
||||
int16_t x; /**< x coordinate **/
|
||||
int16_t y; /**< y coordinate **/
|
||||
int16_t z; /**< z coordinate **/
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Class that stores state and functions for interacting with
|
||||
* STMPE610
|
||||
*/
|
||||
class Adafruit_STMPE610 {
|
||||
public:
|
||||
Adafruit_STMPE610(uint8_t cspin, uint8_t mosipin, uint8_t misopin,
|
||||
uint8_t clkpin);
|
||||
Adafruit_STMPE610(uint8_t cspin, SPIClass *theSPI = &SPI);
|
||||
Adafruit_STMPE610(TwoWire *theWire = &Wire);
|
||||
|
||||
boolean begin(uint8_t i2caddr = STMPE_ADDR);
|
||||
|
||||
void writeRegister8(uint8_t reg, uint8_t val);
|
||||
uint16_t readRegister16(uint8_t reg);
|
||||
uint8_t readRegister8(uint8_t reg);
|
||||
void readData(uint16_t *x, uint16_t *y, uint8_t *z);
|
||||
uint16_t getVersion();
|
||||
boolean touched();
|
||||
boolean bufferEmpty();
|
||||
uint8_t bufferSize();
|
||||
TS_Point getPoint();
|
||||
|
||||
private:
|
||||
uint8_t spiIn();
|
||||
void spiOut(uint8_t x);
|
||||
|
||||
TwoWire *_wire;
|
||||
SPIClass *_spi;
|
||||
int8_t _CS, _MOSI, _MISO, _CLK;
|
||||
uint8_t _i2caddr;
|
||||
|
||||
int m_spiMode;
|
||||
};
|
||||
|
||||
#endif
|
||||
21
libraries/Adafruit_STMPE610/LICENSE
Normal file
21
libraries/Adafruit_STMPE610/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Adafruit Industries
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
20
libraries/Adafruit_STMPE610/README.md
Normal file
20
libraries/Adafruit_STMPE610/README.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# Adafruit STMPE610 Library [](https://github.com/adafruit/Adafruit_STMPE610/actions)[](http://adafruit.github.io/Adafruit_STMPE610/html/index.html)
|
||||
|
||||
<a href="http://www.adafruit.com/products/1571"><img src="assets/board.jpg?raw=true" width="500px"></a>
|
||||
|
||||
This is a library for the Adafruit STMPE610 Resistive
|
||||
touch screen controller breakout
|
||||
* http://www.adafruit.com/products/1571
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams
|
||||
These breakouts use SPI or I2C to communicate
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
|
||||
To install, use the Arduino Library Manager and search for "Adafruit STMPE610" and install the library.
|
||||
|
||||
BIN
libraries/Adafruit_STMPE610/assets/board.jpg
Normal file
BIN
libraries/Adafruit_STMPE610/assets/board.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 277 KiB |
127
libraries/Adafruit_STMPE610/code-of-conduct.md
Normal file
127
libraries/Adafruit_STMPE610/code-of-conduct.md
Normal file
@@ -0,0 +1,127 @@
|
||||
# Adafruit Community Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and leaders pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level or type of
|
||||
experience, education, socio-economic status, nationality, personal appearance,
|
||||
race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
We are committed to providing a friendly, safe and welcoming environment for
|
||||
all.
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Be kind and courteous to others
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Collaborating with other community members
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and sexual attention or advances
|
||||
* The use of inappropriate images, including in a community member's avatar
|
||||
* The use of inappropriate language, including in a community member's nickname
|
||||
* Any spamming, flaming, baiting or other attention-stealing behavior
|
||||
* Excessive or unwelcome helping; answering outside the scope of the question
|
||||
asked
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate
|
||||
|
||||
The goal of the standards and moderation guidelines outlined here is to build
|
||||
and maintain a respectful community. We ask that you don’t just aim to be
|
||||
"technically unimpeachable", but rather try to be your best self.
|
||||
|
||||
We value many things beyond technical expertise, including collaboration and
|
||||
supporting others within our community. Providing a positive experience for
|
||||
other community members can have a much more significant impact than simply
|
||||
providing the correct answer.
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project leaders are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project leaders have the right and responsibility to remove, edit, or
|
||||
reject messages, comments, commits, code, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any community member for other behaviors that they deem
|
||||
inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Moderation
|
||||
|
||||
Instances of behaviors that violate the Adafruit Community Code of Conduct
|
||||
may be reported by any member of the community. Community members are
|
||||
encouraged to report these situations, including situations they witness
|
||||
involving other community members.
|
||||
|
||||
You may report in the following ways:
|
||||
|
||||
In any situation, you may send an email to <support@adafruit.com>.
|
||||
|
||||
On the Adafruit Discord, you may send an open message from any channel
|
||||
to all Community Helpers by tagging @community helpers. You may also send an
|
||||
open message from any channel, or a direct message to @kattni#1507,
|
||||
@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or
|
||||
@Andon#8175.
|
||||
|
||||
Email and direct message reports will be kept confidential.
|
||||
|
||||
In situations on Discord where the issue is particularly egregious, possibly
|
||||
illegal, requires immediate action, or violates the Discord terms of service,
|
||||
you should also report the message directly to Discord.
|
||||
|
||||
These are the steps for upholding our community’s standards of conduct.
|
||||
|
||||
1. Any member of the community may report any situation that violates the
|
||||
Adafruit Community Code of Conduct. All reports will be reviewed and
|
||||
investigated.
|
||||
2. If the behavior is an egregious violation, the community member who
|
||||
committed the violation may be banned immediately, without warning.
|
||||
3. Otherwise, moderators will first respond to such behavior with a warning.
|
||||
4. Moderators follow a soft "three strikes" policy - the community member may
|
||||
be given another chance, if they are receptive to the warning and change their
|
||||
behavior.
|
||||
5. If the community member is unreceptive or unreasonable when warned by a
|
||||
moderator, or the warning goes unheeded, they may be banned for a first or
|
||||
second offense. Repeated offenses will result in the community member being
|
||||
banned.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct and the enforcement policies listed above apply to all
|
||||
Adafruit Community venues. This includes but is not limited to any community
|
||||
spaces (both public and private), the entire Adafruit Discord server, and
|
||||
Adafruit GitHub repositories. Examples of Adafruit Community spaces include
|
||||
but are not limited to meet-ups, audio chats on the Adafruit Discord, or
|
||||
interaction at a conference.
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. As a community
|
||||
member, you are representing our community, and are expected to behave
|
||||
accordingly.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 1.4, available at
|
||||
<https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>,
|
||||
and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html).
|
||||
|
||||
For other projects adopting the Adafruit Community Code of
|
||||
Conduct, please contact the maintainers of those projects for enforcement.
|
||||
If you wish to use this code of conduct for your own project, consider
|
||||
explicitly mentioning your moderation policy or making a copy with your
|
||||
own moderation policy so as to avoid confusion.
|
||||
81
libraries/Adafruit_STMPE610/examples/TouchTest/TouchTest.ino
Normal file
81
libraries/Adafruit_STMPE610/examples/TouchTest/TouchTest.ino
Normal file
@@ -0,0 +1,81 @@
|
||||
/***************************************************
|
||||
This is an example for the Adafruit STMPE610 Resistive
|
||||
touch screen controller breakout
|
||||
----> http://www.adafruit.com/products/1571
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams
|
||||
These breakouts use SPI or I2C to communicate
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
|
||||
#include "Adafruit_STMPE610.h"
|
||||
|
||||
// Pick one of three wiring options below!
|
||||
|
||||
// Option #1 - uses I2C, connect to hardware I2C port only!
|
||||
// SCL to I2C clock (#A5 on Uno) and SDA to I2C data (#A4 on Uno)
|
||||
// tie MODE to GND and POWER CYCLE (there is no reset pin)
|
||||
Adafruit_STMPE610 touch = Adafruit_STMPE610();
|
||||
|
||||
// Option #2 - use hardware SPI, connect to hardware SPI port only!
|
||||
// SDI to MOSI, SDO to MISO, and SCL to SPI CLOCK
|
||||
// on Arduino Uno, that's 11, 12 and 13 respectively
|
||||
// Then pick a CS pin, any pin is OK but we suggest #10 on an Uno
|
||||
// tie MODE to 3.3V and POWER CYCLE the STMPE610 (there is no reset pin)
|
||||
|
||||
//Adafruit_STMPE610 touch = Adafruit_STMPE610(STMPE_CS);
|
||||
|
||||
// Option #3 - use software SPI, connect to *any* 4 I/O pins!
|
||||
// define the following pins to whatever 4 you want and wire up!
|
||||
// Tie MODE to 3.3V and POWER CYCLE the STMPE610 (there is no reset pin)
|
||||
// Adafruit_STMPE610 touch = Adafruit_STMPE610(STMPE_CS, STMPE_SDI, STMPE_SDO, STMPE_SCK);
|
||||
|
||||
/******************/
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("Adafruit STMPE610 example");
|
||||
Serial.flush();
|
||||
|
||||
// if using hardware SPI on an Uno #10 must be an output, remove line
|
||||
// if using software SPI or I2C
|
||||
pinMode(10, OUTPUT);
|
||||
|
||||
// If using I2C you can select the I2C address (there are two options) by calling
|
||||
// touch.begin(0x41), the default, or touch.begin(0x44) if A0 is tied to 3.3V
|
||||
// If no address is passed, 0x41 is used
|
||||
if (! touch.begin()) {
|
||||
Serial.println("STMPE not found!");
|
||||
while(1);
|
||||
}
|
||||
Serial.println("Waiting for touch sense");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
uint16_t x, y;
|
||||
uint8_t z;
|
||||
if (touch.touched()) {
|
||||
// read x & y & z;
|
||||
while (! touch.bufferEmpty()) {
|
||||
Serial.print(touch.bufferSize());
|
||||
touch.readData(&x, &y, &z);
|
||||
Serial.print("->(");
|
||||
Serial.print(x); Serial.print(", ");
|
||||
Serial.print(y); Serial.print(", ");
|
||||
Serial.print(z);
|
||||
Serial.println(")");
|
||||
}
|
||||
touch.writeRegister8(STMPE_INT_STA, 0xFF); // reset all ints, in this example unneeded depending in use
|
||||
}
|
||||
delay(10);
|
||||
}
|
||||
|
||||
9
libraries/Adafruit_STMPE610/library.properties
Normal file
9
libraries/Adafruit_STMPE610/library.properties
Normal file
@@ -0,0 +1,9 @@
|
||||
name=Adafruit STMPE610
|
||||
version=1.1.6
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Arduino library for STMPE610/811 resistive touch screen controllers
|
||||
paragraph=Arduino library for STMPE610/811 resistive touch screen controllers
|
||||
category=Display
|
||||
url=https://github.com/adafruit/Adafruit_STMPE610
|
||||
architectures=*
|
||||
Reference in New Issue
Block a user