Skip to content

Commit

Permalink
[sam] GPIO setOutput overrides peripheral control
Browse files Browse the repository at this point in the history
Calling setOutput now overrides peripheral control of the pin. This
behavior is consistent with the STM32 GPIO implementation, this commit also
ensures output value is set before the output drive is enabled to prevent
glitch.

Co-authored-by: Christopher Durand <[email protected]>
  • Loading branch information
mcbridejc and chris-durand committed Feb 9, 2022
1 parent 845840e commit 148f1f2
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/modm/platform/gpio/sam/pin.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,26 @@ public:
inline static void
setOutput()
{
// Enable PIO control of the pin (disables peripheral control)
setPortReg(PIO_PER_OFFSET);
// Enable output driver
setPortReg(PIO_OER_OFFSET);
}

inline static void
setOutput(bool status)
{
setOutput();
set(status);
setOutput();
}

static void
setInput()
{
setPortReg(PIO_ODR_OFFSET); // Disable output driver
// Enable PIO control of the pin (disables peripheral control)
setPortReg(PIO_PER_OFFSET);
// Disable output driver
setPortReg(PIO_ODR_OFFSET);
}

static void
Expand Down Expand Up @@ -336,19 +342,22 @@ public:
setOutput()
{
setPortReg(PORT_DIRSET_OFFSET);
// Disable peripheral multiplexer
PinCfg::set(0);
}

inline static void
setOutput(bool status)
{
setOutput();
set(status);
setOutput();
}

static void
setInput()
{
setPortReg(PORT_DIRCLR_OFFSET);
PinCfg::set(PORT_PINCFG_INEN);
}

static void
Expand Down

0 comments on commit 148f1f2

Please sign in to comment.