Mercurial > ~darius > hgwebdir.cgi > stm32temp
view touch.c @ 78:4c1db877452b
Add small note.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Tue, 23 Apr 2013 20:46:37 +0930 |
parents | 58d76cf522ff |
children |
line wrap: on
line source
#include <stdint.h> #include "stm32f10x.h" #include "delay.h" #include "spi.h" #include "touch.h" #define TP_SELECT() GPIO_ResetBits(GPIOB, GPIO_Pin_7) #define TP_DESELECT() GPIO_SetBits(GPIOB, GPIO_Pin_7) uint16_t tp_read(uint8_t type) { uint16_t x = 0; /* Select device */ TP_SELECT(); /* Do conversion */ delay(10); SPI_WriteByte(type); /* Read result */ delay(10); x = SPI_WriteByte(0x00); x <<= 8; x |= SPI_WriteByte(0x00); delay(10); /* De-select device */ TP_DESELECT(); /* Right justify 12 bit result */ x = x >> 3; return (x); } void tp_getcoords(uint16_t *x, uint16_t *y, uint16_t *z1, uint16_t *z2, float *t, float *t2) { *x = tp_read(TP_READ_SEL(TP_CHAN_X, TP_MODE_12, TP_REF_DIFF, TP_PD_ON)); *y = tp_read(TP_READ_SEL(TP_CHAN_Y, TP_MODE_12, TP_REF_DIFF, TP_PD_ON)); *z1 = tp_read(TP_READ_SEL(TP_CHAN_Z1, TP_MODE_12, TP_REF_DIFF, TP_PD_ON)); *z2 = tp_read(TP_READ_SEL(TP_CHAN_Z2, TP_MODE_12, TP_REF_DIFF, TP_PD_ON)); *t = ((float)*x / 4096.0) * (((float)*z2 / (float)*z1) - 1); *t2 = (((float)*x / 4096) * ((4096.0 / (float)*z1) - 1)) - (1 - ((float)*y / (float)4096.0)); }