Skip to content

Commit 6edee1a

Browse files
committed
Add basic hardware configuration options for P8
This enables the configuration of the LFCLK source, as well as the target hardware board pin configuration.
1 parent 977936e commit 6edee1a

File tree

5 files changed

+38
-11
lines changed

5 files changed

+38
-11
lines changed

CMakeLists.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,8 @@ 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()
54+
set(TARGET_DEVICE "PINETIME" CACHE STRING "Target device")
55+
set_property(CACHE TARGET_DEVICE PROPERTY STRINGS PINETIME P8A P8B)
6156

6257
set(PROJECT_GIT_COMMIT_HASH "")
6358

doc/buildAndProgram.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ CMake configures the project according to variables you specify the command line
3939
**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`
4040
**GDB_CLIENT_TARGET_REMOTE**|Target remote connection string. Used only if `USE_GDB_CLIENT` is 1.|`-DGDB_CLIENT_TARGET_REMOTE=/dev/ttyACM0`
4141
**BUILD_DFU (\*\*)**|Build DFU files while building (needs [adafruit-nrfutil](https://github.com/adafruit/Adafruit_nRF52_nrfutil)).|`-DBUILD_DFU=1`
42-
**WATCH_COLMI_P8**|Use pin configuration for Colmi P8 watch|`-DWATCH_COLMI_P8=1`
42+
**TARGET_DEVICE**|Target device, used for the pin map and the low frequency clock source. Allowed: `PINETIME, P8A, P8B`|`-DTARGET_DEVICE=PINETIME` (Default)
4343
4444
####(**) Note about **CMAKE_BUILD_TYPE**:
4545
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/InfiniTimeOrg/InfiniTime/releases) new versions of InfiniTime.

src/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,24 @@ add_definitions(-DFREERTOS)
787787
add_definitions(-D__STACK_SIZE=1024)
788788
add_definitions(-D__HEAP_SIZE=4096)
789789

790+
# Note: Only use this for debugging
791+
# Derive the low frequency clock from the main clock (SYNT)
792+
# add_definitions(-DCLOCK_CONFIG_LF_SRC=2)
793+
794+
# Target hardware configuration options
795+
add_definitions(-DTARGET_DEVICE_${TARGET_DEVICE})
796+
if(TARGET_DEVICE STREQUAL "PINETIME")
797+
add_definitions(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
798+
elseif(TARGET_DEVICE STREQUAL "P8A")
799+
add_definitions(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
800+
elseif(TARGET_DEVICE STREQUAL "P8B")
801+
add_definitions(-DCLOCK_CONFIG_LF_SRC=0) # RC
802+
add_definitions(-DMYNEWT_VAL_BLE_LL_SCA=500)
803+
add_definitions(-DCLOCK_CONFIG_LF_CAL_ENABLED=1)
804+
else()
805+
message(FATAL_ERROR "Invalid TARGET_DEVICE")
806+
endif()
807+
790808
# NOTE : Add the following defines to enable debug mode of the NRF SDK:
791809
#add_definitions(-DDEBUG)
792810
#add_definitions(-DDEBUG_NRF_USER)

src/drivers/PinMap.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
namespace Pinetime {
55
namespace PinMap {
66

7-
#ifdef WATCH_P8
8-
// COLMI P8
7+
#if defined(TARGET_DEVICE_P8A) || defined(TARGET_DEVICE_P8B)
8+
// COLMI P8 and variants
99
static constexpr uint8_t Charging = 19;
1010
static constexpr uint8_t Cst816sReset = 13;
1111
static constexpr uint8_t Button = 17;
1212
#else
13-
// Pinetime
13+
// Assume Pinetime
1414
static constexpr uint8_t Charging = 12;
1515
static constexpr uint8_t Cst816sReset = 10;
1616
static constexpr uint8_t Button = 13;

src/main.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,24 @@ void nimble_port_ll_task_func(void* args) {
301301
}
302302
}
303303

304+
void calibrate_lf_clock_rc(nrf_drv_clock_evt_type_t event) {
305+
// 16 * 0.25s = 4s calibration cycle
306+
// Not recursive, call is deferred via internal calibration timer
307+
nrf_drv_clock_calibration_start(16, calibrate_lf_clock_rc);
308+
}
309+
304310
int main(void) {
305311
logger.Init();
306312

307313
nrf_drv_clock_init();
314+
nrf_drv_clock_lfclk_request(NULL);
315+
316+
// The RC source for the LF clock has to be calibrated
317+
#if (CLOCK_CONFIG_LF_SRC == NRF_CLOCK_LFCLK_RC)
318+
while (!nrf_clock_lf_is_running()) {
319+
}
320+
nrf_drv_clock_calibration_start(0, calibrate_lf_clock_rc);
321+
#endif
308322

309323
// Unblock i2c?
310324
nrf_gpio_cfg(Pinetime::PinMap::TwiScl,

0 commit comments

Comments
 (0)