Skip to content

Commit ca7ad62

Browse files
ci(pre-commit): Apply automatic fixes
1 parent ed72c00 commit ca7ad62

File tree

3 files changed

+45
-42
lines changed

3 files changed

+45
-42
lines changed

cores/esp32/esp32-hal-ledc.c

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,11 @@ bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution) {
315315
}
316316
#endif
317317

318-
log_e("No free timers available for freq=%u, resolution=%u. To attach a new channel, use the same frequency and resolution as an already attached channel to share its timer.", freq, resolution);
318+
log_e(
319+
"No free timers available for freq=%u, resolution=%u. To attach a new channel, use the same frequency and resolution as an already attached channel to "
320+
"share its timer.",
321+
freq, resolution
322+
);
319323
return false;
320324
}
321325

@@ -332,11 +336,11 @@ bool ledcWrite(uint8_t pin, uint32_t duty) {
332336
duty = max_duty + 1;
333337
}
334338

335-
if(ledc_set_duty(group, channel, duty) != ESP_OK) {
339+
if (ledc_set_duty(group, channel, duty) != ESP_OK) {
336340
log_e("ledc_set_duty failed");
337341
return false;
338342
}
339-
if(ledc_update_duty(group, channel) != ESP_OK) {
343+
if (ledc_update_duty(group, channel) != ESP_OK) {
340344
log_e("ledc_update_duty failed");
341345
return false;
342346
}
@@ -354,7 +358,7 @@ bool ledcWriteChannel(uint8_t channel, uint32_t duty) {
354358
}
355359
uint8_t group = (channel / SOC_LEDC_CHANNEL_NUM);
356360
ledc_timer_t timer;
357-
361+
358362
// Get the actual timer being used by this channel
359363
ledc_ll_get_channel_timer(LEDC_LL_GET_HW(), group, (channel % SOC_LEDC_CHANNEL_NUM), &timer);
360364

@@ -368,11 +372,11 @@ bool ledcWriteChannel(uint8_t channel, uint32_t duty) {
368372
duty = max_duty + 1;
369373
}
370374

371-
if(ledc_set_duty(group, channel, duty) != ESP_OK) {
375+
if (ledc_set_duty(group, channel, duty) != ESP_OK) {
372376
log_e("ledc_set_duty failed");
373377
return false;
374378
}
375-
if(ledc_update_duty(group, channel) != ESP_OK) {
379+
if (ledc_update_duty(group, channel) != ESP_OK) {
376380
log_e("ledc_update_duty failed");
377381
return false;
378382
}
@@ -497,7 +501,9 @@ bool ledcOutputInvert(uint8_t pin, bool out_invert) {
497501
esp_rom_gpio_connect_out_signal(pin, LEDC_LS_SIG_OUT_PAD_OUT0_IDX + ((bus->channel) % SOC_LEDC_CHANNEL_NUM), out_invert, 0);
498502
#else
499503
#ifdef SOC_LEDC_SUPPORT_HS_MODE
500-
esp_rom_gpio_connect_out_signal(pin, ((bus->channel / SOC_LEDC_CHANNEL_NUM == 0) ? LEDC_HS_SIG_OUT0_IDX : LEDC_LS_SIG_OUT0_IDX) + ((bus->channel) % SOC_LEDC_CHANNEL_NUM), out_invert, 0);
504+
esp_rom_gpio_connect_out_signal(
505+
pin, ((bus->channel / SOC_LEDC_CHANNEL_NUM == 0) ? LEDC_HS_SIG_OUT0_IDX : LEDC_LS_SIG_OUT0_IDX) + ((bus->channel) % SOC_LEDC_CHANNEL_NUM), out_invert, 0
506+
);
501507
#else
502508
esp_rom_gpio_connect_out_signal(pin, LEDC_LS_SIG_OUT0_IDX + ((bus->channel) % SOC_LEDC_CHANNEL_NUM), out_invert, 0);
503509
#endif
@@ -612,7 +618,7 @@ static uint16_t ledcGammaLUTSize = 0;
612618
// Global variable to store current resolution for gamma callback
613619
static uint8_t ledcGammaResolution = 13;
614620

615-
bool ledcSetGammaTable(const float* gamma_table, uint16_t size) {
621+
bool ledcSetGammaTable(const float *gamma_table, uint16_t size) {
616622
if (gamma_table == NULL || size == 0) {
617623
log_e("Invalid gamma table or size");
618624
return false;
@@ -635,17 +641,23 @@ void ledcSetGammaFactor(float factor) {
635641

636642
// Gamma correction calculator function
637643
static uint32_t ledcGammaCorrection(uint32_t duty) {
638-
if (duty == 0) return 0;
639-
644+
if (duty == 0) {
645+
return 0;
646+
}
647+
640648
uint32_t max_duty = (1U << ledcGammaResolution) - 1;
641-
if (duty >= (1U << ledcGammaResolution)) return max_duty;
642-
649+
if (duty >= (1U << ledcGammaResolution)) {
650+
return max_duty;
651+
}
652+
643653
// Use LUT if provided, otherwise use mathematical calculation
644654
if (ledcGammaLUT != NULL && ledcGammaLUTSize > 0) {
645655
// LUT-based gamma correction
646656
uint32_t lut_index = (duty * (ledcGammaLUTSize - 1)) / max_duty;
647-
if (lut_index >= ledcGammaLUTSize) lut_index = ledcGammaLUTSize - 1;
648-
657+
if (lut_index >= ledcGammaLUTSize) {
658+
lut_index = ledcGammaLUTSize - 1;
659+
}
660+
649661
float corrected_normalized = ledcGammaLUT[lut_index];
650662
return (uint32_t)(corrected_normalized * max_duty);
651663
} else {
@@ -694,21 +706,17 @@ static bool ledcFadeGammaConfig(uint8_t pin, uint32_t start_duty, uint32_t targe
694706
// Prepare gamma curve fade parameters
695707
ledc_fade_param_config_t fade_params[SOC_LEDC_GAMMA_CURVE_FADE_RANGE_MAX];
696708
uint32_t actual_fade_ranges = 0;
697-
709+
698710
// Use a moderate number of linear segments for smooth gamma curve
699711
const uint32_t linear_fade_segments = 12;
700-
712+
701713
// Set the global resolution for gamma correction
702714
ledcGammaResolution = bus->channel_resolution;
703715

704716
// Fill multi-fade parameter list using ESP-IDF API
705717
esp_err_t err = ledc_fill_multi_fade_param_list(
706-
group, channel,
707-
start_duty, target_duty,
708-
linear_fade_segments, max_fade_time_ms,
709-
ledcGammaCorrection,
710-
SOC_LEDC_GAMMA_CURVE_FADE_RANGE_MAX,
711-
fade_params, &actual_fade_ranges
718+
group, channel, start_duty, target_duty, linear_fade_segments, max_fade_time_ms, ledcGammaCorrection, SOC_LEDC_GAMMA_CURVE_FADE_RANGE_MAX, fade_params,
719+
&actual_fade_ranges
712720
);
713721

714722
if (err != ESP_OK) {
@@ -734,7 +742,7 @@ static bool ledcFadeGammaConfig(uint8_t pin, uint32_t start_duty, uint32_t targe
734742
}
735743

736744
log_d("Gamma curve fade started on pin %u: %u -> %u over %dms", pin, start_duty, target_duty, max_fade_time_ms);
737-
745+
738746
} else {
739747
log_e("Pin %u is not attached to LEDC. Call ledcAttach first!", pin);
740748
return false;

cores/esp32/esp32-hal-ledc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ bool ledcFadeWithInterruptArg(uint8_t pin, uint32_t start_duty, uint32_t target_
248248
* @note The LUT array must remain valid for as long as gamma fading is used.
249249
* Larger tables provide smoother transitions but use more memory.
250250
*/
251-
bool ledcSetGammaTable(const float* gamma_table, uint16_t size);
251+
bool ledcSetGammaTable(const float *gamma_table, uint16_t size);
252252

253253
/**
254254
* @brief Clear the current gamma correction lookup table.
@@ -309,7 +309,7 @@ bool ledcFadeGammaWithInterrupt(uint8_t pin, uint32_t start_duty, uint32_t targe
309309
* @note This function is only available on ESP32 variants that support gamma curve fading.
310310
*/
311311
bool ledcFadeGammaWithInterruptArg(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, void (*userFunc)(void *), void *arg);
312-
#endif // SOC_LEDC_GAMMA_CURVE_FADE_SUPPORTED
312+
#endif // SOC_LEDC_GAMMA_CURVE_FADE_SUPPORTED
313313

314314
#ifdef __cplusplus
315315
}

libraries/ESP32/examples/AnalogOut/LEDCGammaFade/LEDCGammaFade.ino

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
#define LEDC_FADE_TIME (2000)
2626

2727
// gamma factor for mathematical calculation
28-
#define LEDC_GAMMA_FACTOR (2.6)
28+
#define LEDC_GAMMA_FACTOR (2.6)
2929

3030
// use gamma LUT for better performance instead of mathematical calculation (gamma factor)
31-
#define USE_GAMMA_LUT 1
31+
#define USE_GAMMA_LUT 1
3232

3333
// fade LED pins
3434
const uint8_t ledPinR = 4;
@@ -42,17 +42,13 @@ bool fade_in = true;
4242
// Custom Gamma LUT demonstration with 101 steps (Brightness 0 - 100% gamma correction look up table (gamma = 2.6))
4343
// Y = B ^ 2.6 - Pre-computed LUT to save runtime computation
4444
static const float ledcGammaLUT[101] = {
45-
0.000000, 0.000006, 0.000038, 0.000110, 0.000232, 0.000414, 0.000666, 0.000994, 0.001406, 0.001910,
46-
0.002512, 0.003218, 0.004035, 0.004969, 0.006025, 0.007208, 0.008525, 0.009981, 0.011580, 0.013328,
47-
0.015229, 0.017289, 0.019512, 0.021902, 0.024465, 0.027205, 0.030125, 0.033231, 0.036527, 0.040016,
48-
0.043703, 0.047593, 0.051688, 0.055993, 0.060513, 0.065249, 0.070208, 0.075392, 0.080805, 0.086451,
49-
0.092333, 0.098455, 0.104821, 0.111434, 0.118298, 0.125416, 0.132792, 0.140428, 0.148329, 0.156498,
50-
0.164938, 0.173653, 0.182645, 0.191919, 0.201476, 0.211321, 0.221457, 0.231886, 0.242612, 0.253639,
51-
0.264968, 0.276603, 0.288548, 0.300805, 0.313378, 0.326268, 0.339480, 0.353016, 0.366879, 0.381073,
52-
0.395599, 0.410461, 0.425662, 0.441204, 0.457091, 0.473325, 0.489909, 0.506846, 0.524138, 0.541789,
53-
0.559801, 0.578177, 0.596920, 0.616032, 0.635515, 0.655374, 0.675610, 0.696226, 0.717224, 0.738608,
54-
0.760380, 0.782542, 0.805097, 0.828048, 0.851398, 0.875148, 0.899301, 0.923861, 0.948829, 0.974208,
55-
1.000000,
45+
0.000000, 0.000006, 0.000038, 0.000110, 0.000232, 0.000414, 0.000666, 0.000994, 0.001406, 0.001910, 0.002512, 0.003218, 0.004035, 0.004969, 0.006025,
46+
0.007208, 0.008525, 0.009981, 0.011580, 0.013328, 0.015229, 0.017289, 0.019512, 0.021902, 0.024465, 0.027205, 0.030125, 0.033231, 0.036527, 0.040016,
47+
0.043703, 0.047593, 0.051688, 0.055993, 0.060513, 0.065249, 0.070208, 0.075392, 0.080805, 0.086451, 0.092333, 0.098455, 0.104821, 0.111434, 0.118298,
48+
0.125416, 0.132792, 0.140428, 0.148329, 0.156498, 0.164938, 0.173653, 0.182645, 0.191919, 0.201476, 0.211321, 0.221457, 0.231886, 0.242612, 0.253639,
49+
0.264968, 0.276603, 0.288548, 0.300805, 0.313378, 0.326268, 0.339480, 0.353016, 0.366879, 0.381073, 0.395599, 0.410461, 0.425662, 0.441204, 0.457091,
50+
0.473325, 0.489909, 0.506846, 0.524138, 0.541789, 0.559801, 0.578177, 0.596920, 0.616032, 0.635515, 0.655374, 0.675610, 0.696226, 0.717224, 0.738608,
51+
0.760380, 0.782542, 0.805097, 0.828048, 0.851398, 0.875148, 0.899301, 0.923861, 0.948829, 0.974208, 1.000000,
5652
};
5753
#endif
5854

@@ -69,13 +65,12 @@ void setup() {
6965
ledcAttach(ledPinG, LEDC_BASE_FREQ, LEDC_TIMER_12_BIT);
7066
ledcAttach(ledPinB, LEDC_BASE_FREQ, LEDC_TIMER_12_BIT);
7167

72-
73-
#if USE_GAMMA_LUT // Use default gamma LUT for better performance
68+
#if USE_GAMMA_LUT // Use default gamma LUT for better performance
7469
ledcSetGammaTable(ledcGammaLUT, 101);
7570
#else // Use mathematical gamma correction (default, more flexible)
76-
ledcSetGammaFactor(LEDC_GAMMA_FACTOR); // This is optional to set custom gamma factor (default is 2.8)
71+
ledcSetGammaFactor(LEDC_GAMMA_FACTOR); // This is optional to set custom gamma factor (default is 2.8)
7772
#endif
78-
73+
7974
// Setup and start gamma curve fade on led (duty from 0 to 4095)
8075
ledcFadeGamma(ledPinR, LEDC_START_DUTY, LEDC_TARGET_DUTY, LEDC_FADE_TIME);
8176
ledcFadeGamma(ledPinG, LEDC_START_DUTY, LEDC_TARGET_DUTY, LEDC_FADE_TIME);

0 commit comments

Comments
 (0)