diff options
author | Joey Castillo <jose.castillo@gmail.com> | 2021-09-14 15:12:30 -0400 |
---|---|---|
committer | Joey Castillo <jose.castillo@gmail.com> | 2021-09-14 15:12:30 -0400 |
commit | cb98f29e5778974ebd91b99f9757c63726b62e51 (patch) | |
tree | 8e74eca01b2f7012697725acf400bba29e0d378e /watch-library | |
parent | e4c1700806d348811b8932004cfa268a40a00636 (diff) | |
download | Sensor-Watch-cb98f29e5778974ebd91b99f9757c63726b62e51.tar.gz Sensor-Watch-cb98f29e5778974ebd91b99f9757c63726b62e51.tar.bz2 Sensor-Watch-cb98f29e5778974ebd91b99f9757c63726b62e51.zip |
more work on alternate board pinouts
Diffstat (limited to 'watch-library')
-rw-r--r-- | watch-library/hw/driver_init.c | 54 | ||||
-rw-r--r-- | watch-library/hw/driver_init.h | 10 | ||||
-rw-r--r-- | watch-library/watch/watch_extint.c | 70 | ||||
-rw-r--r-- | watch-library/watch/watch_extint.h | 7 |
4 files changed, 72 insertions, 69 deletions
diff --git a/watch-library/hw/driver_init.c b/watch-library/hw/driver_init.c index 273852cf..2cfdced7 100644 --- a/watch-library/hw/driver_init.c +++ b/watch-library/hw/driver_init.c @@ -66,33 +66,33 @@ void delay_driver_init(void) { } void SEGMENT_LCD_0_PORT_init(void) { - gpio_set_pin_function(COM0, PINMUX_PB06B_SLCD_LP0); - gpio_set_pin_function(COM1, PINMUX_PB07B_SLCD_LP1); - gpio_set_pin_function(COM2, PINMUX_PB08B_SLCD_LP2); - gpio_set_pin_function(SEG0, PINMUX_PB09B_SLCD_LP3); - gpio_set_pin_function(SEG1, PINMUX_PA04B_SLCD_LP4); - gpio_set_pin_function(SEG2, PINMUX_PA05B_SLCD_LP5); - gpio_set_pin_function(SEG3, PINMUX_PA06B_SLCD_LP6); - gpio_set_pin_function(SEG4, PINMUX_PA07B_SLCD_LP7); - gpio_set_pin_function(SEG5, PINMUX_PA08B_SLCD_LP11); - gpio_set_pin_function(SEG6, PINMUX_PA09B_SLCD_LP12); - gpio_set_pin_function(SEG7, PINMUX_PA10B_SLCD_LP13); - gpio_set_pin_function(SEG8, PINMUX_PA11B_SLCD_LP14); - gpio_set_pin_function(SEG9, PINMUX_PB11B_SLCD_LP21); - gpio_set_pin_function(SEG10, PINMUX_PB12B_SLCD_LP22); - gpio_set_pin_function(SEG11, PINMUX_PB13B_SLCD_LP23); - gpio_set_pin_function(SEG12, PINMUX_PB14B_SLCD_LP24); - gpio_set_pin_function(SEG13, PINMUX_PB15B_SLCD_LP25); - gpio_set_pin_function(SEG14, PINMUX_PA12B_SLCD_LP28); - gpio_set_pin_function(SEG15, PINMUX_PA13B_SLCD_LP29); - gpio_set_pin_function(SEG16, PINMUX_PA14B_SLCD_LP30); - gpio_set_pin_function(SEG17, PINMUX_PA15B_SLCD_LP31); - gpio_set_pin_function(SEG18, PINMUX_PA16B_SLCD_LP32); - gpio_set_pin_function(SEG19, PINMUX_PA17B_SLCD_LP33); - gpio_set_pin_function(SEG20, PINMUX_PA18B_SLCD_LP34); - gpio_set_pin_function(SEG21, PINMUX_PA19B_SLCD_LP35); - gpio_set_pin_function(SEG22, PINMUX_PB16B_SLCD_LP42); - gpio_set_pin_function(SEG23, PINMUX_PB17B_SLCD_LP43); + gpio_set_pin_function(SLCD0, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD1, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD2, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD3, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD4, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD5, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD6, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD7, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD8, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD9, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD10, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD11, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD12, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD13, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD14, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD15, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD16, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD17, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD18, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD19, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD20, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD21, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD22, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD23, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD24, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD25, GPIO_PIN_FUNCTION_B); + gpio_set_pin_function(SLCD26, GPIO_PIN_FUNCTION_B); } /** diff --git a/watch-library/hw/driver_init.h b/watch-library/hw/driver_init.h index 6780e20d..019a0b56 100644 --- a/watch-library/hw/driver_init.h +++ b/watch-library/hw/driver_init.h @@ -8,6 +8,16 @@ #ifndef DRIVER_INIT_INCLUDED #define DRIVER_INIT_INCLUDED +#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 + #include "pins.h" #ifdef __cplusplus diff --git a/watch-library/watch/watch_extint.c b/watch-library/watch/watch_extint.c index 1199dd35..f2bad949 100644 --- a/watch-library/watch/watch_extint.c +++ b/watch-library/watch/watch_extint.c @@ -37,62 +37,53 @@ void watch_disable_external_interrupts() { } void watch_register_interrupt_callback(const uint8_t pin, ext_irq_cb_t callback, watch_interrupt_trigger trigger) { - uint32_t pinmux; - hri_eic_config_reg_t config = hri_eic_get_CONFIG_reg(EIC, 0, 0xFFFFFFFF); - + uint8_t config_index; + uint8_t sense_pos; switch (pin) { - case A4: - // same steps for each: determine the correct pin mux... - pinmux = PINMUX_PB00A_EIC_EXTINT0; - // ...clear out the configuration for this EIC channel... - config &= ~EIC_CONFIG_SENSE0_Msk; - // ...and reconfigure it with our new trigger value. - config |= EIC_CONFIG_SENSE0(trigger); + case A0: + // for EIC channels 8-15, we need to set the SENSE value in CONFIG[1] + config_index = (WATCH_A0_EIC_CHANNEL > 7) ? 1 : 0; + // either way the index in CONFIG[n] must be 0-7 + sense_pos = 4 * (WATCH_A0_EIC_CHANNEL % 8); break; case A1: - pinmux = PINMUX_PB01A_EIC_EXTINT1; - config &= ~EIC_CONFIG_SENSE1_Msk; - config |= EIC_CONFIG_SENSE1(trigger); - break; - case BTN_ALARM: - gpio_set_pin_pull_mode(pin, GPIO_PULL_DOWN); - pinmux = PINMUX_PA02A_EIC_EXTINT2; - config &= ~EIC_CONFIG_SENSE2_Msk; - config |= EIC_CONFIG_SENSE2(trigger); + config_index = (WATCH_A1_EIC_CHANNEL > 7) ? 1 : 0; + sense_pos = 4 * (WATCH_A1_EIC_CHANNEL % 8); break; case A2: - pinmux = PINMUX_PB02A_EIC_EXTINT2; - config &= ~EIC_CONFIG_SENSE2_Msk; - config |= EIC_CONFIG_SENSE2(trigger); + config_index = (WATCH_A2_EIC_CHANNEL > 7) ? 1 : 0; + sense_pos = 4 * (WATCH_A2_EIC_CHANNEL % 8); break; case A3: - pinmux = PINMUX_PB03A_EIC_EXTINT3; - config &= ~EIC_CONFIG_SENSE3_Msk; - config |= EIC_CONFIG_SENSE3(trigger); + config_index = (WATCH_A3_EIC_CHANNEL > 7) ? 1 : 0; + sense_pos = 4 * (WATCH_A3_EIC_CHANNEL % 8); break; - case A0: - pinmux = PINMUX_PB04A_EIC_EXTINT4; - config &= ~EIC_CONFIG_SENSE4_Msk; - config |= EIC_CONFIG_SENSE4(trigger); + case A4: + config_index = (WATCH_A4_EIC_CHANNEL > 7) ? 1 : 0; + sense_pos = 4 * (WATCH_A4_EIC_CHANNEL % 8); + break; + case BTN_ALARM: + // for the buttons, we need an internal pull-down. + gpio_set_pin_pull_mode(pin, GPIO_PULL_DOWN); + config_index = (WATCH_BTN_ALARM_EIC_CHANNEL > 7) ? 1 : 0; + sense_pos = 4 * (WATCH_BTN_ALARM_EIC_CHANNEL % 8); break; case BTN_LIGHT: gpio_set_pin_pull_mode(pin, GPIO_PULL_DOWN); - pinmux = WATCH_BTN_LIGHT_EIC_PINMUX; - config &= ~EIC_CONFIG_SENSE6_Msk; - config |= EIC_CONFIG_SENSE6(trigger); + config_index = (WATCH_BTN_LIGHT_EIC_CHANNEL > 7) ? 1 : 0; + sense_pos = 4 * (WATCH_BTN_LIGHT_EIC_CHANNEL % 8); break; case BTN_MODE: gpio_set_pin_pull_mode(pin, GPIO_PULL_DOWN); - pinmux = WATCH_BTN_MODE_EIC_PINMUX; - config &= ~EIC_CONFIG_SENSE7_Msk; - config |= EIC_CONFIG_SENSE7(trigger); + config_index = (WATCH_BTN_MODE_EIC_CHANNEL > 7) ? 1 : 0; + sense_pos = 4 * (WATCH_BTN_MODE_EIC_CHANNEL % 8); break; default: return; } gpio_set_pin_direction(pin, GPIO_DIRECTION_IN); - gpio_set_pin_function(pin, pinmux); + gpio_set_pin_function(pin, GPIO_PIN_FUNCTION_A); // EIC configuration register is enable-protected, so we have to disable it first... if (hri_eic_get_CTRLA_reg(EIC, EIC_CTRLA_ENABLE)) { @@ -101,9 +92,12 @@ void watch_register_interrupt_callback(const uint8_t pin, ext_irq_cb_t callback, hri_eic_wait_for_sync(EIC, EIC_SYNCBUSY_ENABLE); } // now update the configuration... - hri_eic_write_CONFIG_reg(EIC, 0, config); + hri_eic_config_reg_t config = EIC->CONFIG[config_index].reg; + config &= ~(7 << sense_pos); + config |= trigger << (sense_pos); + hri_eic_write_CONFIG_reg(EIC, config_index, config); // ...and re-enable the EIC - hri_eic_set_CTRLA_ENABLE_bit(EIC); + hri_eic_set_CTRLA_ENABLE_bit(EIC); ext_irq_register(pin, callback); } diff --git a/watch-library/watch/watch_extint.h b/watch-library/watch/watch_extint.h index e3084371..9c810534 100644 --- a/watch-library/watch/watch_extint.h +++ b/watch-library/watch/watch_extint.h @@ -59,16 +59,15 @@ void watch_disable_external_interrupts(); * want to detect both rising and falling conditions (i.e. button down and button up), use * INTERRUPT_TRIGGER_BOTH and use watch_get_pin_level to check the pin level in your callback * to determine which condition caused the interrupt. - * @param pin One of pins BTN_LIGHT, BTN_MODE, BTN_ALARM, or A0-A5. If the pin parameter matches one of + * @param pin One of pins BTN_LIGHT, BTN_MODE, BTN_ALARM, or A0-A4. If the pin parameter matches one of * the three button pins, this function will also enable an internal pull-down resistor. If - * the pin parameter is A0-A5, you are responsible for setting any required pull configuration + * the pin parameter is A0-A4, you are responsible for setting any required pull configuration * using watch_enable_pull_up or watch_enable_pull_down. * @param callback The function you wish to have called when the button is pressed. * @param trigger The condition on which you wish to trigger: rising, falling or both. * @note The alarm button and pin A2 share an external interrupt channel EXTINT[2]; you can only use one * or the other. However! These pins both have an alternate method of triggering via the RTC tamper - * interrupt, which for A2 at least has the added benefit of being able to trigger in the low-power - * BACKUP mode. + * interrupt, which has the added benefit of not requiring the external interrupt controller at all. * @see watch_register_extwake_callback */ void watch_register_interrupt_callback(const uint8_t pin, ext_irq_cb_t callback, watch_interrupt_trigger trigger); |