]> git.earman.xyz Git - sensor-watch.git/commitdiff
first steps toward supporting alternate board pinouts
authorJoey Castillo <jose.castillo@gmail.com>
Mon, 13 Sep 2021 20:43:35 +0000 (16:43 -0400)
committerJoey Castillo <jose.castillo@gmail.com>
Mon, 13 Sep 2021 20:44:07 +0000 (16:44 -0400)
boards/OSO-SWAT-A1-04/pins.h [new file with mode: 0644]
make.mk
watch-library/hw/atmel_start_pins.h [deleted file]
watch-library/hw/driver_init.h
watch-library/main.c
watch-library/watch/watch_buzzer.c
watch-library/watch/watch_extint.c
watch-library/watch/watch_led.c
watch-library/watch/watch_private.c

diff --git a/boards/OSO-SWAT-A1-04/pins.h b/boards/OSO-SWAT-A1-04/pins.h
new file mode 100644 (file)
index 0000000..3be122b
--- /dev/null
@@ -0,0 +1,78 @@
+#ifndef PINS_H_INCLUDED
+#define PINS_H_INCLUDED
+
+// Detects if we are on USB power.
+#define VBUS_DET GPIO(GPIO_PORTA, 3)
+
+// Buttons
+#define BTN_ALARM GPIO(GPIO_PORTA, 2)
+#define BTN_LIGHT GPIO(GPIO_PORTA, 22)
+#define WATCH_BTN_LIGHT_EIC_PINMUX PINMUX_PA22A_EIC_EXTINT6
+#define BTN_MODE GPIO(GPIO_PORTA, 23)
+#define WATCH_BTN_MODE_EIC_PINMUX PINMUX_PA23A_EIC_EXTINT7
+
+// Buzzer
+#define BUZZER GPIO(GPIO_PORTA, 27)
+#define WATCH_BUZZER_TCC_PINMUX PINMUX_PA27F_TCC0_WO5
+#define WATCH_BUZZER_TCC_CHANNEL 1
+
+// LEDs
+#ifdef WATCH_SWAP_LED_PINS
+    #define RED GPIO(GPIO_PORTA, 21)
+    #define WATCH_RED_TCC_PINMUX PINMUX_PA21F_TCC0_WO7
+    #define WATCH_RED_TCC_CHANNEL 3
+    #define GREEN GPIO(GPIO_PORTA, 20)
+    #define WATCH_GREEN_TCC_CHANNEL 2
+    #define WATCH_GREEN_TCC_PINMUX PINMUX_PA20F_TCC0_WO6
+#else
+    #define RED GPIO(GPIO_PORTA, 20)
+    #define WATCH_RED_TCC_PINMUX PINMUX_PA20F_TCC0_WO6
+    #define WATCH_RED_TCC_CHANNEL 2
+    #define GREEN GPIO(GPIO_PORTA, 21)
+    #define WATCH_GREEN_TCC_CHANNEL 3
+    #define WATCH_GREEN_TCC_PINMUX PINMUX_PA21F_TCC0_WO7
+#endif
+
+// Segment LCD
+#define COM0 GPIO(GPIO_PORTB, 6)
+#define COM1 GPIO(GPIO_PORTB, 7)
+#define COM2 GPIO(GPIO_PORTB, 8)
+#define SEG0 GPIO(GPIO_PORTB, 9)
+#define SEG1 GPIO(GPIO_PORTA, 4)
+#define SEG2 GPIO(GPIO_PORTA, 5)
+#define SEG3 GPIO(GPIO_PORTA, 6)
+#define SEG4 GPIO(GPIO_PORTA, 7)
+#define SEG5 GPIO(GPIO_PORTA, 8)
+#define SEG6 GPIO(GPIO_PORTA, 9)
+#define SEG7 GPIO(GPIO_PORTA, 10)
+#define SEG8 GPIO(GPIO_PORTA, 11)
+#define SEG9 GPIO(GPIO_PORTB, 11)
+#define SEG10 GPIO(GPIO_PORTB, 12)
+#define SEG11 GPIO(GPIO_PORTB, 13)
+#define SEG12 GPIO(GPIO_PORTB, 14)
+#define SEG13 GPIO(GPIO_PORTB, 15)
+#define SEG14 GPIO(GPIO_PORTA, 12)
+#define SEG15 GPIO(GPIO_PORTA, 13)
+#define SEG16 GPIO(GPIO_PORTA, 14)
+#define SEG17 GPIO(GPIO_PORTA, 15)
+#define SEG18 GPIO(GPIO_PORTA, 16)
+#define SEG19 GPIO(GPIO_PORTA, 17)
+#define SEG20 GPIO(GPIO_PORTA, 18)
+#define SEG21 GPIO(GPIO_PORTA, 19)
+#define SEG22 GPIO(GPIO_PORTB, 16)
+#define SEG23 GPIO(GPIO_PORTB, 17)
+
+// 9-pin connector
+#define A0 GPIO(GPIO_PORTB, 4)
+#define A1 GPIO(GPIO_PORTB, 1)
+#define A2 GPIO(GPIO_PORTB, 2)
+#define A3 GPIO(GPIO_PORTB, 3)
+#define A4 GPIO(GPIO_PORTB, 0)
+#define SDA GPIO(GPIO_PORTB, 30)
+#define SCL GPIO(GPIO_PORTB, 31)
+
+// aliases for as A3/A4; these were mentioned as D0/D1 in early documentation.
+#define D0 GPIO(GPIO_PORTB, 3)
+#define D1 GPIO(GPIO_PORTB, 0)
+
+#endif // PINS_H_INCLUDED
diff --git a/make.mk b/make.mk
index a58aba38df5a432540ec6a4b73b6e6e499a479f3..b892be9807afeda8ad368bb3dda0e97a705f0dfa 100644 (file)
--- a/make.mk
+++ b/make.mk
@@ -2,6 +2,10 @@
 BUILD = ./build
 BIN = watch
 
