Merge branch 'develop' of JF/PineTime into master

This commit is contained in:
JF 2020-06-16 21:15:16 +02:00 committed by Gitea
commit 3a49bbbae4
16 changed files with 93 additions and 35 deletions

View file

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(pinetime VERSION 0.6.0 LANGUAGES C CXX ASM) project(pinetime VERSION 0.6.1 LANGUAGES C CXX ASM)
set(NRF_TARGET "nrf52") set(NRF_TARGET "nrf52")

View file

@ -92,16 +92,24 @@ GDB (Back Magic Probe)
``` ```
$ mkdir build $ mkdir build
$ cd build $ cd build
$ cmake -DARM_NONE_EABI_TOOLCHAIN_PATH=... -DNRF5_SDK_PATH=... -DUSE_GDB_CLIENT=1 -DGDB_CLIENT_BIN_PATH=... -DGDB_CLIENT_TARGET_REMOTE=... -DMERGEHEX=... ../ $ cmake -DARM_NONE_EABI_TOOLCHAIN_PATH=... -DNRF5_SDK_PATH=... -DUSE_GDB_CLIENT=1 -DGDB_CLIENT_BIN_PATH=... -DGDB_CLIENT_TARGET_REMOTE=... ../
``` ```
OpenOCD (STlink v2 clones) OpenOCD (STlink v2 clones)
``` ```
$ mkdir build $ mkdir build
$ cd build $ cd build
$ cmake -DARM_NONE_EABI_TOOLCHAIN_PATH=... -DNRF5_SDK_PATH=... -DUSE_OPENOCD=1 -DGDB_CLIENT_BIN_PATH=[optional] -DMERGEHEX=... ../ $ cmake -DARM_NONE_EABI_TOOLCHAIN_PATH=... -DNRF5_SDK_PATH=... -DUSE_OPENOCD=1 -DGDB_CLIENT_BIN_PATH=[optional] ../
``` ```
**Note** : By default, the build configuration *Release* is applied. It means that the code is built with optimisations enabled (-O3). If you wanto to compile in *Debug* mode to ease debugging and step-by-step debugging, specify the CMake variable `CMAKE_BUILD_TYPE` in the CMake command line:
```
-DCMAKE_BUILD_TYPE=Debug
```
* Make * Make
``` ```
$ make -j pinetime-app $ make -j pinetime-app

View file

