-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
[WIP] Beginnings of a more structured esp32 pwm #2624
base: develop
Are you sure you want to change the base?
Conversation
…e ESP32C3 with up to 5kHz pwm frequency.
This reverts commit 7279c66.
…ter goofing up with git Sigh)
|
…annel classes which in turn use the channel/timer singleton classes that marshal access to the hardware instances. The actual member functions have not been rewritten yet and still use the esp ledc_ interface (and thus will fail).
So I have reconsidered my initial thoughts on this and written two intermediary classes: One limitation is, that one object can not span the speed groups available in the larger esp32 models, so the largest possible number of channels in one instance is 8 (or 6 on the ESP32C3), but I believe that's a logical limitaition, as the two speed groups are also divided in hardware and have at least partially dissimilar capabilities. Again: feedback on the thoughts and architecture is very welcome, especially as I know that some (many?) regard singletons as an anti pattern. I thought it is the easiest way to make sure that the hardware is managed correctly, at least in a single threaded environment. |
I've chewed on this one for a while and have come up with an alternative arrangement.
Some notes. Move code into a separate library, e.g. Leave the HardwarePWM class as-is. The LEDC library can provide a better implementation anyway so applications wouldn't use both.
Use LEDC namespace. Follow Sming coding style; this helps to differentiate between low-level 'C' code (e.g. identifiers_using_underscores) versus upper CamelCaseTypes or lower camelCaseVariableNames. To reduce overhead, put simple code directly in class header, rather than source module, Use There are no plans for Sming to support FreeRTOS, quite the reverse in fact: if we could eliminate it entirely that would be a benefit. Sming is intended to keep 'close to the metal', therefore the framework avoids using The UART driver (Sming/Arch/Esp32/Components/driver/uart.cpp) avoids the SDK uart driver and goes directly to the hardware, |
** this is not currently functional code **
I'm adding this PR to get feedback on the direction.
After thinking about the inital implementation I wrote for PWM on the ESP32, I thought about what would make sense for this platform within the existing interface. Especially, I thought about the fact that there is a differenciation between properties of a timer (frequency, bit width) and properties of a channel (timer, pin, duty cycle). The interface in Sming really only knows about pins, but through the common update() function has a rudimentary idea of grouping channels.
So, my Idea is this: I'll try to keep the existing interface as much as possibe, but will extend the idea by encouraging to use multiple HardwarePWM objects that automatically use the existing hardware.
That is: a program could create one HardwarePWM object to drive three led channels at 400kHz and 10 Bits and another one to drive something else, maybe two motor channels, at 100kHz and 8 Bits (just examples).
My original implementation would not allow that because it has no concept of hardware that is already in use. In order to globally keep track of what is already in use and what is still available, I've added the two singleton classes for channels and timers. They provide an interface to get the number of a timer and a channel and mark that timer and channel as used so another class does not use the same.
It would probably be even better if the class would keep the configuration object for the timer and the channel, but that is beyond my current understanding of how to handle objects in singletons (this already took me quite a bit of learning).
The downside of the current implementation is, that one has to manually keep track of the fact whether a channel / timer is in the high or low speed block, which is messy and prone to error.
It would be better to handle them as objects providing the information in ledc_channel_config_t and ledc_timer_config_t. I'll think about that some more
So here are my questions:
If this is generally a good direction, I'll try to develop it further and actually use it in the HardwarePWM code.
Also: is there a better way to ask for feedback than a PR?
thanks in advance
pj