+ifndef BOARD
+override BOARD = OSO-SWAT-A1-04
+endif
+
 ##############################################################################
 .PHONY: all directory clean size
 
@@ -31,6 +35,7 @@ LDFLAGS += -Wl,--script=../../watch-library/linker/saml22j18.ld
 # ../drivers/
 INCLUDES += \
   -I../../tinyusb/src \
+  -I../../boards/$(BOARD) \
   -I../../watch-library/include \
   -I../../watch-library/hal/ \
   -I../../watch-library/hal/documentation/ \
diff --git a/watch-library/hw/atmel_start_pins.h b/watch-library/hw/atmel_start_pins.h
deleted file mode 100644 (file)
index 4920e67..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Code generated from Atmel Start.
- *
- * This file will be overwritten when reconfiguring your Atmel Start project.
- * Please copy examples or other code you want to keep to a separate file
- * to avoid losing it when reconfiguring.
- */
-#ifndef ATMEL_START_PINS_H_INCLUDED
-#define ATMEL_START_PINS_H_INCLUDED
-
-#include <hal_gpio.h>
-
-// SAML22 has 9 pin functions
-
-#define GPIO_PIN_FUNCTION_A 0
-#define GPIO_PIN_FUNCTION_B 1
-#define GPIO_PIN_FUNCTION_C 2
-#define GPIO_PIN_FUNCTION_D 3
-#define GPIO_PIN_FUNCTION_E 4
-#define GPIO_PIN_FUNCTION_F 5
-#define GPIO_PIN_FUNCTION_G 6
-#define GPIO_PIN_FUNCTION_H 7
-#define GPIO_PIN_FUNCTION_I 8
-
-#define VBUS_DET GPIO(GPIO_PORTA, 3)
-#define SEG1 GPIO(GPIO_PORTA, 4)
-#define SEG2 GPIO(GPIO_PORTA, 5)
-#define SEG3 GPIO(GPIO_PORTA, 6)
-#define SEG4 GPIO(GPIO_PORTA, 7)
-#define SEG5 GPIO(GPIO_PORTA, 8)
-#define SEG6 GPIO(GPIO_PORTA, 9)
-#define SEG7 GPIO(GPIO_PORTA, 10)
-#define SEG8 GPIO(GPIO_PORTA, 11)
-#define SEG14 GPIO(GPIO_PORTA, 12)
-#define SEG15 GPIO(GPIO_PORTA, 13)
-#define SEG16 GPIO(GPIO_PORTA, 14)
-#define SEG17 GPIO(GPIO_PORTA, 15)
-#define SEG18 GPIO(GPIO_PORTA, 16)
-#define SEG19 GPIO(GPIO_PORTA, 17)
-#define SEG20 GPIO(GPIO_PORTA, 18)
-#define SEG21 GPIO(GPIO_PORTA, 19)
-#ifdef WATCH_SWAP_LED_PINS
-    #define RED GPIO(GPIO_PORTA, 21)
-    #define GREEN GPIO(GPIO_PORTA, 20)
-#else
-    #define RED GPIO(GPIO_PORTA, 20)
-    #define GREEN GPIO(GPIO_PORTA, 21)
-#endif
-#define BTN_ALARM GPIO(GPIO_PORTA, 2)
-#define BTN_LIGHT GPIO(GPIO_PORTA, 22)
-#define BTN_MODE GPIO(GPIO_PORTA, 23)
-#define BUZZER GPIO(GPIO_PORTA, 27)
-#define A0 GPIO(GPIO_PORTB, 4)
-#define A1 GPIO(GPIO_PORTB, 1)
-#define A2 GPIO(GPIO_PORTB, 2)
-#define A3 GPIO(GPIO_PORTB, 3)
-#define A4 GPIO(GPIO_PORTB, 0)
-#define D0 GPIO(GPIO_PORTB, 3)
-#define D1 GPIO(GPIO_PORTB, 0)
-#define COM0 GPIO(GPIO_PORTB, 6)
-#define COM1 GPIO(GPIO_PORTB, 7)
-#define COM2 GPIO(GPIO_PORTB, 8)
-#define SEG0 GPIO(GPIO_PORTB, 9)
-#define SEG9 GPIO(GPIO_PORTB, 11)
-#define SEG10 GPIO(GPIO_PORTB, 12)
-#define SEG11 GPIO(GPIO_PORTB, 13)
-#define SEG12 GPIO(GPIO_PORTB, 14)
-#define SEG13 GPIO(GPIO_PORTB, 15)
-#define SEG22 GPIO(GPIO_PORTB, 16)
-#define SEG23 GPIO(GPIO_PORTB, 17)
-#define SDA GPIO(GPIO_PORTB, 30)
-#define SCL GPIO(GPIO_PORTB, 31)
-
-#endif // ATMEL_START_PINS_H_INCLUDED
index a6a3b5656983dbc1360a0b09ee6f8441a0d92ae8..6780e20d6f15a6d1a5a549ce6291ae429f0a94c2 100644 (file)
@@ -8,7 +8,7 @@
 #ifndef DRIVER_INIT_INCLUDED
 #define DRIVER_INIT_INCLUDED
 