@ -546,6 +546,10 @@ add_definitions(-DNRF52 -DNRF52832 -DNRF52832_XXAA -DNRF52_PAN_74 -DNRF52_PAN_64
add_definitions(-DFREERTOS) add_definitions(-DFREERTOS)
add_definitions(-DDEBUG_NRF_USER) add_definitions(-DDEBUG_NRF_USER)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
# Build autonomous binary (without support for bootloader) # Build autonomous binary (without support for bootloader)
set(EXECUTABLE_NAME "pinetime-app") set(EXECUTABLE_NAME "pinetime-app")
set(NRF5_LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/gcc_nrf52.ld") set(NRF5_LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/gcc_nrf52.ld")

View file

@ -2,12 +2,15 @@
#include <FreeRTOS.h> #include <FreeRTOS.h>
#include <queue.h> #include <queue.h>
#include <array>
namespace Pinetime { namespace Pinetime {
namespace Controllers { namespace Controllers {
class Ble { class Ble {
public: public:
using BleAddress = std::array<uint8_t, 6>;
enum class FirmwareUpdateStates {Idle, Running, Validated, Error}; enum class FirmwareUpdateStates {Idle, Running, Validated, Error};
enum class AddressTypes { Public, Random };
Ble() = default; Ble() = default;
bool IsConnected() const {return isConnected;} bool IsConnected() const {return isConnected;}
@ -24,12 +27,18 @@ namespace Pinetime {
uint32_t FirmwareUpdateTotalBytes() const { return firmwareUpdateTotalBytes; } uint32_t FirmwareUpdateTotalBytes() const { return firmwareUpdateTotalBytes; }
uint32_t FirmwareUpdateCurrentBytes() const { return firmwareUpdateCurrentBytes; } uint32_t FirmwareUpdateCurrentBytes() const { return firmwareUpdateCurrentBytes; }
FirmwareUpdateStates State() const { return firmwareUpdateState; } FirmwareUpdateStates State() const { return firmwareUpdateState; }
void Address(BleAddress&& addr) { address = addr; }
const BleAddress& Address() const { return address; }
void AddressType(AddressTypes t) { addressType = t;}
private: private:
bool isConnected = false; bool isConnected = false;
bool isFirmwareUpdating = false; bool isFirmwareUpdating = false;
uint32_t firmwareUpdateTotalBytes = 0; uint32_t firmwareUpdateTotalBytes = 0;
uint32_t firmwareUpdateCurrentBytes = 0; uint32_t firmwareUpdateCurrentBytes = 0;
FirmwareUpdateStates firmwareUpdateState = FirmwareUpdateStates::Idle; FirmwareUpdateStates firmwareUpdateState = FirmwareUpdateStates::Idle;
BleAddress address;
AddressTypes addressType;
}; };
} }

View file

@ -90,8 +90,13 @@ void NimbleController::Init() {
res = ble_hs_id_infer_auto(0, &addrType); res = ble_hs_id_infer_auto(0, &addrType);
ASSERT(res == 0); ASSERT(res == 0);
res = ble_svc_gap_device_name_set(deviceName); res = ble_svc_gap_device_name_set(deviceName);
ASSERT(res == 0); ASSERT(res == 0);
Pinetime::Controllers::Ble::BleAddress address;
res = ble_hs_id_copy_addr(addrType, address.data(), nullptr);
ASSERT(res == 0);
bleController.AddressType((addrType == 0) ? Ble::AddressTypes::Public : Ble::AddressTypes::Random);
bleController.Address(std::move(address));
res = ble_gatts_start(); res = ble_gatts_start();
ASSERT(res == 0); ASSERT(res == 0);
} }

View file

@ -50,7 +50,7 @@ namespace Pinetime {
AlertNotificationClient alertNotificationClient; AlertNotificationClient alertNotificationClient;
CurrentTimeService currentTimeService; CurrentTimeService currentTimeService;
uint8_t addrType; uint8_t addrType; // 1 = Random, 0 = PUBLIC
uint16_t connectionHandle; uint16_t connectionHandle;
ble_uuid128_t dfuServiceUuid { ble_uuid128_t dfuServiceUuid {

View file

@ -47,7 +47,8 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
previousSystickCounter = 0xffffff - (rest - systickCounter); previousSystickCounter = 0xffffff - (rest - systickCounter);
} }
currentDateTime += std::chrono::seconds (correctedDelta); currentDateTime += std::chrono::seconds(correctedDelta);
uptime += std::chrono::seconds(correctedDelta);
auto dp = date::floor<date::days>(currentDateTime); auto dp = date::floor<date::days>(currentDateTime);
auto time = date::make_time(currentDateTime-dp); auto time = date::make_time(currentDateTime-dp);

View file

@ -21,6 +21,7 @@ namespace Pinetime {
uint8_t Seconds() const { return second; } uint8_t Seconds() const { return second; }
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> CurrentDateTime() const { return currentDateTime; } std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> CurrentDateTime() const { return currentDateTime; }
std::chrono::seconds Uptime() const { return uptime; }
private: private:
uint16_t year = 0; uint16_t year = 0;
Months month = Months::Unknown; Months month = Months::Unknown;
@ -32,7 +33,7 @@ namespace Pinetime {
uint32_t previousSystickCounter = 0; uint32_t previousSystickCounter = 0;
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> currentDateTime; std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> currentDateTime;
std::chrono::seconds uptime {0};
}; };
} }
} }

View file

