metro-m0: Demo pin interrupts
authorKeith Packard <keithp@keithp.com>
Tue, 8 Nov 2022 06:23:44 +0000 (22:23 -0800)
committerKeith Packard <keithp@keithp.com>
Tue, 8 Nov 2022 06:23:44 +0000 (22:23 -0800)
Prints 'pressed' whenever D0 goes low.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/metro-m0/ao_pins.h
src/metro-m0/metro-m0.c

index c9a88275eabd0f30e6f929fba970ec6bb7a79d61..1f7daae94a80fa887ace73b1b687c65aad493f9d 100644 (file)
 #define AO_AHB_PRESCALER       1
 #define AO_APBA_PRESCALER      1
 
+#define HAS_SPI_0              1
 #define HAS_SPI_5              1
-#define SPI_5_PB22_PB23_PB03   1
-
-#define HAS_SPI_4              1
-#define SPI_4_PB10_PB11_PA12   1
 
 /*
  * SPI Flash memory
index 80f43672e5aa3cb0ffd1e7dd22de92f483e31375..1a5d3c609262406aa383637b60b176ed7067a6f7 100644 (file)
@@ -15,6 +15,7 @@
 #include <ao.h>
 #include <ao_led.h>
 #include <ao_dma_samd21.h>
+#include <ao_exti.h>
 
 #define SNEK_CS_PORT   (&samd21_port_a)
 #define SNEK_CS_PIN    (11)
@@ -41,6 +42,33 @@ const struct ao_cmds ao_spi_cmds[] = {
        { 0, NULL },
 };
 
+static int     pressed;
+
+static void
+ao_button_callback(void)
+{
+       pressed = 1;
+       ao_wakeup(&pressed);
+}
+
+static void
+ao_button(void)
+{
+       ao_exti_setup(&samd21_port_a, 11, AO_EXTI_MODE_FALLING | AO_EXTI_MODE_PULL_UP, ao_button_callback);
+       ao_exti_enable(&samd21_port_a, 11);
+       for (;;) {
+               ao_arch_block_interrupts();
+               pressed = 0;
+               while (!pressed)
+                       ao_sleep(&pressed);
+               ao_arch_release_interrupts();
+               printf("pressed\n");
+               fflush(stdout);
+       }
+}
+
+static struct ao_task ao_button_task;
+
 int main(void)
 {
        ao_led_init();
@@ -48,12 +76,14 @@ int main(void)
        ao_task_init();
        ao_timer_init();
        ao_dma_init();
+       ao_exti_init();
        ao_spi_init();
        ao_usb_init();
        ao_cmd_register(ao_spi_cmds);
        ao_spi_init_cs(&samd21_port_a, 1 << 11); /* analog 8 for CS */
        ao_storage_init();
        ao_cmd_init();
+       ao_add_task(&ao_button_task, ao_button, "button");
        ao_start_scheduler();
        return 0;
 }