diff --git a/main/adapter/adapter.h b/main/adapter/adapter.h index 10bd379d..cbfee71a 100755 --- a/main/adapter/adapter.h +++ b/main/adapter/adapter.h @@ -253,6 +253,7 @@ enum { WIRED_NEW_DATA, WIRED_SAVE_MEM, WIRED_WAITING_FOR_RELEASE, + WIRED_GPIO_INIT, }; /* Dev mode */ diff --git a/main/adapter/parallel_auto.c b/main/adapter/parallel_auto.c index 048d9eb8..8828df41 100644 --- a/main/adapter/parallel_auto.c +++ b/main/adapter/parallel_auto.c @@ -38,6 +38,26 @@ static const uint32_t para_auto_btns_mask[32] = { 0, 0, 0, 0, }; +static const uint8_t output_list[] = { + 3, 5, 18, 23, 26, 27 +}; + +static void parallel_io_init(void) +{ + gpio_config_t io_conf = {0}; + + io_conf.intr_type = GPIO_PIN_INTR_DISABLE; + io_conf.mode = GPIO_MODE_OUTPUT; + io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE; + io_conf.pull_up_en = GPIO_PULLUP_ENABLE; + + for (uint32_t i = 0; i < ARRAY_SIZE(output_list); i++) { + io_conf.pin_bit_mask = 1ULL << output_list[i]; + gpio_config(&io_conf); + gpio_set_level(output_list[i], 1); + } +} + void para_auto_init_buffer(int32_t dev_mode, struct wired_data *wired_data) { struct para_auto_map *map = (struct para_auto_map *)wired_data->output; @@ -58,6 +78,11 @@ void para_auto_from_generic(int32_t dev_mode, struct generic_ctrl *ctrl_data, st struct para_auto_map map_tmp; memcpy((void *)&map_tmp, wired_data->output, sizeof(map_tmp)); + if (!atomic_test_bit(&wired_data->flags, WIRED_GPIO_INIT)) { + parallel_io_init(); + atomic_set_bit(&wired_data->flags, WIRED_GPIO_INIT); + } + for (uint32_t i = 0; i < ARRAY_SIZE(generic_btns_mask); i++) { if (ctrl_data->map_mask[0] & BIT(i)) { if (ctrl_data->btns[0].value & generic_btns_mask[i]) { diff --git a/main/wired/detect.c b/main/wired/detect.c index 3db0984d..59319344 100644 --- a/main/wired/detect.c +++ b/main/wired/detect.c @@ -42,22 +42,6 @@ static const uint8_t output_list[] = { 3, 5, 18, 23, 26, 27 }; -static void parallel_io_init(void) -{ - gpio_config_t io_conf = {0}; - - io_conf.intr_type = GPIO_PIN_INTR_DISABLE; - io_conf.mode = GPIO_MODE_OUTPUT; - io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE; - io_conf.pull_up_en = GPIO_PULLUP_ENABLE; - - for (uint32_t i = 0; i < ARRAY_SIZE(output_list); i++) { - io_conf.pin_bit_mask = 1ULL << output_list[i]; - gpio_config(&io_conf); - gpio_set_level(output_list[i], 1); - } -} - static void IRAM_ATTR detect_intr(void* arg) { const uint32_t low_io = GPIO.acpu_int; const uint32_t high_io = GPIO.acpu_int1.intr; @@ -122,8 +106,6 @@ void detect_init(void) { io_conf.pull_up_en = GPIO_PULLUP_ENABLE; gpio_config(&io_conf); - parallel_io_init(); - wired_adapter.system_id = WIRED_AUTO; adapter_init_buffer(0);