Skip to content

Commit 8b0559c

Browse files
StarGate01Riksu9000
authored andcommitted
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 bab8663 commit 8b0559c

5 files changed

Lines changed: 48 additions & 10 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,8 @@ if(BUILD_DFU)
5454
set(BUILD_DFU true)
5555
endif()
5656

57-
option(WATCH_COLMI_P8 "Build for the Colmi P8" OFF)
58-
set(TARGET_DEVICE "PineTime")
59-
60-
if(WATCH_COLMI_P8)
61-
set(TARGET_DEVICE "Colmi P8")
62-
add_definitions(-DWATCH_P8)
63-
endif()
57+
set(TARGET_DEVICE "PINETIME" CACHE STRING "Target device")
58+
set_property(CACHE TARGET_DEVICE PROPERTY STRINGS PINETIME MOY-TFK5 MOY-TIN5 MOY-TON5 MOY-UNK)
6459

6560
set(PROJECT_GIT_COMMIT_HASH "")
6661

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 hardware configuration. Allowed: `PINETIME, MOY-TFK5, MOY-TIN5, MOY-TON5, MOY-UNK`|`-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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,35 @@ add_definitions(-DFREERTOS)
779779
add_definitions(-D__STACK_SIZE=1024)
780780
add_definitions(-D__HEAP_SIZE=4096)
781781

782+
# Note: Only use this for debugging
783+
# Derive the low frequency clock from the main clock (SYNT)
784+
# add_definitions(-DCLOCK_CONFIG_LF_SRC=2)
785+
786+
# Target hardware configuration options
787+
add_definitions(-DTARGET_DEVICE_${TARGET_DEVICE})
788+
if(TARGET_DEVICE STREQUAL "PINETIME")
789+
add_definitions(-DDRIVER_PINMAP_PINETIME)
790+
add_definitions(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
791+
elseif(TARGET_DEVICE STREQUAL "MOY-TFK5") # P8a
792+
add_definitions(-DDRIVER_PINMAP_P8)
793+
add_definitions(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
794+
elseif(TARGET_DEVICE STREQUAL "MOY-TIN5") # P8a variant 2
795+
add_definitions(-DDRIVER_PINMAP_P8)
796+
add_definitions(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
797+
elseif(TARGET_DEVICE STREQUAL "MOY-TON5") # P8b
798+
add_definitions(-DDRIVER_PINMAP_P8)
799+
add_definitions(-DCLOCK_CONFIG_LF_SRC=0) # RC
800+
add_definitions(-DMYNEWT_VAL_BLE_LL_SCA=500)
801+
add_definitions(-DCLOCK_CONFIG_LF_CAL_ENABLED=1)
802+
elseif(TARGET_DEVICE STREQUAL "MOY-UNK") # P8b mirrored
803+
add_definitions(-DDRIVER_PINMAP_P8)
804+
add_definitions(-DCLOCK_CONFIG_LF_SRC=0) # RC
805+
add_definitions(-DMYNEWT_VAL_BLE_LL_SCA=500)
806+
add_definitions(-DCLOCK_CONFIG_LF_CAL_ENABLED=1)
807+
else()
808+
message(FATAL_ERROR "Invalid TARGET_DEVICE")
809+
endif()
810+
782811
# Debug configuration
783812
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
784813
add_definitions(-DDEBUG)

src/drivers/PinMap.h

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

7-
#ifdef WATCH_P8
8-
// COLMI P8
7+
#if defined(DRIVER_PINMAP_P8)
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;

src/main.cpp

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

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

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

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

0 commit comments

Comments
 (0)