metro-m0: Hook up ADC sample from A pins
authorKeith Packard <keithp@keithp.com>
Wed, 9 Nov 2022 00:20:07 +0000 (16:20 -0800)
committerKeith Packard <keithp@keithp.com>
Wed, 9 Nov 2022 00:20:07 +0000 (16:20 -0800)
Signed-off-by: Keith Packard <keithp@keithp.com>
src/metro-m0/ao_pins.h
src/metro-m0/metro-m0.c

index 1f7daae94a80fa887ace73b1b687c65aad493f9d..2d404cadffd922de9a1f2e9c2d11b420415d3c9f 100644 (file)
@@ -26,8 +26,6 @@
 
 #define AO_LED_PANIC   LED_BLUE
 
-#define HAS_BEEP       0
-
 #define HAS_USB                1
 #define USE_USB_STDIO  1
 
 
 #endif
 
+/*
+ * Beeper
+ */
+
+#define HAS_BEEP               1
+
+/* Beep on PA11 function F TCC0.3 */
+
+#define AO_BEEP_TCC    (&samd21_tcc0)
+#define AO_BEEP_TCC_APBC_MASK  SAMD21_PM_APBCMASK_TCC0
+#define AO_BEEP_PORT   (&samd21_port_a)
+#define AO_BEEP_PIN    (11)
+#define AO_BEEP_FUNC   SAMD21_PORT_PMUX_FUNC_F
+
+/* ADC */
+#define AO_DATA_RING           32
+
+#define HAS_ADC                        1
+
+struct ao_adc {
+       int16_t                 a[6];
+       int16_t                 temp;
+};
+
+#define AO_NUM_ADC_PIN 6
+#define AO_NUM_ADC     (AO_NUM_ADC_PIN + 1)
+
+#define AO_ADC_DUMP(p)                                                 \
+       printf("tick: %5lu a0: %5d a1: %5d a2: %5d a3: %5d a4: %5d a5: %5d temp: %5d\n", \
+              (p)->tick,                                               \
+              (p)->adc.a[0], (p)->adc.a[1], (p)->adc.a[2],             \
+              (p)->adc.a[3], (p)->adc.a[4], (p)->adc.a[5],             \
+              (p)->adc.temp);
+
+#define AO_ADC_PIN0_PORT       (&samd21_port_a)
+#define AO_ADC_PIN0_PIN                2
+#define AO_ADC_SQ0             0
+
+#define AO_ADC_PIN1_PORT       (&samd21_port_b)
+#define AO_ADC_PIN1_PIN                8
+#define AO_ADC_SQ1             2
+
+#define AO_ADC_PIN2_PORT       (&samd21_port_b)
+#define AO_ADC_PIN2_PIN                9
+#define AO_ADC_SQ2             3
+
+#define AO_ADC_PIN3_PORT       (&samd21_port_a)
+#define AO_ADC_PIN3_PIN                4
+#define AO_ADC_SQ3             4
+
+#define AO_ADC_PIN4_PORT       (&samd21_port_a)
+#define AO_ADC_PIN4_PIN                5
+#define AO_ADC_SQ4             5
+
+#define AO_ADC_PIN5_PORT       (&samd21_port_b)
+#define AO_ADC_PIN5_PIN                2
+#define AO_ADC_SQ5             10
+
+#define AO_ADC_SQ6             SAMD21_ADC_INPUTCTRL_MUXPOS_TEMP
+
 #endif /* _AO_PINS_H_ */
index 1a5d3c609262406aa383637b60b176ed7067a6f7..65a0e05a0dc3156f12a2e51b0a61198a4c94262b 100644 (file)
 #include <ao_dma_samd21.h>
 #include <ao_exti.h>
 
-#define SNEK_CS_PORT   (&samd21_port_a)
-#define SNEK_CS_PIN    (11)
-#define SNEK_SPI_INDEX AO_SPI_0_PA08_PA09_PA10
-#define SNEK_SPI_SPEED ao_spi_speed(1000000)
-
-static const uint8_t spi_test[] = {
-       0xaa,
-       0xcc,
-       0xff,
-       0x00
-};
-
-static void
-ao_spi_test(void)
-{
-       ao_spi_get_bit(SNEK_CS_PORT, SNEK_CS_PIN, SNEK_SPI_INDEX, SNEK_SPI_SPEED);
-       ao_spi_send(spi_test, sizeof(spi_test), SNEK_SPI_INDEX);
-       ao_spi_put_bit(SNEK_CS_PORT, SNEK_CS_PIN, SNEK_SPI_INDEX);
-}
-
-const struct ao_cmds ao_spi_cmds[] = {
-       { ao_spi_test,  "s \0Send some bytes over spi" },
-       { 0, NULL },
-};
-
 static int     pressed;
 
 static void
@@ -51,24 +26,37 @@ ao_button_callback(void)
        ao_wakeup(&pressed);
 }
 
+static void
+ao_beep_test(void)
+{
+       AO_BEEP_TCC->ctrlbset = (SAMD21_TCC_CTRLB_CMD_READSYNC << SAMD21_TCC_CTRLB_CMD);
+       printf("pressed timer %ld\n", AO_BEEP_TCC->count);
+       fflush(stdout);
+       ao_beep_for(AO_BEEP_MID_DEFAULT, AO_MS_TO_TICKS(200));
+}
+
 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);
+       ao_exti_setup(&samd21_port_a, 10, AO_EXTI_MODE_FALLING | AO_EXTI_MODE_PULL_UP, ao_button_callback);
+       ao_exti_enable(&samd21_port_a, 10);
        for (;;) {
                ao_arch_block_interrupts();
                pressed = 0;
                while (!pressed)
                        ao_sleep(&pressed);
                ao_arch_release_interrupts();
-               printf("pressed\n");
-               fflush(stdout);
+               ao_beep_test();
        }
 }
 
 static struct ao_task ao_button_task;
 
+const struct ao_cmds ao_test_cmds[] = {
+       { ao_beep_test, "b \0beep" },
+       { 0, NULL },
+};
+
 int main(void)
 {
        ao_led_init();
@@ -78,12 +66,15 @@ int main(void)
        ao_dma_init();
        ao_exti_init();
        ao_spi_init();
+       ao_adc_init();
+       ao_beep_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_cmd_register(ao_test_cmds);
        ao_add_task(&ao_button_task, ao_button, "button");
        ao_start_scheduler();
+
        return 0;
 }