Skip to content

Added a function to allow inverting the output from a GPIO pin #3039

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions cores/rp2040/api/Common.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#pragma once
#include "../../../ArduinoCore-API/api/Common.h"

void setPinInvert(pin_size_t ulPin, bool invert);
17 changes: 15 additions & 2 deletions cores/rp2040/wiring_digital.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,27 @@ extern void __clearADCPin(pin_size_t p);

static PinMode _pm[__GPIOCNT];

extern "C" void setPinInvert(pin_size_t ulPin, bool invert) __attribute__((weak, alias("__setPinInvert")));
extern "C" void __setPinInvert(pin_size_t ulPin, bool invert) {
if (ulPin >= __GPIOCNT) {
DEBUGCORE("ERROR: Illegal pin in setPinInvert (%d)\n", ulPin);
return;
}

if (invert)
gpio_set_outover(ulPin, GPIO_OVERRIDE_INVERT);
else
gpio_set_outover(ulPin, GPIO_OVERRIDE_NORMAL);
}

extern "C" void pinMode(pin_size_t ulPin, PinMode ulMode) __attribute__((weak, alias("__pinMode")));
extern "C" void __pinMode(pin_size_t ulPin, PinMode ulMode) {
if (ulPin >= __GPIOCNT) {
DEBUGCORE("ERROR: Illegal pin in pinMode (%d)\n", ulPin);
return;
}


gpio_set_function(ulPin, GPIO_FUNC_SIO);
switch (ulMode) {
case INPUT:
gpio_init(ulPin);
Expand Down Expand Up @@ -90,7 +104,6 @@ extern "C" void __digitalWrite(pin_size_t ulPin, PinStatus ulVal) {
DEBUGCORE("ERROR: Illegal pin in pinMode (%d)\n", ulPin);
return;
}
gpio_set_function(ulPin, GPIO_FUNC_SIO);
if (_pm[ulPin] == INPUT_PULLDOWN) {
if (ulVal == LOW) {
gpio_set_dir(ulPin, false);
Expand Down