From 346fec7eb4a9e2542e51a17449b672b034964873 Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 11 Jun 2012 18:37:38 +0200 Subject: [PATCH] added ADS7843 lld support --- drivers/ads7843_lld.c | 39 +++++++++++++++++++++++++++++++++++++++ drivers/ads7843_lld.h | 14 ++++++++++++++ drivers/s6d1121_lld.h | 2 +- drivers/ssd1289_lld.h | 2 +- lcd.mk | 3 ++- touchpad.c | 30 ++---------------------------- touchpad.h | 1 + 7 files changed, 60 insertions(+), 31 deletions(-) create mode 100644 drivers/ads7843_lld.c create mode 100644 drivers/ads7843_lld.h diff --git a/drivers/ads7843_lld.c b/drivers/ads7843_lld.c new file mode 100644 index 00000000..ee0513ea --- /dev/null +++ b/drivers/ads7843_lld.c @@ -0,0 +1,39 @@ +#include "ads7843_lld.h" + +#ifdef TOUCHPAD_USE_ADS7843 + +__inline uint16_t lld_readX(void) { + uint8_t txbuf[1]; + uint8_t rxbuf[2]; + uint16_t x; + + txbuf[0] = 0xd0; + SET_CS(0); + spiSend(&SPID1, 1, txbuf); + spiReceive(&SPID1, 2, rxbuf); + SET_CS(1); + + x = rxbuf[0] << 4; + x |= rxbuf[1] >> 4; + + return x; +} + +__inline uint16_t lld_readY(void) { + uint8_t txbuf[1]; + uint8_t rxbuf[2]; + uint16_t y; + + txbuf[0] = 0x90; + SET_CS(0); + spiSend(&SPID1, 1, txbuf); + spiReceive(&SPID1, 2, rxbuf); + SET_CS(1); + + y = rxbuf[0] << 4; + y |= rxbuf[1] >> 4; + + return y; +} + +#endif diff --git a/drivers/ads7843_lld.h b/drivers/ads7843_lld.h new file mode 100644 index 00000000..6ccae533 --- /dev/null +++ b/drivers/ads7843_lld.h @@ -0,0 +1,14 @@ +#ifndef ADS7843_LLD_H +#define ADS7843_LLD_H + +#include "glcdconf.h" +#include "touchpad.h" + +#ifdef TOUCHPAD_USE_ADS7843 + +uint16_t lld_readX(void); +uint16_t lld_readY(void); + +#endif +#endif + diff --git a/drivers/s6d1121_lld.h b/drivers/s6d1121_lld.h index 42fe3b0f..173f6e40 100644 --- a/drivers/s6d1121_lld.h +++ b/drivers/s6d1121_lld.h @@ -2,7 +2,7 @@ #define S6D1121_H #include "glcd.h" -#include "lcdconf.h" +#include "glcdconf.h" #ifdef LCD_USE_S6D1121 diff --git a/drivers/ssd1289_lld.h b/drivers/ssd1289_lld.h index db109749..1ca187f3 100644 --- a/drivers/ssd1289_lld.h +++ b/drivers/ssd1289_lld.h @@ -2,7 +2,7 @@ #define SSD1289_H #include "glcd.h" -#include "lcdconf.h" +#include "glcdconf.h" #ifdef LCD_USE_SSD1289 diff --git a/lcd.mk b/lcd.mk index 0c9ea4f9..2679e415 100644 --- a/lcd.mk +++ b/lcd.mk @@ -5,7 +5,8 @@ LCDSRC = ${CHIBIOS}/ext/lcd/glcd.c \ ${CHIBIOS}/ext/lcd/graph.c \ ${CHIBIOS}/ext/lcd/gui.c \ ${CHIBIOS}/ext/lcd/drivers/ssd1289_lld.c \ - ${CHIBIOS}/ext/lcd/drivers/s6d1121_lld.c + ${CHIBIOS}/ext/lcd/drivers/s6d1121_lld.c \ + ${CHIBIOS}/ext/lcd/drivers/ads7843_lld.c LCDINC = ${CHIBIOS}/ext/lcd \ ${CHIBIOS}/etc/lcd/drivers diff --git a/touchpad.c b/touchpad.c index 1d052fc3..1a5accd6 100644 --- a/touchpad.c +++ b/touchpad.c @@ -17,37 +17,11 @@ void tpInit(SPIDriver *spip) { } static __inline uint16_t readX(void) { - uint8_t txbuf[1]; - uint8_t rxbuf[2]; - uint16_t x; - - txbuf[0] = 0xd0; - SET_CS(0); - spiSend(&SPID1, 1, txbuf); - spiReceive(&SPID1, 2, rxbuf); - SET_CS(1); - - x = rxbuf[0] << 4; - x |= rxbuf[1] >> 4; - - return x; + return lld_readX(); } static __inline uint16_t readY(void) { - uint8_t txbuf[1]; - uint8_t rxbuf[2]; - uint16_t y; - - txbuf[0] = 0x90; - SET_CS(0); - spiSend(&SPID1, 1, txbuf); - spiReceive(&SPID1, 2, rxbuf); - SET_CS(1); - - y = rxbuf[0] << 4; - y |= rxbuf[1] >> 4; - - return y; + return lld_readY(); } uint8_t tpIRQ(void) { diff --git a/touchpad.h b/touchpad.h index 947077cc..9cf678a2 100644 --- a/touchpad.h +++ b/touchpad.h @@ -4,6 +4,7 @@ #include "ch.h" #include "hal.h" #include "glcd.h" +#include "drivers/ads7843_lld.h" #define CONVERSIONS 3