Skip to content

Commit

Permalink
Add basic hardware configuration options for P8
Browse files Browse the repository at this point in the history
This enables the configuration of the LFCLK source,
as well as the target hardware board pin configuration.
  • Loading branch information
StarGate01 committed May 16, 2022
1 parent 09b852d commit 3f9fcd8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 25 deletions.
9 changes: 2 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,8 @@ if(BUILD_DFU)
set(BUILD_DFU true)
endif()

option(WATCH_COLMI_P8 "Build for the Colmi P8" OFF)
set(TARGET_DEVICE "PineTime")

if(WATCH_COLMI_P8)
set(TARGET_DEVICE "Colmi P8")
add_definitions(-DWATCH_P8)
endif()
set(TARGET_DEVICE "PINETIME" CACHE STRING "Target device")
set_property(CACHE TARGET_DEVICE PROPERTY STRINGS PINETIME P8A P8B)

set(PROJECT_GIT_COMMIT_HASH "")

Expand Down
2 changes: 1 addition & 1 deletion doc/buildAndProgram.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CMake configures the project according to variables you specify the command line
**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`
**GDB_CLIENT_TARGET_REMOTE**|Target remote connection string. Used only if `USE_GDB_CLIENT` is 1.|`-DGDB_CLIENT_TARGET_REMOTE=/dev/ttyACM0`
**BUILD_DFU (\*\*)**|Build DFU files while building (needs [adafruit-nrfutil](https://github.com/adafruit/Adafruit_nRF52_nrfutil)).|`-DBUILD_DFU=1`
**WATCH_COLMI_P8**|Use pin configuration for Colmi P8 watch|`-DWATCH_COLMI_P8=1`
**TARGET_DEVICE**|Target device, used for the pin map and the low frequency clock source. Allowed: `PINETIME, P8A, P8B`|`-DTARGET_DEVICE=PINETIME` (Default)
####(**) Note about **CMAKE_BUILD_TYPE**:
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.
Expand Down
18 changes: 18 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,24 @@ 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(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
elseif(TARGET_DEVICE STREQUAL "P8A")
add_definitions(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
elseif(TARGET_DEVICE STREQUAL "P8B")
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()

# NOTE : Add the following defines to enable debug mode of the NRF SDK:
#add_definitions(-DDEBUG)
#add_definitions(-DDEBUG_NRF_USER)
Expand Down
24 changes: 12 additions & 12 deletions src/drivers/PinMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

namespace Pinetime {
namespace PinMap {
#ifdef WATCH_P8
// COLMI P8
static constexpr uint8_t Charging = 19;
static constexpr uint8_t Cst816sReset = 13;
static constexpr uint8_t Button = 17;
#else
// Pinetime
static constexpr uint8_t Charging = 12;
static constexpr uint8_t Cst816sReset = 10;
static constexpr uint8_t Button = 13;
#endif

#if defined(TARGET_DEVICE_P8A) || defined(TARGET_DEVICE_P8B)
// COLMI P8 and variants
static constexpr uint8_t Charging = 19;
static constexpr uint8_t Cst816sReset = 13;
static constexpr uint8_t Button = 17;
#else
// Assume Pinetime
static constexpr uint8_t Charging = 12;
static constexpr uint8_t Cst816sReset = 10;
static constexpr uint8_t Button = 13;
#endif

static constexpr uint8_t Cst816sIrq = 28;
static constexpr uint8_t PowerPresent = 19;
Expand Down
22 changes: 17 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Pinetime::System::SystemTask systemTask(spi,
touchHandler,
buttonHandler);

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


void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
if (pin == Pinetime::PinMap::Cst816sIrq) {
systemTask.OnTouchEvent();
Expand Down Expand Up @@ -302,10 +301,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,
Expand All @@ -327,12 +340,11 @@ int main(void) {
// retrieve version stored by bootloader
Pinetime::BootloaderVersion::SetVersion(NRF_TIMER2->CC[0]);


if (NoInit_MagicWord == NoInit_MagicValue) {
dateTimeController.SetCurrentTime(NoInit_BackUpTime);
} else {
//Clear Memory to known state
memset(&__start_noinit_data,0,(uintptr_t)&__stop_noinit_data-(uintptr_t)&__start_noinit_data);
// Clear Memory to known state
memset(&__start_noinit_data, 0, (uintptr_t) &__stop_noinit_data - (uintptr_t) &__start_noinit_data);
NoInit_MagicWord = NoInit_MagicValue;
}

Expand Down

0 comments on commit 3f9fcd8

Please sign in to comment.