Skip to content
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

Initial functioning version of ESP32 HardwarePWM. #2599

Merged
merged 29 commits into from
Apr 28, 2023
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c7e7e33
initial functioning version of ESP32 HardwarePWM. Tested to run on th…
pljakobs Jan 1, 2023
806b9de
some documentation updates
pljakobs Jan 1, 2023
34ca146
more documentation
pljakobs Jan 1, 2023
246744e
more documentation
pljakobs Jan 1, 2023
30b5f1a
implemented requested changes from initial PR
pljakobs Feb 12, 2023
f67fb1a
implemented requested changes from initial PR (now *with* changes. Sigh)
pljakobs Feb 12, 2023
21ecf9a
Revert "more documentation"
pljakobs Feb 12, 2023
be7d04a
implemented requested changes from initial PR (now *with* changes. af…
pljakobs Feb 12, 2023
9e9928c
fixed some things I didn't understand at first.
pljakobs Feb 12, 2023
b48fcd9
HardwarePWM.h was not part of the last commit
pljakobs Feb 12, 2023
9fe74a1
.cpp was also missing. why?
pljakobs Feb 12, 2023
f510bba
Apply coding style
Feb 21, 2023
84e69f1
Rebase, tidy
Feb 21, 2023
eaf77f9
Tidy Esp8266 implementation, add new 'getFrequency' method
Feb 21, 2023
333db82
Add missing include
Feb 21, 2023
b90ea67
Tidy driver/pwm.h
Feb 21, 2023
3c9785f
Use static initializers
Feb 21, 2023
fc2fca2
minor updates as suggested by mikee47
pljakobs Mar 18, 2023
d96bc2f
minor updates as suggested by mikee47
pljakobs Mar 18, 2023
8b82fe0
removed unused variables
pljakobs Mar 30, 2023
d03688b
missed one occurrence and also messed up in a merge - cleaned out now
pljakobs Mar 30, 2023
0e06be0
removed a piece of code that was doubled
pljakobs Apr 1, 2023
b3489a1
fixed typos and coding style
pljakobs Apr 5, 2023
e5c1138
removed ToDos from the comments that are to be implemented in the nex…
pljakobs Apr 8, 2023
5457b4a
fixed return values
pljakobs Apr 19, 2023
dcf2834
changed some coding style issues in esp8266 code
pljakobs Apr 23, 2023
bbacc5a
removed unnecessary and improved useful debug output
pljakobs Apr 23, 2023
e1413ff
corrected the PWM_CHANNEL_NUM_MAX define in pwm.h to reflect the corr…
pljakobs Apr 23, 2023
f03ce14
Small coding style fixes.
slav-at-attachix Apr 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more documentation
  • Loading branch information
pljakobs authored and mikee47 committed Feb 21, 2023
commit 34ca1461403d0ca7a6f262a852f7bd159149c8d3
76 changes: 73 additions & 3 deletions Sming/Arch/Esp32/Core/HardwarePWM.cpp
Original file line number Diff line number Diff line change
@@ -14,8 +14,60 @@
* the ESP32 PWM Hardware is much more powerful than the ESP8266, allowing wider PWM timers (up to 20 bit)
* as well as much higher PWM frequencies (up to 40MHz for a 1 Bit wide PWM)
*
* Timer width for PWM:
* ====================
* Overview:
* +------------------------------------------------------------------------------------------------+
* | LED_PWM |
* | +-------------------------------------------+ +-------------------------------------------+ |
* | | High_Speed_Channels¹ | | Low_Speed_Channels | |
* | | +-----+ +--------+ | | +-----+ +--------+ | |
* | | | | --> | h_ch 0 | | | | | --> | l_ch 0 | | |
* | | +-----------+ | | +--------+ | | +-----------+ | | +--------+ | |
* | | | h_timer 0 | --> | | | | | l_timer 0 | --> | | | |
* | | +-----------+ | | +--------+ | | +-----------+ | | +--------+ | |
* | | | | --> | h_ch 1 | | | | | --> | l_ch 1 | | |
* | | | | +--------+ | | | | +--------+ | |
* | | | | | | | | | |
* | | | | +--------+ | | | | +--------+ | |
* | | | | --> | h_ch 2 | | | | | --> | l_ch 2 | | |
* | | +-----------+ | | +--------+ | | +-----------+ | | +--------+ | |
* | | | h_timer 1 | --> | | | | | l_timer 1 | --> | | | |
* | | +-----------+ | | +--------+ | | +-----------+ | | +--------+ | |
* | | | | --> | h_ch 3 | | | | | --> | l_ch 3 | | |
* | | | MUX | | | | MUX | | |
* | | | | +--------+ | | | | +--------+ | |
* | | | | --> | h_ch 4 | | | | | --> | l_ch 4 | | |
* | | +-----------+ | | +--------+ | | +-----------+ | | +--------+ | |
* | | | h_timer 2 | --> | | | | | l_timer 2 | --> | | | |
* | | +-----------+ | | +--------+ | | +-----------+ | | +--------+ | |
* | | | | --> | h_ch 5 | | | | | --> | l_ch 5 | | |
* | | | | +--------+ | | | | +--------+ | |
* | | | | | | | | | |
* | | | | +--------+ | | | | +--------+ | |
* | | | | --> | h_ch 6 | | | | | --> | l_ch 6²| | |
* | | +-----------+ | | +--------+ | | +-----------+ | | +--------+ | |
* | | | h_timer 3 | --> | | | | | l_timer 3 | --> | | | |
* | | +-----------+ | | +--------+ | | +-----------+ | | +--------+ | |
* | | | | --> | h_ch 7 | | | | | --> | l_ch 7²| | |
* | | | | +--------+ | | | | +--------+ | |
* | | +-----+ | | +-----+ | |
* | +-------------------------------------------+ +-------------------------------------------+ |
* +------------------------------------------------------------------------------------------------+
* ¹ High speed channels are only available when SOC_LEDC_SUPPORT_HS_MODE is defined as 1
* ² The ESP32C3 does only support six channels, so 6 and 7 are not available on that SoC
*
* The nomenclature of timers in the high speed / low speed blocks is a bit misleading as the idf api
* speaks of "speed mode", which, to me, implies that this would be a mode configurable in a specific timer
* while in reality, it does select a block of timers. I am considering re-naming that to "speed mode block"
* in my interface impmenentation.
*
* As an example, I would use
* setTimerFrequency(speedModeBlock, timer, frequency);
*
* ToDo: see, how this can be implemented to provide maximum overlap with the RP2040 pwm hardware so code does
* not become overly SoC specific.
*
* Maximum Timer width for PWM:
* ============================
* esp32 SOC_LEDC_TIMER_BIT_WIDE_NUM (20)
* esp32c3 SOC_LEDC_TIMER_BIT_WIDE_NUM (14)
* esp32s2 SOC_LEDC_TIMER_BIT_WIDE_NUM (14)
@@ -28,7 +80,7 @@
* esp32s2 SOC_LEDC_CHANNEL_NUM (8)
* esp32s3 SOC_LEDC_CHANNEL_NUM 8
*
* Some Architectures support a mode called HIGHSPEED_MODE which is essentially another full block of PWM hardware
* Some SoSs support a mode called HIGHSPEED_MODE which is essentially another full block of PWM hardware
* that adds SOC_LEDC_CHANNEL_NUM channels.
* Those Architectures have SOC_LEDC_SUPPORT_HS_MODE defined as 1.
* In esp-idf-4.3 that's currently only the esp32 SOC
@@ -38,6 +90,24 @@
* esp32 SOC_LEDC_SUPPORT_HS_MODE (1)
*
* ToDo: implement awareness of hs mode availablility
* ==================================================
* currently, the code just uses a % 8 operation on the pin index to calculate whether to assign a pin to either
* high speed or low speed pwm blocks. This doesn't make a whole lot of sense since it makes it impossible
* for Sming devs to actually use the functionality behind it.
* Also, it currently does not reflect the fact that different SOCs have a different number of channels per block
* (specifically, the esp32c3 only has six channels and no highspeed mode).
* I will continue in two ways:
* - implement the "vanilla" Sming HardwarePWM interface that will hide the underlying architecture but allow up to 16
* channels on an ESP32
* - implement overloads for the relevant functions that allow selecting hs mode where applicable.
*
* ToDo: implement PWM bit width control
* =====================================
* the current HardwarePWM implementation does not care about the PWM timer bit width. To leverage the functionality
* of the ESP32 hardware, it's necessary to make this configurable. As the width is per timer and all the Sming defined
* functions are basically per pin, this needs to be an extension of the overal model, exposing at least timers.
* This, too, will require a compatible "basic" interface and an advanced interface that allows assiging pins (channels)
* to timers and the configuration of the timers themselves.
*
* hardware technical reference:
* =============================