Skip to content

Commit

Permalink
[MGR] Split flash and pulse LED duty param
Browse files Browse the repository at this point in the history
  • Loading branch information
darthcloud committed Feb 3, 2024
1 parent 1fef16c commit 0769da5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
12 changes: 8 additions & 4 deletions main/adapter/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ struct hw_config hw_config = {
.hw1_ports_led_pins = {2, 4, 12, 15},
.led_flash_duty_cycle = 0x80000,
.led_flash_hz = {2, 4, 8},
.led_off_duty_cycle = 0,
.led_on_duty_cycle = 0xFFFFF,
.led_flash_off_duty_cycle = 0,
.led_flash_on_duty_cycle = 0xFFFFF,
.led_pulse_duty_max = 2000,
.led_pulse_duty_min = 50,
.led_pulse_fade_cycle_delay_ms = 500,
.led_pulse_fade_time_ms = 500,
.led_pulse_hz = 5000,
.led_pulse_off_duty_cycle = 0,
.led_pulse_on_duty_cycle = 0x1FFF,
.port_cnt = 2,
.ports_sense_input_polarity = 0,
.ports_sense_output_ms = 1000,
Expand Down Expand Up @@ -66,13 +68,15 @@ static char *hw_config_name_idx[] = {
"led_flash_hz_0",
"led_flash_hz_1",
"led_flash_hz_2",
"led_off_duty",
"led_on_duty",
"led_f_off_duty",
"led_f_on_duty",
"led_p_duty_max",
"led_p_duty_min",
"led_p_fade_c_ms",
"led_p_fade_t_ms",
"led_pulse_hz",
"led_p_off_duty",
"led_p_on_duty",
"port_cnt",
"ports_s_in_pol",
"ports_s_out_ms",
Expand Down
8 changes: 5 additions & 3 deletions main/adapter/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ struct hw_config {
uint32_t hw1_ports_led_pins[4];
uint32_t led_flash_duty_cycle;
uint32_t led_flash_hz[3];
uint32_t led_off_duty_cycle;
uint32_t led_on_duty_cycle;
uint32_t led_flash_off_duty_cycle;
uint32_t led_flash_on_duty_cycle;
uint32_t led_pulse_duty_max;
uint32_t led_pulse_duty_min;
uint32_t led_pulse_fade_cycle_delay_ms;
uint32_t led_pulse_fade_time_ms;
uint32_t led_pulse_hz;
uint32_t led_pulse_off_duty_cycle;
uint32_t led_pulse_on_duty_cycle;
uint32_t port_cnt;
uint32_t ports_sense_input_polarity;
uint32_t ports_sense_output_ms;
Expand All @@ -89,7 +91,7 @@ struct hw_config {
uint32_t sw_io0_hold_thres_ms[3];
uint32_t ps_ctrl_colors[8];
};
uint32_t data32[41];
uint32_t data32[43];
};
uint8_t bdaddr[6];
} __packed;
Expand Down
8 changes: 4 additions & 4 deletions main/system/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void err_led_init(uint32_t package) {
};
ledc_channel_config_t ledc_channel = {
.channel = LEDC_CHANNEL_0,
.duty = hw_config.led_off_duty_cycle,
.duty = hw_config.led_pulse_off_duty_cycle,
.gpio_num = ERR_LED_PIN,
.speed_mode = LEDC_HIGH_SPEED_MODE,
.hpoint = 0,
Expand All @@ -69,7 +69,7 @@ void err_led_init(uint32_t package) {
ledc_timer_config(&ledc_timer);
ledc_channel_config(&ledc_channel);
ledc_fade_func_install(0);
ledc_set_duty_and_update(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, hw_config.led_off_duty_cycle, 0);
ledc_set_duty_and_update(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, hw_config.led_pulse_off_duty_cycle, 0);

xTaskCreatePinnedToCore(&err_led_task, "err_led_task", 768, NULL, 5, &err_led_task_hdl, 0);
err_led_clear();
Expand All @@ -81,15 +81,15 @@ void err_led_cfg_update(void) {

void err_led_set(void) {
vTaskSuspend(err_led_task_hdl);
ledc_set_duty_and_update(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, hw_config.led_on_duty_cycle, 0);
ledc_set_duty_and_update(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, hw_config.led_pulse_on_duty_cycle, 0);
atomic_set_bit(&led_flags, ERR_LED_SET);
}

void err_led_clear(void) {
/* When error is set it stay on until power cycle */
if (!atomic_test_bit(&led_flags, ERR_LED_SET)) {
vTaskSuspend(err_led_task_hdl);
ledc_set_duty_and_update(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, hw_config.led_off_duty_cycle, 0);
ledc_set_duty_and_update(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, hw_config.led_pulse_off_duty_cycle, 0);
}
}

Expand Down
4 changes: 2 additions & 2 deletions main/system/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ static void port_led_pulse(uint32_t pin) {
}

static void set_leds_as_btn_status(uint8_t state) {
ledc_set_duty_and_update(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, hw_config.led_on_duty_cycle, 0);
ledc_set_duty_and_update(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, hw_config.led_flash_on_duty_cycle, 0);

/* Use all port LEDs */
for (uint32_t i = 0; i < hw_config.port_cnt; i++) {
Expand Down Expand Up @@ -564,7 +564,7 @@ void sys_mgr_init(uint32_t package) {
};
ledc_channel_config_t ledc_channel = {
.channel = LEDC_CHANNEL_1,
.duty = hw_config.led_on_duty_cycle,
.duty = hw_config.led_flash_on_duty_cycle,
.gpio_num = LED_P1_PIN,
.speed_mode = LEDC_LOW_SPEED_MODE,
.hpoint = 0,
Expand Down

0 comments on commit 0769da5

Please sign in to comment.