Skip to content

Commit b7beaa3

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 09b852d commit b7beaa3

File tree

5 files changed

+54
-25
lines changed

5 files changed

+54
-25
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
@@ -35,7 +35,7 @@ CMake configures the project according to variables you specify the command line
3535
**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`
3636
**GDB_CLIENT_TARGET_REMOTE**|Target remote connection string. Used only if `USE_GDB_CLIENT` is 1.|`-DGDB_CLIENT_TARGET_REMOTE=/dev/ttyACM0`
3737
**BUILD_DFU (\*\*)**|Build DFU files while building (needs [adafruit-nrfutil](https://github.com/adafruit/Adafruit_nRF52_nrfutil)).|`-DBUILD_DFU=1`
38-
**WATCH_COLMI_P8**|Use pin configuration for Colmi P8 watch|`-DWATCH_COLMI_P8=1`
38+
**TARGET_DEVICE**|Target device, used for the pin map and the low frequency clock source. Allowed: `PINETIME, P8A, P8B`|`-DTARGET_DEVICE=PINETIME` (Default)
3939
4040
####(**) Note about **CMAKE_BUILD_TYPE**:
4141
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
@@ -795,6 +795,24 @@ add_definitions(-DFREERTOS)
795795
add_definitions(-D__STACK_SIZE=1024)
796796
add_definitions(-D__HEAP_SIZE=4096)
797797

798+
# Note: Only use this for debugging
799+
# Derive the low frequency clock from the main clock (SYNT)
800+
# add_definitions(-DCLOCK_CONFIG_LF_SRC=2)
801+
802+
# Target hardware configuration options
803+
add_definitions(-DTARGET_DEVICE_${TARGET_DEVICE})
804+
if(TARGET_DEVICE STREQUAL "PINETIME")
805+
add_definitions(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
806+
elseif(TARGET_DEVICE STREQUAL "P8A")
807+
add_definitions(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
808+
elseif(TARGET_DEVICE STREQUAL "P8B")
809+
add_definitions(-DCLOCK_CONFIG_LF_SRC=0) # RC
810+
add_definitions(-DMYNEWT_VAL_BLE_LL_SCA=500)
811+
add_definitions(-DCLOCK_CONFIG_LF_CAL_ENABLED=1)
812+
else()
813+
message(FATAL_ERROR "Invalid TARGET_DEVICE")
814+
endif()
815+
798816
# NOTE : Add the following defines to enable debug mode of the NRF SDK:
799817
#add_definitions(-DDEBUG)
800818
#add_definitions(-DDEBUG_NRF_USER)

src/drivers/PinMap.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
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
6+
7+
#if defined(TARGET_DEVICE_P8A) || defined(TARGET_DEVICE_P8B)
8+
// COLMI P8 and variants
9+
static constexpr uint8_t Charging = 19;
10+
static constexpr uint8_t Cst816sReset = 13;
11+
static constexpr uint8_t Button = 17;
12+
#else
13+
// Assume Pinetime
14+
static constexpr uint8_t Charging = 12;
15+
static constexpr uint8_t Cst816sReset = 10;
16+
static constexpr uint8_t Button = 13;
17+
#endif
1818

1919
static constexpr uint8_t Cst816sIrq = 28;
2020
static constexpr uint8_t PowerPresent = 19;

src/main.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Pinetime::System::SystemTask systemTask(spi,
159159
touchHandler,
160160
buttonHandler);
161161

162-
/* Variable Declarations for variables in noinit SRAM
162+
/* Variable Declarations for variables in noinit SRAM
163163
Increment NoInit_MagicValue upon adding variables to this area
164164
*/
165165
extern uint32_t __start_noinit_data;
@@ -168,7 +168,6 @@ static constexpr uint32_t NoInit_MagicValue = 0xDEAD0000;
168168
uint32_t NoInit_MagicWord __attribute__((section(".noinit")));
169169
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> NoInit_BackUpTime __attribute__((section(".noinit")));
170170

171-
172171
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
173172
if (pin == Pinetime::PinMap::Cst816sIrq) {
174173
systemTask.OnTouchEvent();
@@ -302,11 +301,29 @@ void nimble_port_ll_task_func(void* args) {
302301
}
303302
}
304303

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+
305310
int main(void) {
306311
logger.Init();
307312

308313
nrf_drv_clock_init();
309314

315+
// In some cases (eg. when a watchdog is enabled),
316+
// the NRF SDK incorrectly assumes the LF clock is already running,
317+
nrf_drv_clock_lfclk_request(NULL);
318+
nrfx_clock_lfclk_start();
319+
while (!nrf_clock_lf_is_running()) {
320+
}
321+
322+
// The RC source for the LF clock has to be calibrated
323+
#if (CLOCK_CONFIG_LF_SRC == NRF_CLOCK_LFCLK_RC)
324+
nrf_drv_clock_calibration_start(0, calibrate_lf_clock_rc);
325+
#endif
326+
310327
// Unblock i2c?
311328
nrf_gpio_cfg(Pinetime::PinMap::TwiScl,
312329
NRF_GPIO_PIN_DIR_OUTPUT,
@@ -327,12 +344,11 @@ int main(void) {
327344
// retrieve version stored by bootloader
328345
Pinetime::BootloaderVersion::SetVersion(NRF_TIMER2->CC[0]);
329346

330-
331347
if (NoInit_MagicWord == NoInit_MagicValue) {
332348
dateTimeController.SetCurrentTime(NoInit_BackUpTime);
333349
} else {
334-
//Clear Memory to known state
335-
memset(&__start_noinit_data,0,(uintptr_t)&__stop_noinit_data-(uintptr_t)&__start_noinit_data);
350+
// Clear Memory to known state
351+
memset(&__start_noinit_data, 0, (uintptr_t) &__stop_noinit_data - (uintptr_t) &__start_noinit_data);
336352
NoInit_MagicWord = NoInit_MagicValue;
337353
}
338354

0 commit comments

Comments
 (0)