Skip to content

Commit f0049eb

Browse files
committed
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.
1 parent 21f80d1 commit f0049eb

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

src/drivers/PinMap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ namespace Pinetime {
1616
static constexpr uint8_t Button = 13;
1717
#endif
1818

19+
static constexpr uint8_t ButtonEnable = 15;
1920
static constexpr uint8_t Cst816sIrq = 28;
2021
static constexpr uint8_t PowerPresent = 19;
22+
static constexpr uint8_t Bma421Irq = 8;
2123

2224
static constexpr uint8_t Motor = 16;
2325

src/systemtask/SystemTask.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -172,39 +172,29 @@ void SystemTask::Work() {
172172

173173
buttonHandler.Init(this);
174174

175-
// Button
176-
nrf_gpio_cfg_output(15);
177-
nrf_gpio_pin_set(15);
178-
175+
// Setup Interrupts
179176
nrfx_gpiote_in_config_t pinConfig;
180177
pinConfig.skip_gpio_setup = false;
181178
pinConfig.hi_accuracy = false;
182179
pinConfig.is_watcher = false;
183-
pinConfig.sense = static_cast<nrf_gpiote_polarity_t>(NRF_GPIOTE_POLARITY_TOGGLE);
184-
pinConfig.pull = static_cast<nrf_gpio_pin_pull_t>(GPIO_PIN_CNF_PULL_Pulldown);
185180

181+
// Button
182+
nrf_gpio_cfg_output(PinMap::ButtonEnable);
183+
nrf_gpio_pin_set(PinMap::ButtonEnable);
184+
pinConfig.sense = NRF_GPIOTE_POLARITY_TOGGLE;
185+
pinConfig.pull = NRF_GPIO_PIN_PULLDOWN;
186186
nrfx_gpiote_in_init(PinMap::Button, &pinConfig, nrfx_gpiote_evt_handler);
187187
nrfx_gpiote_in_event_enable(PinMap::Button, true);
188188

189189
// Touchscreen
190-
nrf_gpio_cfg_sense_input(PinMap::Cst816sIrq,
191-
static_cast<nrf_gpio_pin_pull_t>(GPIO_PIN_CNF_PULL_Pullup),
192-
static_cast<nrf_gpio_pin_sense_t>(GPIO_PIN_CNF_SENSE_Low));
193-
194-
pinConfig.skip_gpio_setup = true;
195-
pinConfig.hi_accuracy = false;
196-
pinConfig.is_watcher = false;
197-
pinConfig.sense = static_cast<nrf_gpiote_polarity_t>(NRF_GPIOTE_POLARITY_HITOLO);
198-
pinConfig.pull = static_cast<nrf_gpio_pin_pull_t>(GPIO_PIN_CNF_PULL_Pullup);
199-
190+
pinConfig.sense = NRF_GPIOTE_POLARITY_HITOLO;
191+
pinConfig.pull = NRF_GPIO_PIN_PULLUP;
200192
nrfx_gpiote_in_init(PinMap::Cst816sIrq, &pinConfig, nrfx_gpiote_evt_handler);
193+
nrfx_gpiote_in_event_enable(PinMap::Cst816sIrq, true);
201194

202195
// Power present
203196
pinConfig.sense = NRF_GPIOTE_POLARITY_TOGGLE;
204197
pinConfig.pull = NRF_GPIO_PIN_NOPULL;
205-
pinConfig.is_watcher = false;
206-
pinConfig.hi_accuracy = false;
207-
pinConfig.skip_gpio_setup = false;
208198
nrfx_gpiote_in_init(PinMap::PowerPresent, &pinConfig, nrfx_gpiote_evt_handler);
209199
nrfx_gpiote_in_event_enable(PinMap::PowerPresent, true);
210200

0 commit comments

Comments
 (0)