Skip to content

Fix for Broken Arduino libraries due to implementaion of commonly used GPIO constants, issue #98 #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cores/arduino/ard_sup/analog/ap3_analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ ap3_err_t ap3_set_pin_to_analog(uint8_t pinNumber)
ap3_err_t retval = AP3_ERR;

uint8_t funcsel = 0;
am_hal_gpio_pincfg_t pincfg = INPUT;
am_hal_gpio_pincfg_t pincfg = AP3_PINCFG_INPUT;
retval = ap3_analog_pad_funcsel(ap3_gpio_pin2pad(pinNumber), &funcsel);

if (retval != AP3_OK)
Expand Down
22 changes: 16 additions & 6 deletions cores/arduino/ard_sup/ap3_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,21 @@ extern const am_hal_gpio_pincfg_t g_AM_HAL_GPIO_OUTPUT_WITH_READ_12;
extern const am_hal_gpio_pincfg_t g_AM_HAL_GPIO_OPEN_DRAIN_WITH_READ_12;
extern const am_hal_gpio_pincfg_t g_AM_HAL_GPIO_INPUT_PULLDOWN;

#define INPUT (g_AM_HAL_GPIO_INPUT)
#define OUTPUT (g_AM_HAL_GPIO_OUTPUT_WITH_READ_12)
#define OPEN_DRAIN (g_AM_HAL_GPIO_OPEN_DRAIN_WITH_READ_12)
#define TRISTATE (g_AM_HAL_GPIO_TRISTATE)
#define INPUT_PULLUP (g_AM_HAL_GPIO_INPUT_PULLUP)
#define INPUT_PULLDOWN (g_AM_HAL_GPIO_INPUT_PULLDOWN)
// macros pointing to internal apollo3 GPIO pincfg structures
#define AP3_PINCFG_INPUT (g_AM_HAL_GPIO_INPUT)
#define AP3_PINCFG_OUTPUT (g_AM_HAL_GPIO_OUTPUT_WITH_READ_12)
#define AP3_PINCFG_INPUT_PULLUP (g_AM_HAL_GPIO_INPUT_PULLUP)
#define AP3_PINCFG_INPUT_PULLDOWN (g_AM_HAL_GPIO_INPUT_PULLDOWN)
#define AP3_PINCFG_OPEN_DRAIN (g_AM_HAL_GPIO_OPEN_DRAIN_WITH_READ_12)
#define AP3_PINCFG_TRISTATE (g_AM_HAL_GPIO_TRISTATE)

// constants for Arduino pin modes
#define INPUT (0x00)
#define OUTPUT (0x01)
#define INPUT_PULLUP (0x02)
#define INPUT_PULLDOWN (0x03)
#define OPEN_DRAIN (0x04)
#define TRISTATE (0x05)

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

void pinMode(uint8_t pin, uint8_t mode);
void pinMode(uint8_t pin, am_hal_gpio_pincfg_t mode);
void pinMode(uint8_t pin, am_hal_gpio_pincfg_t mode, ap3_err_t *retval);
void digitalWrite(uint8_t pin, uint8_t val);
Expand Down
32 changes: 32 additions & 0 deletions cores/arduino/ard_sup/gpio/ap3_gpio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,38 @@ void padMode(uint8_t pad, am_hal_gpio_pincfg_t mode)
padMode(pad, mode, NULL);
}

// translate Arduino style pin mode function to apollo3 implementation
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;
}

pinMode(pin, pinmode);
}

void pinMode(uint8_t pin, am_hal_gpio_pincfg_t mode, ap3_err_t *retval)
{
ap3_gpio_pad_t pad = ap3_gpio_pin2pad(pin);
Expand Down
1 change: 1 addition & 0 deletions docs/ACKNOWLEDGEMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ Contributors
* Jim Lindblom
* Kenny Hora
* Owen Lyke
* Aaron Micyus
* Nathan Seidle