diff --git a/Sming/Arch/Esp32/Components/driver/include/driver/pwm.h b/Sming/Arch/Esp32/Components/driver/include/driver/pwm.h index 570369049a..5b6e1c79b2 100644 --- a/Sming/Arch/Esp32/Components/driver/include/driver/pwm.h +++ b/Sming/Arch/Esp32/Components/driver/include/driver/pwm.h @@ -10,9 +10,6 @@ #pragma once -#ifdef SOC_LEDC_CHANNEL_NUM +#include + #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 diff --git a/Sming/Arch/Esp32/Core/HardwarePWM.cpp b/Sming/Arch/Esp32/Core/HardwarePWM.cpp index fcc387dc34..0b1a74f583 100644 --- a/Sming/Arch/Esp32/Core/HardwarePWM.cpp +++ b/Sming/Arch/Esp32/Core/HardwarePWM.cpp @@ -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];