-
-
Notifications
You must be signed in to change notification settings - Fork 7k
macro digitalPinToTimer(P) breaks on DUE #1833
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
Comments
Guys, it's been 6 months, several releases and no fix yet. The code I've seen using this is trying to detect if the pin supports pwm or not. The current behavior for analogWrite() is that on non PWM pins < 128 is LOW and > 127 is HIGH. Anyway, for this fix, there are multiple choices, it could return NOT_ON_TIMER which would indicate that pwm is never supported, or it could return something else to indicate that pwm is supported, perhaps even call due_get_channel_status() to detect if pwm is supported. I think the most important thing is to make sure that any code that uses this macro doesn't error off with a compile error. |
Hey Bill, it seems that digitialPinToTimer is the wrong way to detect if PWM is Having said that, in (at least) 1.5.x there is a digitalPinHasPWM()
Isn't this sufficient for what you need? Gr. Matthijs |
That is a good alternative for this application. However, I still think that the the variant header file needs to be fixed since the way it is now it is defining a broken macro. |
Seems I missed that this was a github issue, I thought I replied to a
Leaving it out allows code to do #if defined(digitalPinToTimer) and know @cmaglie, any thoughts? |
I went and dug a little deeper. The digitalPinToTimer() macro is in Arduino.h for the AVR in both 1.x and 1.5x which is down in the core area. On the 1.5x SAM it used to be in Arduino.h but has been moved to the variant file starting in 1.5.6-r2 Given the functionality relaly doesn't exist for the SAM core, I have corrected my code to check for the existence of digitalPinHasPWM() to use it; otherwise fall back to using digitalPinToTimer() and then if that a doesn't exist, assume no PWM. |
Just as a final thought, maybe when the digitalPinToTimer() macro is removed, a comment could be added in its place Although, it might be usueful to put this comment back up in Arduino.h rather than in the variant file so that it isn't missed should there ever be other SAM variants and also to make its location consistent with the AVR definition which is in Arduino.h rather than the variant files. |
…ent to uninplemented portModeRegister Fix arduino#1833
fixed with #2319. Do you have some suggestions on how to handle portModeRegister too (apart completely disabling it)? |
So the macro is gone and
From your discussion I am assuming that is the way it should work / report error. |
I'm assuming you are working with fm's LiquidCrystal library. Here is the updated code I that I use: // Check if the pin is associated to a timer, i.e. PWM
// Newer 1.5x Arduino has a macro to check for PWM capability on a pin
// ---------------------------------------------------
#if digitalPinHasPWM
if(digitalPinHasPWM(_backlightPin))
#elif digitalPinToTimer
// On 1.x Arduino have to check differently
if(digitalPinToTimer(_backlightPin) != NOT_ON_TIMER)
#else
if(0) // no way to tell so assume no PWM
#endif --- bill |
…ent to uninplemented portModeRegister Fix arduino#1833
The macro digitalPinToTimer(P) is supposed to report whether the pin
supports PWM.
This allows doing something like this:
The macro in DUE not only doesn't work but is improperly defined:
This creates a compile error on DUE code.
This needs to be updated and corrected to work correctly.
The text was updated successfully, but these errors were encountered: