Skip to content

Commit 97620d4

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 08bacc1 commit 97620d4

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

src/drivers/PinMap.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@
33

44
namespace Pinetime {
55
namespace PinMap {
6-
7-
#ifdef WATCH_P8
8-
// COLMI P8
9-
static constexpr uint8_t Charging = 19;
10-
static constexpr uint8_t Cst816sReset = 13;
11-
static constexpr uint8_t Button = 17;
12-
#else
13-
// Pinetime
14-
static constexpr uint8_t Charging = 12;
15-
static constexpr uint8_t Cst816sReset = 10;
16-
static constexpr uint8_t Button = 13;
17-
#endif
186

7+
#ifdef WATCH_P8
8+
// COLMI P8
9+
static constexpr uint8_t Charging = 19;
10+
static constexpr uint8_t Cst816sReset = 13;
11+
static constexpr uint8_t Button = 17;
12+
#else
13+
// Pinetime
14+
static constexpr uint8_t Charging = 12;
15+
static constexpr uint8_t Cst816sReset = 10;
16+
static constexpr uint8_t Button = 13;
17+
#endif
18+
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: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -172,39 +172,35 @@ 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);
194+
195+
// Acceleration
196+
pinConfig.sense = NRF_GPIOTE_POLARITY_HITOLO;
197+
pinConfig.pull = NRF_GPIO_PIN_PULLUP;
198+
nrfx_gpiote_in_init(PinMap::Bma421Irq, &pinConfig, nrfx_gpiote_evt_handler);
199+
nrfx_gpiote_in_event_enable(PinMap::Bma421Irq, true);
201200

202201
// Power present
203202
pinConfig.sense = NRF_GPIOTE_POLARITY_TOGGLE;
204203
pinConfig.pull = NRF_GPIO_PIN_NOPULL;
205-
pinConfig.is_watcher = false;
206-
pinConfig.hi_accuracy = false;
207-
pinConfig.skip_gpio_setup = false;
208204
nrfx_gpiote_in_init(PinMap::PowerPresent, &pinConfig, nrfx_gpiote_evt_handler);
209205
nrfx_gpiote_in_event_enable(PinMap::PowerPresent, true);
210206

0 commit comments

Comments
 (0)