aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt29
-rw-r--r--src/drivers/PinMap.h4
-rw-r--r--src/main.cpp14
3 files changed, 45 insertions, 2 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index db0612ff..3b7503fd 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -779,6 +779,35 @@ add_definitions(-DFREERTOS)
add_definitions(-D__STACK_SIZE=1024)
add_definitions(-D__HEAP_SIZE=4096)
+# Note: Only use this for debugging
+# Derive the low frequency clock from the main clock (SYNT)
+# add_definitions(-DCLOCK_CONFIG_LF_SRC=2)
+
+# Target hardware configuration options
+add_definitions(-DTARGET_DEVICE_${TARGET_DEVICE})
+if(TARGET_DEVICE STREQUAL "PINETIME")
+ add_definitions(-DDRIVER_PINMAP_PINETIME)
+ add_definitions(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
+elseif(TARGET_DEVICE STREQUAL "MOY-TFK5") # P8a
+ add_definitions(-DDRIVER_PINMAP_P8)
+ add_definitions(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
+elseif(TARGET_DEVICE STREQUAL "MOY-TIN5") # P8a variant 2
+ add_definitions(-DDRIVER_PINMAP_P8)
+ add_definitions(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
+elseif(TARGET_DEVICE STREQUAL "MOY-TON5") # P8b
+ add_definitions(-DDRIVER_PINMAP_P8)
+ add_definitions(-DCLOCK_CONFIG_LF_SRC=0) # RC
+ add_definitions(-DMYNEWT_VAL_BLE_LL_SCA=500)
+ add_definitions(-DCLOCK_CONFIG_LF_CAL_ENABLED=1)
+elseif(TARGET_DEVICE STREQUAL "MOY-UNK") # P8b mirrored
+ add_definitions(-DDRIVER_PINMAP_P8)
+ add_definitions(-DCLOCK_CONFIG_LF_SRC=0) # RC
+ add_definitions(-DMYNEWT_VAL_BLE_LL_SCA=500)
+ add_definitions(-DCLOCK_CONFIG_LF_CAL_ENABLED=1)
+else()
+ message(FATAL_ERROR "Invalid TARGET_DEVICE")
+endif()
+
# Debug configuration
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
add_definitions(-DDEBUG)
diff --git a/src/drivers/PinMap.h b/src/drivers/PinMap.h
index 833c6477..a70cfc41 100644
--- a/src/drivers/PinMap.h
+++ b/src/drivers/PinMap.h
@@ -4,8 +4,8 @@
namespace Pinetime {
namespace PinMap {
-#ifdef WATCH_P8
- // COLMI P8
+#if defined(DRIVER_PINMAP_P8)
+ // COLMI P8 and variants
static constexpr uint8_t Charging = 19;
static constexpr uint8_t Cst816sReset = 13;
static constexpr uint8_t Button = 17;
diff --git a/src/main.cpp b/src/main.cpp
index 3d70af49..98d8cafb 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -300,10 +300,24 @@ void nimble_port_ll_task_func(void* args) {
}
}
+void calibrate_lf_clock_rc(nrf_drv_clock_evt_type_t event) {
+ // 16 * 0.25s = 4s calibration cycle
+ // Not recursive, call is deferred via internal calibration timer
+ nrf_drv_clock_calibration_start(16, calibrate_lf_clock_rc);
+}
+
int main(void) {
logger.Init();
nrf_drv_clock_init();
+ nrf_drv_clock_lfclk_request(NULL);
+
+// The RC source for the LF clock has to be calibrated
+#if (CLOCK_CONFIG_LF_SRC == NRF_CLOCK_LFCLK_RC)
+ while (!nrf_clock_lf_is_running()) {
+ }
+ nrf_drv_clock_calibration_start(0, calibrate_lf_clock_rc);
+#endif
// Unblock i2c?
nrf_gpio_cfg(Pinetime::PinMap::TwiScl,