aboutsummaryrefslogtreecommitdiffstats
path: root/src/keypad.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/keypad.c')
-rw-r--r--src/keypad.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/src/keypad.c b/src/keypad.c
index 5b04eec..22fc967 100644
--- a/src/keypad.c
+++ b/src/keypad.c
@@ -53,16 +53,29 @@ static const port_t keypad_cols[COLS] = {
{ COL_3 }, { COL_4 }
};
+#define K_2ND 0x000000FF
+#define K_HOLD 0x000001FF
+
static const char keypad_map[ROWS * COLS * 4] = {
- "&\0\0\0" "|\0\0\0" "pi\0\0" "==\0\0" "!=\0\0"
- "x\0\0\0" "y\0\0\0" "z\0\0\0" "=\0\0\0" "sin\0"
- "7\0\0\0" "8\0\0\0" "9\0\0\0" "(\0\0\0" ")\0\0\0"
- "4\0\0\0" "5\0\0\0" "6\0\0\0" "/\0\0\0" "%\0\0\0"
- "1\0\0\0" "2\0\0\0" "3\0\0\0" "*\0\0\0" "-\0\0\0"
- ".\0\0\0" "0\0\0\0" "\b\0\0\0" "\n\0\0\0" "+\0\0\0"
+ "\xFF\0\0\0" ">\0\0\0" ">=\0\0" "==\0\0" "=\0\0\0"
+ "x\0\0\0" "<\0\0\0" "<=\0\0" "!=\0\0" "%\0\0\0"
+ "7\0\0\0" "8\0\0\0" "9\0\0\0" "(\0\0\0" ")\0\0\0"
+ "4\0\0\0" "5\0\0\0" "6\0\0\0" "/\0\0\0" "*\0\0\0"
+ "1\0\0\0" "2\0\0\0" "3\0\0\0" "-\0\0\0" "+\0\0\0"
+ ".\0\0\0" "0\0\0\0" "\0\0\0\0" "\b\0\0\0" "\n\0\0\0"
+};
+
+static const char keypad_map_2nd[ROWS * COLS * 4] = {
+ "a\0\0\0" "b\0\0\0" "c\0\0\0" "d\0\0\0" "e\0\0\0"
+ "f\0\0\0" "g\0\0\0" "h\0\0\0" "i\0\0\0" "j\0\0\0"
+ "k\0\0\0" "l\0\0\0" "m\0\0\0" "n\0\0\0" "o\0\0\0"
+ "p\0\0\0" "q\0\0\0" "r\0\0\0" "s\0\0\0" "t\0\0\0"
+ "u\0\0\0" "v\0\0\0" "w\0\0\0" "x\0\0\0" "y\0\0\0"
+ "z\0\0\0" "\0\0\0\0" "\0\0\0\0" "\0\0\0\0" "\xFF\x01\0\0"
};
-#define KEY(r, c, i) keypad_map[r * COLS * 4 + c * 4 + i]
+#define KEY(r, c, i) map[r * COLS * 4 + c * 4 + i]
+#define KEYCODE(r, c) *((uint32_t *)(map + (r * COLS * 4 + c * 4)))
#define BUFFER_SIZE 8
static char keypad_buffer[BUFFER_SIZE];
@@ -71,12 +84,24 @@ static int keypad_buffer_pos = -1;
void keypad_task(void)
{
unsigned int col = 0;
+ unsigned char use2nd = 0;
+ unsigned char hold = 0;
while (1) {
gpio_dout(keypad_cols[col].port, keypad_cols[col].pin, 1);
delay(10);
for (unsigned int row = 0; row < ROWS; row++) {
if (gpio_din(keypad_rows[row].port, keypad_rows[row].pin)) {
- if (keypad_buffer_pos < BUFFER_SIZE) {
+ char *map = (use2nd == 0) ? keypad_map : keypad_map_2nd;
+ if (KEYCODE(row, col) == K_2ND) {
+ use2nd = 1;
+ } else if (KEYCODE(row, col) == K_HOLD) {
+ if (use2nd != 0) {
+ if ((hold ^= 1) == 0)
+ use2nd = 0;
+ }
+ } else if (keypad_buffer_pos < BUFFER_SIZE) {
+ if (use2nd != 0 && hold == 0)
+ use2nd = 0;
for (unsigned int i = 0; KEY(row, col, i) != '\0'; i++)
keypad_buffer[++keypad_buffer_pos] = KEY(row, col, i);
}