Skip to content

Commit 1acdd78

Browse files
committed
feat(ledc): Replace log2 with __builtin_ctz
1 parent 994e3f2 commit 1acdd78

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

cores/esp32/esp32-hal-ledc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution)
136136
log_e("No more LEDC channels available! (maximum is %u channels)", LEDC_CHANNELS);
137137
return false;
138138
}
139-
uint8_t channel = log2(free_channel & -free_channel);
139+
uint8_t channel = __builtin_ctz(free_channel); // Convert the free_channel bit to channel number
140140

141141
return ledcAttachChannel(pin, freq, resolution, channel);
142142
}

0 commit comments

Comments
 (0)