more work on alternate board pinouts

This commit is contained in:
Joey Castillo 2021-09-14 15:12:30 -04:00
parent e4c1700806
commit cb98f29e57
6 changed files with 108 additions and 99 deletions

View file

@ -76,7 +76,7 @@ void app_wake_from_deep_sleep() {
* still be configured with the correct date and time.
*/
void app_setup() {
watch_enable_led(false); // enable LED with plain digital IO, not PWM
watch_enable_leds();
watch_enable_external_interrupts();
// This starter app demonstrates three different ways of using the button interrupts.

View file

@ -6,10 +6,11 @@
// Buttons
#define BTN_ALARM GPIO(GPIO_PORTA, 2)
#define WATCH_BTN_ALARM_EIC_CHANNEL 2
#define BTN_LIGHT GPIO(GPIO_PORTA, 22)
#define WATCH_BTN_LIGHT_EIC_PINMUX PINMUX_PA22A_EIC_EXTINT6
#define WATCH_BTN_LIGHT_EIC_CHANNEL 6
#define BTN_MODE GPIO(GPIO_PORTA, 23)
#define WATCH_BTN_MODE_EIC_PINMUX PINMUX_PA23A_EIC_EXTINT7
#define WATCH_BTN_MODE_EIC_CHANNEL 7
// Buzzer
#define BUZZER GPIO(GPIO_PORTA, 27)
@ -34,40 +35,45 @@
#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)
#define SLCD0 GPIO(GPIO_PORTB, 6)
#define SLCD1 GPIO(GPIO_PORTB, 7)
#define SLCD2 GPIO(GPIO_PORTB, 8)
#define SLCD3 GPIO(GPIO_PORTB, 9)
#define SLCD4 GPIO(GPIO_PORTA, 4)
#define SLCD5 GPIO(GPIO_PORTA, 5)
#define SLCD6 GPIO(GPIO_PORTA, 6)
#define SLCD7 GPIO(GPIO_PORTA, 7)
#define SLCD8 GPIO(GPIO_PORTA, 8)
#define SLCD9 GPIO(GPIO_PORTA, 9)
#define SLCD10 GPIO(GPIO_PORTA, 10)
#define SLCD11 GPIO(GPIO_PORTA, 11)
#define SLCD12 GPIO(GPIO_PORTB, 11)
#define SLCD13 GPIO(GPIO_PORTB, 12)
#define SLCD14 GPIO(GPIO_PORTB, 13)
#define SLCD15 GPIO(GPIO_PORTB, 14)
#define SLCD16 GPIO(GPIO_PORTB, 15)
#define SLCD17 GPIO(GPIO_PORTA, 12)
#define SLCD18 GPIO(GPIO_PORTA, 13)
#define SLCD19 GPIO(GPIO_PORTA, 14)
#define SLCD20 GPIO(GPIO_PORTA, 15)
#define SLCD21 GPIO(GPIO_PORTA, 16)
#define SLCD22 GPIO(GPIO_PORTA, 17)
#define SLCD23 GPIO(GPIO_PORTA, 18)
#define SLCD24 GPIO(GPIO_PORTA, 19)
#define SLCD25 GPIO(GPIO_PORTB, 16)
#define SLCD26 GPIO(GPIO_PORTB, 17)
// 9-pin connector
#define A0 GPIO(GPIO_PORTB, 4)
#define WATCH_A0_EIC_CHANNEL 4
#define A1 GPIO(GPIO_PORTB, 1)
#define WATCH_A1_EIC_CHANNEL 1
#define A2 GPIO(GPIO_PORTB, 2)
#define WATCH_A2_EIC_CHANNEL 2
#define A3 GPIO(GPIO_PORTB, 3)
#define WATCH_A3_EIC_CHANNEL 3
#define A4 GPIO(GPIO_PORTB, 0)
#define WATCH_A4_EIC_CHANNEL 0
#define SDA GPIO(GPIO_PORTB, 30)
#define SCL GPIO(GPIO_PORTB, 31)

View file

@ -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);
}
/**

View file

@ -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

View file

@ -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);
}

View file

@ -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);