Revert "Merge upstream"

This reverts commit 1d43adcdfa.
This commit is contained in:
Mark Russell 2021-09-16 16:12:20 -04:00
parent 1d43adcdfa
commit cdf99b08f4
33 changed files with 232 additions and 300 deletions

View file

@ -9,13 +9,13 @@ name: Build PineTime Firmware
# When to run this Workflow... # When to run this Workflow...
on: on:
# Run this Workflow when files are updated (Pushed) in the "master" and "develop" Branch # Run this Workflow when files are updated (Pushed) in the "master" Branch
push: push:
branches: [ master, develop ] branches: [ master ]
# Also run this Workflow when a Pull Request is created or updated in the "master" and "develop" Branch # Also run this Workflow when a Pull Request is created or updated in the "master" Branch
pull_request: pull_request:
branches: [ master, develop ] branches: [ master ]
# Steps to run for the Workflow # Steps to run for the Workflow
jobs: jobs:

View file

@ -51,14 +51,6 @@ if(BUILD_DFU)
set(BUILD_DFU true) set(BUILD_DFU true)
endif() 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(PROJECT_GIT_COMMIT_HASH "") set(PROJECT_GIT_COMMIT_HASH "")
execute_process(COMMAND git rev-parse --short HEAD execute_process(COMMAND git rev-parse --short HEAD
@ -76,7 +68,6 @@ message(" * Version : " ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${P
message(" * Toolchain : " ${ARM_NONE_EABI_TOOLCHAIN_PATH}) message(" * Toolchain : " ${ARM_NONE_EABI_TOOLCHAIN_PATH})
message(" * GitRef(S) : " ${PROJECT_GIT_COMMIT_HASH}) message(" * GitRef(S) : " ${PROJECT_GIT_COMMIT_HASH})
message(" * NRF52 SDK : " ${NRF5_SDK_PATH}) message(" * NRF52 SDK : " ${NRF5_SDK_PATH})
message(" * Target device : " ${TARGET_DEVICE})
set(PROGRAMMER "???") set(PROGRAMMER "???")
if(USE_JLINK) if(USE_JLINK)
message(" * Programmer/debugger : JLINK") message(" * Programmer/debugger : JLINK")

View file

@ -1,10 +1,20 @@
# InfiniTime # PineTime
[![Build PineTime Firmware](https://github.com/JF002/InfiniTime/workflows/Build%20PineTime%20Firmware/badge.svg?branch=master)](https://github.com/JF002/InfiniTime/actions) [![Build PineTime Firmware](https://github.com/JF002/InfiniTime/workflows/Build%20PineTime%20Firmware/badge.svg?branch=master)](https://github.com/JF002/InfiniTime/actions)
> The PineTime is a free and open source smartwatch capable of running custom-built open operating systems. Some of the notable features include a heart rate monitor, a week-long battery as well as a capacitive touch IPS display that is legible in direct sunlight. It is a fully community driven side-project, which means that it will ultimately be up to the developers and end-users to determine when they deem the PineTime ready to ship.
> We envision the PineTime as a companion for not only your PinePhone but also for your favorite devices — any phone, tablet, or even PC.
*https://www.pine64.org/pinetime/*
The **Pinetime** smartwatch is built around the NRF52832 MCU (512KB Flash, 64KB RAM), a 240*240 LCD display driven by the ST7789 controller, an accelerometer, a heart rate sensor, and a vibration motor.
# InfiniTime
![InfiniTime logo](images/infinitime-logo.jpg "InfiniTime Logo") ![InfiniTime logo](images/infinitime-logo.jpg "InfiniTime Logo")
The goal of this project is to design an open-source firmware for the [Pinetime smartwatch](https://www.pine64.org/pinetime/) : The goal of this project is to design an open-source firmware for the Pinetime smartwatch :
- Code written in **modern C++**; - Code written in **modern C++**;
- Build system based on **CMake**; - Build system based on **CMake**;
@ -12,11 +22,6 @@ The goal of this project is to design an open-source firmware for the [Pinetime
- Using **[LittleVGL/LVGL 7](https://lvgl.io/)** as UI library... - Using **[LittleVGL/LVGL 7](https://lvgl.io/)** as UI library...
- ... and **[NimBLE 1.3.0](https://github.com/apache/mynewt-nimble)** as BLE stack. - ... and **[NimBLE 1.3.0](https://github.com/apache/mynewt-nimble)** as BLE stack.
## New to InfiniTime?
- [Getting started with InfiniTime 1.0 (quick user guide, update bootloader and InfiniTime,...)](doc/gettingStarted/gettingStarted-1.0.md)
- [Flash, upgrade (OTA), time synchronization,...](doc/gettingStarted/ota-gadgetbridge-nrfconnect.md)
## Overview ## Overview
![Pinetime screens](images/1.0.0/collage.png "PinetimeScreens") ![Pinetime screens](images/1.0.0/collage.png "PinetimeScreens")
@ -65,12 +70,16 @@ As of now, here is the list of achievements of this project:
* [Amazfish](https://openrepos.net/content/piggz/amazfish) (on SailfishOS and Linux) * [Amazfish](https://openrepos.net/content/piggz/amazfish) (on SailfishOS and Linux)
* [Siglo](https://github.com/alexr4535/siglo) (on Linux) * [Siglo](https://github.com/alexr4535/siglo) (on Linux)
* **[Experimental]** [WebBLEWatch](https://hubmartin.github.io/WebBLEWatch/) Synchronize time directly from your web browser. [video](https://youtu.be/IakiuhVDdrY) * **[Experimental]** [WebBLEWatch](https://hubmartin.github.io/WebBLEWatch/) Synchronize time directly from your web browser. [video](https://youtu.be/IakiuhVDdrY)
* **[Experimental]** [Infini-iOS](https://github.com/xan-m/Infini-iOS) (on iOS)
- OTA (Over-the-air) update via BLE - OTA (Over-the-air) update via BLE
- [Bootloader](https://github.com/JF002/pinetime-mcuboot-bootloader) based on [MCUBoot](https://juullabs-oss.github.io/mcuboot/) - [Bootloader](https://github.com/JF002/pinetime-mcuboot-bootloader) based on [MCUBoot](https://juullabs-oss.github.io/mcuboot/)
## Documentation ## Documentation
### Getting started
- [Getting started with InfiniTime 1.0 (quick user guide, update bootloader and InfiniTime,...)](doc/gettingStarted/gettingStarted-1.0.md)
- [Flash, upgrade (OTA), time synchronization,...](doc/gettingStarted/ota-gadgetbridge-nrfconnect.md)
### Develop ### Develop
- [Generate the fonts and symbols](src/displayapp/fonts/README.md) - [Generate the fonts and symbols](src/displayapp/fonts/README.md)

View file

@ -98,7 +98,7 @@ The script makes use of the following tools:
After setup you can use cmake as usual: After setup you can use cmake as usual:
1. Generate the actual build files (out-of-source builds are strongly recommended): 1. Generate the actual build files (out-of-source builds are strongly recomended):
```commandline ```commandline
cmake -H. -B"cmake-build" -G "Unix Makefiles" cmake -H. -B"cmake-build" -G "Unix Makefiles"

View file

@ -28,7 +28,6 @@ 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_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` **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` **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`
####(**) Note about **CMAKE_BUILD_TYPE**: ####(**) 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/JF002/InfiniTime/releases) new versions of InfiniTime. 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/JF002/InfiniTime/releases) new versions of InfiniTime.

View file

@ -47,8 +47,6 @@ Read carefully the warning and tap **Install**:
Wait for the transfer to finish. Your PineTime should reset and reboot with the new version of InfiniTime! Wait for the transfer to finish. Your PineTime should reset and reboot with the new version of InfiniTime!
Don't forget to **validate** your firmware. In the InfiniTime go to the settings (swipe right, select gear icon) and Firmware option and click **validate**. Otherwise after reboot the previous firmware will be used.
![Gadgetbridge 5](gadgetbridge5.jpg) ![Gadgetbridge 5](gadgetbridge5.jpg)
### Using NRFConnect ### Using NRFConnect
@ -66,8 +64,6 @@ Select **Distribution packet (ZIP)**:
Browse to the DFU file you downloaded previously, the DFU transfer will start automatically. When the transfer is finished, your PineTime will reset and restart on the new version of InfiniTime! Browse to the DFU file you downloaded previously, the DFU transfer will start automatically. When the transfer is finished, your PineTime will reset and restart on the new version of InfiniTime!
Don't forget to **validate** your firmware. In the InfiniTime go to the settings (swipe right, select gear icon) and Firmware option and click **validate**. Otherwise after reboot the previous firmware will be used.
![NRFConnect 3](nrfconnect3.jpg) ![NRFConnect 3](nrfconnect3.jpg)
## How to flash InfiniTime using the SWD interface ## How to flash InfiniTime using the SWD interface
@ -92,10 +88,6 @@ If you are using OpenOCD with a STLinkV2, you can find more info [on this page](
### Using Gadgetbridge ### Using Gadgetbridge
Good news! Gadgetbridge **automatically** synchronizes the time when connecting to your PineTime! Good news! Gadgetbridge **automatically** synchronizes the time when connecting to your PineTime!
### Using any Chromium-based web browser
You can use it from your PC, Mac, Android. Browsers now have BLE support.
https://hubmartin.github.io/WebBLEWatch/
### Using NRFConnect ### Using NRFConnect
You must enable the **CTS** *GATT server* into NRFConnect so that InfiniTime can synchronize the time with your smartphone. You must enable the **CTS** *GATT server* into NRFConnect so that InfiniTime can synchronize the time with your smartphone.

View file

@ -3,4 +3,4 @@ The versioning of this project is based on [Semantic versionning](https://semver
- The **patch** is incremented when we fix a bug on a **released** version (most of the time using a **hotfix** branch). - The **patch** is incremented when we fix a bug on a **released** version (most of the time using a **hotfix** branch).
- The **minor** is incremented when we release a new version with new features. It corresponds to a merge of **develop** into **master**. - The **minor** is incremented when we release a new version with new features. It corresponds to a merge of **develop** into **master**.
- The **major** should be incremented when a breaking change is made to the application. We still have to define what is a breaking change in the context of this project. For now, I suggest that it stays **0** until we have a fully functioning firmware suited for the final user. - The **major** should be incremented when a breaking change is made to the application. We still have to define what is a breaking change in the context of this project. For now, I suggest that it stays **0** until we have a fully functionning firmware suited for the final user.

View file

@ -92,9 +92,6 @@ set(SDK_SOURCE_FILES
set(TINYCRYPT_SRC set(TINYCRYPT_SRC
libs/mynewt-nimble/ext/tinycrypt/src/aes_encrypt.c libs/mynewt-nimble/ext/tinycrypt/src/aes_encrypt.c
libs/mynewt-nimble/ext/tinycrypt/src/utils.c libs/mynewt-nimble/ext/tinycrypt/src/utils.c
libs/mynewt-nimble/ext/tinycrypt/src/cmac_mode.c
libs/mynewt-nimble/ext/tinycrypt/src/ecc.c
libs/mynewt-nimble/ext/tinycrypt/src/ecc_dh.c
) )
set(NIMBLE_SRC set(NIMBLE_SRC
@ -107,10 +104,6 @@ set(NIMBLE_SRC
libs/mynewt-nimble/nimble/host/src/ble_l2cap.c libs/mynewt-nimble/nimble/host/src/ble_l2cap.c
libs/mynewt-nimble/nimble/host/src/ble_hs_mbuf.c libs/mynewt-nimble/nimble/host/src/ble_hs_mbuf.c
libs/mynewt-nimble/nimble/host/src/ble_sm.c libs/mynewt-nimble/nimble/host/src/ble_sm.c
libs/mynewt-nimble/nimble/host/src/ble_sm_cmd.c
libs/mynewt-nimble/nimble/host/src/ble_sm_lgcy.c
libs/mynewt-nimble/nimble/host/src/ble_sm_alg.c
libs/mynewt-nimble/nimble/host/src/ble_sm_sc.c
libs/mynewt-nimble/nimble/host/src/ble_gap.c libs/mynewt-nimble/nimble/host/src/ble_gap.c
libs/mynewt-nimble/nimble/host/src/ble_gatts.c libs/mynewt-nimble/nimble/host/src/ble_gatts.c
libs/mynewt-nimble/nimble/host/src/ble_gattc.c libs/mynewt-nimble/nimble/host/src/ble_gattc.c
@ -134,6 +127,10 @@ set(NIMBLE_SRC
libs/mynewt-nimble/nimble/host/src/ble_hs_atomic.c libs/mynewt-nimble/nimble/host/src/ble_hs_atomic.c
libs/mynewt-nimble/nimble/host/src/ble_hs_adv.c libs/mynewt-nimble/nimble/host/src/ble_hs_adv.c
libs/mynewt-nimble/nimble/host/src/ble_hs_flow.c libs/mynewt-nimble/nimble/host/src/ble_hs_flow.c
libs/mynewt-nimble/nimble/host/src/ble_sm.c
libs/mynewt-nimble/nimble/host/src/ble_sm_cmd.c
libs/mynewt-nimble/nimble/host/src/ble_sm_lgcy.c
libs/mynewt-nimble/nimble/host/src/ble_sm_alg.c
libs/mynewt-nimble/nimble/host/src/ble_hs_mqueue.c libs/mynewt-nimble/nimble/host/src/ble_hs_mqueue.c
libs/mynewt-nimble/nimble/host/src/ble_hs_stop.c libs/mynewt-nimble/nimble/host/src/ble_hs_stop.c
libs/mynewt-nimble/nimble/host/src/ble_hs_startup.c libs/mynewt-nimble/nimble/host/src/ble_hs_startup.c
@ -628,7 +625,6 @@ set(INCLUDE_FILES
drivers/DebugPins.h drivers/DebugPins.h
drivers/InternalFlash.h drivers/InternalFlash.h
drivers/Hrs3300.h drivers/Hrs3300.h
drivers/PinMap.h
drivers/Bma421.h drivers/Bma421.h
drivers/Bma421_C/bma4.c drivers/Bma421_C/bma4.c
drivers/Bma421_C/bma423.c drivers/Bma421_C/bma423.c

View file

@ -1,5 +1,4 @@
#include "BatteryController.h" #include "BatteryController.h"
#include "drivers/PinMap.h"
#include <hal/nrf_gpio.h> #include <hal/nrf_gpio.h>
#include <nrfx_saadc.h> #include <nrfx_saadc.h>
#include <algorithm> #include <algorithm>
@ -10,12 +9,15 @@ Battery* Battery::instance = nullptr;
Battery::Battery() { Battery::Battery() {
instance = this; instance = this;
nrf_gpio_cfg_input(PinMap::Charging, static_cast<nrf_gpio_pin_pull_t> GPIO_PIN_CNF_PULL_Disabled); }
void Battery::Init() {
nrf_gpio_cfg_input(chargingPin, static_cast<nrf_gpio_pin_pull_t> GPIO_PIN_CNF_PULL_Pullup);
} }
void Battery::Update() { void Battery::Update() {
isCharging = !nrf_gpio_pin_read(PinMap::Charging); isCharging = !nrf_gpio_pin_read(chargingPin);
isPowerPresent = !nrf_gpio_pin_read(PinMap::PowerPresent); isPowerPresent = !nrf_gpio_pin_read(powerPresentPin);
if (isReading) { if (isReading) {
return; return;
@ -73,11 +75,5 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
nrfx_saadc_uninit(); nrfx_saadc_uninit();
isReading = false; isReading = false;
systemTask->PushMessage(System::Messages::BatteryMeasurementDone);
} }
} }
void Battery::Register(Pinetime::System::SystemTask* systemTask) {
this->systemTask = systemTask;
}

View file

@ -1,7 +1,8 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <drivers/include/nrfx_saadc.h> #include <drivers/include/nrfx_saadc.h>
#include <systemtask/SystemTask.h> #include <array>
#include <numeric>
namespace Pinetime { namespace Pinetime {
namespace Controllers { namespace Controllers {
@ -10,8 +11,8 @@ namespace Pinetime {
public: public:
Battery(); Battery();
void Init();
void Update(); void Update();
void Register(System::SystemTask* systemTask);
uint8_t PercentRemaining() const { uint8_t PercentRemaining() const {
return percentRemaining; return percentRemaining;
@ -33,6 +34,8 @@ namespace Pinetime {
static Battery* instance; static Battery* instance;
nrf_saadc_value_t saadc_value; nrf_saadc_value_t saadc_value;
static constexpr uint32_t chargingPin = 12;
static constexpr uint32_t powerPresentPin = 19;
static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7; static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7;
uint16_t voltage = 0; uint16_t voltage = 0;
uint8_t percentRemaining = 0; uint8_t percentRemaining = 0;
@ -46,8 +49,6 @@ namespace Pinetime {
static void AdcCallbackStatic(nrfx_saadc_evt_t const* event); static void AdcCallbackStatic(nrfx_saadc_evt_t const* event);
bool isReading = false; bool isReading = false;
Pinetime::System::SystemTask* systemTask = nullptr;
}; };
} }
} }

View file

@ -42,19 +42,6 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
serviceDiscovery({&currentTimeClient, &alertNotificationClient}) { serviceDiscovery({&currentTimeClient, &alertNotificationClient}) {
} }
void nimble_on_reset(int reason) {
NRF_LOG_INFO("Resetting state; reason=%d\n", reason);
}
void nimble_on_sync(void) {
int rc;
rc = ble_hs_util_ensure_addr(0);
ASSERT(rc == 0);
nptr->StartAdvertising();
}
int GAPEventCallback(struct ble_gap_event* event, void* arg) { int GAPEventCallback(struct ble_gap_event* event, void* arg) {
auto nimbleController = static_cast<NimbleController*>(arg); auto nimbleController = static_cast<NimbleController*>(arg);
return nimbleController->OnGAPEvent(event); return nimbleController->OnGAPEvent(event);
@ -64,10 +51,6 @@ void NimbleController::Init() {
while (!ble_hs_synced()) { while (!ble_hs_synced()) {
} }
nptr = this;
ble_hs_cfg.reset_cb = nimble_on_reset;
ble_hs_cfg.sync_cb = nimble_on_sync;
ble_svc_gap_init(); ble_svc_gap_init();
ble_svc_gatt_init(); ble_svc_gatt_init();
@ -81,31 +64,28 @@ void NimbleController::Init() {
batteryInformationService.Init(); batteryInformationService.Init();
immediateAlertService.Init(); immediateAlertService.Init();
heartRateService.Init(); heartRateService.Init();
int res;
int rc; res = ble_hs_util_ensure_addr(0);
rc = ble_hs_util_ensure_addr(0); ASSERT(res == 0);
ASSERT(rc == 0); res = ble_hs_id_infer_auto(0, &addrType);
rc = ble_hs_id_infer_auto(0, &addrType); ASSERT(res == 0);
ASSERT(rc == 0); res = ble_svc_gap_device_name_set(deviceName);
rc = ble_svc_gap_device_name_set(deviceName); ASSERT(res == 0);
ASSERT(rc == 0);
rc = ble_svc_gap_device_appearance_set(0xC2);
ASSERT(rc == 0);
Pinetime::Controllers::Ble::BleAddress address; Pinetime::Controllers::Ble::BleAddress address;
rc = ble_hs_id_copy_addr(addrType, address.data(), nullptr); res = ble_hs_id_copy_addr(addrType, address.data(), nullptr);
ASSERT(rc == 0); ASSERT(res == 0);
bleController.AddressType((addrType == 0) ? Ble::AddressTypes::Public : Ble::AddressTypes::Random); bleController.AddressType((addrType == 0) ? Ble::AddressTypes::Public : Ble::AddressTypes::Random);
bleController.Address(std::move(address)); bleController.Address(std::move(address));
rc = ble_gatts_start(); res = ble_gatts_start();
ASSERT(rc == 0); ASSERT(res == 0);
if (!ble_gap_adv_active() && !bleController.IsConnected())
StartAdvertising();
} }
void NimbleController::StartAdvertising() { void NimbleController::StartAdvertising() {
int rc; if (bleController.IsConnected() || ble_gap_conn_active() || ble_gap_adv_active())
return;
ble_svc_gap_device_name_set(deviceName);
/* set adv parameters */ /* set adv parameters */
struct ble_gap_adv_params adv_params; struct ble_gap_adv_params adv_params;
@ -122,17 +102,11 @@ void NimbleController::StartAdvertising() {
adv_params.conn_mode = BLE_GAP_CONN_MODE_UND; adv_params.conn_mode = BLE_GAP_CONN_MODE_UND;
adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN; adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN;
/* fast advertise for 30 sec */
if (fastAdvCount < 15) {
adv_params.itvl_min = 32;
adv_params.itvl_max = 47;
fastAdvCount++;
} else {
adv_params.itvl_min = 1636;
adv_params.itvl_max = 1651;
}
fields.flags = BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP; fields.flags = BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP;
// fields.uuids128 = BLE_UUID128(BLE_UUID128_DECLARE(
// 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
// 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff));
fields.uuids128 = &dfuServiceUuid; fields.uuids128 = &dfuServiceUuid;
fields.num_uuids128 = 1; fields.num_uuids128 = 1;
fields.uuids128_is_complete = 1; fields.uuids128_is_complete = 1;
@ -142,25 +116,28 @@ void NimbleController::StartAdvertising() {
rsp_fields.name_len = strlen(deviceName); rsp_fields.name_len = strlen(deviceName);
rsp_fields.name_is_complete = 1; rsp_fields.name_is_complete = 1;
rc = ble_gap_adv_set_fields(&fields); ble_gap_adv_set_fields(&fields);
ASSERT(rc == 0); // ASSERT(res == 0); // TODO this one sometimes fails with error 22 (notsync)
rc = ble_gap_adv_rsp_set_fields(&rsp_fields); ble_gap_adv_rsp_set_fields(&rsp_fields);
ASSERT(rc == 0); // ASSERT(res == 0);
rc = ble_gap_adv_start(addrType, NULL, 2000, &adv_params, GAPEventCallback, this); ble_gap_adv_start(addrType, NULL, 180000, &adv_params, GAPEventCallback, this);
ASSERT(rc == 0); // ASSERT(res == 0);// TODO I've disabled these ASSERT as they sometime asserts and reset the mcu.
// For now, the advertising is restarted as soon as it ends. There may be a race condition
// that prevent the advertising from restarting reliably.
// I remove the assert to prevent this uncesseray crash, but in the long term, the management of
// the advertising should be improve (better error handling, and advertise for 3 minutes after
// the application has been woken up, for example.
} }
int NimbleController::OnGAPEvent(ble_gap_event* event) { int NimbleController::OnGAPEvent(ble_gap_event* event) {
switch (event->type) { switch (event->type) {
case BLE_GAP_EVENT_ADV_COMPLETE: case BLE_GAP_EVENT_ADV_COMPLETE:
NRF_LOG_INFO("Advertising event : BLE_GAP_EVENT_ADV_COMPLETE"); NRF_LOG_INFO("Advertising event : BLE_GAP_EVENT_ADV_COMPLETE");
NRF_LOG_INFO("reason=%d; status=%d", event->adv_complete.reason, event->connect.status); NRF_LOG_INFO("advertise complete; reason=%dn status=%d", event->adv_complete.reason, event->connect.status);
StartAdvertising();
break; break;
case BLE_GAP_EVENT_CONNECT: {
case BLE_GAP_EVENT_CONNECT:
NRF_LOG_INFO("Advertising event : BLE_GAP_EVENT_CONNECT"); NRF_LOG_INFO("Advertising event : BLE_GAP_EVENT_CONNECT");
/* A new connection was established or a connection attempt failed. */ /* A new connection was established or a connection attempt failed. */
@ -168,44 +145,35 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
if (event->connect.status != 0) { if (event->connect.status != 0) {
/* Connection failed; resume advertising. */ /* Connection failed; resume advertising. */
currentTimeClient.Reset();
alertNotificationClient.Reset();
connectionHandle = BLE_HS_CONN_HANDLE_NONE;
bleController.Disconnect();
fastAdvCount = 0;
StartAdvertising(); StartAdvertising();
bleController.Disconnect();
} else { } else {
connectionHandle = event->connect.conn_handle;
bleController.Connect(); bleController.Connect();
systemTask.PushMessage(Pinetime::System::Messages::BleConnected); systemTask.PushMessage(Pinetime::System::Messages::BleConnected);
// Service discovery is deferred via systemtask connectionHandle = event->connect.conn_handle;
// Service discovery is deffered via systemtask
} }
break; } break;
case BLE_GAP_EVENT_DISCONNECT: case BLE_GAP_EVENT_DISCONNECT:
NRF_LOG_INFO("Advertising event : BLE_GAP_EVENT_DISCONNECT"); NRF_LOG_INFO("Advertising event : BLE_GAP_EVENT_DISCONNECT");
NRF_LOG_INFO("disconnect reason=%d", event->disconnect.reason); NRF_LOG_INFO("disconnect; reason=%d", event->disconnect.reason);
/* Connection terminated; resume advertising. */ /* Connection terminated; resume advertising. */
currentTimeClient.Reset(); currentTimeClient.Reset();
alertNotificationClient.Reset(); alertNotificationClient.Reset();
connectionHandle = BLE_HS_CONN_HANDLE_NONE; connectionHandle = BLE_HS_CONN_HANDLE_NONE;
bleController.Disconnect(); bleController.Disconnect();
fastAdvCount = 0;
StartAdvertising(); StartAdvertising();
break; break;
case BLE_GAP_EVENT_CONN_UPDATE: case BLE_GAP_EVENT_CONN_UPDATE:
NRF_LOG_INFO("Advertising event : BLE_GAP_EVENT_CONN_UPDATE"); NRF_LOG_INFO("Advertising event : BLE_GAP_EVENT_CONN_UPDATE");
/* The central has updated the connection parameters. */ /* The central has updated the connection parameters. */
NRF_LOG_INFO("update status=%d ", event->conn_update.status); NRF_LOG_INFO("connection updated; status=%d ", event->conn_update.status);
break; break;
case BLE_GAP_EVENT_ENC_CHANGE: case BLE_GAP_EVENT_ENC_CHANGE:
/* Encryption has been enabled or disabled for this connection. */ /* Encryption has been enabled or disabled for this connection. */
NRF_LOG_INFO("encryption change event; status=%d ", event->enc_change.status); NRF_LOG_INFO("encryption change event; status=%d ", event->enc_change.status);
break; return 0;
case BLE_GAP_EVENT_SUBSCRIBE: case BLE_GAP_EVENT_SUBSCRIBE:
NRF_LOG_INFO("subscribe event; conn_handle=%d attr_handle=%d " NRF_LOG_INFO("subscribe event; conn_handle=%d attr_handle=%d "
"reason=%d prevn=%d curn=%d previ=%d curi=???\n", "reason=%d prevn=%d curn=%d previ=%d curi=???\n",
@ -215,12 +183,10 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
event->subscribe.prev_notify, event->subscribe.prev_notify,
event->subscribe.cur_notify, event->subscribe.cur_notify,
event->subscribe.prev_indicate); event->subscribe.prev_indicate);
break; return 0;
case BLE_GAP_EVENT_MTU: case BLE_GAP_EVENT_MTU:
NRF_LOG_INFO("mtu update event; conn_handle=%d cid=%d mtu=%d\n", NRF_LOG_INFO("mtu update event; conn_handle=%d cid=%d mtu=%d\n", event->mtu.conn_handle, event->mtu.channel_id, event->mtu.value);
event->mtu.conn_handle, event->mtu.channel_id, event->mtu.value); return 0;
break;
case BLE_GAP_EVENT_REPEAT_PAIRING: { case BLE_GAP_EVENT_REPEAT_PAIRING: {
/* We already have a bond with the peer, but it is attempting to /* We already have a bond with the peer, but it is attempting to
@ -251,7 +217,8 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
notifSize); notifSize);
alertNotificationClient.OnNotification(event); alertNotificationClient.OnNotification(event);
} break; return 0;
}
/* Attribute data is contained in event->notify_rx.attr_data. */ /* Attribute data is contained in event->notify_rx.attr_data. */
default: default:
@ -262,9 +229,7 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
} }
void NimbleController::StartDiscovery() { void NimbleController::StartDiscovery() {
if (connectionHandle != BLE_HS_CONN_HANDLE_NONE) { serviceDiscovery.StartDiscovery(connectionHandle);
serviceDiscovery.StartDiscovery(connectionHandle);
}
} }
uint16_t NimbleController::connHandle() { uint16_t NimbleController::connHandle() {
@ -272,7 +237,7 @@ uint16_t NimbleController::connHandle() {
} }
void NimbleController::NotifyBatteryLevel(uint8_t level) { void NimbleController::NotifyBatteryLevel(uint8_t level) {
if (connectionHandle != BLE_HS_CONN_HANDLE_NONE) { if(connectionHandle != BLE_HS_CONN_HANDLE_NONE) {
batteryInformationService.NotifyBatteryLevel(connectionHandle, level); batteryInformationService.NotifyBatteryLevel(connectionHandle, level);
} }
} }

View file

@ -72,10 +72,6 @@ namespace Pinetime {
uint16_t connHandle(); uint16_t connHandle();
void NotifyBatteryLevel(uint8_t level); void NotifyBatteryLevel(uint8_t level);
void RestartFastAdv() {
fastAdvCount = 0;
}
private: private:
static constexpr const char* deviceName = "InfiniTime"; static constexpr const char* deviceName = "InfiniTime";
Pinetime::System::SystemTask& systemTask; Pinetime::System::SystemTask& systemTask;
@ -98,7 +94,6 @@ namespace Pinetime {
uint8_t addrType; // 1 = Random, 0 = PUBLIC uint8_t addrType; // 1 = Random, 0 = PUBLIC
uint16_t connectionHandle = BLE_HS_CONN_HANDLE_NONE; uint16_t connectionHandle = BLE_HS_CONN_HANDLE_NONE;
uint8_t fastAdvCount = 0;
ble_uuid128_t dfuServiceUuid { ble_uuid128_t dfuServiceUuid {
.u {.type = BLE_UUID_TYPE_128}, .u {.type = BLE_UUID_TYPE_128},
@ -106,7 +101,5 @@ namespace Pinetime {
ServiceDiscovery serviceDiscovery; ServiceDiscovery serviceDiscovery;
}; };
static NimbleController* nptr;
} }
} }

View file

@ -1,13 +1,13 @@
#include "BrightnessController.h" #include "BrightnessController.h"
#include <hal/nrf_gpio.h> #include <hal/nrf_gpio.h>
#include "displayapp/screens/Symbols.h" #include "displayapp/screens/Symbols.h"
#include "drivers/PinMap.h"
using namespace Pinetime::Controllers; using namespace Pinetime::Controllers;
void BrightnessController::Init() { void BrightnessController::Init() {
nrf_gpio_cfg_output(PinMap::LcdBacklightLow); nrf_gpio_cfg_output(pinLcdBacklight1);
nrf_gpio_cfg_output(PinMap::LcdBacklightMedium); nrf_gpio_cfg_output(pinLcdBacklight2);
nrf_gpio_cfg_output(PinMap::LcdBacklightHigh); nrf_gpio_cfg_output(pinLcdBacklight3);
Set(level); Set(level);
} }
@ -16,24 +16,24 @@ void BrightnessController::Set(BrightnessController::Levels level) {
switch (level) { switch (level) {
default: default:
case Levels::High: case Levels::High:
nrf_gpio_pin_clear(PinMap::LcdBacklightLow); nrf_gpio_pin_clear(pinLcdBacklight1);
nrf_gpio_pin_clear(PinMap::LcdBacklightMedium); nrf_gpio_pin_clear(pinLcdBacklight2);
nrf_gpio_pin_clear(PinMap::LcdBacklightHigh); nrf_gpio_pin_clear(pinLcdBacklight3);
break; break;
case Levels::Medium: case Levels::Medium:
nrf_gpio_pin_clear(PinMap::LcdBacklightLow); nrf_gpio_pin_clear(pinLcdBacklight1);
nrf_gpio_pin_clear(PinMap::LcdBacklightMedium); nrf_gpio_pin_clear(pinLcdBacklight2);
nrf_gpio_pin_set(PinMap::LcdBacklightHigh); nrf_gpio_pin_set(pinLcdBacklight3);
break; break;
case Levels::Low: case Levels::Low:
nrf_gpio_pin_clear(PinMap::LcdBacklightLow); nrf_gpio_pin_clear(pinLcdBacklight1);
nrf_gpio_pin_set(PinMap::LcdBacklightMedium); nrf_gpio_pin_set(pinLcdBacklight2);
nrf_gpio_pin_set(PinMap::LcdBacklightHigh); nrf_gpio_pin_set(pinLcdBacklight3);
break; break;
case Levels::Off: case Levels::Off:
nrf_gpio_pin_set(PinMap::LcdBacklightLow); nrf_gpio_pin_set(pinLcdBacklight1);
nrf_gpio_pin_set(PinMap::LcdBacklightMedium); nrf_gpio_pin_set(pinLcdBacklight2);
nrf_gpio_pin_set(PinMap::LcdBacklightHigh); nrf_gpio_pin_set(pinLcdBacklight3);
break; break;
} }
} }

View file

@ -22,6 +22,9 @@ namespace Pinetime {
const char* ToString(); const char* ToString();
private: private:
static constexpr uint8_t pinLcdBacklight1 = 14;
static constexpr uint8_t pinLcdBacklight2 = 22;
static constexpr uint8_t pinLcdBacklight3 = 23;
Levels level = Levels::High; Levels level = Levels::High;
Levels backupLevel = Levels::High; Levels backupLevel = Levels::High;
}; };

View file

@ -2,7 +2,6 @@
#include <hal/nrf_gpio.h> #include <hal/nrf_gpio.h>
#include "systemtask/SystemTask.h" #include "systemtask/SystemTask.h"
#include "app_timer.h" #include "app_timer.h"
#include "drivers/PinMap.h"
APP_TIMER_DEF(shortVibTimer); APP_TIMER_DEF(shortVibTimer);
APP_TIMER_DEF(longVibTimer); APP_TIMER_DEF(longVibTimer);
@ -13,8 +12,8 @@ MotorController::MotorController(Controllers::Settings& settingsController) : se
} }
void MotorController::Init() { void MotorController::Init() {
nrf_gpio_cfg_output(PinMap::Motor); nrf_gpio_cfg_output(pinMotor);
nrf_gpio_pin_set(PinMap::Motor); nrf_gpio_pin_set(pinMotor);
app_timer_init(); app_timer_init();
app_timer_create(&shortVibTimer, APP_TIMER_MODE_SINGLE_SHOT, StopMotor); app_timer_create(&shortVibTimer, APP_TIMER_MODE_SINGLE_SHOT, StopMotor);
@ -31,7 +30,7 @@ void MotorController::RunForDuration(uint8_t motorDuration) {
return; return;
} }
nrf_gpio_pin_clear(PinMap::Motor); nrf_gpio_pin_clear(pinMotor);
app_timer_start(shortVibTimer, APP_TIMER_TICKS(motorDuration), nullptr); app_timer_start(shortVibTimer, APP_TIMER_TICKS(motorDuration), nullptr);
} }
@ -45,9 +44,9 @@ void MotorController::StartRinging() {
void MotorController::StopRinging() { void MotorController::StopRinging() {
app_timer_stop(longVibTimer); app_timer_stop(longVibTimer);
nrf_gpio_pin_set(PinMap::Motor); nrf_gpio_pin_set(pinMotor);
} }
void MotorController::StopMotor(void* p_context) { void MotorController::StopMotor(void* p_context) {
nrf_gpio_pin_set(PinMap::Motor); nrf_gpio_pin_set(pinMotor);
} }

View file

@ -1,10 +1,12 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include "app_timer.h"
#include "components/settings/Settings.h" #include "components/settings/Settings.h"
namespace Pinetime { namespace Pinetime {
namespace Controllers { namespace Controllers {
static constexpr uint8_t pinMotor = 16;
class MotorController { class MotorController {
public: public:

View file

@ -114,7 +114,7 @@ namespace Pinetime {
}; };
void setWakeUpMode(WakeUpMode wakeUp, bool enabled) { void setWakeUpMode(WakeUpMode wakeUp, bool enabled) {
if (enabled != isWakeUpModeOn(wakeUp)) { if (!isWakeUpModeOn(wakeUp)) {
settingsChanged = true; settingsChanged = true;
} }
settings.wakeUpMode.set(static_cast<size_t>(wakeUp), enabled); settings.wakeUpMode.set(static_cast<size_t>(wakeUp), enabled);

View file

@ -139,6 +139,9 @@ void DisplayApp::InitHw() {
brightnessController.Set(settingsController.GetBrightness()); brightnessController.Set(settingsController.GetBrightness());
} }
uint32_t acc = 0;
uint32_t count = 0;
bool toggle = true;
void DisplayApp::Refresh() { void DisplayApp::Refresh() {
TickType_t queueTimeout; TickType_t queueTimeout;
TickType_t delta; TickType_t delta;
@ -194,6 +197,9 @@ void DisplayApp::Refresh() {
// clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected : // clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected :
// Screens::Clock::BleConnectionStates::NotConnected); // Screens::Clock::BleConnectionStates::NotConnected);
break; break;
case Messages::UpdateBatteryLevel:
batteryController.Update();
break;
case Messages::NewNotification: case Messages::NewNotification:
LoadApp(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down); LoadApp(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down);
break; break;

View file

@ -5,7 +5,6 @@
#include <components/rle/RleDecoder.h> #include <components/rle/RleDecoder.h>
#include <touchhandler/TouchHandler.h> #include <touchhandler/TouchHandler.h>
#include "displayapp/icons/infinitime/infinitime-nb.c" #include "displayapp/icons/infinitime/infinitime-nb.c"
#include "components/ble/BleController.h"
using namespace Pinetime::Applications; using namespace Pinetime::Applications;

View file

@ -6,38 +6,32 @@
#include <bits/unique_ptr.h> #include <bits/unique_ptr.h>
#include <queue.h> #include <queue.h>
#include "components/gfx/Gfx.h" #include "components/gfx/Gfx.h"
#include "components/battery/BatteryController.h"
#include "components/brightness/BrightnessController.h"
#include "components/ble/BleController.h"
#include "components/datetime/DateTimeController.h"
#include "components/ble/NotificationManager.h"
#include "components/firmwarevalidator/FirmwareValidator.h"
#include "drivers/Cst816s.h" #include "drivers/Cst816s.h"
#include <date/date.h> #include <date/date.h>
#include <drivers/Watchdog.h> #include <drivers/Watchdog.h>
#include <components/heartrate/HeartRateController.h>
#include <components/motion/MotionController.h>
#include <components/motor/MotorController.h> #include <components/motor/MotorController.h>
#include <components/settings/Settings.h>
#include "TouchEvents.h" #include "TouchEvents.h"
#include "Apps.h" #include "Apps.h"
#include "Messages.h" #include "Messages.h"
#include "DummyLittleVgl.h" #include "DummyLittleVgl.h"
#include "components/timer/TimerController.h"
namespace Pinetime { namespace Pinetime {
namespace Drivers {
class St7789;
class Cst816S;
class WatchdogView;
}
namespace Controllers {
class Settings;
class Battery;
class Ble;
class DateTime;
class NotificationManager;
class HeartRateController;
class MotionController;
class TouchHandler;
class MotorController;
class TimerController;
}
namespace System { namespace System {
class SystemTask; class SystemTask;
}; };
namespace Controllers {
class TouchHandler;
}
namespace Applications { namespace Applications {
class DisplayApp { class DisplayApp {
public: public:

View file

@ -7,6 +7,7 @@ namespace Pinetime {
GoToRunning, GoToRunning,
UpdateDateTime, UpdateDateTime,
UpdateBleConnection, UpdateBleConnection,
UpdateBatteryLevel,
TouchEvent, TouchEvent,
ButtonPushed, ButtonPushed,
NewNotification, NewNotification,

View file

@ -55,6 +55,8 @@ BatteryInfo::~BatteryInfo() {
void BatteryInfo::Refresh() { void BatteryInfo::Refresh() {
batteryController.Update();
batteryPercent = batteryController.PercentRemaining(); batteryPercent = batteryController.PercentRemaining();
batteryVoltage = batteryController.Voltage(); batteryVoltage = batteryController.Voltage();

View file

@ -152,7 +152,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
uint8_t notifNb, uint8_t notifNb,
Modes mode, Modes mode,
Pinetime::Controllers::AlertNotificationService& alertNotificationService) Pinetime::Controllers::AlertNotificationService& alertNotificationService)
: mode {mode}, alertNotificationService {alertNotificationService} { : notifNr {notifNr}, notifNb {notifNb}, mode {mode}, alertNotificationService {alertNotificationService} {
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), NULL); lv_obj_t* container1 = lv_cont_create(lv_scr_act(), NULL);
lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x222222)); lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x222222));

View file

@ -43,13 +43,21 @@ namespace Pinetime {
void OnCallButtonEvent(lv_obj_t*, lv_event_t event); void OnCallButtonEvent(lv_obj_t*, lv_event_t event);
private: private:
uint8_t notifNr = 0;
uint8_t notifNb = 0;
char pageText[4];
lv_obj_t* container1; lv_obj_t* container1;
lv_obj_t* t1;
lv_obj_t* l1;
lv_obj_t* l2;
lv_obj_t* bt_accept; lv_obj_t* bt_accept;
lv_obj_t* bt_mute; lv_obj_t* bt_mute;
lv_obj_t* bt_reject; lv_obj_t* bt_reject;
lv_obj_t* label_accept; lv_obj_t* label_accept;
lv_obj_t* label_mute; lv_obj_t* label_mute;
lv_obj_t* label_reject; lv_obj_t* label_reject;
lv_obj_t* bottomPlaceholder;
Modes mode; Modes mode;
Pinetime::Controllers::AlertNotificationService& alertNotificationService; Pinetime::Controllers::AlertNotificationService& alertNotificationService;
bool running = true; bool running = true;

View file

@ -50,8 +50,8 @@ std::unique_ptr<Screen> Settings::CreateScreen2() {
std::array<Screens::List::Applications, 4> applications {{ std::array<Screens::List::Applications, 4> applications {{
{Symbols::shoe, "Steps", Apps::SettingSteps}, {Symbols::shoe, "Steps", Apps::SettingSteps},
{Symbols::batteryHalf, "Battery", Apps::BatteryInfo}, {Symbols::batteryHalf, "Battery", Apps::BatteryInfo},
{Symbols::paintbrush, "PTS Colors", Apps::SettingPineTimeStyle},
{Symbols::check, "Firmware", Apps::FirmwareValidation}, {Symbols::check, "Firmware", Apps::FirmwareValidation},
{Symbols::list, "About", Apps::SysInfo},
}}; }};
return std::make_unique<Screens::List>(1, 3, app, settingsController, applications); return std::make_unique<Screens::List>(1, 3, app, settingsController, applications);
@ -60,7 +60,7 @@ std::unique_ptr<Screen> Settings::CreateScreen2() {
std::unique_ptr<Screen> Settings::CreateScreen3() { std::unique_ptr<Screen> Settings::CreateScreen3() {
std::array<Screens::List::Applications, 4> applications {{ std::array<Screens::List::Applications, 4> applications {{
{Symbols::list, "About", Apps::SysInfo}, {Symbols::paintbrush, "PTS Colors", Apps::SettingPineTimeStyle},
{Symbols::none, "None", Apps::None}, {Symbols::none, "None", Apps::None},
{Symbols::none, "None", Apps::None}, {Symbols::none, "None", Apps::None},
{Symbols::none, "None", Apps::None}, {Symbols::none, "None", Apps::None},

View file

@ -3,7 +3,6 @@
#include <legacy/nrf_drv_gpiote.h> #include <legacy/nrf_drv_gpiote.h>
#include <nrfx_log.h> #include <nrfx_log.h>
#include <task.h> #include <task.h>
#include "drivers/PinMap.h"
using namespace Pinetime::Drivers; using namespace Pinetime::Drivers;
@ -19,12 +18,12 @@ Cst816S::Cst816S(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaste
} }
void Cst816S::Init() { void Cst816S::Init() {
nrf_gpio_cfg_output(PinMap::Cst816sReset); nrf_gpio_cfg_output(pinReset);
nrf_gpio_pin_set(PinMap::Cst816sReset); nrf_gpio_pin_set(pinReset);
vTaskDelay(50); vTaskDelay(50);
nrf_gpio_pin_clear(PinMap::Cst816sReset); nrf_gpio_pin_clear(pinReset);
vTaskDelay(5); vTaskDelay(5);
nrf_gpio_pin_set(PinMap::Cst816sReset); nrf_gpio_pin_set(pinReset);
vTaskDelay(50); vTaskDelay(50);
// Wake the touchpanel up // Wake the touchpanel up
@ -81,9 +80,9 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() {
} }
void Cst816S::Sleep() { void Cst816S::Sleep() {
nrf_gpio_pin_clear(PinMap::Cst816sReset); nrf_gpio_pin_clear(pinReset);
vTaskDelay(5); vTaskDelay(5);
nrf_gpio_pin_set(PinMap::Cst816sReset); nrf_gpio_pin_set(pinReset);
vTaskDelay(50); vTaskDelay(50);
static constexpr uint8_t sleepValue = 0x03; static constexpr uint8_t sleepValue = 0x03;
twiMaster.Write(twiAddress, 0xA5, &sleepValue, 1); twiMaster.Write(twiAddress, 0xA5, &sleepValue, 1);

View file

@ -36,6 +36,9 @@ namespace Pinetime {
void Wakeup(); void Wakeup();
private: private:
static constexpr uint8_t pinIrq = 28;
static constexpr uint8_t pinReset = 10;
// Unused/Unavailable commented out // Unused/Unavailable commented out
static constexpr uint8_t gestureIndex = 1; static constexpr uint8_t gestureIndex = 1;
static constexpr uint8_t touchPointNumIndex = 2; static constexpr uint8_t touchPointNumIndex = 2;

View file

@ -1,38 +0,0 @@
#pragma once
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
static constexpr uint8_t Cst816sIrq = 28;
static constexpr uint8_t PowerPresent = 19;
static constexpr uint8_t Motor = 16;
static constexpr uint8_t LcdBacklightLow = 14;
static constexpr uint8_t LcdBacklightMedium = 22;
static constexpr uint8_t LcdBacklightHigh = 23;
static constexpr uint8_t SpiSck = 2;
static constexpr uint8_t SpiMosi = 3;
static constexpr uint8_t SpiMiso = 4;
static constexpr uint8_t SpiFlashCsn = 5;
static constexpr uint8_t SpiLcdCsn = 25;
static constexpr uint8_t LcdDataCommand = 18;
static constexpr uint8_t TwiScl = 7;
static constexpr uint8_t TwiSda = 6;
}
}

View file

@ -43,9 +43,7 @@
#include "drivers/St7789.h" #include "drivers/St7789.h"
#include "drivers/TwiMaster.h" #include "drivers/TwiMaster.h"
#include "drivers/Cst816s.h" #include "drivers/Cst816s.h"
#include "drivers/PinMap.h"
#include "systemtask/SystemTask.h" #include "systemtask/SystemTask.h"
#include "drivers/PinMap.h"
#include "touchhandler/TouchHandler.h" #include "touchhandler/TouchHandler.h"
#if NRF_LOG_ENABLED #if NRF_LOG_ENABLED
@ -56,6 +54,14 @@ Pinetime::Logging::NrfLogger logger;
Pinetime::Logging::DummyLogger logger; Pinetime::Logging::DummyLogger logger;
#endif #endif
static constexpr uint8_t pinSpiSck = 2;
static constexpr uint8_t pinSpiMosi = 3;
static constexpr uint8_t pinSpiMiso = 4;
static constexpr uint8_t pinSpiFlashCsn = 5;
static constexpr uint8_t pinLcdCsn = 25;
static constexpr uint8_t pinLcdDataCommand = 18;
static constexpr uint8_t pinTwiScl = 7;
static constexpr uint8_t pinTwiSda = 6;
static constexpr uint8_t touchPanelTwiAddress = 0x15; static constexpr uint8_t touchPanelTwiAddress = 0x15;
static constexpr uint8_t motionSensorTwiAddress = 0x18; static constexpr uint8_t motionSensorTwiAddress = 0x18;
static constexpr uint8_t heartRateSensorTwiAddress = 0x44; static constexpr uint8_t heartRateSensorTwiAddress = 0x44;
@ -64,30 +70,33 @@ Pinetime::Drivers::SpiMaster spi {Pinetime::Drivers::SpiMaster::SpiModule::SPI0,
{Pinetime::Drivers::SpiMaster::BitOrder::Msb_Lsb, {Pinetime::Drivers::SpiMaster::BitOrder::Msb_Lsb,
Pinetime::Drivers::SpiMaster::Modes::Mode3, Pinetime::Drivers::SpiMaster::Modes::Mode3,
Pinetime::Drivers::SpiMaster::Frequencies::Freq8Mhz, Pinetime::Drivers::SpiMaster::Frequencies::Freq8Mhz,
Pinetime::PinMap::SpiSck, pinSpiSck,
Pinetime::PinMap::SpiMosi, pinSpiMosi,
Pinetime::PinMap::SpiMiso}}; pinSpiMiso}};
Pinetime::Drivers::Spi lcdSpi {spi, Pinetime::PinMap::SpiLcdCsn}; Pinetime::Drivers::Spi lcdSpi {spi, pinLcdCsn};
Pinetime::Drivers::St7789 lcd {lcdSpi, Pinetime::PinMap::LcdDataCommand}; Pinetime::Drivers::St7789 lcd {lcdSpi, pinLcdDataCommand};
Pinetime::Drivers::Spi flashSpi {spi, Pinetime::PinMap::SpiFlashCsn}; Pinetime::Drivers::Spi flashSpi {spi, pinSpiFlashCsn};
Pinetime::Drivers::SpiNorFlash spiNorFlash {flashSpi}; Pinetime::Drivers::SpiNorFlash spiNorFlash {flashSpi};
// The TWI device should work @ up to 400Khz but there is a HW bug which prevent it from // The TWI device should work @ up to 400Khz but there is a HW bug which prevent it from
// respecting correct timings. According to erratas heet, this magic value makes it run // respecting correct timings. According to erratas heet, this magic value makes it run
// at ~390Khz with correct timings. // at ~390Khz with correct timings.
static constexpr uint32_t MaxTwiFrequencyWithoutHardwareBug {0x06200000}; static constexpr uint32_t MaxTwiFrequencyWithoutHardwareBug {0x06200000};
Pinetime::Drivers::TwiMaster twiMaster {NRF_TWIM1, MaxTwiFrequencyWithoutHardwareBug, Pinetime::PinMap::TwiSda, Pinetime::PinMap::TwiScl}; Pinetime::Drivers::TwiMaster twiMaster {NRF_TWIM1, MaxTwiFrequencyWithoutHardwareBug, pinTwiSda, pinTwiScl};
Pinetime::Drivers::Cst816S touchPanel {twiMaster, touchPanelTwiAddress}; Pinetime::Drivers::Cst816S touchPanel {twiMaster, touchPanelTwiAddress};
#ifdef PINETIME_IS_RECOVERY #ifdef PINETIME_IS_RECOVERY
static constexpr bool isFactory = true;
#include "displayapp/DummyLittleVgl.h" #include "displayapp/DummyLittleVgl.h"
#include "displayapp/DisplayAppRecovery.h" #include "displayapp/DisplayAppRecovery.h"
Pinetime::Components::LittleVgl lvgl {lcd, touchPanel};
#else #else
static constexpr bool isFactory = false;
#include "displayapp/LittleVgl.h" #include "displayapp/LittleVgl.h"
#include "displayapp/DisplayApp.h" #include "displayapp/DisplayApp.h"
#endif
Pinetime::Components::LittleVgl lvgl {lcd, touchPanel}; Pinetime::Components::LittleVgl lvgl {lcd, touchPanel};
#endif
Pinetime::Drivers::Bma421 motionSensor {twiMaster, motionSensorTwiAddress}; Pinetime::Drivers::Bma421 motionSensor {twiMaster, motionSensorTwiAddress};
Pinetime::Drivers::Hrs3300 heartRateSensor {twiMaster, heartRateSensorTwiAddress}; Pinetime::Drivers::Hrs3300 heartRateSensor {twiMaster, heartRateSensorTwiAddress};
@ -96,8 +105,10 @@ TimerHandle_t debounceTimer;
TimerHandle_t debounceChargeTimer; TimerHandle_t debounceChargeTimer;
Pinetime::Controllers::Battery batteryController; Pinetime::Controllers::Battery batteryController;
Pinetime::Controllers::Ble bleController; Pinetime::Controllers::Ble bleController;
static constexpr uint8_t pinTouchIrq = Pinetime::PinMap::Cst816sIrq; void ble_manager_set_ble_connection_callback(void (*connection)());
static constexpr uint8_t pinPowerPresentIrq = Pinetime::PinMap::PowerPresent; void ble_manager_set_ble_disconnection_callback(void (*disconnection)());
static constexpr uint8_t pinTouchIrq = 28;
static constexpr uint8_t pinPowerPresentIrq = 19;
Pinetime::Controllers::HeartRateController heartRateController; Pinetime::Controllers::HeartRateController heartRateController;
Pinetime::Applications::HeartRateTask heartRateApp(heartRateSensor, heartRateController); Pinetime::Applications::HeartRateTask heartRateApp(heartRateSensor, heartRateController);
@ -157,14 +168,14 @@ Pinetime::System::SystemTask systemTask(spi,
touchHandler); touchHandler);
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
if (pin == Pinetime::PinMap::Cst816sIrq) { if (pin == pinTouchIrq) {
systemTask.OnTouchEvent(); systemTask.OnTouchEvent();
return; return;
} }
BaseType_t xHigherPriorityTaskWoken = pdFALSE; BaseType_t xHigherPriorityTaskWoken = pdFALSE;
if (pin == Pinetime::PinMap::PowerPresent and action == NRF_GPIOTE_POLARITY_TOGGLE) { if (pin == pinPowerPresentIrq and action == NRF_GPIOTE_POLARITY_TOGGLE) {
xTimerStartFromISR(debounceChargeTimer, &xHigherPriorityTaskWoken); xTimerStartFromISR(debounceChargeTimer, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken); portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
return; return;
@ -297,18 +308,18 @@ int main(void) {
nrf_drv_clock_init(); nrf_drv_clock_init();
// Unblock i2c? // Unblock i2c?
nrf_gpio_cfg(Pinetime::PinMap::TwiScl, nrf_gpio_cfg(pinTwiScl,
NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_DIR_OUTPUT,
NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_INPUT_DISCONNECT,
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_NOPULL,
NRF_GPIO_PIN_S0D1, NRF_GPIO_PIN_S0D1,
NRF_GPIO_PIN_NOSENSE); NRF_GPIO_PIN_NOSENSE);
nrf_gpio_pin_set(Pinetime::PinMap::TwiScl); nrf_gpio_pin_set(pinTwiScl);
for (uint8_t i = 0; i < 16; i++) { for (uint8_t i = 0; i < 16; i++) {
nrf_gpio_pin_toggle(Pinetime::PinMap::TwiScl); nrf_gpio_pin_toggle(pinTwiScl);
nrf_delay_us(5); nrf_delay_us(5);
} }
nrf_gpio_cfg_default(Pinetime::PinMap::TwiScl); nrf_gpio_cfg_default(pinTwiScl);
debounceTimer = xTimerCreate("debounceTimer", 200, pdFALSE, (void*) 0, DebounceTimerCallback); debounceTimer = xTimerCreate("debounceTimer", 200, pdFALSE, (void*) 0, DebounceTimerCallback);
debounceChargeTimer = xTimerCreate("debounceTimerCharge", 200, pdFALSE, (void*) 0, DebounceTimerChargeCallback); debounceChargeTimer = xTimerCreate("debounceTimerCharge", 200, pdFALSE, (void*) 0, DebounceTimerChargeCallback);

View file

@ -15,7 +15,6 @@
#include <components/brightness/BrightnessController.h> #include <components/brightness/BrightnessController.h>
#include <algorithm> #include <algorithm>
#include "recoveryImage.h" #include "recoveryImage.h"
#include "drivers/PinMap.h"
#include "displayapp/icons/infinitime/infinitime-nb.c" #include "displayapp/icons/infinitime/infinitime-nb.c"
#include "components/rle/RleDecoder.h" #include "components/rle/RleDecoder.h"
@ -28,6 +27,12 @@ Pinetime::Logging::NrfLogger logger;
Pinetime::Logging::DummyLogger logger; Pinetime::Logging::DummyLogger logger;
#endif #endif
static constexpr uint8_t pinSpiSck = 2;
static constexpr uint8_t pinSpiMosi = 3;
static constexpr uint8_t pinSpiMiso = 4;
static constexpr uint8_t pinSpiFlashCsn = 5;
static constexpr uint8_t pinLcdCsn = 25;
static constexpr uint8_t pinLcdDataCommand = 18;
static constexpr uint8_t displayWidth = 240; static constexpr uint8_t displayWidth = 240;
static constexpr uint8_t displayHeight = 240; static constexpr uint8_t displayHeight = 240;
@ -40,14 +45,14 @@ Pinetime::Drivers::SpiMaster spi {Pinetime::Drivers::SpiMaster::SpiModule::SPI0,
{Pinetime::Drivers::SpiMaster::BitOrder::Msb_Lsb, {Pinetime::Drivers::SpiMaster::BitOrder::Msb_Lsb,
Pinetime::Drivers::SpiMaster::Modes::Mode3, Pinetime::Drivers::SpiMaster::Modes::Mode3,
Pinetime::Drivers::SpiMaster::Frequencies::Freq8Mhz, Pinetime::Drivers::SpiMaster::Frequencies::Freq8Mhz,
Pinetime::PinMap::SpiSck, pinSpiSck,
Pinetime::PinMap::SpiMosi, pinSpiMosi,
Pinetime::PinMap::SpiMiso}}; pinSpiMiso}};
Pinetime::Drivers::Spi flashSpi {spi, Pinetime::PinMap::SpiFlashCsn}; Pinetime::Drivers::Spi flashSpi {spi, pinSpiFlashCsn};
Pinetime::Drivers::SpiNorFlash spiNorFlash {flashSpi}; Pinetime::Drivers::SpiNorFlash spiNorFlash {flashSpi};
Pinetime::Drivers::Spi lcdSpi {spi, Pinetime::PinMap::SpiLcdCsn}; Pinetime::Drivers::Spi lcdSpi {spi, pinLcdCsn};
Pinetime::Drivers::St7789 lcd {lcdSpi, Pinetime::PinMap::LcdDataCommand}; Pinetime::Drivers::St7789 lcd {lcdSpi, pinLcdDataCommand};
Pinetime::Components::Gfx gfx {lcd}; Pinetime::Components::Gfx gfx {lcd};
Pinetime::Controllers::BrightnessController brightnessController; Pinetime::Controllers::BrightnessController brightnessController;

View file

@ -22,9 +22,7 @@ namespace Pinetime {
OnNewDay, OnNewDay,
OnChargingEvent, OnChargingEvent,
SetOffAlarm, SetOffAlarm,
StopRinging, StopRinging
MeasureBatteryTimerExpired,
BatteryMeasurementDone,
}; };
} }
} }

View file

@ -21,10 +21,8 @@
#include "drivers/SpiNorFlash.h" #include "drivers/SpiNorFlash.h"
#include "drivers/TwiMaster.h" #include "drivers/TwiMaster.h"
#include "drivers/Hrs3300.h" #include "drivers/Hrs3300.h"
#include "drivers/PinMap.h"
#include "main.h" #include "main.h"
#include <memory> #include <memory>
using namespace Pinetime::System; using namespace Pinetime::System;
@ -49,11 +47,6 @@ void IdleTimerCallback(TimerHandle_t xTimer) {
sysTask->OnIdle(); sysTask->OnIdle();
} }
void MeasureBatteryTimerCallback(TimerHandle_t xTimer) {
auto* sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer));
sysTask->PushMessage(Pinetime::System::Messages::MeasureBatteryTimerExpired);
}
SystemTask::SystemTask(Drivers::SpiMaster& spi, SystemTask::SystemTask(Drivers::SpiMaster& spi,
Drivers::St7789& lcd, Drivers::St7789& lcd,
Pinetime::Drivers::SpiNorFlash& spiNorFlash, Pinetime::Drivers::SpiNorFlash& spiNorFlash,
@ -130,13 +123,13 @@ void SystemTask::Work() {
fs.Init(); fs.Init();
nimbleController.Init(); nimbleController.Init();
nimbleController.StartAdvertising();
lcd.Init(); lcd.Init();
twiMaster.Init(); twiMaster.Init();
touchPanel.Init(); touchPanel.Init();
dateTimeController.Register(this); dateTimeController.Register(this);
batteryController.Register(this); batteryController.Init();
batteryController.Update();
motorController.Init(); motorController.Init();
motionSensor.SoftReset(); motionSensor.SoftReset();
timerController.Register(this); timerController.Register(this);
@ -154,11 +147,13 @@ void SystemTask::Work() {
displayApp.Register(this); displayApp.Register(this);
displayApp.Start(); displayApp.Start();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel);
heartRateSensor.Init(); heartRateSensor.Init();
heartRateSensor.Disable(); heartRateSensor.Disable();
heartRateApp.Start(); heartRateApp.Start();
nrf_gpio_cfg_sense_input(PinMap::Button, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pulldown, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_High); nrf_gpio_cfg_sense_input(pinButton, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pulldown, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_High);
nrf_gpio_cfg_output(15); nrf_gpio_cfg_output(15);
nrf_gpio_pin_set(15); nrf_gpio_pin_set(15);
@ -169,9 +164,9 @@ void SystemTask::Work() {
pinConfig.sense = (nrf_gpiote_polarity_t) NRF_GPIOTE_POLARITY_HITOLO; pinConfig.sense = (nrf_gpiote_polarity_t) NRF_GPIOTE_POLARITY_HITOLO;
pinConfig.pull = (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pulldown; pinConfig.pull = (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pulldown;
nrfx_gpiote_in_init(PinMap::Button, &pinConfig, nrfx_gpiote_evt_handler); nrfx_gpiote_in_init(pinButton, &pinConfig, nrfx_gpiote_evt_handler);
nrf_gpio_cfg_sense_input(PinMap::Cst816sIrq, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_Low); nrf_gpio_cfg_sense_input(pinTouchIrq, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_Low);
pinConfig.skip_gpio_setup = true; pinConfig.skip_gpio_setup = true;
pinConfig.hi_accuracy = false; pinConfig.hi_accuracy = false;
@ -179,26 +174,24 @@ void SystemTask::Work() {
pinConfig.sense = (nrf_gpiote_polarity_t) NRF_GPIOTE_POLARITY_HITOLO; pinConfig.sense = (nrf_gpiote_polarity_t) NRF_GPIOTE_POLARITY_HITOLO;
pinConfig.pull = (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup; pinConfig.pull = (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup;
nrfx_gpiote_in_init(PinMap::Cst816sIrq, &pinConfig, nrfx_gpiote_evt_handler); nrfx_gpiote_in_init(pinTouchIrq, &pinConfig, nrfx_gpiote_evt_handler);
pinConfig.sense = NRF_GPIOTE_POLARITY_TOGGLE; pinConfig.sense = NRF_GPIOTE_POLARITY_TOGGLE;
pinConfig.pull = NRF_GPIO_PIN_NOPULL; pinConfig.pull = NRF_GPIO_PIN_NOPULL;
pinConfig.is_watcher = false; pinConfig.is_watcher = false;
pinConfig.hi_accuracy = false; pinConfig.hi_accuracy = false;
pinConfig.skip_gpio_setup = true; pinConfig.skip_gpio_setup = true;
nrfx_gpiote_in_init(PinMap::PowerPresent, &pinConfig, nrfx_gpiote_evt_handler); nrfx_gpiote_in_init(pinPowerPresentIrq, &pinConfig, nrfx_gpiote_evt_handler);
if (nrf_gpio_pin_read(PinMap::PowerPresent)) { if (nrf_gpio_pin_read(pinPowerPresentIrq)) {
nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW); nrf_gpio_cfg_sense_input(pinPowerPresentIrq, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW);
} else { } else {
nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH); nrf_gpio_cfg_sense_input(pinPowerPresentIrq, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH);
} }
idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(2000), pdFALSE, this, IdleTimerCallback); idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(2000), pdFALSE, this, IdleTimerCallback);
dimTimer = xTimerCreate("dimTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), pdFALSE, this, DimTimerCallback); dimTimer = xTimerCreate("dimTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), pdFALSE, this, DimTimerCallback);
measureBatteryTimer = xTimerCreate("measureBattery", batteryMeasurementPeriod, pdTRUE, this, MeasureBatteryTimerCallback);
xTimerStart(dimTimer, 0); xTimerStart(dimTimer, 0);
xTimerStart(measureBatteryTimer, portMAX_DELAY);
// Suppress endless loop diagnostic // Suppress endless loop diagnostic
#pragma clang diagnostic push #pragma clang diagnostic push
@ -208,6 +201,11 @@ void SystemTask::Work() {
uint8_t msg; uint8_t msg;
if (xQueueReceive(systemTasksMsgQueue, &msg, 100)) { if (xQueueReceive(systemTasksMsgQueue, &msg, 100)) {
batteryController.Update();
// the battery does not emit events when changing charge levels, so we piggyback
// on any system event to read and update the current values
Messages message = static_cast<Messages>(msg); Messages message = static_cast<Messages>(msg);
switch (message) { switch (message) {
case Messages::EnableSleeping: case Messages::EnableSleeping:
@ -231,16 +229,15 @@ void SystemTask::Work() {
touchPanel.Wakeup(); touchPanel.Wakeup();
} }
nimbleController.StartAdvertising();
xTimerStart(dimTimer, 0); xTimerStart(dimTimer, 0);
spiNorFlash.Wakeup(); spiNorFlash.Wakeup();
lcd.Wakeup(); lcd.Wakeup();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::GoToRunning); displayApp.PushMessage(Pinetime::Applications::Display::Messages::GoToRunning);
displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel);
heartRateApp.PushMessage(Pinetime::Applications::HeartRateTask::Messages::WakeUp); heartRateApp.PushMessage(Pinetime::Applications::HeartRateTask::Messages::WakeUp);
if (!bleController.IsConnected())
nimbleController.RestartFastAdv();
isSleeping = false; isSleeping = false;
isWakingUp = false; isWakingUp = false;
isDimmed = false; isDimmed = false;
@ -343,18 +340,8 @@ void SystemTask::Work() {
stepCounterMustBeReset = true; stepCounterMustBeReset = true;
break; break;
case Messages::OnChargingEvent: case Messages::OnChargingEvent:
batteryController.Update();
motorController.RunForDuration(15); motorController.RunForDuration(15);
break; // Battery level is updated on every message - there's no need to do anything
case Messages::MeasureBatteryTimerExpired:
sendBatteryNotification = true;
batteryController.Update();
break;
case Messages::BatteryMeasurementDone:
if (sendBatteryNotification) {
sendBatteryNotification = false;
nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());
}
break; break;
default: default:
@ -366,17 +353,22 @@ void SystemTask::Work() {
if (bleDiscoveryTimer == 0) { if (bleDiscoveryTimer == 0) {
isBleDiscoveryTimerRunning = false; isBleDiscoveryTimerRunning = false;
// Services discovery is deffered from 3 seconds to avoid the conflicts between the host communicating with the // Services discovery is deffered from 3 seconds to avoid the conflicts between the host communicating with the
// target and vice-versa. I'm not sure if this is the right way to handle this... // tharget and vice-versa. I'm not sure if this is the right way to handle this...
nimbleController.StartDiscovery(); nimbleController.StartDiscovery();
} else { } else {
bleDiscoveryTimer--; bleDiscoveryTimer--;
} }
} }
if (xTaskGetTickCount() - batteryNotificationTick > batteryNotificationPeriod) {
nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());
batteryNotificationTick = xTaskGetTickCount();
}
monitor.Process(); monitor.Process();
uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG); uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG);
dateTimeController.UpdateTime(systick_counter); dateTimeController.UpdateTime(systick_counter);
if (!nrf_gpio_pin_read(PinMap::Button)) if (!nrf_gpio_pin_read(pinButton))
watchdog.Kick(); watchdog.Kick();
} }
// Clear diagnostic suppression // Clear diagnostic suppression

View file

@ -8,7 +8,6 @@
#include <heartratetask/HeartRateTask.h> #include <heartratetask/HeartRateTask.h>
#include <components/settings/Settings.h> #include <components/settings/Settings.h>
#include <drivers/Bma421.h> #include <drivers/Bma421.h>
#include <drivers/PinMap.h>
#include <components/motion/MotionController.h> #include <components/motion/MotionController.h>
#include "SystemMonitor.h" #include "SystemMonitor.h"
@ -124,6 +123,15 @@ namespace Pinetime {
Pinetime::Controllers::TouchHandler& touchHandler; Pinetime::Controllers::TouchHandler& touchHandler;
Pinetime::Controllers::NimbleController nimbleController; Pinetime::Controllers::NimbleController nimbleController;
static constexpr uint8_t pinSpiSck = 2;
static constexpr uint8_t pinSpiMosi = 3;
static constexpr uint8_t pinSpiMiso = 4;
static constexpr uint8_t pinSpiCsn = 25;
static constexpr uint8_t pinLcdDataCommand = 18;
static constexpr uint8_t pinButton = 13;
static constexpr uint8_t pinTouchIrq = 28;
static constexpr uint8_t pinPowerPresentIrq = 19;
static void Process(void* instance); static void Process(void* instance);
void Work(); void Work();
void ReloadIdleTimer(); void ReloadIdleTimer();
@ -131,15 +139,13 @@ namespace Pinetime {
uint8_t bleDiscoveryTimer = 0; uint8_t bleDiscoveryTimer = 0;
TimerHandle_t dimTimer; TimerHandle_t dimTimer;
TimerHandle_t idleTimer; TimerHandle_t idleTimer;
TimerHandle_t measureBatteryTimer;
bool sendBatteryNotification = false;
bool doNotGoToSleep = false; bool doNotGoToSleep = false;
void GoToRunning(); void GoToRunning();
void UpdateMotion(); void UpdateMotion();
bool stepCounterMustBeReset = false; bool stepCounterMustBeReset = false;
static constexpr TickType_t batteryMeasurementPeriod = pdMS_TO_TICKS(10 * 60 * 1000); static constexpr TickType_t batteryNotificationPeriod = 1000 * 60 * 10; // 1 tick ~= 1ms. 1ms * 60 * 10 = 10 minutes
TickType_t lastBatteryNotificationTime = 0; TickType_t batteryNotificationTick = 0;
#if configUSE_TRACE_FACILITY == 1 #if configUSE_TRACE_FACILITY == 1
SystemMonitor<FreeRtosMonitor> monitor; SystemMonitor<FreeRtosMonitor> monitor;