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 --- 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 +++++----- 4 files changed, 11 insertions(+), 19 deletions(-) (limited to 'watch-library/watch') 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