Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison touch.c @ 8:58d76cf522ff
Split out code into separate files.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Sat, 04 Feb 2012 13:29:31 +1030 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7:9404b9869c27 | 8:58d76cf522ff |
---|---|
1 #include <stdint.h> | |
2 | |
3 #include "stm32f10x.h" | |
4 #include "delay.h" | |
5 #include "spi.h" | |
6 #include "touch.h" | |
7 | |
8 #define TP_SELECT() GPIO_ResetBits(GPIOB, GPIO_Pin_7) | |
9 #define TP_DESELECT() GPIO_SetBits(GPIOB, GPIO_Pin_7) | |
10 | |
11 uint16_t | |
12 tp_read(uint8_t type) { | |
13 uint16_t x = 0; | |
14 | |
15 /* Select device */ | |
16 TP_SELECT(); | |
17 | |
18 /* Do conversion */ | |
19 delay(10); | |
20 SPI_WriteByte(type); | |
21 | |
22 /* Read result */ | |
23 delay(10); | |
24 x = SPI_WriteByte(0x00); | |
25 x <<= 8; | |
26 x |= SPI_WriteByte(0x00); | |
27 delay(10); | |
28 | |
29 /* De-select device */ | |
30 TP_DESELECT(); | |
31 | |
32 /* Right justify 12 bit result */ | |
33 x = x >> 3; | |
34 return (x); | |
35 } | |
36 | |
37 void | |
38 tp_getcoords(uint16_t *x, uint16_t *y, uint16_t *z1, uint16_t *z2, float *t, float *t2) { | |
39 *x = tp_read(TP_READ_SEL(TP_CHAN_X, TP_MODE_12, TP_REF_DIFF, TP_PD_ON)); | |
40 *y = tp_read(TP_READ_SEL(TP_CHAN_Y, TP_MODE_12, TP_REF_DIFF, TP_PD_ON)); | |
41 *z1 = tp_read(TP_READ_SEL(TP_CHAN_Z1, TP_MODE_12, TP_REF_DIFF, TP_PD_ON)); | |
42 *z2 = tp_read(TP_READ_SEL(TP_CHAN_Z2, TP_MODE_12, TP_REF_DIFF, TP_PD_ON)); | |
43 *t = ((float)*x / 4096.0) * (((float)*z2 / (float)*z1) - 1); | |
44 *t2 = (((float)*x / 4096) * ((4096.0 / (float)*z1) - 1)) - (1 - ((float)*y / (float)4096.0)); | |
45 } |