diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/touch.c	Sat Feb 04 13:29:31 2012 +1030
@@ -0,0 +1,45 @@
+#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));
+}