Skip to content

Commit 9f3a11a

Browse files
committed
fix(esp32-hal-ledc): Clear bit in used_channels bitmap
When we attach pin to LEDC channel we set bit in used_channels bitmap variable. But used_channels bit was not cleared on detach, as result simply repeating attach/detach around 16 times will falsely use all available channels and emit error that channel is not available. This happen for example in IRSenderESP32.cpp. This patch fixes this bug. Signed-off-by: Denys Fedoryshchenko <[email protected]>
1 parent f5be003 commit 9f3a11a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,13 @@ uint32_t ledcWriteNote(uint8_t pin, note_t note, uint8_t octave) {
271271
bool ledcDetach(uint8_t pin) {
272272
ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC);
273273
if (bus != NULL) {
274+
/* ledc_handle.used_channels use bitmap to indicate if channel is used
275+
bit is set if channel is used, in ledcAttachChannel/ledcAttach
276+
bit is cleared if channel is detached here
277+
*/
278+
if (ledc_handle.used_channels & (1UL << bus->channel)) {
279+
ledc_handle.used_channels &= ~(1UL << bus->channel);
280+
}
274281
// will call ledcDetachBus
275282
return perimanClearPinBus(pin);
276283
} else {

0 commit comments

Comments
 (0)