From b55240eb43a92c552003b8b324a385e041f84f12 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 1 Dec 2015 02:10:53 +0000 Subject: fish --- app/keypad.c | 155 ----------------------------------------------------------- 1 file changed, 155 deletions(-) delete mode 100644 app/keypad.c (limited to 'app/keypad.c') diff --git a/app/keypad.c b/app/keypad.c deleted file mode 100644 index d4a82db..0000000 --- a/app/keypad.c +++ /dev/null @@ -1,155 +0,0 @@ -#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) - - -#define SCAN_INTERVAL 73 -#define DEBOUNCE_INTERVAL 1 -#define DEBOUNCE_COUNT 3 - -static uint32_t next_scan; - - -uint16_t -keypad_raw_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; -} - -uint16_t -keypad_read (void) -{ - int c; - const uint8_t lut[] = "cdef89ab45670123"; - uint8_t ret = 0; - - - -/*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 = 0; c < 16; ++c) - { - gpio_set (GPIO_CLOCK, CLOCK); - KEYPAD_DELAY; - if (!(gpio_get (GPIO_DATA, DATA) & DATA)) - ret = lut[c]; - gpio_clear (GPIO_CLOCK, CLOCK); - KEYPAD_DELAY; - } - - gpio_set (GPIO_CLOCK, CLOCK); - - return ret; -} - - -static void -keypad_scan (void) -{ - static uint8_t last_v; - static uint8_t key_down; - static int same; - uint8_t v; - - v = keypad_read (); - - next_scan = DEBOUNCE_INTERVAL; - - if (v!=last_v) { - last_v=v; - same=0; - return; - } else { - if (same