summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames McKenzie <git@madingley.org>2015-08-03 00:22:04 +0100
committerJames McKenzie <git@madingley.org>2015-08-03 00:22:04 +0100
commit85caee84eec03dd1f04ceb8d01494322e713fd65 (patch)
tree583dc060c0fd4bd9b31cab19cdfe14c937e20424
parentff7e2824011f787acd730ac788b06610c6e40132 (diff)
downloadcandlestick-85caee84eec03dd1f04ceb8d01494322e713fd65.tar.gz
candlestick-85caee84eec03dd1f04ceb8d01494322e713fd65.tar.bz2
candlestick-85caee84eec03dd1f04ceb8d01494322e713fd65.zip
fish
-rw-r--r--app/i2c.c (renamed from app/i2c1.c)0
-rw-r--r--app/i2c2.c132
-rw-r--r--app/keypad.c91
-rw-r--r--doc/TTP229.pdfbin0 -> 132234 bytes
4 files changed, 91 insertions, 132 deletions
diff --git a/app/i2c1.c b/app/i2c.c
index db60931..db60931 100644
--- a/app/i2c1.c
+++ b/app/i2c.c
diff --git a/app/i2c2.c b/app/i2c2.c
deleted file mode 100644
index 77701cc..0000000
--- a/app/i2c2.c
+++ /dev/null
@@ -1,132 +0,0 @@
-#include "project.h"
-
-
-#define GPIO_SCL GPIOA
-#define GPIO_SDA GPIOB
-#define SCL GPIO5
-#define SDA GPIO11
-
-#define I2C_BB_DELAY do { delay_us(1); } while (0)
-
-int
-i2c2_bb (int scl, int sda)
-{
- if (scl)
- gpio_set (GPIO_SCL, SCL);
- else
- gpio_clear (GPIO_SCL, SCL);
- if (sda)
- gpio_set (GPIO_SDA, SDA);
- else
- gpio_clear (GPIO_SDA, SDA);
-
- return ! !(gpio_get (GPIO_SDA, SDA) & SDA);
-
-}
-
-
-void
-i2c2_bb_start (void)
-{
- i2c2_bb (1, 1);
- I2C_BB_DELAY;
- i2c2_bb (1, 0);
- I2C_BB_DELAY;
- i2c2_bb (0, 0);
- I2C_BB_DELAY;
-}
-
-
-void
-i2c2_bb_stop (void)
-{
- i2c2_bb (0, 0);
- I2C_BB_DELAY;
- i2c2_bb (1, 0);
- I2C_BB_DELAY;
- i2c2_bb (1, 1);
- I2C_BB_DELAY;
-}
-
-int
-i2c2_bb_send_data (uint8_t v)
-{
- int c;
-
-
- for (c = 0x80; c; c >>= 1)
- {
- i2c2_bb (0, c & v);
- I2C_BB_DELAY;
- i2c2_bb (1, c & v);
- I2C_BB_DELAY;
- i2c2_bb (0, c & v);
- I2C_BB_DELAY;
- }
-
- i2c2_bb (0, 1);
- I2C_BB_DELAY;
- i2c2_bb (1, 1);
- I2C_BB_DELAY;
- c = i2c2_bb (1, 1);
- i2c2_bb (0, 1);
-
- return c;
-}
-
-
-int
-i2c2_bb_start_transaction (uint8_t a, int wnr)
-{
- int ret;
-
- i2c2_bb_start ();
- ret = i2c2_bb_send_data (a << 1 | ! !(wnr));
-
-
- return ret;
-}
-
-#if 0
-void
-i2c2_bb_scan (void)
-{
- int i, r;
-
- return;
- i2cp_reset ();
-
- printf ("Probing bus\r\n");
- for (i = 0; i < 128; ++i)
- {
- while (i2cp_lock ());
- i2cp_start ();
- i2cp_abort_start ();
- i2cp_stop ();
- i2cp_abort_stop ();
- r = i2cp_start_transaction (i, I2C_WRITE);
- i2cp_stop ();
- i2cp_unlock ();
- if (!r)
- printf ("Found device at address 0x%x\r\n", i);
- usart1_drain ();
- }
- printf ("Done\r\n");
- i2cp_reset ();
-
-}
-#endif
-
-void
-i2c2_bb_init (void)
-{
- gpio_set_mode (GPIO_SCL, GPIO_MODE_OUTPUT_50_MHZ,
- GPIO_CNF_OUTPUT_OPENDRAIN, SCL);
- gpio_set_mode (GPIO_SDA, GPIO_MODE_OUTPUT_50_MHZ,
- GPIO_CNF_OUTPUT_OPENDRAIN, SDA);
-
- i2c2_bb_start ();
- i2c2_bb_stop ();
-
-
-}
diff --git a/app/keypad.c b/app/keypad.c
new file mode 100644
index 0000000..daea5c7
--- /dev/null
+++ b/app/keypad.c
@@ -0,0 +1,91 @@
+#include "project.h"
+
+#define GPIO_CLOCK GPIOA
+#define GPIO_DATA GPIOB
+#define CLOCK GPIO5
+#define DATA GPIO11
+
+#define KEYPAD_DELAY do { delay_us(1); } while (0)
+
+uint16_t keypad_read(void)
+{
+uint16_t ret=0;
+uint16_t c;
+
+/*Reset the state machine in the keypad */
+
+gpio_set (GPIO_DATA, DATA);
+KEYPAD_DELAY;
+gpio_clear (GPIO_DATA, DATA);
+KEYPAD_DELAY;
+gpio_set (GPIO_DATA, DATA);
+KEYPAD_DELAY;
+
+gpio_clear (GPIO_CLOCK, CLOCK);
+KEYPAD_DELAY;
+
+for (c=0x8000;c;c>>=1)
+{
+gpio_set (GPIO_CLOCK, CLOCK);
+KEYPAD_DELAY;
+if (!(gpio_get (GPIO_DATA, DATA) & DATA)) ret|=c;
+gpio_clear (GPIO_CLOCK, CLOCK);
+KEYPAD_DELAY;
+}
+
+gpio_set (GPIO_CLOCK, CLOCK);
+
+return ret;
+}
+
+static void
+keypad_scan (void)
+{
+
+ uint16_t v;
+ char buf[16];
+
+
+ v=keypad_read();
+
+ sprintf (buf, "%04x", v);
+ lcd_write (buf, 0, 1);
+
+
+}
+
+void
+keypad_tick (void)
+{
+ static int c;
+
+ c++;
+
+ if (c < 73)
+ return;
+
+ c = 0;
+
+
+ keypad_scan ();
+
+
+}
+
+
+
+
+
+
+void
+keypad_init (void)
+{
+
+ gpio_set_mode (GPIO_CLOCK, GPIO_MODE_OUTPUT_50_MHZ,
+ GPIO_CNF_OUTPUT_OPENDRAIN, CLOCK);
+ gpio_set_mode (GPIO_DATA, GPIO_MODE_OUTPUT_50_MHZ,
+ GPIO_CNF_OUTPUT_OPENDRAIN, DATA);
+
+
+
+}
diff --git a/doc/TTP229.pdf b/doc/TTP229.pdf
new file mode 100644
index 0000000..ca4c896
--- /dev/null
+++ b/doc/TTP229.pdf
Binary files differ