From 2aebbe3f474bfaa5058879bde045146f5561fb66 Mon Sep 17 00:00:00 2001 From: hubmartin Date: Sun, 3 Oct 2021 16:47:01 +0200 Subject: [PATCH 1/3] GPIOTE fix of button and power detection experiment --- src/systemtask/SystemTask.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 5441c162..a2ff60f8 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -158,19 +158,21 @@ void SystemTask::Work() { heartRateSensor.Disable(); heartRateApp.Start(); - nrf_gpio_cfg_sense_input(PinMap::Button, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pulldown, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_High); + // Button nrf_gpio_cfg_output(15); nrf_gpio_pin_set(15); nrfx_gpiote_in_config_t pinConfig; - pinConfig.skip_gpio_setup = true; + pinConfig.skip_gpio_setup = false; pinConfig.hi_accuracy = false; pinConfig.is_watcher = false; - pinConfig.sense = (nrf_gpiote_polarity_t) NRF_GPIOTE_POLARITY_HITOLO; + pinConfig.sense = (nrf_gpiote_polarity_t) NRF_GPIOTE_POLARITY_TOGGLE; pinConfig.pull = (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pulldown; nrfx_gpiote_in_init(PinMap::Button, &pinConfig, nrfx_gpiote_evt_handler); + nrfx_gpiote_in_event_enable(PinMap::Button, true); + // Touchscreen nrf_gpio_cfg_sense_input(PinMap::Cst816sIrq, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_Low); pinConfig.skip_gpio_setup = true; @@ -181,18 +183,20 @@ void SystemTask::Work() { nrfx_gpiote_in_init(PinMap::Cst816sIrq, &pinConfig, nrfx_gpiote_evt_handler); + // Power present pinConfig.sense = NRF_GPIOTE_POLARITY_TOGGLE; pinConfig.pull = NRF_GPIO_PIN_NOPULL; pinConfig.is_watcher = false; pinConfig.hi_accuracy = false; - pinConfig.skip_gpio_setup = true; + pinConfig.skip_gpio_setup = false; nrfx_gpiote_in_init(PinMap::PowerPresent, &pinConfig, nrfx_gpiote_evt_handler); + nrfx_gpiote_in_event_enable(PinMap::PowerPresent, true); - if (nrf_gpio_pin_read(PinMap::PowerPresent)) { - nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW); - } else { - nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH); - } + // if (nrf_gpio_pin_read(PinMap::PowerPresent)) { + // nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW); + // } else { + // nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH); + // } idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(2000), pdFALSE, this, IdleTimerCallback); dimTimer = xTimerCreate("dimTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), pdFALSE, this, DimTimerCallback); From f5725714d13a66407b0556f8ac3cbd7e6db8901f Mon Sep 17 00:00:00 2001 From: hubmartin Date: Sun, 3 Oct 2021 17:00:38 +0200 Subject: [PATCH 2/3] Call battery controller update --- src/systemtask/SystemTask.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index a2ff60f8..fc2c5cfd 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -136,7 +136,6 @@ void SystemTask::Work() { touchPanel.Init(); dateTimeController.Register(this); batteryController.Register(this); - batteryController.Update(); motorController.Init(); motionSensor.SoftReset(); timerController.Register(this); @@ -197,6 +196,9 @@ void SystemTask::Work() { // } else { // nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH); // } + + // Update controller based on current gpio pin state, needs to be called after gpio config + batteryController.Update(); idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(2000), pdFALSE, this, IdleTimerCallback); dimTimer = xTimerCreate("dimTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), pdFALSE, this, DimTimerCallback); From 9ef1babb9dfea4be0ef2179254dc3dd8afd1d7e1 Mon Sep 17 00:00:00 2001 From: hubmartin Date: Sun, 3 Oct 2021 17:03:08 +0200 Subject: [PATCH 3/3] Code cleanup --- src/systemtask/SystemTask.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index fc2c5cfd..8412540f 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -191,12 +191,6 @@ void SystemTask::Work() { nrfx_gpiote_in_init(PinMap::PowerPresent, &pinConfig, nrfx_gpiote_evt_handler); nrfx_gpiote_in_event_enable(PinMap::PowerPresent, true); - // if (nrf_gpio_pin_read(PinMap::PowerPresent)) { - // nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW); - // } else { - // nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH); - // } - // Update controller based on current gpio pin state, needs to be called after gpio config batteryController.Update();