Skip to content

Commit a02e31d

Browse files
committed
fix(ledc): Added freq check to ledcChangeFrequency
1 parent 68abeae commit a02e31d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

cores/esp32/esp32-hal-ledc.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,12 @@ uint32_t ledcChangeFrequency(uint8_t pin, uint32_t freq, uint8_t resolution)
254254
{
255255
ledc_channel_handle_t *bus = (ledc_channel_handle_t*)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC);
256256
if(bus != NULL){
257-
258-
if(resolution > LEDC_MAX_BIT_WIDTH){
259-
log_e("LEDC resolution too big (maximum %u)", LEDC_MAX_BIT_WIDTH);
257+
if (freq == 0) {
258+
log_e("LEDC pin %u - frequency can't be zero.", pin);
259+
return 0;
260+
}
261+
if (resolution == 0 || resolution > LEDC_MAX_BIT_WIDTH){
262+
log_e("LEDC pin %u - resolution is zero or it is too big (maximum %u)", pin, LEDC_MAX_BIT_WIDTH);
260263
return 0;
261264
}
262265
uint8_t group=(bus->channel/8), timer=((bus->channel/2)%4);

0 commit comments

Comments
 (0)