Skip to content

Commit b0bdd2b

Browse files
authored
Merge pull request #549 from hubmartin/pinmap
Put all duplicated GPIO pin definitions to a single file
2 parents 84a93b5 + e614af1 commit b0bdd2b

16 files changed

Lines changed: 118 additions & 92 deletions

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ if(BUILD_DFU)
5151
set(BUILD_DFU true)
5252
endif()
5353

54+
option(WATCH_COLMI_P8 "Build for the Colmi P8" OFF)
55+
set(TARGET_DEVICE "PineTime")
56+
57+
if(WATCH_COLMI_P8)
58+
set(TARGET_DEVICE "Colmi P8")
59+
add_definitions(-DWATCH_P8)
60+
endif()
61+
5462
set(PROJECT_GIT_COMMIT_HASH "")
5563

5664
execute_process(COMMAND git rev-parse --short HEAD
@@ -68,6 +76,7 @@ message(" * Version : " ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${P
6876
message(" * Toolchain : " ${ARM_NONE_EABI_TOOLCHAIN_PATH})
6977
message(" * GitRef(S) : " ${PROJECT_GIT_COMMIT_HASH})
7078
message(" * NRF52 SDK : " ${NRF5_SDK_PATH})
79+
message(" * Target device : " ${TARGET_DEVICE})
7180
set(PROGRAMMER "???")
7281
if(USE_JLINK)
7382
message(" * Programmer/debugger : JLINK")

doc/buildAndProgram.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ CMake configures the project according to variables you specify the command line
2828
**GDB_CLIENT_BIN_PATH**|Path to arm-none-eabi-gdb executable. Used only if `USE_GDB_CLIENT` is 1.|`-DGDB_CLIENT_BIN_PATH=/home/jf/nrf52/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gdb`
2929
**GDB_CLIENT_TARGET_REMOTE**|Target remote connection string. Used only if `USE_GDB_CLIENT` is 1.|`-DGDB_CLIENT_TARGET_REMOTE=/dev/ttyACM0`
3030
**BUILD_DFU (\*\*)**|Build DFU files while building (needs [adafruit-nrfutil](https://github.com/adafruit/Adafruit_nRF52_nrfutil)).|`-DBUILD_DFU=1`
31+
**WATCH_COLMI_P8**|Use pin configuration for Colmi P8 watch|`-DWATCH_COLMI_P8=1`
3132

3233
####(**) Note about **CMAKE_BUILD_TYPE**:
3334
By default, this variable is set to *Release*. It compiles the code with size and speed optimizations. We use this value for all the binaries we publish when we [release](https://github.com/JF002/InfiniTime/releases) new versions of InfiniTime.

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ set(INCLUDE_FILES
621621
drivers/DebugPins.h
622622
drivers/InternalFlash.h
623623
drivers/Hrs3300.h
624+
drivers/PinMap.h
624625
drivers/Bma421.h
625626
drivers/Bma421_C/bma4.c
626627
drivers/Bma421_C/bma423.c

src/components/battery/BatteryController.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "BatteryController.h"
2+
#include "drivers/PinMap.h"
23
#include <hal/nrf_gpio.h>
34
#include <nrfx_saadc.h>
45
#include <algorithm>
@@ -9,12 +10,12 @@ Battery* Battery::instance = nullptr;
910

1011
Battery::Battery() {
1112
instance = this;
12-
nrf_gpio_cfg_input(chargingPin, static_cast<nrf_gpio_pin_pull_t> GPIO_PIN_CNF_PULL_Disabled);
13+
nrf_gpio_cfg_input(PinMap::Charging, static_cast<nrf_gpio_pin_pull_t> GPIO_PIN_CNF_PULL_Disabled);
1314
}
1415

1516
void Battery::Update() {
16-
isCharging = !nrf_gpio_pin_read(chargingPin);
17-
isPowerPresent = !nrf_gpio_pin_read(powerPresentPin);
17+
isCharging = !nrf_gpio_pin_read(PinMap::Charging);
18+
isPowerPresent = !nrf_gpio_pin_read(PinMap::PowerPresent);
1819

1920
if (isReading) {
2021
return;

src/components/battery/BatteryController.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ namespace Pinetime {
3333
static Battery* instance;
3434
nrf_saadc_value_t saadc_value;
3535

36-
static constexpr uint32_t chargingPin = 12;
37-
static constexpr uint32_t powerPresentPin = 19;
3836
static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7;
3937
uint16_t voltage = 0;
4038
uint8_t percentRemaining = 0;

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::LcdBacklightLow);
9+
nrf_gpio_cfg_output(PinMap::LcdBacklightMedium);
10+
nrf_gpio_cfg_output(PinMap::LcdBacklightHigh);
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::LcdBacklightLow);
20+
nrf_gpio_pin_clear(PinMap::LcdBacklightMedium);
21+
nrf_gpio_pin_clear(PinMap::LcdBacklightHigh);
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::LcdBacklightLow);
25+
nrf_gpio_pin_clear(PinMap::LcdBacklightMedium);
26+
nrf_gpio_pin_set(PinMap::LcdBacklightHigh);
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::LcdBacklightLow);
30+
nrf_gpio_pin_set(PinMap::LcdBacklightMedium);
31+
nrf_gpio_pin_set(PinMap::LcdBacklightHigh);
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::LcdBacklightLow);
35+
nrf_gpio_pin_set(PinMap::LcdBacklightMedium);
36+
nrf_gpio_pin_set(PinMap::LcdBacklightHigh);
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: 6 additions & 5 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(shortVibTimer);
78
APP_TIMER_DEF(longVibTimer);
@@ -12,8 +13,8 @@ MotorController::MotorController(Controllers::Settings& settingsController) : se
1213
}
1314

1415
void MotorController::Init() {
15-
nrf_gpio_cfg_output(pinMotor);
16-
nrf_gpio_pin_set(pinMotor);
16+
nrf_gpio_cfg_output(PinMap::Motor);
17+
nrf_gpio_pin_set(PinMap::Motor);
1718
app_timer_init();
1819

1920
app_timer_create(&shortVibTimer, APP_TIMER_MODE_SINGLE_SHOT, StopMotor);
@@ -30,7 +31,7 @@ void MotorController::RunForDuration(uint8_t motorDuration) {
3031
return;
3132
}
3233

33-
nrf_gpio_pin_clear(pinMotor);
34+
nrf_gpio_pin_clear(PinMap::Motor);
3435
app_timer_start(shortVibTimer, APP_TIMER_TICKS(motorDuration), nullptr);
3536
}
3637

@@ -44,9 +45,9 @@ void MotorController::StartRinging() {
4445

4546
void MotorController::StopRinging() {
4647
app_timer_stop(longVibTimer);
47-
nrf_gpio_pin_set(pinMotor);
48+
nrf_gpio_pin_set(PinMap::Motor);
4849
}
4950

5051
void MotorController::StopMotor(void* p_context) {
51-
nrf_gpio_pin_set(pinMotor);
52+
nrf_gpio_pin_set(PinMap::Motor);
5253
}

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
@@ -80,9 +81,9 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() {
8081
}
8182

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

0 commit comments

Comments
 (0)