style: apply clang-format and enforce left pointer alignment

This commit is contained in:
Sebastien L
2026-02-12 04:48:38 +00:00
parent df225c120c
commit bf2fff44b8
148 changed files with 11508 additions and 12904 deletions

View File

@@ -51,8 +51,7 @@ static const struct rmt_led_param_s {
uint32_t green, red;
uint32_t (*scale)(uint32_t, uint8_t);
} rmt_led_param[] = {
{sys_led_types_WS2812, 24, {{{350 / RMT_CLK, 1, 1000 / RMT_CLK, 0}}},
{{{1000 / RMT_CLK, 1, 350 / RMT_CLK, 0}}}, 0xff0000, 0x00ff00, scale24},
{sys_led_types_WS2812, 24, {{{350 / RMT_CLK, 1, 1000 / RMT_CLK, 0}}}, {{{1000 / RMT_CLK, 1, 350 / RMT_CLK, 0}}}, 0xff0000, 0x00ff00, scale24},
{.type = -1}};
static EXT_RAM_ATTR struct led_s {
@@ -93,21 +92,20 @@ static uint32_t scale24(uint32_t color, uint8_t scale) {
*
*/
static void set_level(struct led_s* led, bool on) {
if (led->rmt) {
if(led->rmt) {
uint32_t data = on ? led->rmt->scale(led->color, led->bright) : 0;
uint32_t mask = 1 << (led->rmt->bits - 1);
rmt_item32_t buffer[led->rmt->bits];
for (uint32_t bit = 0; bit < led->rmt->bits; bit++) {
for(uint32_t bit = 0; bit < led->rmt->bits; bit++) {
uint32_t set = data & mask;
buffer[bit] = set ? led->rmt->bit_1 : led->rmt->bit_0;
mask >>= 1;
}
rmt_write_items(led->channel, buffer, led->rmt->bits, false);
} else if (led->bright < 0 || led->gpio >= GPIO_NUM_MAX) {
} else if(led->bright < 0 || led->gpio >= GPIO_NUM_MAX) {
gpio_set_level_x(led->gpio, on ? led->color : !led->color);
} else {
ledc_set_duty(
LEDC_SPEED_MODE, led->channel, on ? led->bright : (led->color ? 0 : pwm_system.max));
ledc_set_duty(LEDC_SPEED_MODE, led->channel, on ? led->bright : (led->color ? 0 : pwm_system.max));
ledc_update_duty(LEDC_SPEED_MODE, led->channel);
}
}
@@ -118,31 +116,29 @@ static void set_level(struct led_s* led, bool on) {
static void vCallbackFunction(TimerHandle_t xTimer) {
struct led_s* led = (struct led_s*)pvTimerGetTimerID(xTimer);
if (!led->timer) return;
if(!led->timer) return;
led->on = !led->on;
ESP_EARLY_LOGV(TAG, "led vCallbackFunction setting gpio %d level %d (bright:%d)", led->gpio,
led->on, led->bright);
ESP_EARLY_LOGV(TAG, "led vCallbackFunction setting gpio %d level %d (bright:%d)", led->gpio, led->on, led->bright);
set_level(led, led->on);
// was just on for a while
if (!led->on && led->offtime == -1) return;
if(!led->on && led->offtime == -1) return;
// regular blinking
xTimerChangePeriod(
xTimer, (led->on ? led->ontime : led->offtime) / portTICK_PERIOD_MS, BLOCKTIME);
xTimerChangePeriod(xTimer, (led->on ? led->ontime : led->offtime) / portTICK_PERIOD_MS, BLOCKTIME);
}
/****************************************************************************************
*
*/
bool led_blink_core(int idx, int ontime, int offtime, bool pushed) {
if (!leds[idx].gpio || leds[idx].gpio < 0) return false;
if(!leds[idx].gpio || leds[idx].gpio < 0) return false;
ESP_LOGD(TAG, "led_blink_core %d on:%d off:%d, pushed:%u", idx, ontime, offtime, pushed);
if (leds[idx].timer) {
if(leds[idx].timer) {
// normal requests waits if a pop is pending
if (!pushed && leds[idx].pushed) {
if(!pushed && leds[idx].pushed) {
leds[idx].pushedon = ontime;
leds[idx].pushedoff = offtime;
return true;
@@ -151,7 +147,7 @@ bool led_blink_core(int idx, int ontime, int offtime, bool pushed) {
}
// save current state if not already pushed
if (!leds[idx].pushed) {
if(!leds[idx].pushed) {
leds[idx].pushedon = leds[idx].ontime;
leds[idx].pushedoff = leds[idx].offtime;
leds[idx].pushed = pushed;
@@ -161,23 +157,22 @@ bool led_blink_core(int idx, int ontime, int offtime, bool pushed) {
leds[idx].ontime = ontime;
leds[idx].offtime = offtime;
if (ontime == 0) {
if(ontime == 0) {
ESP_LOGD(TAG, "led %d, setting reverse level", idx);
set_level(leds + idx, false);
} else if (offtime == 0) {
} else if(offtime == 0) {
ESP_LOGD(TAG, "led %d, setting level", idx);
set_level(leds + idx, true);
} else {
if (!leds[idx].timer) {
if(!leds[idx].timer) {
ESP_LOGD(TAG, "led %d, Creating timer", idx);
leds[idx].timer = xTimerCreate("ledTimer", ontime / portTICK_PERIOD_MS, pdFALSE,
(void*)&leds[idx], vCallbackFunction);
leds[idx].timer = xTimerCreate("ledTimer", ontime / portTICK_PERIOD_MS, pdFALSE, (void*)&leds[idx], vCallbackFunction);
}
leds[idx].on = true;
set_level(leds + idx, true);
ESP_LOGD(TAG, "led %d, Setting gpio %d and starting timer", idx, leds[idx].gpio);
if (xTimerStart(leds[idx].timer, BLOCKTIME) == pdFAIL) return false;
if(xTimerStart(leds[idx].timer, BLOCKTIME) == pdFAIL) return false;
}
return true;
@@ -187,13 +182,13 @@ bool led_blink_core(int idx, int ontime, int offtime, bool pushed) {
*
*/
bool led_brightness(int idx, int bright) {
if (bright > 100) bright = 100;
if(bright > 100) bright = 100;
if (leds[idx].rmt) {
if(leds[idx].rmt) {
leds[idx].bright = bright;
} else {
leds[idx].bright = pwm_system.max * powf(bright / 100.0, 3);
if (!leds[idx].color) leds[idx].bright = pwm_system.max - leds[idx].bright;
if(!leds[idx].color) leds[idx].bright = pwm_system.max - leds[idx].bright;
ledc_set_duty(LEDC_SPEED_MODE, leds[idx].channel, leds[idx].bright);
ledc_update_duty(LEDC_SPEED_MODE, leds[idx].channel);
@@ -206,7 +201,7 @@ bool led_brightness(int idx, int bright) {
*
*/
bool led_unpush(int idx) {
if (!leds[idx].gpio || leds[idx].gpio < 0) return false;
if(!leds[idx].gpio || leds[idx].gpio < 0) return false;
led_blink_core(idx, leds[idx].pushedon, leds[idx].pushedoff, true);
leds[idx].pushed = false;
@@ -218,7 +213,7 @@ bool led_unpush(int idx) {
*
*/
int led_allocate(void) {
if (led_max < MAX_LED) return led_max++;
if(led_max < MAX_LED) return led_max++;
return -1;
}
@@ -226,29 +221,29 @@ int led_allocate(void) {
*
*/
bool led_config(int idx, sys_led_config* led_config) {
if (!led_config->has_gpio) {
ESP_LOGD(TAG,"No GPIO configured for %s LED",idx == LED_GREEN ? "GREEN" : "RED");
if(!led_config->has_gpio) {
ESP_LOGD(TAG, "No GPIO configured for %s LED", idx == LED_GREEN ? "GREEN" : "RED");
return false;
}
if (led_config->gpio.pin < 0) {
ESP_LOGD(TAG,"GPIO -1 ignored for %s LED",idx == LED_GREEN ? "GREEN" : "RED");
if(led_config->gpio.pin < 0) {
ESP_LOGD(TAG, "GPIO -1 ignored for %s LED", idx == LED_GREEN ? "GREEN" : "RED");
return false;
}
if (idx >= MAX_LED) return false;
if (led_config->brightness > 100) led_config->brightness = 100;
if(idx >= MAX_LED) return false;
if(led_config->brightness > 100) led_config->brightness = 100;
leds[idx].gpio = led_config->gpio.pin;
leds[idx].color = led_config->gpio.level;
leds[idx].rmt = NULL;
leds[idx].bright = -1;
if (led_config->led_type != sys_led_types_GPIO) {
if(led_config->led_type != sys_led_types_GPIO) {
// first make sure we have a known addressable led
for (const struct rmt_led_param_s* p = rmt_led_param; !leds[idx].rmt && p->type >= 0; p++)
if (p->type == led_config->led_type) leds[idx].rmt = p;
if (!leds[idx].rmt) return false;
for(const struct rmt_led_param_s* p = rmt_led_param; !leds[idx].rmt && p->type >= 0; p++)
if(p->type == led_config->led_type) leds[idx].rmt = p;
if(!leds[idx].rmt) return false;
if (led_rmt_channel < 0) led_rmt_channel = RMT_NEXT_TX_CHANNEL();
if(led_rmt_channel < 0) led_rmt_channel = RMT_NEXT_TX_CHANNEL();
leds[idx].channel = led_rmt_channel;
leds[idx].bright = led_config->brightness > 0 ? led_config->brightness : 100;
@@ -258,13 +253,13 @@ bool led_config(int idx, sys_led_config* led_config) {
rmt_config(&config);
rmt_driver_install(config.channel, 0, 0);
} else if (led_config->brightness < 0 || led_config->gpio.pin >= GPIO_NUM_MAX) {
} else if(led_config->brightness < 0 || led_config->gpio.pin >= GPIO_NUM_MAX) {
gpio_pad_select_gpio_x(led_config->gpio.pin);
gpio_set_direction_x(led_config->gpio.pin, GPIO_MODE_OUTPUT);
} else {
leds[idx].channel = pwm_system.base_channel++;
leds[idx].bright = pwm_system.max * powf(led_config->brightness / 100.0, 3);
if (!led_config->gpio.level) leds[idx].bright = pwm_system.max - leds[idx].bright;
if(!led_config->gpio.level) leds[idx].bright = pwm_system.max - leds[idx].bright;
ledc_channel_config_t ledc_channel = {
.channel = leds[idx].channel,
@@ -279,9 +274,8 @@ bool led_config(int idx, sys_led_config* led_config) {
}
set_level(leds + idx, false);
ESP_LOGI(TAG, "Configuring LED %s %d (on:%d rmt:%s %d%% )", idx == LED_GREEN ? "GREEN" : "RED",
led_config->gpio.pin, led_config->gpio.level, sys_led_types_name(led_config->led_type),
led_config->brightness);
ESP_LOGI(TAG, "Configuring LED %s %d (on:%d rmt:%s %d%% )", idx == LED_GREEN ? "GREEN" : "RED", led_config->gpio.pin, led_config->gpio.level,
sys_led_types_name(led_config->led_type), led_config->brightness);
return true;
}
@@ -289,7 +283,7 @@ bool led_config(int idx, sys_led_config* led_config) {
*
*/
static void led_suspend(void) {
ESP_LOGD(TAG,"led_suspend: turning off leds");
ESP_LOGD(TAG, "led_suspend: turning off leds");
led_off(LED_GREEN);
led_off(LED_RED);
}
@@ -300,27 +294,27 @@ static void led_suspend(void) {
void set_led_gpio(int gpio, char* value) {
struct led_config_s* config;
if (strcasestr(value, "green"))
if(strcasestr(value, "green"))
config = &green;
else if (strcasestr(value, "red"))
else if(strcasestr(value, "red"))
config = &red;
else
return;
config->gpio = gpio;
char* p = value;
while ((p = strchr(p, ':')) != NULL) {
while((p = strchr(p, ':')) != NULL) {
p++;
if ((strcasestr(p, "ws2812")) != NULL)
if((strcasestr(p, "ws2812")) != NULL)
config->type = sys_led_types_WS2812;
else
config->color = atoi(p);
}
if (config->type != sys_led_types_GPIO) {
for (const struct rmt_led_param_s* p = rmt_led_param; p->type >= 0; p++) {
if (p->type == config->type) {
if (config == &green)
if(config->type != sys_led_types_GPIO) {
for(const struct rmt_led_param_s* p = rmt_led_param; p->type >= 0; p++) {
if(p->type == config->type) {
if(config == &green)
config->color = p->green;
else
config->color = p->red;
@@ -333,23 +327,19 @@ void set_led_gpio(int gpio, char* value) {
void led_svc_init(void) {
sys_gpios_config* gpios = NULL;
bool found = false;
if (!platform->has_gpios) {
if(!platform->has_gpios) {
ESP_LOGI(TAG, "No LED configured");
return;
}
ESP_LOGI(TAG,"Setting up leds");
ESP_LOGI(TAG, "Setting up leds");
gpios = &platform->gpios;
if (gpios->has_greenLED) {
found = found | led_config(LED_GREEN, &gpios->greenLED);
}
if (gpios->has_redLED) {
found = found | led_config(LED_RED, &gpios->redLED);
}
ESP_LOGD(TAG,"Done setting up leds");
if(gpios->has_greenLED) { found = found | led_config(LED_GREEN, &gpios->greenLED); }
if(gpios->has_redLED) { found = found | led_config(LED_RED, &gpios->redLED); }
ESP_LOGD(TAG, "Done setting up leds");
// make sure we switch off all leds (useful for gpio expanders)
if (found) {
ESP_LOGD(TAG,"Switching leds off");
if(found) {
ESP_LOGD(TAG, "Switching leds off");
services_sleep_setsuspend(led_suspend);
}
}