Skip to content

feature(ledc): Add output invert option for LEDC pin + minor fixes #9257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 21, 2024
Merged
Prev Previous commit
Next Next commit
fix(ledc): Apply suggestions from code review
Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com>
  • Loading branch information
P-R-O-C-H-Y and SuGlider authored Feb 20, 2024
commit 68abeaeb1f3f3b8dd60bab1003b74df1c3301317
9 changes: 6 additions & 3 deletions cores/esp32/esp32-hal-ledc.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, uint8_t c
log_e("Channel %u is not available (maximum %u) or already used!", channel, LEDC_CHANNELS);
return false;
}

if (resolution > LEDC_MAX_BIT_WIDTH){
log_e("LEDC resolution too big (maximum %u)", LEDC_MAX_BIT_WIDTH);
if (freq == 0) {
log_e("LEDC pin %u - frequency can't be zero.", pin);
return false;
}
if (resolution == 0 || resolution > LEDC_MAX_BIT_WIDTH){
log_e("LEDC pin %u - resolution is zero or it is too big (maximum %u)", pin, LEDC_MAX_BIT_WIDTH);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion cores/esp32/esp32-hal-ledc.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ uint32_t ledcChangeFrequency(uint8_t pin, uint32_t freq, uint8_t resolution);
* @brief Sets inverting of the output signal for a given LEDC pin.
*
* @param pin GPIO pin
* @param out_invert select, if output should be inverted (1 = inverting output).
* @param out_invert select, if output should be inverted (true = inverting output).
*
* @return true if output inverting was successfully set, false otherwise.
*/
Expand Down
2 changes: 1 addition & 1 deletion docs/en/api/ledc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ This function is used to set inverting output for the LEDC pin.
bool ledcOutputInvert(uint8_t pin, bool out_invert);

* ``pin`` select LEDC pin.
* ``out_invert`` select, if output should be inverted (1 = inverting output).
* ``out_invert`` select, if output should be inverted (true = inverting output).

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