From ebd65727e42e2809e2587aa804023bd25f7747f5 Mon Sep 17 00:00:00 2001 From: Jacques Gagnon Date: Thu, 2 Nov 2023 23:32:58 -0400 Subject: [PATCH] [SYS] Fix port LEDs on system that overwrite whole GPIO out register --- main/system/manager.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/main/system/manager.c b/main/system/manager.c index 23081007..0dc4bc8b 100644 --- a/main/system/manager.c +++ b/main/system/manager.c @@ -149,7 +149,12 @@ static inline void set_power_off(uint32_t state) { } static inline void set_port_led(uint32_t index, uint32_t state) { - gpio_set_level(led_list[index], state); + if (state) { + esp_rom_gpio_connect_out_signal(led_list[index], ledc_periph_signal[LEDC_LOW_SPEED_MODE].sig_out0_idx + LEDC_CHANNEL_1, 0, 0); + } + else { + esp_rom_gpio_connect_out_signal(led_list[index], ledc_periph_signal[LEDC_LOW_SPEED_MODE].sig_out0_idx + LEDC_CHANNEL_2, 0, 0); + } } static inline uint32_t get_port_led_pin(uint32_t index) { @@ -179,12 +184,6 @@ static void internal_flag_init(void) { } } -static void port_led_reset(uint32_t pin) { - if (pin) { - gpio_set_direction(pin, GPIO_MODE_OUTPUT); - } -} - static void port_led_pulse(uint32_t pin) { if (pin) { gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[pin], PIN_FUNC_GPIO); @@ -310,8 +309,6 @@ static void wired_port_hdl(void) { if (!bt_ready && !err_led_set) { uint8_t new_led = (device->ids.out_idx < port_cnt) ? get_port_led_pin(device->ids.out_idx) : 0; - port_led_reset(current_pulse_led); - if (bt_hci_get_inquiry()) { port_led_pulse(new_led); err_led_set = 1; @@ -664,6 +661,9 @@ void sys_mgr_init(uint32_t package) { gpio_set_level(led_list[i], 0); io_conf.pin_bit_mask = 1ULL << led_list[i]; gpio_config(&io_conf); + /* Can't use GPIO mode on port LED as some wired driver overwrite whole GPIO port */ + /* Use unused LEDC channel 2 to force output low */ + esp_rom_gpio_connect_out_signal(led_list[i], ledc_periph_signal[LEDC_LOW_SPEED_MODE].sig_out0_idx + LEDC_CHANNEL_2, 0, 0); } #ifdef CONFIG_BLUERETRO_HW2