Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bd405d2

Browse files
fix(ledc): Allow setting AnalogWrite freq and res before ledc init
1 parent 956b687 commit bd405d2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

‎cores/esp32/esp32-hal-ledc.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -784,17 +784,23 @@ void analogWrite(uint8_t pin, int value) {
784784
}
785785

786786
void analogWriteFrequency(uint8_t pin, uint32_t freq) {
787-
if (ledcChangeFrequency(pin, freq, analog_resolution) == 0) {
788-
log_e("analogWrite frequency cant be set due to selected resolution! Try to adjust resolution first");
789-
return;
787+
ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC);
788+
if (bus != NULL) { // if pin is attached to LEDC change frequency, otherwise update the global frequency
789+
if (ledcChangeFrequency(pin, freq, analog_resolution) == 0) {
790+
log_e("analogWrite frequency cant be set due to selected resolution! Try to adjust resolution first");
791+
return;
792+
}
790793
}
791794
analog_frequency = freq;
792795
}
793796

794797
void analogWriteResolution(uint8_t pin, uint8_t resolution) {
795-
if (ledcChangeFrequency(pin, analog_frequency, resolution) == 0) {
796-
log_e("analogWrite resolution cant be set due to selected frequency! Try to adjust frequency first");
797-
return;
798+
ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC);
799+
if (bus != NULL) { // if pin is attached to LEDC change resolution, otherwise update the global resolution
800+
if (ledcChangeFrequency(pin, analog_frequency, resolution) == 0) {
801+
log_e("analogWrite resolution cant be set due to selected frequency! Try to adjust frequency first");
802+
return;
803+
}
798804
}
799805
analog_resolution = resolution;
800806
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /