Update to touchpad LLDs to use new structure.

ugfx_release_2.6
Kumar Abhishek 2012-08-09 16:26:08 +05:30
parent 58ddfd9210
commit 823db82c7f
2 changed files with 28 additions and 43 deletions

View File

@ -52,19 +52,11 @@
/* Driver exported variables. */ /* Driver exported variables. */
/*===========================================================================*/ /*===========================================================================*/
#if !defined(__DOXYGEN__)
TOUCHPADDriver Touchpad;
#endif
/*===========================================================================*/ /*===========================================================================*/
/* Driver local variables. */ /* Driver local variables. */
/*===========================================================================*/ /*===========================================================================*/
static const SPIConfig spicfg = { static TOUCHPADDriver* tpDriver;
NULL,
TP_CS_PORT,
TP_CS,
SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0,
};
/*===========================================================================*/ /*===========================================================================*/
/* Driver local functions. */ /* Driver local functions. */
@ -86,7 +78,7 @@ static const SPIConfig spicfg = {
* @notapi * @notapi
*/ */
void tp_lld_init(TOUCHPADDriver *tp) { 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; uint16_t y;
txbuf[0] = 0xd0; txbuf[0] = 0xd0;
TP_CS_LOW; palClearPad(tpDriver->spicfg->ssport, tpDriver->spicfg->sspad);
spiSend(&SPID1, 1, txbuf); spiSend(&SPID1, 1, txbuf);
spiReceive(&SPID1, 2, rxbuf); spiReceive(&SPID1, 2, rxbuf);
TP_CS_HIGH; palSetPad(tpDriver->spicfg->ssport, tpDriver->spicfg->sspad);
y = rxbuf[0] << 4; y = rxbuf[0] << 4;
y |= rxbuf[1] >> 4; y |= rxbuf[1] >> 4;
@ -122,10 +114,10 @@ uint16_t tp_lld_read_y(void) {
uint16_t y; uint16_t y;
txbuf[0] = 0x90; txbuf[0] = 0x90;
TP_CS_LOW; palClearPad(tpDriver->spicfg->ssport, tpDriver->spicfg->sspad);
spiSend(&SPID1, 1, txbuf); spiSend(&SPID1, 1, txbuf);
spiReceive(&SPID1, 2, rxbuf); spiReceive(&SPID1, 2, rxbuf);
TP_CS_HIGH; palSetPad(tpDriver->spicfg->ssport, tpDriver->spicfg->sspad);
y = rxbuf[0] << 4; y = rxbuf[0] << 4;
y |= rxbuf[1] >> 4; y |= rxbuf[1] >> 4;
@ -142,9 +134,9 @@ uint16_t tp_lld_read_y(void) {
* *
* @noapi * @noapi
*/ */
uint8_t tp_lld_irq(void) { uint8_t tp_lld_irq(void) {
return (!palReadPad(TP_IRQ_PORT, TP_IRQ)); return (!palReadPad(tpDriver->tpIRQPort, tpDriver->tpIRQPin));
} }
#endif #endif
#endif /* HAL_USE_TOUCHPAD */ #endif /* HAL_USE_TOUCHPAD */

View File

@ -36,9 +36,6 @@
/* Driver local definitions. */ /* 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 #ifdef UNUSED
#elif defined(__GNUC__) #elif defined(__GNUC__)
# define UNUSED(x) UNUSED_ ## x __attribute__((unused)) # define UNUSED(x) UNUSED_ ## x __attribute__((unused))
@ -52,32 +49,27 @@
/* Driver exported variables. */ /* Driver exported variables. */
/*===========================================================================*/ /*===========================================================================*/
#if !defined(__DOXYGEN__)
TOUCHPADDriver Touchpad;
#endif
/*===========================================================================*/ /*===========================================================================*/
/* Driver local variables. */ /* Driver local variables. */
/*===========================================================================*/ /*===========================================================================*/
static const SPIConfig spicfg = { static TOUCHPADDriver* tpDriver;
NULL,
TP_CS_PORT,
TP_CS,
SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0,
};
/*===========================================================================*/ /*===========================================================================*/
/* Driver local functions. */ /* Driver local functions. */
/*===========================================================================*/ /*===========================================================================*/
/*===========================================================================*/ /*===========================================================================*/
/* Driver interrupt handlers. */ /* Driver interrupt handlers. */
/*===========================================================================*/ /*===========================================================================*/
/*===========================================================================*/ /*===========================================================================*/
/* Driver exported functions. */ /* Driver exported functions. */
/*===========================================================================*/ /*===========================================================================*/
/* ---- Required Routines ---- */ /* ---- Required Routines ---- */
/** /**
@ -86,7 +78,9 @@ static const SPIConfig spicfg = {
* @notapi * @notapi
*/ */
void tp_lld_init(TOUCHPADDriver *tp) { 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; uint16_t y;
txbuf[0] = 0xd0; txbuf[0] = 0xd0;
TP_CS_LOW; palClearPad(tpDriver->spicfg->ssport, tpDriver->spicfg->sspad);
spiSend(&SPID1, 1, txbuf); spiSend(&SPID1, 1, txbuf);
spiReceive(&SPID1, 2, rxbuf); spiReceive(&SPID1, 2, rxbuf);
TP_CS_HIGH; palSetPad(tpDriver->spicfg->ssport, tpDriver->spicfg->sspad);
y = rxbuf[0] << 4; y = rxbuf[0] << 4;
y |= rxbuf[1] >> 4; y |= rxbuf[1] >> 4;
@ -122,10 +115,10 @@ uint16_t tp_lld_read_y(void) {
uint16_t y; uint16_t y;
txbuf[0] = 0x90; txbuf[0] = 0x90;
TP_CS_LOW; palClearPad(tpDriver->spicfg->ssport, tpDriver->spicfg->sspad);
spiSend(&SPID1, 1, txbuf); spiSend(&SPID1, 1, txbuf);
spiReceive(&SPID1, 2, rxbuf); spiReceive(&SPID1, 2, rxbuf);
TP_CS_HIGH; palSetPad(tpDriver->spicfg->ssport, tpDriver->spicfg->sspad);
y = rxbuf[0] << 4; y = rxbuf[0] << 4;
y |= rxbuf[1] >> 4; y |= rxbuf[1] >> 4;
@ -135,15 +128,15 @@ uint16_t tp_lld_read_y(void) {
/* ---- Optional Routines ---- */ /* ---- Optional Routines ---- */
#if TOUCHPAD_HAS_IRQ || defined(__DOXYGEN__) #if TOUCHPAD_HAS_IRQ || defined(__DOXYGEN__)
/* /*
* @brief for checking if touchpad is pressed or not. * @brief for checking if touchpad is pressed or not.
* *
* @return 1 if pressed / 0 if not pressed * @return 1 if pressed / 0 if not pressed
* *
* @noapi * @noapi
*/ */
uint8_t tp_lld_irq(void) { uint8_t tp_lld_irq(void) {
return (!palReadPad(TP_IRQ_PORT, TP_IRQ)); return (!palReadPad(tpDriver->tpIRQPort, tpDriver->tpIRQPin));
} }
#endif #endif