Skip to content

Commit

Permalink
[PARA] Only init auto mode GPIO on BT controller connection
Browse files Browse the repository at this point in the history
  • Loading branch information
darthcloud committed Nov 7, 2020
1 parent 21e7dd0 commit b39b32c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions main/adapter/adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ enum {
WIRED_NEW_DATA,
WIRED_SAVE_MEM,
WIRED_WAITING_FOR_RELEASE,
WIRED_GPIO_INIT,
};

/* Dev mode */
Expand Down
25 changes: 25 additions & 0 deletions main/adapter/parallel_auto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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]) {
Expand Down
18 changes: 0 additions & 18 deletions main/wired/detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b39b32c

Please sign in to comment.