diff --git a/cores/arduino/ard_sup/gpio/ap3_gpio.cpp b/cores/arduino/ard_sup/gpio/ap3_gpio.cpp index a7991296..4d56230e 100644 --- a/cores/arduino/ard_sup/gpio/ap3_gpio.cpp +++ b/cores/arduino/ard_sup/gpio/ap3_gpio.cpp @@ -12,11 +12,16 @@ ap3_gpio_isr_entry_t gpio_isr_entries[AP3_GPIO_MAX_PADS] = {NULL}; uint8_t gpio_num_isr = 0; //***************************************************************************** -// Local defines. Copied from am_hal_gpio.c +// Local function declarations +//***************************************************************************** +static inline uint32_t ap3_get_funct_sel(ap3_gpio_pad_t pad); + +//***************************************************************************** +// Local defines. //***************************************************************************** // // Generally define GPIO PADREG and GPIOCFG bitfields -// +// Copied from am_hal_gpio.c #define PADREG_FLD_76_S 6 #define PADREG_FLD_FNSEL_S 3 #define PADREG_FLD_DRVSTR_S 2 @@ -27,6 +32,10 @@ uint8_t gpio_num_isr = 0; #define GPIOCFG_FLD_OUTCFG_S 1 #define GPIOCFG_FLD_INCFG_S 0 +//Additional Defines +#define PADREG_FNSEL_Msk 0x38 +#define GPIO_FUNCTION 3 + ap3_gpio_pad_t ap3_gpio_pin2pad(ap3_gpio_pin_t pin) { return ap3_variant_pinmap[pin]; @@ -76,32 +85,34 @@ void padMode(uint8_t pad, am_hal_gpio_pincfg_t mode) } // translate Arduino style pin mode function to apollo3 implementation -void pinMode(uint8_t pin, uint8_t mode) { +void pinMode(uint8_t pin, uint8_t mode) +{ am_hal_gpio_pincfg_t pinmode = AP3_GPIO_PINCFG_NULL; - switch (mode) { - case INPUT: - pinmode = AP3_PINCFG_INPUT; - break; - case OUTPUT: - pinmode = AP3_PINCFG_OUTPUT; - break; - case INPUT_PULLUP: - pinmode = AP3_PINCFG_INPUT_PULLUP; - break; - case INPUT_PULLDOWN: - pinmode = AP3_PINCFG_INPUT_PULLDOWN; - break; - case OPEN_DRAIN: - pinmode = AP3_PINCFG_OPEN_DRAIN; - break; - case TRISTATE: - pinmode = AP3_PINCFG_TRISTATE; - break; - default: - //no match, just do nothing - return; + switch (mode) + { + case INPUT: + pinmode = AP3_PINCFG_INPUT; + break; + case OUTPUT: + pinmode = AP3_PINCFG_OUTPUT; + break; + case INPUT_PULLUP: + pinmode = AP3_PINCFG_INPUT_PULLUP; + break; + case INPUT_PULLDOWN: + pinmode = AP3_PINCFG_INPUT_PULLDOWN; + break; + case OPEN_DRAIN: + pinmode = AP3_PINCFG_OPEN_DRAIN; + break; + case TRISTATE: + pinmode = AP3_PINCFG_TRISTATE; + break; + default: + //no match, just do nothing + return; } pinMode(pin, pinmode); @@ -135,6 +146,16 @@ extern void digitalWrite(uint8_t pin, uint8_t val) } } +static inline uint32_t ap3_get_funct_sel(ap3_gpio_pad_t pad) +{ + uint32_t padregAddr = AM_REGADDR(GPIO, PADREGA) + (pad & ~0x3); + uint32_t padShft = ((pad & 0x3) << 3); + uint32_t functSelShift = PADREG_FLD_FNSEL_S; + uint32_t functSelMask = PADREG_FNSEL_Msk; + + return (((AM_REGVAL(padregAddr) >> padShft) & functSelMask) >> functSelShift); +} + extern int digitalRead(uint8_t pin) { ap3_gpio_pad_t pad = ap3_gpio_pin2pad(pin);