2012-06-01 08:33:08 +00:00
|
|
|
#include "touchpad.h"
|
2012-06-01 09:46:30 +00:00
|
|
|
#include "glcd.h"
|
2012-06-01 08:33:08 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:44:48 +00:00
|
|
|
static uint16_t readX(void) {
|
2012-06-01 08:33:08 +00:00
|
|
|
uint8_t txbuf[1];
|
|
|
|
uint8_t rxbuf[2];
|
|
|
|
uint16_t x;
|
|
|
|
|
2012-06-01 10:48:26 +00:00
|
|
|
txbuf[0] = 0xd0;
|
2012-06-01 08:33:08 +00:00
|
|
|
SET_CS(0);
|
|
|
|
spiSend(&SPID1, 1, txbuf);
|
|
|
|
spiReceive(&SPID1, 2, rxbuf);
|
|
|
|
SET_CS(1);
|
|
|
|
|
|
|
|
x = rxbuf[0] << 4;
|
|
|
|
x |= rxbuf[1] >> 4;
|
2012-06-01 09:46:30 +00:00
|
|
|
|
2012-06-01 09:52:16 +00:00
|
|
|
return x;
|
2012-06-01 08:33:08 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 10:44:48 +00:00
|
|
|
static uint16_t readY(void) {
|
2012-06-01 08:33:08 +00:00
|
|
|
uint8_t txbuf[1];
|
|
|
|
uint8_t rxbuf[2];
|
|
|
|
uint16_t y;
|
|
|
|
|
2012-06-01 10:48:26 +00:00
|
|
|
txbuf[0] = 0x90;
|
2012-06-01 08:33:08 +00:00
|
|
|
SET_CS(0);
|
|
|
|
spiSend(&SPID1, 1, txbuf);
|
|
|
|
spiReceive(&SPID1, 2, rxbuf);
|
|
|
|
SET_CS(1);
|
|
|
|
|
|
|
|
y = rxbuf[0] << 4;
|
|
|
|
y |= rxbuf[1] >> 4;
|
|
|
|
|
2012-06-01 10:44:48 +00:00
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t tpReadX(void) {
|
|
|
|
uint32_t results;
|
|
|
|
uint16_t i, x;
|
|
|
|
|
|
|
|
for(i=0; i<CONVERSIONS; i++) {
|
|
|
|
results += readX();
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:48:26 +00:00
|
|
|
x = (((lcdGetHeight()-1) * (results/CONVERSIONS)) / 2048);
|
2012-06-01 10:44:48 +00:00
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t tpReadY(void) {
|
|
|
|
uint32_t results;
|
|
|
|
uint16_t i, y;
|
|
|
|
|
|
|
|
for(i=0; i<CONVERSIONS; i++)
|
|
|
|
results += readY();
|
|
|
|
|
2012-06-01 10:48:26 +00:00
|
|
|
y = (((lcdGetWidth()-1) * (results/CONVERSIONS)) / 2048);
|
2012-06-01 09:46:30 +00:00
|
|
|
|
|
|
|
return y;
|
2012-06-01 08:33:08 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 10:44:48 +00:00
|
|
|
|