-
Notifications
You must be signed in to change notification settings - Fork 493
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
base: master
Are you sure you want to change the base?
Conversation
…t having to rewrite large chunks of code. Not sure if the function declaration is properly located tho.
Thanks, but could we add the declaration to Also, a line or two in the docs about this and an example (something simple like blink.ino but with toggling the invert pin) would be much appreciated. It's non-standard so users won't be able to discover it otherwise... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the example and docs!
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While adding this in pinMode
seems fine, I think deleting here will break the case where you have someone else controlling the pin (i.e. tone
which uses PIO) and then you stop that process and then digitalWrite
. Let me whip up a simple test case...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this breaks normal functionality. Can you re-add the line?
Simple example blinks after analogWrite with master
, remains PWN (connected to PIO) with this patch
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
analogWriteRange(100);
analogWrite(LED_BUILTIN, 50);
delay(1000);
analogWrite(LED_BUILTIN, 70);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
digitalWrite(LED_BUILTIN, HIGH);
}
void loop() {
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
digitalWrite(LED_BUILTIN, HIGH);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gpio_set_function clears the override register so I will need to save the state somehow. I'll get back....
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this breaks normal functionality. Can you re-add the line?
Simple example blinks after analogWrite with master
, remains PWN (connected to PIO) with this patch
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
analogWriteRange(100);
analogWrite(LED_BUILTIN, 50);
delay(1000);
analogWrite(LED_BUILTIN, 70);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
digitalWrite(LED_BUILTIN, HIGH);
}
void loop() {
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
digitalWrite(LED_BUILTIN, HIGH);
}
This allows a user to simply by calling the setPinInvert function to invert the output of a GPIO pin instead of rewriting existing code.... if required =) I am not sure if the function declaration is correctly positioned though so please advice.