Skip to content
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

[sam] GPIO setOutput overrides peripheral control #822

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 26 additions & 4 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 @@ -272,6 +278,7 @@ template<class... PinConfigs>
struct PinCfgMixin
{
inline static void set(uint8_t){};
inline static void set(uint8_t, uint8_t){};
};

template<class PinConfig, class... PinConfigs>
Expand All @@ -286,6 +293,18 @@ struct PinCfgMixin<PinConfig, PinConfigs...>
%% endfor
PinCfgMixin<PinConfigs...>::set(cfg);
}

inline static void
set(uint8_t setBits, uint8_t clearMask)
{
%% for port in ports
if constexpr (PinConfig::port == PortName::{{ port }}) {
auto& reg = PORT->Group[{{loop.index0}}].PINCFG[PinConfig::pin].reg;
reg = (reg & (~clearMask)) | setBits;
}
%% endfor
PinCfgMixin<PinConfigs...>::set(setBits, clearMask);
}
};

template<class... PinConfigs>
Expand Down Expand Up @@ -336,19 +355,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 All @@ -362,7 +384,7 @@ public:
configure(InputType type)
{
set(type == InputType::PullUp);
PinCfg::set(PORT_PINCFG_INEN | (type != InputType::Floating) << PORT_PINCFG_PULLEN_Pos);
PinCfg::set(PORT_PINCFG_INEN | (type != InputType::Floating) << PORT_PINCFG_PULLEN_Pos, PORT_PINCFG_PULLEN);
}

static void
Expand Down