aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/keypad.c121
-rw-r--r--src/main.c24
-rw-r--r--src/stdlib.c1
3 files changed, 91 insertions, 55 deletions
diff --git a/src/keypad.c b/src/keypad.c
index fad774a..06cef51 100644
--- a/src/keypad.c
+++ b/src/keypad.c
@@ -18,66 +18,105 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+#include <clock.h>
#include <keypad.h>
#include <gpio.h>
+#include <task.h>
-#define PIN_0 GPIO_PORT(B, 2)
-#define PIN_1 GPIO_PORT(B, 1)
-#define PIN_2 GPIO_PORT(A, 11)
-#define PIN_3 GPIO_PORT(C, 8)
-#define PIN_4 GPIO_PORT(B, 15)
-#define PIN_5 GPIO_PORT(B, 12)
-#define PIN_6 GPIO_PORT(C, 6)
-#define PIN_7 GPIO_PORT(B, 14)
-#define PIN_8 GPIO_PORT(B, 11)
-#define PIN_9 GPIO_PORT(C, 5)
-#define PIN_S GPIO_PORT(B, 13)
-#define PIN_P GPIO_PORT(A, 12)
+#define ROW_0 GPIO_PORT(B, 15)
+#define ROW_1 GPIO_PORT(B, 14)
+#define ROW_2 GPIO_PORT(B, 13)
+#define ROW_3 GPIO_PORT(C, 4)
+#define COL_0 GPIO_PORT(B, 1)
+#define COL_1 GPIO_PORT(B, 2)
+#define COL_2 GPIO_PORT(B, 11)
+#define COL_3 GPIO_PORT(B, 12)
+#define COL_4 GPIO_PORT(A, 11)
+
+#define ROWS 4
+#define COLS 5
typedef struct {
GPIO_TypeDef *port;
uint16_t pin;
- uint16_t keycode;
-} key_t;
+} port_t;
+
+static const port_t keypad_rows[ROWS] = {
+ { ROW_0 }, { ROW_1 }, { ROW_2 }, { ROW_3 }
+};
+
+static const port_t keypad_cols[COLS] = {
+ { COL_0 }, { COL_1 }, { COL_2 }, { COL_3 }, { COL_4 }
+};
-static const key_t keypad_map[12] = {
- { PIN_0, K0 },
- { PIN_1, K1 },
- { PIN_2, K2 },
- { PIN_3, K3 },
- { PIN_4, K4 },
- { PIN_5, K5 },
- { PIN_6, K6 },
- { PIN_7, K7 },
- { PIN_8, K8 },
- { PIN_9, K9 },
- { PIN_S, KS },
- { PIN_P, KP }
+static const int keypad_map[ROWS][COLS] = {
+ { '7', '8', '9', 'x', '/' },
+ { '4', '5', '6', 'y', '*' },
+ { '3', '2', '1', 'z', '-' },
+ { '.', '0', '\b', '\n', '+' }
};
+#define BUFFER_SIZE 8
+static char keypad_buffer = 'A';//[BUFFER_SIZE];
+//static int keypad_buffer_pos = -1;
+
+void keypad_task(void)
+{
+ unsigned int col = 0;
+ while (1) {
+ gpio_dout(keypad_cols[col].port, keypad_cols[col].pin, 1);
+ 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)
+ keypad_buffer/*[++keypad_buffer_pos]*/ = keypad_map[row][col];
+ while (gpio_din(keypad_rows[row].port, keypad_rows[row].pin))
+ delay(1);
+ break;
+ }
+ }
+ gpio_dout(keypad_cols[col].port, keypad_cols[col].pin, 0);
+ col++;
+ if (col == COLS)
+ col = 0;
+
+ delay(10);
+ }
+}
+
void keypad_init(void)
{
- for (uint8_t i = 0; i < 12; i++) {
- GPIO_TypeDef *p = keypad_map[i].port;
- uint16_t pin = keypad_map[i].pin;
+ for (uint8_t i = 0; i < ROWS; i++) {
+ GPIO_TypeDef *p = keypad_rows[i].port;
+ uint16_t pin = keypad_rows[i].pin;
gpio_mode(p, pin, OUTPUT);
+ gpio_speed(p, pin, VERYHIGH);
gpio_dout(p, pin, 0);
gpio_mode(p, pin, INPUT);
- //gpio_pupd(p, pin, PULLDOWN);
+ gpio_pupd(p, pin, PULLDOWN);
}
-}
-uint16_t keypad_get(void)
-{
- uint16_t state = 0;
- for (uint8_t i = 0; i < 12; i++) {
- if (gpio_din(keypad_map[i].port, keypad_map[i].pin))
- state |= keypad_map[i].keycode;
+ for (uint8_t i = 0; i < COLS; i++) {
+ GPIO_TypeDef *p = keypad_cols[i].port;
+ uint16_t pin = keypad_cols[i].pin;
+ gpio_mode(p, pin, OUTPUT);
+ gpio_speed(p, pin, VERYHIGH);
+ gpio_dout(p, pin, 0);
}
- return state;
+
+ task_start(keypad_task, 1024);
}
-uint8_t keypad_isdown(uint16_t keycode)
+int keypad_get(void)
{
- return (keypad_get() & keycode);
+ //if (keypad_buffer_pos < 0)
+ // return 0;
+
+ //int key = keypad_buffer[0];
+ //for (int i = keypad_buffer_pos - 1; i > 0; i--)
+ // keypad_buffer[i - 1] = keypad_buffer[i];
+ //keypad_buffer_pos--;
+ //return key;
+ int ret = keypad_buffer;
+ keypad_buffer = 0;
+ return ret;
}
diff --git a/src/main.c b/src/main.c
index 9844199..1e9b58d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -18,22 +18,22 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-#include <stm32l476xx.h>
#include <clock.h>
-#include <heap.h>
-#include <task.h>
-#include <gpio.h>
-#include <lcd.h>
#include <display.h>
#include <display_draw.h>
+#include <flash.h>
+#include <gpio.h>
+#include <heap.h>
#include <initrd.h>
+#include <keypad.h>
+#include <lcd.h>
#include <parser.h>
+#include <random.h>
+#include <script.h>
#include <serial.h>
+#include <stm32l476xx.h>
#include <string.h>
-#include <script.h>
-#include <random.h>
-#include <keypad.h>
-#include <flash.h>
+#include <task.h>
extern uint8_t __bss_end__;
extern char *itoa(int, char *, int);
@@ -54,12 +54,9 @@ int main(void)
clock_init();
heap_init(&__bss_end__);
gpio_init();
- keypad_init();
serial_init();
random_init();
-
- //extern void keypad_init(void);
- //keypad_init();
+ keypad_init();
gpio_mode(GPIOA, 5, OUTPUT);
@@ -77,6 +74,7 @@ void kmain(void)
dsp_init();
dsp_rect(0, 0, LCD_WIDTH, LCD_HEIGHT, dsp_color(0, 0, 0));
dsp_cursoron();
+ keypad_init();
task_start(task_interpreter, 4096);
/*char buf[2];
diff --git a/src/stdlib.c b/src/stdlib.c
index f5f9cc8..950f356 100644
--- a/src/stdlib.c
+++ b/src/stdlib.c
@@ -62,7 +62,6 @@ char *snprintf(char *buf, unsigned int max, const char *format, ...)
break;
case 'f':
itoa((int)va_arg(args, double), nbuf, 10);
- continue;
break;
default:
buf[off++] = format[i];