@@ -186,7 +186,7 @@ static bool ledcDetachBus(void *bus) {
186
186
return true;
187
187
}
188
188
189
- bool ledcAttachChannel (uint8_t pin , uint32_t freq , uint8_t resolution , uint8_t channel ) {
189
+ bool ledcAttachChannel (uint8_t pin , uint32_t freq , uint8_t resolution , uint8_t channel , bool inverted = false ) {
190
190
if (channel >= LEDC_CHANNELS ) {
191
191
log_e ("Channel %u is not available (maximum %u)!" , channel , LEDC_CHANNELS );
192
192
return false;
@@ -256,6 +256,7 @@ bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, uint8_t c
256
256
ledc_channel .gpio_num = pin ;
257
257
ledc_channel .duty = duty ;
258
258
ledc_channel .hpoint = 0 ;
259
+ ledc_channel .flags .output_invert = inverted ? 1 : 0 ;
259
260
260
261
ledc_channel_config (& ledc_channel );
261
262
}
@@ -289,7 +290,7 @@ bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, uint8_t c
289
290
return true;
290
291
}
291
292
292
- bool ledcAttach (uint8_t pin , uint32_t freq , uint8_t resolution ) {
293
+ bool ledcAttach (uint8_t pin , uint32_t freq , uint8_t resolution , bool inverted = false ) {
293
294
int free_channel = ~ledc_handle .used_channels & (ledc_handle .used_channels + 1 );
294
295
if (free_channel == 0 ) {
295
296
log_e ("No more LEDC channels available! (maximum is %u channels)" , LEDC_CHANNELS );
@@ -298,7 +299,7 @@ bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution) {
298
299
uint8_t channel = __builtin_ctz (free_channel ); // Convert the free_channel bit to channel number
299
300
300
301
// Try the first available channel
301
- if (ledcAttachChannel (pin , freq , resolution , channel )) {
302
+ if (ledcAttachChannel (pin , freq , resolution , channel , inverted )) {
302
303
return true;
303
304
}
304
305
@@ -311,7 +312,7 @@ bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution) {
311
312
int group1_free_channel = (~ledc_handle .used_channels ) & group1_mask ;
312
313
if (group1_free_channel != 0 ) {
313
314
uint8_t group1_channel = __builtin_ctz (group1_free_channel );
314
- if (ledcAttachChannel (pin , freq , resolution , group1_channel )) {
315
+ if (ledcAttachChannel (pin , freq , resolution , group1_channel , inverted )) {
315
316
return true;
316
317
}
317
318
}
0 commit comments