summaryrefslogtreecommitdiffstats
path: root/watch-library/watch
diff options
context:
space:
mode:
authorJoey Castillo <jose.castillo@gmail.com>2021-09-14 15:12:30 -0400
committerJoey Castillo <jose.castillo@gmail.com>2021-09-14 15:12:30 -0400
commitcb98f29e5778974ebd91b99f9757c63726b62e51 (patch)
tree8e74eca01b2f7012697725acf400bba29e0d378e /watch-library/watch
parente4c1700806d348811b8932004cfa268a40a00636 (diff)
downloadSensor-Watch-cb98f29e5778974ebd91b99f9757c63726b62e51.tar.gz
Sensor-Watch-cb98f29e5778974ebd91b99f9757c63726b62e51.tar.bz2
Sensor-Watch-cb98f29e5778974ebd91b99f9757c63726b62e51.zip
more work on alternate board pinouts
Diffstat (limited to 'watch-library/watch')
-rw-r--r--watch-library/watch/watch_extint.c70
-rw-r--r--watch-library/watch/watch_extint.h7
2 files changed, 35 insertions, 42 deletions
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);