From 08511c7839885024b3c4cde5e8bb8f2398484b45 Mon Sep 17 00:00:00 2001 From: Tectu Date: Fri, 1 Jun 2012 10:33:08 +0200 Subject: [PATCH] added touchpad support --- touchpad.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ touchpad.h | 15 ++++++++++++++ 2 files changed, 75 insertions(+) create mode 100755 touchpad.c create mode 100755 touchpad.h diff --git a/touchpad.c b/touchpad.c new file mode 100755 index 00000000..cb4603d4 --- /dev/null +++ b/touchpad.c @@ -0,0 +1,60 @@ +#include "touchpad.h" + +static void spicb(SPIDriver *spip); +static const SPIConfig spicfg = { + NULL, + GPIOC, + TP_CS, + SPI_CR1_SPE | SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0, +}; + +void tpInit(void) { + spiStart(&SPID1, &spicfg); +} + +void tpWriteData(uint8_t data) { + uint16_t tx = 0xAA; + + SET_CS(0); + spiSend(&SPID1, 1, &tx); + SET_CS(1); +} + +uint16_t tpReadData(void) { + +} + +uint16_t tpReadX(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; +} + +uint16_t tpReadY(void) { + uint8_t txbuf[1]; + uint8_t rxbuf[2]; + uint16_t y; + + txbuf[0] = 0xd0; + SET_CS(0); + spiSend(&SPID1, 1, txbuf); + spiReceive(&SPID1, 2, rxbuf); + SET_CS(1); + + y = rxbuf[0] << 4; + y |= rxbuf[1] >> 4; + + return y; +} + diff --git a/touchpad.h b/touchpad.h new file mode 100755 index 00000000..942ba110 --- /dev/null +++ b/touchpad.h @@ -0,0 +1,15 @@ +#ifndef TOUCHPAD_H +#define TOUCHPAD_H + +#include "ch.h" +#include "hal.h" + +#define SET_CS(a) (TP_PORT->BSRR = 1 << (TP_CS + (a ? 0 : 16))) + +void tpInit(void); +void tpWriteData(uint8_t data); +uint16_t tpReadData(void); +uint16_t tpReadX(void); +uint16_t tpReadY(void); + +#endif