cortexelf-v1: Add buttons
authorKeith Packard <keithp@keithp.com>
Sun, 2 Apr 2017 23:37:42 +0000 (16:37 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 2 Apr 2017 23:37:42 +0000 (16:37 -0700)
Signed-off-by: Keith Packard <keithp@keithp.com>
src/cortexelf-v1/Makefile
src/cortexelf-v1/ao_cortexelf.c
src/cortexelf-v1/ao_pins.h

index cea75ddf4fdd617b7a65c2bcaba1bda5b9f2371e..f7c892bcfd7a9e1ac2dcd174fa770588a885ad69 100644 (file)
@@ -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 \
index f9be59e835a11e7e78be52493f95f2cefac4b8c6..8be7ef151457acd362733157709f0684dd7ff159 100644 (file)
@@ -28,6 +28,8 @@
 #include <ao_sdcard.h>
 #include <ao_fat.h>
 #include <ao_lisp.h>
+#include <ao_button.h>
+#include <ao_event.h>
 
 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();
index e9c9deb3b67fc7e0048ef1d8a774593a383f9fcd..d39f402234d915c0434a414c1279fd2e071bdfb4 100644 (file)
 #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_ */