Skip to content

Commit 7efc42e

Browse files
committed
Make sure that we have channels available
1 parent 4a74236 commit 7efc42e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Diff for: cores/esp32/esp32-hal-ledc.c

+4
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ void analogWrite(uint8_t pin, int value) {
339339
// Use ledc hardware for internal pins
340340
if (pin < SOC_GPIO_PIN_COUNT) {
341341
if (pin_to_channel[pin] == 0) {
342+
if (!cnt_channel) {
343+
log_e("No more analogWrite channels available! You can have maximum %u", SOC_LEDC_CHANNEL_NUM);
344+
return;
345+
}
342346
pin_to_channel[pin] = cnt_channel--;
343347
ledcAttachPin(pin, cnt_channel);
344348
ledcSetup(cnt_channel, 1000, 8);

0 commit comments

Comments
 (0)