Skip to content

Commit 68abeae

Browse files
fix(ledc): Apply suggestions from code review
Co-authored-by: Rodrigo Garcia <[email protected]>
1 parent 651d19f commit 68abeae

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

cores/esp32/esp32-hal-ledc.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, uint8_t c
6464
log_e("Channel %u is not available (maximum %u) or already used!", channel, LEDC_CHANNELS);
6565
return false;
6666
}
67-
68-
if (resolution > LEDC_MAX_BIT_WIDTH){
69-
log_e("LEDC resolution too big (maximum %u)", LEDC_MAX_BIT_WIDTH);
67+
if (freq == 0) {
68+
log_e("LEDC pin %u - frequency can't be zero.", pin);
69+
return false;
70+
}
71+
if (resolution == 0 || resolution > LEDC_MAX_BIT_WIDTH){
72+
log_e("LEDC pin %u - resolution is zero or it is too big (maximum %u)", pin, LEDC_MAX_BIT_WIDTH);
7073
return false;
7174
}
7275

cores/esp32/esp32-hal-ledc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ uint32_t ledcChangeFrequency(uint8_t pin, uint32_t freq, uint8_t resolution);
145145
* @brief Sets inverting of the output signal for a given LEDC pin.
146146
*
147147
* @param pin GPIO pin
148-
* @param out_invert select, if output should be inverted (1 = inverting output).
148+
* @param out_invert select, if output should be inverted (true = inverting output).
149149
*
150150
* @return true if output inverting was successfully set, false otherwise.
151151
*/

docs/en/api/ledc.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ This function is used to set inverting output for the LEDC pin.
178178
bool ledcOutputInvert(uint8_t pin, bool out_invert);
179179
180180
* ``pin`` select LEDC pin.
181-
* ``out_invert`` select, if output should be inverted (1 = inverting output).
181+
* ``out_invert`` select, if output should be inverted (true = inverting output).
182182

183183
This function returns ``true`` if setting inverting output was successful.
184184
If ``false`` is returned, an error occurred and the inverting output was not set.

0 commit comments

Comments
 (0)