Skip to content

Commit

Permalink
HardwarePWM Esp32 - added assert for max pwm channels (#2904)
Browse files Browse the repository at this point in the history
  • Loading branch information
pljakobs authored Nov 4, 2024
1 parent 20b4865 commit 9054e94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
7 changes: 2 additions & 5 deletions Sming/Arch/Esp32/Components/driver/include/driver/pwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

#pragma once

#ifdef SOC_LEDC_CHANNEL_NUM
#include <soc/soc_caps.h>

#define PWM_CHANNEL_NUM_MAX SOC_LEDC_CHANNEL_NUM
#else
// this should not happen if the correct esp32 includes are used, just to be absolutely sure
#define PWM_CHANNEL_NUM_MAX 8
#endif
7 changes: 3 additions & 4 deletions Sming/Arch/Esp32/Core/HardwarePWM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,10 @@ uint32_t maxDuty(ledc_timer_bit_t bits)

HardwarePWM::HardwarePWM(uint8_t* pins, uint8_t no_of_pins) : channel_count(no_of_pins)
{
debug_d("starting HardwarePWM init");
assert(no_of_pins > 0 && no_of_pins <= SOC_LEDC_CHANNEL_NUM);
no_of_pins = std::min(uint8_t(SOC_LEDC_CHANNEL_NUM), no_of_pins);

periph_module_enable(PERIPH_LEDC_MODULE);
if((no_of_pins == 0) || (no_of_pins > SOC_LEDC_CHANNEL_NUM)) {
return;
}

for(uint8_t i = 0; i < no_of_pins; i++) {
channels[i] = pins[i];
Expand Down

0 comments on commit 9054e94

Please sign in to comment.