diff options
Diffstat (limited to 'app/keypad.c')
-rw-r--r-- | app/keypad.c | 91 |
1 files changed, 91 insertions, 0 deletions
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); + + + +} |