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

Appearance settings

Commit 2173373

Browse filesBrowse files
authored
ledc.c: Fix analogWrite() last channel available verification (espressif#8509)
* Fix analogWrite channel available verification The last channel allocated is number 0, which conflicted with the value given to an uninitialized pin, giving the "No more analogWrite channels available!" error when trying to use it Pins are now given the value -1 to indicate that they are not used so channel 0 can be used without errors. * Fix incorrect array initialization Keeping array of zeros for `pin_to_channel` and shifting stored channel values by +1 to keep the pin with channel 0 from being interpreted as unused. ref: espressif#8509 (comment)
1 parent e2c4799 commit 2173373
Copy full SHA for 2173373

File tree

Expand file treeCollapse file tree

1 file changed

+2
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+2
-2
lines changed

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

Copy file name to clipboardExpand all lines: cores/esp32/esp32-hal-ledc.c
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,13 @@ void analogWrite(uint8_t pin, int value) {
234234
return;
235235
}
236236
ledcAttachPin(pin, channel);
237-
pin_to_channel[pin] = channel;
237+
pin_to_channel[pin] = channel + 1;
238238
ledcWrite(channel, value);
239239
}
240240
}
241241

242242
int8_t analogGetChannel(uint8_t pin) {
243-
return pin_to_channel[pin];
243+
return pin_to_channel[pin] - 1;
244244
}
245245

246246
void analogWriteFrequency(uint32_t freq) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.