Skip to content

define digitalPinHasPWM for UNOWIFIR4 & MINIMA #287

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

Merged
merged 5 commits into from
May 24, 2024
Merged

define digitalPinHasPWM for UNOWIFIR4 & MINIMA #287

merged 5 commits into from
May 24, 2024

Conversation

isidromv
Copy link
Contributor

@isidromv isidromv commented Apr 5, 2024

Defining digitalPinHasPWM will make that those sketches using it from older boards, like UNO R3 or Nano, can also be used with UNO R4, without extra complications for non advanced users (like me).

@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Apr 5, 2024
@facchinm facchinm requested review from maidnl and navalog May 21, 2024 09:51
Copy link
Contributor

@maidnl maidnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually there is no need to add such define because the same result can be achieved with something that is already defined in the Arduino core.
IS_PIN_PWM(getPinCfgs(p, PIN_CFG_REQ_PWM)[0]) where p is the pin number (D0, D1... and so on).
So that a general macro (to be more readable) can be written as
#define digitalPinHasPWM(p) (IS_PIN_PWM(getPinCfgs(p, PIN_CFG_REQ_PWM)[0]))

This approach is more generic because uses core functions already available, however has some drawbacks: it does not lie.
The pin marked with ~ on the Arduino board are not in fact the only pin with PWM capability but the pin that have guarantee independent PWM .
Almost all available pin on Uno have PWM capability however some share the same timer and so are not completely independent

  • D0 and D1 shares the same timer
  • D2 and D3~ shares the same timer
  • D4 and D5~ shares the same timer
  • D6~ and D7 shares the same timer
  • D8 and D9~ shares the same timer
  • D10~ and D13 shares the same timer
  • D11~ and D12 shares the same timer

@isidromv
Copy link
Contributor Author

My main point is about defining the macro to make old sketches for R3 compile.
I've updated the definition following the recommendation, thanks.

@facchinm facchinm merged commit 0620eb3 into arduino:main May 24, 2024
6 of 7 checks passed
delta-G pushed a commit to delta-G/ArduinoCore-renesas that referenced this pull request Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants