@@ -12,11 +12,16 @@ ap3_gpio_isr_entry_t gpio_isr_entries[AP3_GPIO_MAX_PADS] = {NULL};
1212uint8_t gpio_num_isr = 0 ;
1313
1414// *****************************************************************************
15- // Local defines. Copied from am_hal_gpio.c
15+ // Local function declarations
16+ // *****************************************************************************
17+ static inline uint32_t ap3_get_funct_sel (ap3_gpio_pad_t pad);
18+
19+ // *****************************************************************************
20+ // Local defines.
1621// *****************************************************************************
1722//
1823// Generally define GPIO PADREG and GPIOCFG bitfields
19- //
24+ // Copied from am_hal_gpio.c
2025#define PADREG_FLD_76_S 6
2126#define PADREG_FLD_FNSEL_S 3
2227#define PADREG_FLD_DRVSTR_S 2
@@ -27,6 +32,10 @@ uint8_t gpio_num_isr = 0;
2732#define GPIOCFG_FLD_OUTCFG_S 1
2833#define GPIOCFG_FLD_INCFG_S 0
2934
35+ // Additional Defines
36+ #define PADREG_FNSEL_Msk 0x38
37+ #define GPIO_FUNCTION 3
38+
3039ap3_gpio_pad_t ap3_gpio_pin2pad (ap3_gpio_pin_t pin)
3140{
3241 return ap3_variant_pinmap[pin];
@@ -76,32 +85,34 @@ void padMode(uint8_t pad, am_hal_gpio_pincfg_t mode)
7685}
7786
7887// translate Arduino style pin mode function to apollo3 implementation
79- void pinMode (uint8_t pin, uint8_t mode) {
88+ void pinMode (uint8_t pin, uint8_t mode)
89+ {
8090
8191 am_hal_gpio_pincfg_t pinmode = AP3_GPIO_PINCFG_NULL;
8292
83- switch (mode) {
84- case INPUT:
85- pinmode = AP3_PINCFG_INPUT;
86- break ;
87- case OUTPUT:
88- pinmode = AP3_PINCFG_OUTPUT;
89- break ;
90- case INPUT_PULLUP:
91- pinmode = AP3_PINCFG_INPUT_PULLUP;
92- break ;
93- case INPUT_PULLDOWN:
94- pinmode = AP3_PINCFG_INPUT_PULLDOWN;
95- break ;
96- case OPEN_DRAIN:
97- pinmode = AP3_PINCFG_OPEN_DRAIN;
98- break ;
99- case TRISTATE:
100- pinmode = AP3_PINCFG_TRISTATE;
101- break ;
102- default :
103- // no match, just do nothing
104- return ;
93+ switch (mode)
94+ {
95+ case INPUT:
96+ pinmode = AP3_PINCFG_INPUT;
97+ break ;
98+ case OUTPUT:
99+ pinmode = AP3_PINCFG_OUTPUT;
100+ break ;
101+ case INPUT_PULLUP:
102+ pinmode = AP3_PINCFG_INPUT_PULLUP;
103+ break ;
104+ case INPUT_PULLDOWN:
105+ pinmode = AP3_PINCFG_INPUT_PULLDOWN;
106+ break ;
107+ case OPEN_DRAIN:
108+ pinmode = AP3_PINCFG_OPEN_DRAIN;
109+ break ;
110+ case TRISTATE:
111+ pinmode = AP3_PINCFG_TRISTATE;
112+ break ;
113+ default :
114+ // no match, just do nothing
115+ return ;
105116 }
106117
107118 pinMode (pin, pinmode);
@@ -135,6 +146,16 @@ extern void digitalWrite(uint8_t pin, uint8_t val)
135146 }
136147}
137148
149+ static inline uint32_t ap3_get_funct_sel (ap3_gpio_pad_t pad)
150+ {
151+ uint32_t padregAddr = AM_REGADDR (GPIO, PADREGA) + (pad & ~0x3 );
152+ uint32_t padShft = ((pad & 0x3 ) << 3 );
153+ uint32_t functSelShift = PADREG_FLD_FNSEL_S;
154+ uint32_t functSelMask = PADREG_FNSEL_Msk;
155+
156+ return (((AM_REGVAL (padregAddr) >> padShft) & functSelMask) >> functSelShift);
157+ }
158+
138159extern int digitalRead (uint8_t pin)
139160{
140161 ap3_gpio_pad_t pad = ap3_gpio_pin2pad (pin);
0 commit comments