Just for fun and to learn, I'm writing code to drive a 800x480 TFT with resistive touch driven by an RA8875 and an ATmega328P and avr-libc.
It works fine so far but when reading touch events, I don't get touch points close to the edge of the screen; it seems like the coordinates are "scaled" down to an area of about (40, 60) and (760, 440):
This is how the touch controller of the RA8875 is initialized:
// enable touch panel, wait 4096 clocks, system clock/8
regWrite(TPCR0, 0x80 | 0x30 | 0x03);
// enable debounce for touch interrupt
regWrite(TPCR1, 0x04);
// enable touch interrupt
regWrite(INTC1, 0x04);
The touch point is read like this:
void readTouch(Point *point) {
uint8_t tpxh = regRead(TPXH);
uint8_t tpyh = regRead(TPYH);
uint8_t tpxyl = regRead(TPXYL);
point->x = (tpxh << 2);
point->x |= (tpxyl & 0x03);
point->y = (tpyh << 2);
point->y |= ((tpxyl & 0x0c) >> 2);
// 10-bit ADC
point->x = ((uint32_t)point->x * DISPLAY_WIDTH) >> 10;
point->y = ((uint32_t)point->y * DISPLAY_HEIGHT) >> 10;
}
The point is used to draw a green circle with a radius of 10, then the touch interrupt is cleared.
Am I doing something wrong or is this common behaviour of such a touch panel and/or the RA8875 touch controller? Could this be improved by calibration, like "scaling up" the touch area to the display size?