From 58ddfd92104854ba58a68e85021a4bd0a6a8a99d Mon Sep 17 00:00:00 2001 From: Kumar Abhishek Date: Thu, 9 Aug 2012 16:25:23 +0530 Subject: [PATCH 1/2] Changes to the Touchpad Configuration structure Added field to the driver structure to set PENIRQ pin and port, defines removed --- halext/include/touchpad_lld.h | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/halext/include/touchpad_lld.h b/halext/include/touchpad_lld.h index c0339e05..a654299b 100644 --- a/halext/include/touchpad_lld.h +++ b/halext/include/touchpad_lld.h @@ -53,17 +53,36 @@ /* Driver types. */ /*===========================================================================*/ -typedef struct TOUCHPADDriver TOUCHPADDriver; +typedef struct _TOUCHPADDriver TOUCHPADDriver; /** * @brief Structure representing a Touchpad driver. */ -struct TOUCHPADDriver { +struct _TOUCHPADDriver { /* * @brief Pointer to SPI driver. - * @note SPI driver must be enabled in mcu- and halconf.h + * @note SPI driver must be enabled in mcuconf.h and halconf.h */ - SPIDriver *spid; + SPIDriver *spip; + + /* + * @brief Pointer to the SPI configuration structure. + * @note The lowest possible speed ~ 1-2MHz is to be used, otherwise + * will result in a lot of noise + */ + SPIConfig *spicfg; + + /* + * @brief Touchscreen controller TPIRQ pin GPIO port + */ + ioportid_t tpIRQPort; + + /* + * @brief Touchscreen controller TPIRQ GPIO pin + * @note The lowest possible speed ~ 1-2MHz is to be used, otherwise + * will result in a lot of noise + */ + ioportmask_t tpIRQPin; }; /*===========================================================================*/ From 823db82c7ff6584fdee8caf02de79dd82bfac25c Mon Sep 17 00:00:00 2001 From: Kumar Abhishek Date: Thu, 9 Aug 2012 16:26:08 +0530 Subject: [PATCH 2/2] Update to touchpad LLDs to use new structure. --- .../touchpad/touchpadADS7843/touchpad_lld.c | 26 ++++------- .../touchpad/touchpadXPT2046/touchpad_lld.c | 45 ++++++++----------- 2 files changed, 28 insertions(+), 43 deletions(-) diff --git a/halext/drivers/touchpad/touchpadADS7843/touchpad_lld.c b/halext/drivers/touchpad/touchpadADS7843/touchpad_lld.c index 85db56e7..313fdb86 100644 --- a/halext/drivers/touchpad/touchpadADS7843/touchpad_lld.c +++ b/halext/drivers/touchpad/touchpadADS7843/touchpad_lld.c @@ -52,19 +52,11 @@ /* Driver exported variables. */ /*===========================================================================*/ -#if !defined(__DOXYGEN__) - TOUCHPADDriver Touchpad; -#endif /*===========================================================================*/ /* 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, -}; +static TOUCHPADDriver* tpDriver; /*===========================================================================*/ /* Driver local functions. */ @@ -86,7 +78,7 @@ static const SPIConfig spicfg = { * @notapi */ void tp_lld_init(TOUCHPADDriver *tp) { - spiStart(tp->spid, &spicfg); + spiStart(tp->spip, tp->spicfg); } /** @@ -100,10 +92,10 @@ uint16_t tp_lld_read_x(void) { uint16_t y; txbuf[0] = 0xd0; - TP_CS_LOW; + palClearPad(tpDriver->spicfg->ssport, tpDriver->spicfg->sspad); spiSend(&SPID1, 1, txbuf); spiReceive(&SPID1, 2, rxbuf); - TP_CS_HIGH; + palSetPad(tpDriver->spicfg->ssport, tpDriver->spicfg->sspad); y = rxbuf[0] << 4; y |= rxbuf[1] >> 4; @@ -122,10 +114,10 @@ uint16_t tp_lld_read_y(void) { uint16_t y; txbuf[0] = 0x90; - TP_CS_LOW; + palClearPad(tpDriver->spicfg->ssport, tpDriver->spicfg->sspad); spiSend(&SPID1, 1, txbuf); spiReceive(&SPID1, 2, rxbuf); - TP_CS_HIGH; + palSetPad(tpDriver->spicfg->ssport, tpDriver->spicfg->sspad); y = rxbuf[0] << 4; y |= rxbuf[1] >> 4; @@ -142,9 +134,9 @@ uint16_t tp_lld_read_y(void) { * * @noapi */ - uint8_t tp_lld_irq(void) { - return (!palReadPad(TP_IRQ_PORT, TP_IRQ)); - } + uint8_t tp_lld_irq(void) { + return (!palReadPad(tpDriver->tpIRQPort, tpDriver->tpIRQPin)); + } #endif #endif /* HAL_USE_TOUCHPAD */ diff --git a/halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.c b/halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.c index 00f6336c..876cb4ba 100644 --- a/halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.c +++ b/halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.c @@ -36,9 +36,6 @@ /* Driver local definitions. */ /*===========================================================================*/ -#define TP_CS_HIGH palSetPad(TP_CS_PORT, TP_CS) -#define TP_CS_LOW palClearPad(TP_CS_PORT, TP_CS) - #ifdef UNUSED #elif defined(__GNUC__) # define UNUSED(x) UNUSED_ ## x __attribute__((unused)) @@ -52,32 +49,27 @@ /* Driver exported variables. */ /*===========================================================================*/ -#if !defined(__DOXYGEN__) - TOUCHPADDriver Touchpad; -#endif /*===========================================================================*/ /* 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, -}; +static TOUCHPADDriver* tpDriver; /*===========================================================================*/ /* Driver local functions. */ /*===========================================================================*/ + /*===========================================================================*/ /* Driver interrupt handlers. */ /*===========================================================================*/ + /*===========================================================================*/ /* Driver exported functions. */ /*===========================================================================*/ + /* ---- Required Routines ---- */ /** @@ -86,7 +78,9 @@ static const SPIConfig spicfg = { * @notapi */ void tp_lld_init(TOUCHPADDriver *tp) { - spiStart(tp->spid, &spicfg); + tpDriver=tp; + + spiStart(tp->spip, tp->spicfg); } /** @@ -100,11 +94,10 @@ uint16_t tp_lld_read_x(void) { uint16_t y; txbuf[0] = 0xd0; - TP_CS_LOW; + palClearPad(tpDriver->spicfg->ssport, tpDriver->spicfg->sspad); spiSend(&SPID1, 1, txbuf); spiReceive(&SPID1, 2, rxbuf); - TP_CS_HIGH; - + palSetPad(tpDriver->spicfg->ssport, tpDriver->spicfg->sspad); y = rxbuf[0] << 4; y |= rxbuf[1] >> 4; @@ -122,10 +115,10 @@ uint16_t tp_lld_read_y(void) { uint16_t y; txbuf[0] = 0x90; - TP_CS_LOW; + palClearPad(tpDriver->spicfg->ssport, tpDriver->spicfg->sspad); spiSend(&SPID1, 1, txbuf); spiReceive(&SPID1, 2, rxbuf); - TP_CS_HIGH; + palSetPad(tpDriver->spicfg->ssport, tpDriver->spicfg->sspad); y = rxbuf[0] << 4; y |= rxbuf[1] >> 4; @@ -135,15 +128,15 @@ uint16_t tp_lld_read_y(void) { /* ---- Optional Routines ---- */ #if TOUCHPAD_HAS_IRQ || defined(__DOXYGEN__) - /* - * @brief for checking if touchpad is pressed or not. - * - * @return 1 if pressed / 0 if not pressed - * - * @noapi - */ + /* + * @brief for checking if touchpad is pressed or not. + * + * @return 1 if pressed / 0 if not pressed + * + * @noapi + */ uint8_t tp_lld_irq(void) { - return (!palReadPad(TP_IRQ_PORT, TP_IRQ)); + return (!palReadPad(tpDriver->tpIRQPort, tpDriver->tpIRQPin)); } #endif