@ -185,7 +185,7 @@ void DisplayApp::RunningState() {
onClockApp = true; onClockApp = true;
break; break;
// case Apps::Test: currentScreen.reset(new Screens::Message(this)); break; // case Apps::Test: currentScreen.reset(new Screens::Message(this)); break;
case Apps::SysInfo: currentScreen.reset(new Screens::ScreenList(this, dateTimeController, batteryController, brightnessController, watchdog)); break; case Apps::SysInfo: currentScreen.reset(new Screens::ScreenList(this, dateTimeController, batteryController, brightnessController, bleController, watchdog)); break;
case Apps::Meter: currentScreen.reset(new Screens::Meter(this)); break; case Apps::Meter: currentScreen.reset(new Screens::Meter(this)); break;
case Apps::Gauge: currentScreen.reset(new Screens::Gauge(this)); break; case Apps::Gauge: currentScreen.reset(new Screens::Gauge(this)); break;
case Apps::Brightness : currentScreen.reset(new Screens::Brightness(this, brightnessController)); break; case Apps::Brightness : currentScreen.reset(new Screens::Brightness(this, brightnessController)); break;

View file

@ -8,10 +8,15 @@ using namespace Pinetime::Applications::Screens;
// move operation. // move operation.
// It should accept many type of "sub screen" (it only supports Label for now). // It should accept many type of "sub screen" (it only supports Label for now).
// The number of sub screen it supports must be dynamic. // The number of sub screen it supports must be dynamic.
ScreenList::ScreenList(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController, ScreenList::ScreenList(Pinetime::Applications::DisplayApp *app,
Pinetime::Controllers::Battery& batteryController, Pinetime::Controllers::BrightnessController& brightnessController, Pinetime::Drivers::WatchdogView& watchdog) : Pinetime::Controllers::DateTime &dateTimeController,
Pinetime::Controllers::Battery& batteryController,
Pinetime::Controllers::BrightnessController& brightnessController,
Pinetime::Controllers::Ble& bleController,
Pinetime::Drivers::WatchdogView& watchdog) :
Screen(app), Screen(app),
dateTimeController{dateTimeController}, batteryController{batteryController}, brightnessController{brightnessController}, watchdog{watchdog} { dateTimeController{dateTimeController}, batteryController{batteryController},
brightnessController{brightnessController}, bleController{bleController}, watchdog{watchdog} {
screens.reserve(3); screens.reserve(3);
// TODO all of this is far too heavy (string processing). This should be improved. // TODO all of this is far too heavy (string processing). This should be improved.
@ -43,27 +48,45 @@ ScreenList::ScreenList(Pinetime::Applications::DisplayApp *app, Pinetime::Contro
} }
}(); }();
// uptime
static constexpr uint32_t secondsInADay = 60*60*24;
static constexpr uint32_t secondsInAnHour = 60*60;
static constexpr uint32_t secondsInAMinute = 60;
uint32_t uptimeSeconds = dateTimeController.Uptime().count();
uint32_t uptimeDays = (uptimeSeconds / secondsInADay);
uptimeSeconds = uptimeSeconds % secondsInADay;
uint32_t uptimeHours = uptimeSeconds / secondsInAnHour;
uptimeSeconds = uptimeSeconds % secondsInAnHour;
uint32_t uptimeMinutes = uptimeSeconds / secondsInAMinute;
uptimeSeconds = uptimeSeconds % secondsInAMinute;
// TODO handle more than 100 days of uptime
sprintf(t1, "Pinetime\n" sprintf(t1, "Pinetime\n"
"Version:%d.%d.%d\n" "Version:%d.%d.%d\n"
"Build: xx/xx/xxxx\n" "Build: %s\n"
" %s\n"
"Date: %02d/%02d/%04d\n"
"Time: %02d:%02d:%02d\n" "Time: %02d:%02d:%02d\n"
"date: %02d/%02d/%04d\n" "Uptime: %02lud %02lu:%02lu:%02lu\n"
"Uptime: xd xxhxx:xx\n"
"Battery: %d%%\n" "Battery: %d%%\n"
"Backlight: %d/3\n" "Backlight: %d/3\n"
"Last reset: %s\n" "Last reset: %s\n",
"BLE MAC: \n AA:BB:CC:DD:EE:FF", Version::Major(), Version::Minor(), Version::Patch(), Version::Major(), Version::Minor(), Version::Patch(),
dateTimeController.Hours(), dateTimeController.Minutes(), dateTimeController.Seconds(), __DATE__, __TIME__,
dateTimeController.Day(), dateTimeController.Month(), dateTimeController.Year(), dateTimeController.Day(), dateTimeController.Month(), dateTimeController.Year(),
dateTimeController.Hours(), dateTimeController.Minutes(), dateTimeController.Seconds(),
uptimeDays, uptimeHours, uptimeMinutes, uptimeSeconds,
batteryPercent, brightness, resetReason); batteryPercent, brightness, resetReason);
screens.emplace_back(t1); screens.emplace_back(t1);
strncpy(t2, "Hello from\nthe developper!", 27); auto& bleAddr = bleController.Address();
sprintf(t2, "BLE MAC: \n %2x:%2x:%2x:%2x:%2x:%2x",
bleAddr[5], bleAddr[4], bleAddr[3], bleAddr[2], bleAddr[1], bleAddr[0]);
screens.emplace_back(t2); screens.emplace_back(t2);
strncpy(t3, "Place holder\nin case we need\nmore room!", 40); strncpy(t3, "Hello from\nthe developper!", 27);
screens.emplace_back(t3); screens.emplace_back(t3);
auto &screen = screens[screenIndex]; auto &screen = screens[screenIndex];

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <vector> #include <vector>
#include <Components/Ble/NimbleController.h>
#include "Screen.h" #include "Screen.h"
#include "Label.h" #include "Label.h"
@ -13,6 +14,7 @@ namespace Pinetime {
Pinetime::Controllers::DateTime& dateTimeController, Pinetime::Controllers::DateTime& dateTimeController,
Pinetime::Controllers::Battery& batteryController, Pinetime::Controllers::Battery& batteryController,
Pinetime::Controllers::BrightnessController& brightnessController, Pinetime::Controllers::BrightnessController& brightnessController,
Pinetime::Controllers::Ble& bleController,
Pinetime::Drivers::WatchdogView& watchdog); Pinetime::Drivers::WatchdogView& watchdog);
~ScreenList() override; ~ScreenList() override;
bool Refresh() override; bool Refresh() override;
@ -27,11 +29,13 @@ namespace Pinetime {
Pinetime::Controllers::DateTime& dateTimeController; Pinetime::Controllers::DateTime& dateTimeController;
Pinetime::Controllers::Battery& batteryController; Pinetime::Controllers::Battery& batteryController;
Pinetime::Controllers::BrightnessController& brightnessController; Pinetime::Controllers::BrightnessController& brightnessController;
Pinetime::Controllers::Ble& bleController;
Pinetime::Drivers::WatchdogView& watchdog; Pinetime::Drivers::WatchdogView& watchdog;
char t1[200]; char t1[200];
char t2[30]; char t2[200];
char t3[42]; char t3[30];
}; };
} }
} }