-#include "atmel_start_pins.h"
+#include "pins.h"
 
 #ifdef __cplusplus
 extern "C" {
index af34d8506059fc9787f961e3bbf14c5ad193512c..c9f24150be74ba4aab4f3fa7f5d9cdf4f5d67715 100755 (executable)
@@ -30,7 +30,7 @@
 #include <stdio.h>
 #include "saml22.h"
 #include "hal_init.h"
-#include "atmel_start_pins.h"
+#include "pins.h"
 #include "watch.h"
 #include "tusb.h"
 
index c6c89a0e7216b1ffeadb7d67f871f8a8427d44f4..9cb37393378c71a747ceeccaccf1e007239cfa68 100644 (file)
@@ -37,7 +37,7 @@ void watch_disable_buzzer() {
 
 inline void watch_set_buzzer_on() {
     gpio_set_pin_direction(BUZZER, GPIO_DIRECTION_OUT);
-    gpio_set_pin_function(BUZZER, PINMUX_PA27F_TCC0_WO5);
+    gpio_set_pin_function(BUZZER, WATCH_BUZZER_TCC_PINMUX);
 }
 
 inline void watch_set_buzzer_off() {
@@ -54,7 +54,7 @@ void watch_buzzer_play_note(BuzzerNote note, uint16_t duration_ms) {
         watch_set_buzzer_off();
     } else {
         hri_tcc_write_PERBUF_reg(TCC0, NotePeriods[note]);
-        hri_tcc_write_CCBUF_reg(TCC0, 1, NotePeriods[note] / 2);
+        hri_tcc_write_CCBUF_reg(TCC0, WATCH_BUZZER_TCC_CHANNEL, NotePeriods[note] / 2);
         watch_set_buzzer_on();
     }
     delay_ms(duration_ms);
index 421700bc9f07ab016daf79980e1a9702c2374dd8..1199dd3557d0e915c1b7da9c946b840a81a5c601 100644 (file)
@@ -77,13 +77,13 @@ void watch_register_interrupt_callback(const uint8_t pin, ext_irq_cb_t callback,
             break;
         case BTN_LIGHT:
             gpio_set_pin_pull_mode(pin, GPIO_PULL_DOWN);
-            pinmux = PINMUX_PA22A_EIC_EXTINT6;
+            pinmux = WATCH_BTN_LIGHT_EIC_PINMUX;
             config &= ~EIC_CONFIG_SENSE6_Msk;
             config |= EIC_CONFIG_SENSE6(trigger);
             break;
         case BTN_MODE:
             gpio_set_pin_pull_mode(pin, GPIO_PULL_DOWN);
-            pinmux = PINMUX_PA23A_EIC_EXTINT7;
+            pinmux = WATCH_BTN_MODE_EIC_PINMUX;
             config &= ~EIC_CONFIG_SENSE7_Msk;
             config |= EIC_CONFIG_SENSE7(trigger);
             break;
index f6419737062280cb7bb7a64a05c9dd73aeb558b6..7b1894529511da4f75af20ac15925ea8384819b1 100644 (file)
  * SOFTWARE.
  */
 
-#ifdef WATCH_SWAP_LED_PINS
-    #define WATCH_RED_CHANNEL 3
-    #define WATCH_GREEN_CHANNEL 2
-#else
-    #define WATCH_RED_CHANNEL 2
-    #define WATCH_GREEN_CHANNEL 3
-#endif
-
 void watch_enable_leds() {
     if (!hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) {
         _watch_enable_tcc();
@@ -53,8 +45,8 @@ void watch_disable_led(bool unused) {
 void watch_set_led_color(uint8_t red, uint8_t green) {
     if (hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) {
         uint32_t period = hri_tcc_get_PER_reg(TCC0, TCC_PER_MASK);
-        hri_tcc_write_CCBUF_reg(TCC0, WATCH_RED_CHANNEL, ((period * red * 1000ull) / 255000ull));
-        hri_tcc_write_CCBUF_reg(TCC0, WATCH_GREEN_CHANNEL, ((period * green * 1000ull) / 255000ull));
+        hri_tcc_write_CCBUF_reg(TCC0, WATCH_RED_TCC_CHANNEL, ((period * red * 1000ull) / 255000ull));
+        hri_tcc_write_CCBUF_reg(TCC0, WATCH_GREEN_TCC_CHANNEL, ((period * green * 1000ull) / 255000ull));
     }
 }
 
index 8dfd10f98b97b89f223e72a8a3f9812408ec5b1b..dd3cba0badc6b404bbe62aee951009604b9119c5 100644 (file)
@@ -93,18 +93,18 @@ void _watch_enable_tcc() {
     // get the LED working. Almost any period will do, tho it should be below 20000 (i.e. 50 Hz) to avoid flickering.
     hri_tcc_write_PER_reg(TCC0, 4096);
     // Set the duty cycle of all pins to 0: LED's off, buzzer not buzzing.
-    hri_tcc_write_CC_reg(TCC0, 1, 0);
-    hri_tcc_write_CC_reg(TCC0, 2, 0);
-    hri_tcc_write_CC_reg(TCC0, 3, 0);
+    hri_tcc_write_CC_reg(TCC0, WATCH_BUZZER_TCC_CHANNEL, 0);
+    hri_tcc_write_CC_reg(TCC0, WATCH_RED_TCC_CHANNEL, 0);
+    hri_tcc_write_CC_reg(TCC0, WATCH_GREEN_TCC_CHANNEL, 0);
     // Enable the TCC
     hri_tcc_set_CTRLA_ENABLE_bit(TCC0);
     hri_tcc_wait_for_sync(TCC0, TCC_SYNCBUSY_ENABLE);
 
     // enable LED PWM pins (the LED driver assumes if the TCC is on, the pins are enabled)
     gpio_set_pin_direction(RED, GPIO_DIRECTION_OUT);
-    gpio_set_pin_function(RED, PINMUX_PA20F_TCC0_WO6);
+    gpio_set_pin_function(RED, WATCH_RED_TCC_PINMUX);
     gpio_set_pin_direction(GREEN, GPIO_DIRECTION_OUT);
-    gpio_set_pin_function(GREEN, PINMUX_PA21F_TCC0_WO7);
+    gpio_set_pin_function(GREEN, WATCH_GREEN_TCC_PINMUX);
 }
 
 void _watch_disable_tcc() {