periph/pwm: support for PWM extension API#10533
periph/pwm: support for PWM extension API#10533gschorcht wants to merge 13 commits intoRIOT-OS:masterfrom
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
leandrolanzieri
left a comment
There was a problem hiding this comment.
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.
On error 0 should be returned.
| return -1; | |
| return 0; |
There was a problem hiding this comment.
Yes, of course. Thanks.
| /** | ||
| * @brief Default number of PWM extension devices | ||
| */ | ||
| #ifndef PWM_EXT_NUMOF |
There was a problem hiding this comment.
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
#endifThere was a problem hiding this comment.
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.
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. |
ZetaR60
left a comment
There was a problem hiding this comment.
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.
Please mark your #endifs with a comment after when you have nested #ifs: #endif /* MODULE_PERIPH_PWM */. This will make it much easier to read.
tests/extend_pwm/Makefile
Outdated
| include $(RIOTBASE)/Makefile.include | ||
|
|
||
| test: | ||
| ./tests/01-run.py |
There was a problem hiding this comment.
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_*_llindrivers/include/periph.h.pwm_*functions to redirect a function call either to the low level functionspwm_*_llor to thepwm_ext_*function provided by an PWM extension device driver.pwm_*_llfor all CPUs that support PWM devices.The PWM extension API does not require feature
periph_pwmwhich 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_pwmis required of course.Issues/PRs references
Implements #9582
Corresponds to #9860 and #9958
The changes in the
makefiles/pseudomodules.mkand indrivers/Makefile.includemade 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.