View file

@ -16,6 +16,8 @@
using namespace Pinetime::System; using namespace Pinetime::System;
void IdleTimerCallback(TimerHandle_t xTimer) { void IdleTimerCallback(TimerHandle_t xTimer) {
NRF_LOG_INFO("IdleTimerCallback");
auto sysTask = static_cast<SystemTask *>(pvTimerGetTimerID(xTimer)); auto sysTask = static_cast<SystemTask *>(pvTimerGetTimerID(xTimer));
sysTask->OnIdle(); sysTask->OnIdle();
} }
@ -113,6 +115,7 @@ void SystemTask::Work() {
break; break;
case Messages::GoToSleep: case Messages::GoToSleep:
NRF_LOG_INFO("[SystemTask] Going to sleep"); NRF_LOG_INFO("[SystemTask] Going to sleep");
xTimerStop(idleTimer, 0);
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::GoToSleep); displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::GoToSleep);
isSleeping = true; isSleeping = true;
break; break;

View file

@ -67,7 +67,7 @@ namespace Pinetime {
void Work(); void Work();
bool isBleDiscoveryTimerRunning = false; bool isBleDiscoveryTimerRunning = false;
uint8_t bleDiscoveryTimer = 0; uint8_t bleDiscoveryTimer = 0;
static constexpr uint32_t idleTime = 5000; static constexpr uint32_t idleTime = 15000;
TimerHandle_t idleTimer; TimerHandle_t idleTimer;
bool doNotGoToSleep = false; bool doNotGoToSleep = false;

View file

@ -1,4 +1,4 @@
#include <sdk/modules/nrfx/mdk/nrf.h> #include <mdk/nrf.h>
#include "InternalFlash.h" #include "InternalFlash.h"
using namespace Pinetime::Drivers; using namespace Pinetime::Drivers;

View file

@ -32,17 +32,17 @@ void Watchdog::Kick() {
} }
Watchdog::ResetReasons Watchdog::ActualResetReason() const { Watchdog::ResetReasons Watchdog::ActualResetReason() const {
uint32_t resetReason; uint32_t reason = NRF_POWER->RESETREAS;
// sd_power_reset_reason_get(&resetReason); NRF_POWER->RESETREAS = 0xffffffff;
// sd_power_reset_reason_clr(0xFFFFFFFF);
// if(resetReason & 0x01u) return ResetReasons::ResetPin; if(reason & 0x01u) return ResetReasons::ResetPin;
// if((resetReason >> 1u) & 0x01u) return ResetReasons::Watchdog; if((reason >> 1u) & 0x01u) return ResetReasons::Watchdog;
// if((resetReason >> 2u) & 0x01u) return ResetReasons::SoftReset; if((reason >> 2u) & 0x01u) return ResetReasons::SoftReset;
// if((resetReason >> 3u) & 0x01u) return ResetReasons::CpuLockup; if((reason >> 3u) & 0x01u) return ResetReasons::CpuLockup;
// if((resetReason >> 16u) & 0x01u) return ResetReasons::SystemOff; if((reason >> 16u) & 0x01u) return ResetReasons::SystemOff;
// if((resetReason >> 17u) & 0x01u) return ResetReasons::LpComp; if((reason >> 17u) & 0x01u) return ResetReasons::LpComp;
// if((resetReason >> 18u) & 0x01u) return ResetReasons::DebugInterface; if((reason) & 0x01u) return ResetReasons::DebugInterface;
// if((resetReason >> 19u) & 0x01u) return ResetReasons::NFC; if((reason >> 19u) & 0x01u) return ResetReasons::NFC;
return ResetReasons::HardReset; return ResetReasons::HardReset;
} }

View file

@ -3,7 +3,7 @@
#include <drivers/SpiMaster.h> #include <drivers/SpiMaster.h>
#include <drivers/Spi.h> #include <drivers/Spi.h>
#include <drivers/SpiNorFlash.h> #include <drivers/SpiNorFlash.h>
#include <sdk/components/libraries/log/nrf_log.h> #include <libraries/log/nrf_log.h>
#include "bootloader/boot_graphics.h" #include "bootloader/boot_graphics.h"
#include <FreeRTOS.h> #include <FreeRTOS.h>
#include <task.h> #include <task.h>