Skip to content

Commit b7aa04e

Browse files
committed
PinMap with namespace and constexpr
1 parent 28abeae commit b7aa04e

13 files changed

Lines changed: 96 additions & 87 deletions

src/components/battery/BatteryController.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ Battery::Battery() {
1212
}
1313

1414
void Battery::Init() {
15-
nrf_gpio_cfg_input(chargingPin, static_cast<nrf_gpio_pin_pull_t> GPIO_PIN_CNF_PULL_Pullup);
15+
nrf_gpio_cfg_input(PinMap::Charging, static_cast<nrf_gpio_pin_pull_t> GPIO_PIN_CNF_PULL_Pullup);
1616
}
1717

1818
void Battery::Update() {
19-
isCharging = !nrf_gpio_pin_read(chargingPin);
20-
isPowerPresent = !nrf_gpio_pin_read(powerPresentPin);
19+
isCharging = !nrf_gpio_pin_read(PinMap::Charging);
20+
isPowerPresent = !nrf_gpio_pin_read(PinMap::PowerPresent);
2121

2222
if (isReading) {
2323
return;

src/components/battery/BatteryController.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ namespace Pinetime {
7373
static constexpr uint8_t percentRemainingSamples = 5;
7474
CircBuffer<percentRemainingSamples> percentRemainingBuffer {};
7575

76-
static constexpr uint32_t chargingPin = PINMAP_CHARGING_PIN;
77-
static constexpr uint32_t powerPresentPin = 19;
7876
static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7;
7977
uint16_t voltage = 0;
8078
int percentRemaining = -1;

src/components/brightness/BrightnessController.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include "BrightnessController.h"
22
#include <hal/nrf_gpio.h>
33
#include "displayapp/screens/Symbols.h"
4-
4+
#include "drivers/PinMap.h"
55
using namespace Pinetime::Controllers;
66

77
void BrightnessController::Init() {
8-
nrf_gpio_cfg_output(pinLcdBacklight1);
9-
nrf_gpio_cfg_output(pinLcdBacklight2);
10-
nrf_gpio_cfg_output(pinLcdBacklight3);
8+
nrf_gpio_cfg_output(PinMap::LcdBacklight1);
9+
nrf_gpio_cfg_output(PinMap::LcdBacklight2);
10+
nrf_gpio_cfg_output(PinMap::LcdBacklight3);
1111
Set(level);
1212
}
1313

@@ -16,24 +16,24 @@ void BrightnessController::Set(BrightnessController::Levels level) {
1616
switch (level) {
1717
default:
1818
case Levels::High:
19-
nrf_gpio_pin_clear(pinLcdBacklight1);
20-
nrf_gpio_pin_clear(pinLcdBacklight2);
21-
nrf_gpio_pin_clear(pinLcdBacklight3);
19+
nrf_gpio_pin_clear(PinMap::LcdBacklight1);
20+
nrf_gpio_pin_clear(PinMap::LcdBacklight2);
21+
nrf_gpio_pin_clear(PinMap::LcdBacklight3);
2222
break;
2323
case Levels::Medium:
24-
nrf_gpio_pin_clear(pinLcdBacklight1);
25-
nrf_gpio_pin_clear(pinLcdBacklight2);
26-
nrf_gpio_pin_set(pinLcdBacklight3);
24+
nrf_gpio_pin_clear(PinMap::LcdBacklight1);
25+
nrf_gpio_pin_clear(PinMap::LcdBacklight2);
26+
nrf_gpio_pin_set(PinMap::LcdBacklight3);
2727
break;
2828
case Levels::Low:
29-
nrf_gpio_pin_clear(pinLcdBacklight1);
30-
nrf_gpio_pin_set(pinLcdBacklight2);
31-
nrf_gpio_pin_set(pinLcdBacklight3);
29+
nrf_gpio_pin_clear(PinMap::LcdBacklight1);
30+
nrf_gpio_pin_set(PinMap::LcdBacklight2);
31+
nrf_gpio_pin_set(PinMap::LcdBacklight3);
3232
break;
3333
case Levels::Off:
34-
nrf_gpio_pin_set(pinLcdBacklight1);
35-
nrf_gpio_pin_set(pinLcdBacklight2);
36-
nrf_gpio_pin_set(pinLcdBacklight3);
34+
nrf_gpio_pin_set(PinMap::LcdBacklight1);
35+
nrf_gpio_pin_set(PinMap::LcdBacklight2);
36+
nrf_gpio_pin_set(PinMap::LcdBacklight3);
3737
break;
3838
}
3939
}

src/components/brightness/BrightnessController.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ namespace Pinetime {
2222
const char* ToString();
2323

2424
private:
25-
static constexpr uint8_t pinLcdBacklight1 = 14;
26-
static constexpr uint8_t pinLcdBacklight2 = 22;
27-
static constexpr uint8_t pinLcdBacklight3 = 23;
2825
Levels level = Levels::High;
2926
Levels backupLevel = Levels::High;
3027
};

src/components/motor/MotorController.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <hal/nrf_gpio.h>
33
#include "systemtask/SystemTask.h"
44
#include "app_timer.h"
5+
#include "drivers/PinMap.h"
56

67
APP_TIMER_DEF(vibTimer);
78

@@ -11,8 +12,8 @@ MotorController::MotorController(Controllers::Settings& settingsController) : se
1112
}
1213

1314
void MotorController::Init() {
14-
nrf_gpio_cfg_output(pinMotor);
15-
nrf_gpio_pin_set(pinMotor);
15+
nrf_gpio_cfg_output(PinMap::Motor);
16+
nrf_gpio_pin_set(PinMap::Motor);
1617
app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
1718
}
1819

@@ -21,11 +22,11 @@ void MotorController::SetDuration(uint8_t motorDuration) {
2122
if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF)
2223
return;
2324

24-
nrf_gpio_pin_clear(pinMotor);
25+
nrf_gpio_pin_clear(PinMap::Motor);
2526
/* Start timer for motorDuration miliseconds and timer triggers vibrate() when it finishes*/
2627
app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL);
2728
}
2829

