From 163a42e48eae8f611075d88a6151ffc6dd343bba Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 11 Jun 2012 13:21:17 +0200 Subject: [PATCH] added ads7843 lld functions --- drivers/ads7843.c | 41 +++++++++++++++++++++++++++++++++++++++++ drivers/ads7843.h | 11 +++++++++++ touchpad.c | 30 ++---------------------------- 3 files changed, 54 insertions(+), 28 deletions(-) create mode 100644 drivers/ads7843.c create mode 100644 drivers/ads7843.h diff --git a/drivers/ads7843.c b/drivers/ads7843.c new file mode 100644 index 00000000..5349ab08 --- /dev/null +++ b/drivers/ads7843.c @@ -0,0 +1,41 @@ +#include "drivers/ads7843.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 x; + + txbuf[0] = 0x90; + SET_CS(0); + spiSend(&SPID1, 1, txbuf); + spiReceive(&SPID1, 2, rxbuf); + SET_CS(1); + + x = rxbuf[0] << 4; + x |= rxbuf[1] >> 4; + + return x; + +} + +#endif + diff --git a/drivers/ads7843.h b/drivers/ads7843.h new file mode 100644 index 00000000..a04678e5 --- /dev/null +++ b/drivers/ads7843.h @@ -0,0 +1,11 @@ +#ifndef ADS7843_H +#define ADS7843_h + +#ifdef TOUCHPAD_USE_ADS7843 +#include "touchpad.h" + +uint16_t lld_readX(void): +uint16_t lld_readY(void) + +#endif +#endif diff --git a/touchpad.c b/touchpad.c index 6f786f77..611bd6bc 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) {