System: Refactor pin and interrupt setup

This should ensure better readability of the pin setup procedure,
as well as allow the configuration of the hardware button enable pin
and the accelerometer interrupt pin via the pin mapping header.
This commit is contained in:
Christoph Honal 2022-05-10 21:10:28 +02:00 committed by Riku Isokoski
parent 03a2059e87
commit 977936e8e2
2 changed files with 11 additions and 19 deletions

View file

@ -16,8 +16,10 @@ namespace Pinetime {
static constexpr uint8_t Button = 13; static constexpr uint8_t Button = 13;
#endif #endif
static constexpr uint8_t ButtonEnable = 15;
static constexpr uint8_t Cst816sIrq = 28; static constexpr uint8_t Cst816sIrq = 28;
static constexpr uint8_t PowerPresent = 19; static constexpr uint8_t PowerPresent = 19;
static constexpr uint8_t Bma421Irq = 8;
static constexpr uint8_t Motor = 16; static constexpr uint8_t Motor = 16;

View file

@ -172,39 +172,29 @@ void SystemTask::Work() {
buttonHandler.Init(this); buttonHandler.Init(this);
// Button // Setup Interrupts
nrf_gpio_cfg_output(15);
nrf_gpio_pin_set(15);
nrfx_gpiote_in_config_t pinConfig; nrfx_gpiote_in_config_t pinConfig;
pinConfig.skip_gpio_setup = false; pinConfig.skip_gpio_setup = false;
pinConfig.hi_accuracy = false; pinConfig.hi_accuracy = false;
pinConfig.is_watcher = false; pinConfig.is_watcher = false;
pinConfig.sense = static_cast<nrf_gpiote_polarity_t>(NRF_GPIOTE_POLARITY_TOGGLE);
pinConfig.pull = static_cast<nrf_gpio_pin_pull_t>(GPIO_PIN_CNF_PULL_Pulldown);
// Button
nrf_gpio_cfg_output(PinMap::ButtonEnable);
nrf_gpio_pin_set(PinMap::ButtonEnable);
pinConfig.sense = NRF_GPIOTE_POLARITY_TOGGLE;
pinConfig.pull = NRF_GPIO_PIN_PULLDOWN;
nrfx_gpiote_in_init(PinMap::Button, &pinConfig, nrfx_gpiote_evt_handler); nrfx_gpiote_in_init(PinMap::Button, &pinConfig, nrfx_gpiote_evt_handler);
nrfx_gpiote_in_event_enable(PinMap::Button, true); nrfx_gpiote_in_event_enable(PinMap::Button, true);
// Touchscreen // Touchscreen
nrf_gpio_cfg_sense_input(PinMap::Cst816sIrq, pinConfig.sense = NRF_GPIOTE_POLARITY_HITOLO;
static_cast<nrf_gpio_pin_pull_t>(GPIO_PIN_CNF_PULL_Pullup), pinConfig.pull = NRF_GPIO_PIN_PULLUP;
static_cast<nrf_gpio_pin_sense_t>(GPIO_PIN_CNF_SENSE_Low));
pinConfig.skip_gpio_setup = true;
pinConfig.hi_accuracy = false;
pinConfig.is_watcher = false;
pinConfig.sense = static_cast<nrf_gpiote_polarity_t>(NRF_GPIOTE_POLARITY_HITOLO);
pinConfig.pull = static_cast<nrf_gpio_pin_pull_t>(GPIO_PIN_CNF_PULL_Pullup);
nrfx_gpiote_in_init(PinMap::Cst816sIrq, &pinConfig, nrfx_gpiote_evt_handler); nrfx_gpiote_in_init(PinMap::Cst816sIrq, &pinConfig, nrfx_gpiote_evt_handler);
nrfx_gpiote_in_event_enable(PinMap::Cst816sIrq, true);
// Power present // Power present
pinConfig.sense = NRF_GPIOTE_POLARITY_TOGGLE; pinConfig.sense = NRF_GPIOTE_POLARITY_TOGGLE;
pinConfig.pull = NRF_GPIO_PIN_NOPULL; pinConfig.pull = NRF_GPIO_PIN_NOPULL;
pinConfig.is_watcher = false;
pinConfig.hi_accuracy = false;
pinConfig.skip_gpio_setup = false;
nrfx_gpiote_in_init(PinMap::PowerPresent, &pinConfig, nrfx_gpiote_evt_handler); nrfx_gpiote_in_init(PinMap::PowerPresent, &pinConfig, nrfx_gpiote_evt_handler);
nrfx_gpiote_in_event_enable(PinMap::PowerPresent, true); nrfx_gpiote_in_event_enable(PinMap::PowerPresent, true);