diff options
author | Tectu <joel@unormal.org> | 2012-08-09 02:03:26 +0200 |
---|---|---|
committer | Tectu <joel@unormal.org> | 2012-08-09 02:03:26 +0200 |
commit | 19bb3b15dd368b019cdab1b12565156b84f9d32a (patch) | |
tree | bcb183d368992ccd8795fb6c19bf9dc232e5caf9 | |
parent | 79c053567816521b601e44981bf3af5b0e40f752 (diff) | |
download | uGFX-19bb3b15dd368b019cdab1b12565156b84f9d32a.tar.gz uGFX-19bb3b15dd368b019cdab1b12565156b84f9d32a.tar.bz2 uGFX-19bb3b15dd368b019cdab1b12565156b84f9d32a.zip |
tpInit()
-rw-r--r-- | halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.c | 16 | ||||
-rw-r--r-- | halext/drivers/touchpad/touchpadXPT2046/xpt2046_lld.c.h | 46 | ||||
-rw-r--r-- | halext/include/touchpad.h | 6 | ||||
-rw-r--r-- | halext/include/touchpad_lld.h | 8 |
4 files changed, 55 insertions, 21 deletions
diff --git a/halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.c b/halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.c index 8a2de34e..4dc29dbe 100644 --- a/halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.c +++ b/halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.c @@ -56,6 +56,12 @@ /*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
+static const SPIConfig spicfg = {
+ NULL,
+ TP_CS_PORT,
+ TP_CS,
+ SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0,
+};
/*===========================================================================*/
/* Driver local functions. */
@@ -78,11 +84,8 @@ *
* @notapi
*/
-void tp_lld_init(void) {
- /* Initialise the TOUCHPAD structure */
-
- /* ToDo */
- (void)tp;
+void tp_lld_init(TOUCHPADDriver *tp) {
+ spiStart(tp->spid, &spicfg);
}
/**
@@ -112,7 +115,7 @@ uint16_t tp_lld_read_y(void) { *
* @notapi
*/
- uint16_t tp_lld_read_y(void) {
+ uint16_t tp_lld_read_z(void) {
/* ToDo */
return 42;
}
@@ -120,3 +123,4 @@ uint16_t tp_lld_read_y(void) { #endif /* HAL_USE_TOUCHPAD */
/** @} */
+
diff --git a/halext/drivers/touchpad/touchpadXPT2046/xpt2046_lld.c.h b/halext/drivers/touchpad/touchpadXPT2046/xpt2046_lld.c.h index 2e891684..97adc1ad 100644 --- a/halext/drivers/touchpad/touchpadXPT2046/xpt2046_lld.c.h +++ b/halext/drivers/touchpad/touchpadXPT2046/xpt2046_lld.c.h @@ -21,20 +21,50 @@ #ifndef _XPT2046_H #define _XPT2046_H -void tp_lld_init(TOUCHPADDriver *tp) { +#include "ch.h" +#include "hal.h" -} +#define TP_CS_HIGH palSetPad(TP_CS_PORT, TP_CS) +#define TP_CS_LOW palClearPad(TP_CS_PORT, TP_CS) + +__inline uint16_t lld_tpReadX(void) { + uint8_t txbuf[1]; + uint8_t rxbuf[2]; + uint16_t x; -uint16_t tp_lld_read_x(void) { - return 42; + txbuf[0] = 0xd0; + TP_CS_LOW; + spiSend(&SPID1, 1, txbuf); + spiReceive(&SPID1, 2, rxbuf); + TP_CS_HIGH; + + x = rxbuf[0] << 4; + x |= rxbuf[1] >> 4; + + return x; } -uint16_t tp_lld_read_y(void) { - return 42; +__inline uint16_t lld_tpReadY(void) { + uint8_t txbuf[1]; + uint8_t rxbuf[2]; + uint16_t y; + + txbuf[0] = 0x90; + TP_CS_LOW; + spiSend(&SPID1, 1, txbuf); + spiReceive(&SPID1, 2, rxbuf); + TP_CS_HIGH; + + y = rxbuf[0] << 4; + y |= rxbuf[1] >> 4; + + return y; } -uint16_t tp_lld_read_z(void) { - return 42; +__inline uint16_t lld_tpReadZ(void) { + return 0; } + #endif /* _XPT2046_H */ + diff --git a/halext/include/touchpad.h b/halext/include/touchpad.h index 12b462fd..c6e44b55 100644 --- a/halext/include/touchpad.h +++ b/halext/include/touchpad.h @@ -60,21 +60,17 @@ extern "C" { uint16_t tpReadY(void); #if TOUCHPAD_PRESSURE - uint16_t tpReadZ(void); - #endif #else - #define tpInit(tp) tp_lld_init() + #define tpInit(tp) tp_lld_init(tp) #define tpReadX() tp_lld_read_x() #define tpReadY() tp_lld_read_y() #if TOUCHPAD_PRESSURE - #define tpReadZ() tp_lld_read_z() - #endif #endif diff --git a/halext/include/touchpad_lld.h b/halext/include/touchpad_lld.h index ccff7d4d..ab2e54d6 100644 --- a/halext/include/touchpad_lld.h +++ b/halext/include/touchpad_lld.h @@ -55,7 +55,11 @@ typedef struct TOUCHPADDriver TOUCHPADDriver; * @brief Structure representing a Touchpad driver. */ struct TOUCHPADDriver { - /* ToDo */ + /* + * @brief Pointer to SPI driver. + * @note SPI driver must be enabled in mcu- and halconf.h + */ + SPIDriver *spid; }; /*===========================================================================*/ @@ -71,7 +75,7 @@ extern "C" { #endif /* Core functions */ - void tp_lld_init(void); + void tp_lld_init(TOUCHPADDriver *tp); uint16_t tp_lld_read_x(void); uint16_t tp_lld_read_y(void); |