STMPE610 touch sensor driver library
Dependents: TS_Eyes Tokei testUniGraphic_150217 AfficheurTFTAdafruit ... more
Revision 1:43990f1c0a8b, committed 2014-11-08
- Comitter:
- Rhyme
- Date:
- Sat Nov 08 06:51:34 2014 +0000
- Parent:
- 0:68779c92cffa
- Child:
- 2:ee910b63c077
- Commit message:
- First version with document
Changed in this revision
| SPI_STMPE610.cpp | Show annotated file Show diff for this revision Revisions of this file |
| SPI_STMPE610.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SPI_STMPE610.cpp Sat Nov 08 05:17:25 2014 +0000
+++ b/SPI_STMPE610.cpp Sat Nov 08 06:51:34 2014 +0000
@@ -205,17 +205,12 @@
readRegs(REG_TSC_CTRL, data, 1) ;
touched = data[0] & 0x80 ;
- if (touched) { //Touch Detected
- readRegs(REG_TSC_DATA_X, data,5) ;
+
+ readRegs(REG_TSC_DATA_X, data,5) ;
*x = (data[0] << 8) | data[1] ;
*y = (data[2] << 8) | data[3] ;
*z = data[4] ;
- } else {
- *x = 0 ;
- *y = 0 ;
- *z = 0 ;
- }
-
+
data[0] = 0x4B ;
data[1] = 0x01 ;
writeRegs(data, 2) ; // clear FIFO
@@ -224,5 +219,5 @@
data[1] = 0x00 ; // disable TSC
writeRegs(data, 2) ;
- return( touched & (*x || *y || *z)) ;
+ return( touched ) ;
}
--- a/SPI_STMPE610.h Sat Nov 08 05:17:25 2014 +0000
+++ b/SPI_STMPE610.h Sat Nov 08 06:51:34 2014 +0000
@@ -1,17 +1,41 @@
-/*
- * File description
+/**
+ * STMPE610 Touch Sensor
+ *
*
*/
-
#ifndef SPI_STMPE610_H
#define SPI_STMPE610_H
#include "mbed.h"
-/**
- * STMPE610 Touch Sensor
+
+/** SPI_STMPE610 Touch Sensor
+ * Example:
+ * @code
+ * #include "mbed.h"
+ * #include "SPI_STMPE610.h"
+ *
+ * #define PIN_MOSI PTD2
+ * #define PIN_MISO PTD3
+ * #define PIN_SCLK PTD1
+ * #define PIN_CS_TSC PTA13
+ * #define PIN_TSC_INTR PTC9
*
+ * SPI_STMPE610 TSC(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC) ;
*
+ * int main()
+ * {
+ * uint16_t touched, x, y, z ;
+ * printf("Test SPI STMPE610\n\r") ;
+ * while (true) {
+ * touched = TSC.getRAWPoint(&x, &y, &z) ;
+ * if (touched) {
+ * printf("x = %d, y = %d, z = %d\n\r", x, y, z) ;
+ * }
+ * wait(0.1) ;
+ * }
+ * }
+ * @endcode
*/
class SPI_STMPE610
@@ -25,8 +49,12 @@
* @param sclk SPI_CLK pin
* @param cs SPI_CS pin
*/
+
SPI_STMPE610(PinName mosi, PinName miso, PinName sclk, PinName cs) ;
+ /**
+ * Destructor
+ */
~SPI_STMPE610() ;
/*
@@ -44,8 +72,18 @@
uint16_t read16(int addr) ;
void write16(int addr, uint16_t data) ;
+ /**
+ * get RAW value of x, y, z
+ * @param *x raw value of x
+ * @param *y raw value of y
+ * @param *z raw value of z
+ * @return if touched
+ * @note For my device usually the value seems to be between 300 ~ 3000
+ * @note when it fails to acquire value the value of 0 seems to be returned
+ */
int getRAWPoint(uint16_t *x, uint16_t *y, uint16_t *z) ;
private:
} ;
+
#endif /* SPI_STMPE610_H */
\ No newline at end of file