-
Notifications
You must be signed in to change notification settings - Fork 2k
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
periph/pwm: support for PWM extension API #10533
base: master
Are you sure you want to change the base?
Conversation
02e3ee5
to
45f6532
Compare
Adds low level function prototypes and redirection functions as well as some default macro definitions for PWM extensions to the API.
Renames all low level function for peripheral PWM drivers of MCUs
Adds the PWM extension driver including redirection and not supported functions
45f6532
to
89229a1
Compare
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.
Nice implementation. Just those comments. I ran the provided test in nucleo-f091rc and works as intended.
drivers/extend/pwm_redir.c
Outdated
|
||
if (entry == NULL) { | ||
DEBUG("[%s] ext entry doesn't exist for dev %u\n", __func__, dev); | ||
return -1; |
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.
On error 0
should be returned.
return -1; | |
return 0; |
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, of course. Thanks.
/** | ||
* @brief Default number of PWM extension devices | ||
*/ | ||
#ifndef PWM_EXT_NUMOF |
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.
Should we only keep the definition of PWM_EXT_NUMOF
if MODULE_EXTEND_PWM
is not defined, instead of having it both here and in drivers/include/extend/pwm.h
? Like:
#ifndef PWM_EXT_NUMOF
#if !(MODULE_EXTEND_PWM)
#define PWM_EXT_NUMOF (0U)
#endif
#endif
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.
Ok, I just placed it also in drivers/include/periph/pwm.h
to avoid wrong definitions if someone includes drivers/include/periph/pwm.h
before drivers/include/extend/pwm.h
.
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.
This should be placed only in periph/pwm.h
because it is included by extend/pwm.h
, which means that periph/pwm.h
is always loaded first.
Also, needs to be something like:
#ifndef PWM_EXT_NUMOF
#if MODULE_EXTEND_PWM
#define PWM_EXT_NUMOF (sizeof(pwm_ext_list) / sizeof(pwm_ext_list[0]))
#else
#define PWM_EXT_NUMOF (0U)
#endif /* MODULE_EXTEND_PWM */
#endif /* PWM_EXT_NUMOF */
@leandrolanzieri Thank you for reviewing and testing. |
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.
Looks good. atmega_common
is missing the _ll
functions though.
drivers/include/periph/pwm.h
Outdated
} | ||
#else | ||
return pwm_init_redir(dev, mode, freq, res); | ||
#endif |
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.
Please mark your #endif
s with a comment after when you have nested #if
s: #endif /* MODULE_PERIPH_PWM */
. This will make it much easier to read.
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, of course.
tests/extend_pwm/Makefile
Outdated
include $(RIOTBASE)/Makefile.include | ||
|
||
test: | ||
./tests/01-run.py |
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.
Explicitly referencing the test is no longer necessary. If ./tests/01-run.py
exists, then it will be used.
Clarification on waiting for PR: This is waiting on approval of the methods outlined in #9582 via the approval by a senior maintainer of this or any of the other extension API PRs: #9860 + #9958, or #10512, #10527, #10533. They are all identical in method, and have only minor differences in implementation. As a split PR #9860 and #9958 are intended to make this easier. |
I don't know why |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
Since this PR has been stale for several years, I'll convert it to a draft. Please feel free to remove the draft state if anyone wants to pick this up again. |
Contribution description
This is an implementation of the extension API as proposed in #9582 for PWM extensions. It corresponds to the implementation of the GPIO extension API in #9860 and #9958. The PR contains the following contributions:
pwm_*_ll
indrivers/include/periph.h
.pwm_*
functions to redirect a function call either to the low level functionspwm_*_ll
or to thepwm_ext_*
function provided by an PWM extension device driver.pwm_*_ll
for all CPUs that support PWM devices.The PWM extension API does not require feature
periph_pwm
which makes it possible to extend boards that do not provide PWM capabilities by the MCU by external PWM modules.Testing procedure
A test case is provided that implements a soft-driver for the PWM extension interface. The test case uses this driver to confirm that interception and redirection of the API call are working properly. This has been tested and is working properly on esp8266-esp-12x, esp32-wroom-32 and arduino-mega2560.
To test only the PWM extension API use
To test the PWM extension API together with internal PWM channels use
In that case feature
periph_pwm
is required of course.Issues/PRs references
Implements #9582
Corresponds to #9860 and #9958
The changes in the
makefiles/pseudomodules.mk
and indrivers/Makefile.include
made to get it working are the same as in #9958. These changes might be removed once #9958 is merged.PR #10556 provides a working PWM extension driver that use the PWM extension API and serves as a proof of concept.