Skip to content

Digital w after analog fix #148

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 3 commits into from
Apr 15, 2020
Merged
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
71 changes: 46 additions & 25 deletions cores/arduino/ard_sup/gpio/ap3_gpio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down