From 5a53916f0e51f02aab6d892c87310e5730abce5c Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Mon, 13 Sep 2021 16:43:35 -0400 Subject: first steps toward supporting alternate board pinouts --- boards/OSO-SWAT-A1-04/pins.h | 78 +++++++++++++++++++++++++++++++++++++ make.mk | 5 +++ watch-library/hw/atmel_start_pins.h | 74 ----------------------------------- watch-library/hw/driver_init.h | 2 +- watch-library/main.c | 2 +- watch-library/watch/watch_buzzer.c | 4 +- watch-library/watch/watch_extint.c | 4 +- watch-library/watch/watch_led.c | 12 +----- watch-library/watch/watch_private.c | 10 ++--- 9 files changed, 96 insertions(+), 95 deletions(-) create mode 100644 boards/OSO-SWAT-A1-04/pins.h delete mode 100644 watch-library/hw/atmel_start_pins.h diff --git a/boards/OSO-SWAT-A1-04/pins.h b/boards/OSO-SWAT-A1-04/pins.h new file mode 100644 index 00000000..3be122bd --- /dev/null +++ b/boards/OSO-SWAT-A1-04/pins.h @@ -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 a58aba38..b892be98 100644 --- 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 index 4920e67e..00000000 --- a/watch-library/hw/atmel_start_pins.h +++ /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 - -// 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 diff --git a/watch-library/hw/driver_init.h b/watch-library/hw/driver_init.h index a6a3b565..6780e20d 100644 --- a/watch-library/hw/driver_init.h +++ b/watch-library/hw/driver_init.h @@ -8,7 +8,7 @@ #ifndef DRIVER_INIT_INCLUDED #define DRIVER_INIT_INCLUDED -#include "atmel_start_pins.h" +#include "pins.h" #ifdef __cplusplus extern "C" { diff --git a/watch-library/main.c b/watch-library/main.c index af34d850..c9f24150 100755 --- a/watch-library/main.c +++ b/watch-library/main.c @@ -30,7 +30,7 @@ #include #include "saml22.h" #include "hal_init.h" -#include "atmel_start_pins.h" +#include "pins.h" #include "watch.h" #include "tusb.h" diff --git a/watch-library/watch/watch_buzzer.c b/watch-library/watch/watch_buzzer.c index c6c89a0e..9cb37393 100644 --- a/watch-library/watch/watch_buzzer.c +++ b/watch-library/watch/watch_buzzer.c @@ -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); diff --git a/watch-library/watch/watch_extint.c b/watch-library/watch/watch_extint.c index 421700bc..1199dd35 100644 --- a/watch-library/watch/watch_extint.c +++ b/watch-library/watch/watch_extint.c @@ -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; diff --git a/watch-library/watch/watch_led.c b/watch-library/watch/watch_led.c index f6419737..7b189452 100644 --- a/watch-library/watch/watch_led.c +++ b/watch-library/watch/watch_led.c @@ -22,14 +22,6 @@ * 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)); } } diff --git a/watch-library/watch/watch_private.c b/watch-library/watch/watch_private.c index 8dfd10f9..dd3cba0b 100644 --- a/watch-library/watch/watch_private.c +++ b/watch-library/watch/watch_private.c @@ -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() { -- cgit v1.2.3