2930
void MotorController::vibrate(void* p_context) {
30-
nrf_gpio_pin_set(pinMotor);
31+
nrf_gpio_pin_set(PinMap::Motor);
3132
}

src/components/motor/MotorController.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
namespace Pinetime {
88
namespace Controllers {
9-
static constexpr uint8_t pinMotor = 16;
109

1110
class MotorController {
1211
public:

src/drivers/Cst816s.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <legacy/nrf_drv_gpiote.h>
44
#include <nrfx_log.h>
55
#include <task.h>
6+
#include "drivers/PinMap.h"
67

78
using namespace Pinetime::Drivers;
89

@@ -18,12 +19,12 @@ Cst816S::Cst816S(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaste
1819
}
1920

2021
void Cst816S::Init() {
21-
nrf_gpio_cfg_output(pinReset);
22-
nrf_gpio_pin_set(pinReset);
22+
nrf_gpio_cfg_output(PinMap::Cst816sReset);
23+
nrf_gpio_pin_set(PinMap::Cst816sReset);
2324
vTaskDelay(50);
24-
nrf_gpio_pin_clear(pinReset);
25+
nrf_gpio_pin_clear(PinMap::Cst816sReset);
2526
vTaskDelay(5);
26-
nrf_gpio_pin_set(pinReset);
27+
nrf_gpio_pin_set(PinMap::Cst816sReset);
2728
vTaskDelay(50);
2829

2930
// Wake the touchpanel up
@@ -78,9 +79,9 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() {
7879
}
7980

8081
void Cst816S::Sleep() {
81-
nrf_gpio_pin_clear(pinReset);
82+
nrf_gpio_pin_clear(PinMap::Cst816sReset);
8283
vTaskDelay(5);
83-
nrf_gpio_pin_set(pinReset);
84+
nrf_gpio_pin_set(PinMap::Cst816sReset);
8485
vTaskDelay(50);
8586
static constexpr uint8_t sleepValue = 0x03;
8687
twiMaster.Write(twiAddress, 0xA5, &sleepValue, 1);

src/drivers/Cst816s.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include "TwiMaster.h"
4-
#include <drivers/PinMap.h>
54

65
namespace Pinetime {
76
namespace Drivers {
@@ -40,8 +39,6 @@ namespace Pinetime {
4039
void Wakeup();
4140

4241
private:
43-
static constexpr uint8_t pinIrq = 28;
44-
static constexpr uint8_t pinReset = PINMAP_CST816S_RESET_PIN;
4542
static constexpr uint8_t lastTouchId = 0x0f;
4643
static constexpr uint8_t touchPointNumIndex = 2;
4744
static constexpr uint8_t touchMiscIndex = 8;

src/drivers/PinMap.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
#pragma once
22

3+
namespace Pinetime {
4+
namespace PinMap {
5+
#define WATCH_P8
6+
#ifdef WATCH_P8
7+
static constexpr uint8_t Charging = 19;
8+
static constexpr uint8_t Cst816sReset = 13;
9+
static constexpr uint8_t Button = 17;
10+
#else
11+
static constexpr uint8_t Charging = 12;
12+
static constexpr uint8_t Cst816sReset = 10;
13+
static constexpr uint8_t Button = 13;
14+
#endif
15+
16+
static constexpr uint8_t Cst816sIrq = 28;
17+
static constexpr uint8_t PowerPresent = 19;
18+
19+
static constexpr uint8_t Motor = 16;
20+
21+
static constexpr uint8_t LcdBacklight1 = 14;
22+
static constexpr uint8_t LcdBacklight2 = 22;
23+
static constexpr uint8_t LcdBacklight3 = 23;
24+
25+
static constexpr uint8_t SpiSck = 2;
26+
static constexpr uint8_t SpiMosi = 3;
27+
static constexpr uint8_t SpiMiso = 4;
28+
29+
static constexpr uint8_t SpiFlashCsn = 5;
30+
static constexpr uint8_t SpiLcdCsn = 25;
31+
static constexpr uint8_t LcdDataCommand = 18;
32+
33+
static constexpr uint8_t TwiScl = 7;
34+
static constexpr uint8_t TwiSda = 6;
35+
36+
}
37+
}
38+
39+
340
#ifdef WATCH_P8
441

542
// BatteryController.h

src/main.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "drivers/St7789.h"
4343
#include "drivers/TwiMaster.h"
4444
#include "drivers/Cst816s.h"
45+
#include "drivers/PinMap.h"
4546
#include "systemtask/SystemTask.h"
4647

4748
#if NRF_LOG_ENABLED
@@ -52,14 +53,6 @@ Pinetime::Logging::NrfLogger logger;
5253
Pinetime::Logging::DummyLogger logger;
5354
#endif
5455

55-
static constexpr uint8_t pinSpiSck = 2;
56-
static constexpr uint8_t pinSpiMosi = 3;
57-
static constexpr uint8_t pinSpiMiso = 4;
58-
static constexpr uint8_t pinSpiFlashCsn = 5;
59-
static constexpr uint8_t pinLcdCsn = 25;
60-
static constexpr uint8_t pinLcdDataCommand = 18;
61-
static constexpr uint8_t pinTwiScl = 7;
62-
static constexpr uint8_t pinTwiSda = 6;
6356
static constexpr uint8_t touchPanelTwiAddress = 0x15;
6457
static constexpr uint8_t motionSensorTwiAddress = 0x18;
6558
static constexpr uint8_t heartRateSensorTwiAddress = 0x44;
@@ -68,22 +61,22 @@ Pinetime::Drivers::SpiMaster spi {Pinetime::Drivers::SpiMaster::SpiModule::SPI0,
6861
{Pinetime::Drivers::SpiMaster::BitOrder::Msb_Lsb,
6962
Pinetime::Drivers::SpiMaster::Modes::Mode3,
7063
Pinetime::Drivers::SpiMaster::Frequencies::Freq8Mhz,
71-
pinSpiSck,
72-
pinSpiMosi,
73-
pinSpiMiso}};
64+
Pinetime::PinMap::SpiSck,
65+
Pinetime::PinMap::SpiMosi,
66+
Pinetime::PinMap::SpiMiso}};
7467

75-
Pinetime::Drivers::Spi lcdSpi {spi, pinLcdCsn};
76-
Pinetime::Drivers::St7789 lcd {lcdSpi, pinLcdDataCommand};
68+
Pinetime::Drivers::Spi lcdSpi {spi, Pinetime::PinMap::SpiLcdCsn};
69+
Pinetime::Drivers::St7789 lcd {lcdSpi, Pinetime::PinMap::LcdDataCommand};
7770

78-
Pinetime::Drivers::Spi flashSpi {spi, pinSpiFlashCsn};
71+
Pinetime::Drivers::Spi flashSpi {spi, Pinetime::PinMap::SpiFlashCsn};
7972
Pinetime::Drivers::SpiNorFlash spiNorFlash {flashSpi};
8073

8174
// The TWI device should work @ up to 400Khz but there is a HW bug which prevent it from
8275
// respecting correct timings. According to erratas heet, this magic value makes it run
8376
// at ~390Khz with correct timings.
8477
static constexpr uint32_t MaxTwiFrequencyWithoutHardwareBug {0x06200000};
8578
Pinetime::Drivers::TwiMaster twiMaster {Pinetime::Drivers::TwiMaster::Modules::TWIM1,
86-
Pinetime::Drivers::TwiMaster::Parameters {MaxTwiFrequencyWithoutHardwareBug, pinTwiSda, pinTwiScl}};
79+
Pinetime::Drivers::TwiMaster::Parameters {MaxTwiFrequencyWithoutHardwareBug, Pinetime::PinMap::TwiSda, Pinetime::PinMap::TwiScl}};
8780
Pinetime::Drivers::Cst816S touchPanel {twiMaster, touchPanelTwiAddress};
8881
#ifdef PINETIME_IS_RECOVERY
8982
static constexpr bool isFactory = true;
@@ -106,8 +99,6 @@ Pinetime::Controllers::Battery batteryController;
10699
Pinetime::Controllers::Ble bleController;
107100
void ble_manager_set_ble_connection_callback(void (*connection)());
108101
void ble_manager_set_ble_disconnection_callback(void (*disconnection)());
109-
static constexpr uint8_t pinTouchIrq = 28;
110-
static constexpr uint8_t pinPowerPresentIrq = 19;
111102

112103
Pinetime::Controllers::HeartRateController heartRateController;
113104
Pinetime::Applications::HeartRateTask heartRateApp(heartRateSensor, heartRateController);
@@ -161,14 +152,14 @@ Pinetime::System::SystemTask systemTask(spi,
161152
fs);
162153

163154
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
164-
if (pin == pinTouchIrq) {
155+
if (pin == Pinetime::PinMap::Cst816sIrq) {
165156
systemTask.OnTouchEvent();
166157
return;
167158
}
168159

169160
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
170161

171-
if (pin == pinPowerPresentIrq and action == NRF_GPIOTE_POLARITY_TOGGLE) {
162+
if (pin == Pinetime::PinMap::PowerPresent and action == NRF_GPIOTE_POLARITY_TOGGLE) {
172163
xTimerStartFromISR(debounceChargeTimer, &xHigherPriorityTaskWoken);
173164
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
174165
return;

0 commit comments

Comments
 (0)