Skip to content

Commit d50bdcf

Browse files
author
Owen
authored
Fix for Broken Arduino libraries due to implementaion of commonly… (#99)
Fix for Broken Arduino libraries due to implementaion of commonly used GPIO constants, issue #98
2 parents 88682f4 + 8baba3e commit d50bdcf

File tree

4 files changed

+50
-7
lines changed

4 files changed

+50
-7
lines changed

cores/arduino/ard_sup/analog/ap3_analog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ ap3_err_t ap3_set_pin_to_analog(uint8_t pinNumber)
313313
ap3_err_t retval = AP3_ERR;
314314

315315
uint8_t funcsel = 0;
316-
am_hal_gpio_pincfg_t pincfg = INPUT;
316+
am_hal_gpio_pincfg_t pincfg = AP3_PINCFG_INPUT;
317317
retval = ap3_analog_pad_funcsel(ap3_gpio_pin2pad(pinNumber), &funcsel);
318318

319319
if (retval != AP3_OK)

cores/arduino/ard_sup/ap3_gpio.h

+16-6
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,21 @@ extern const am_hal_gpio_pincfg_t g_AM_HAL_GPIO_OUTPUT_WITH_READ_12;
3434
extern const am_hal_gpio_pincfg_t g_AM_HAL_GPIO_OPEN_DRAIN_WITH_READ_12;
3535
extern const am_hal_gpio_pincfg_t g_AM_HAL_GPIO_INPUT_PULLDOWN;
3636

37-
#define INPUT (g_AM_HAL_GPIO_INPUT)
38-
#define OUTPUT (g_AM_HAL_GPIO_OUTPUT_WITH_READ_12)
39-
#define OPEN_DRAIN (g_AM_HAL_GPIO_OPEN_DRAIN_WITH_READ_12)
40-
#define TRISTATE (g_AM_HAL_GPIO_TRISTATE)
41-
#define INPUT_PULLUP (g_AM_HAL_GPIO_INPUT_PULLUP)
42-
#define INPUT_PULLDOWN (g_AM_HAL_GPIO_INPUT_PULLDOWN)
37+
// macros pointing to internal apollo3 GPIO pincfg structures
38+
#define AP3_PINCFG_INPUT (g_AM_HAL_GPIO_INPUT)
39+
#define AP3_PINCFG_OUTPUT (g_AM_HAL_GPIO_OUTPUT_WITH_READ_12)
40+
#define AP3_PINCFG_INPUT_PULLUP (g_AM_HAL_GPIO_INPUT_PULLUP)
41+
#define AP3_PINCFG_INPUT_PULLDOWN (g_AM_HAL_GPIO_INPUT_PULLDOWN)
42+
#define AP3_PINCFG_OPEN_DRAIN (g_AM_HAL_GPIO_OPEN_DRAIN_WITH_READ_12)
43+
#define AP3_PINCFG_TRISTATE (g_AM_HAL_GPIO_TRISTATE)
44+
45+
// constants for Arduino pin modes
46+
#define INPUT (0x00)
47+
#define OUTPUT (0x01)
48+
#define INPUT_PULLUP (0x02)
49+
#define INPUT_PULLDOWN (0x03)
50+
#define OPEN_DRAIN (0x04)
51+
#define TRISTATE (0x05)
4352

4453
#define AP3_GPIO_MAX_PADS (50)
4554
#define AP3_GPIO_IS_VALID(pad) ((pad >= 0) && (pad < AP3_GPIO_MAX_PADS))
@@ -59,6 +68,7 @@ uint32_t ap3_gpio_enable_interrupts(uint32_t ui32Pin, uint32_t eIntDir);
5968
void padMode(uint8_t pad, am_hal_gpio_pincfg_t mode);
6069
void padMode(uint8_t pad, am_hal_gpio_pincfg_t mode, ap3_err_t *retval);
6170

71+
void pinMode(uint8_t pin, uint8_t mode);
6272
void pinMode(uint8_t pin, am_hal_gpio_pincfg_t mode);
6373
void pinMode(uint8_t pin, am_hal_gpio_pincfg_t mode, ap3_err_t *retval);
6474
void digitalWrite(uint8_t pin, uint8_t val);

cores/arduino/ard_sup/gpio/ap3_gpio.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,38 @@ void padMode(uint8_t pad, am_hal_gpio_pincfg_t mode)
7575
padMode(pad, mode, NULL);
7676
}
7777

78+
// translate Arduino style pin mode function to apollo3 implementation
79+
void pinMode(uint8_t pin, uint8_t mode) {
80+
81+
am_hal_gpio_pincfg_t pinmode = AP3_GPIO_PINCFG_NULL;
82+
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;
105+
}
106+
107+
pinMode(pin, pinmode);
108+
}
109+
78110
void pinMode(uint8_t pin, am_hal_gpio_pincfg_t mode, ap3_err_t *retval)
79111
{
80112
ap3_gpio_pad_t pad = ap3_gpio_pin2pad(pin);

docs/ACKNOWLEDGEMENTS.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ Contributors
1111
* Jim Lindblom
1212
* Kenny Hora
1313
* Owen Lyke
14+
* Aaron Micyus
1415
* Nathan Seidle

0 commit comments

Comments
 (0)