From 1bc48b075f76bfef258f516549573429b24f284c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 2 Apr 2017 16:37:42 -0700 Subject: [PATCH] cortexelf-v1: Add buttons Signed-off-by: Keith Packard --- src/cortexelf-v1/Makefile | 2 ++ src/cortexelf-v1/ao_cortexelf.c | 20 ++++++++++++++++++++ src/cortexelf-v1/ao_pins.h | 24 ++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/src/cortexelf-v1/Makefile b/src/cortexelf-v1/Makefile index cea75ddf..f7c892bc 100644 --- a/src/cortexelf-v1/Makefile +++ b/src/cortexelf-v1/Makefile @@ -68,6 +68,8 @@ ALTOS_SRC = \ ao_bufio.c \ ao_fat.c \ ao_flash_stm.c \ + ao_button.c \ + ao_event.c \ ao_lisp_lex.c \ ao_lisp_mem.c \ ao_lisp_cons.c \ diff --git a/src/cortexelf-v1/ao_cortexelf.c b/src/cortexelf-v1/ao_cortexelf.c index f9be59e8..8be7ef15 100644 --- a/src/cortexelf-v1/ao_cortexelf.c +++ b/src/cortexelf-v1/ao_cortexelf.c @@ -28,6 +28,8 @@ #include #include #include +#include +#include struct ao_task ball_task; @@ -208,6 +210,21 @@ __code struct ao_cmds ao_demo_cmds[] = { { 0, NULL } }; +static struct ao_task event_task; + +static void +ao_event_loop(void) +{ + for (;;) { + struct ao_event ev; + + ao_event_get(&ev); + printf("type %d uint %d tick %d value %d\n", + ev.type, ev.unit, ev.tick, ev.value); + flush(); + } +} + int main(void) { @@ -236,9 +253,12 @@ main(void) ao_usb_init(); + ao_button_init(); + ao_config_init(); ao_add_task(&ball_task, ao_ball, "ball"); + ao_add_task(&event_task, ao_event_loop, "events"); ao_cmd_register(&ao_demo_cmds[0]); ao_start_scheduler(); diff --git a/src/cortexelf-v1/ao_pins.h b/src/cortexelf-v1/ao_pins.h index e9c9deb3..d39f4022 100644 --- a/src/cortexelf-v1/ao_pins.h +++ b/src/cortexelf-v1/ao_pins.h @@ -125,4 +125,28 @@ #define AO_SDCARD_SPI_MISO_PIN 3 #define AO_SDCARD_SPI_MOSI_PIN 4 +/* Buttons */ + +#define AO_EVENT 1 + +#define AO_BUTTON_COUNT 4 +#define AO_BUTTON_MODE AO_EXTI_MODE_PULL_DOWN + +/* INPUT */ +#define AO_BUTTON_0_PORT (&stm_gpioc) +#define AO_BUTTON_0 8 + +/* MP */ +#define AO_BUTTON_1_PORT (&stm_gpioc) +#define AO_BUTTON_1 9 + +/* RUN */ +#define AO_BUTTON_2_PORT (&stm_gpioc) +#define AO_BUTTON_2 10 + +/* LOAD */ +#define AO_BUTTON_3_PORT (&stm_gpioc) +#define AO_BUTTON_3 11 + + #endif /* _AO_PINS_H_ */ -- 2.30.2