Build system : add the possibility to build the app / factory firmware.

This commit is contained in:
JF 2020-12-01 21:13:15 +01:00
parent 89783286da
commit a7484e6daa
13 changed files with 342 additions and 55 deletions

View File

@ -0,0 +1,46 @@
@startuml
start
partition Custom {
:Check button for 5s;
note right
Display is updated to show when
//revert firmware// and //factory reset//
are taken into account
end note
if (Pushed >50% of the time) then (yes)
:Mark previous firmware \n(in secondary slot) __pending__.\nIt'll be swapped in primary\nafter reset;
#pink:Reset;
detach
elseif (Pushed > 25% of the time) then (yes)
:Copy factory firmware in\nsecondary slot and\nmark it __pending__.\nIt'll be swapped in primary\nafter reset;
#pink:Reset;
detach
else (not pushed)
partition MCUBoot {
:Inspect swap status region;
if (is an interrupted swap being resumed?) then (yes)
:Complete the partial swap operation;
:Boot into image in primary slot;
stop
else(no)
endif
:Inspect image trailers;
if(s a swap requested?) then(yes)
if(Is the requested image valid (integrity and security check)?) then (yes)
:Perform swap operation;
:Persist completion of swap procedure to image trailers;
else (no)
:Erase invalid image;
:Persist failure of swap procedure to image trailers;
endif
else(no)
endif
:Boot into image in primary slot;
}
endif
}
stop
@enduml

View File

@ -382,6 +382,45 @@ list(APPEND SOURCE_FILES
systemtask/SystemTask.cpp systemtask/SystemTask.cpp
drivers/TwiMaster.cpp drivers/TwiMaster.cpp
)
list(APPEND FACTORY_SOURCE_FILES
BootloaderVersion.cpp
logging/NrfLogger.cpp
displayapp/DisplayAppFactory.cpp
main.cpp
drivers/St7789.cpp
drivers/SpiNorFlash.cpp
drivers/SpiMaster.cpp
drivers/Spi.cpp
drivers/Watchdog.cpp
drivers/DebugPins.cpp
drivers/InternalFlash.cpp
components/battery/BatteryController.cpp
components/ble/BleController.cpp
components/ble/NotificationManager.cpp
components/datetime/DateTimeController.cpp
components/brightness/BrightnessController.cpp
components/ble/NimbleController.cpp
components/ble/DeviceInformationService.cpp
components/ble/CurrentTimeClient.cpp
components/ble/AlertNotificationClient.cpp
components/ble/DfuService.cpp
components/ble/CurrentTimeService.cpp
components/ble/AlertNotificationService.cpp
components/ble/MusicService.cpp
components/ble/BatteryInformationService.cpp
components/ble/ImmediateAlertService.cpp
components/ble/ServiceDiscovery.cpp
components/firmwarevalidator/FirmwareValidator.cpp
drivers/Cst816s.cpp
FreeRTOS/port.c
FreeRTOS/port_cmsis_systick.c
FreeRTOS/port_cmsis.c
systemtask/SystemTask.cpp
drivers/TwiMaster.cpp
components/gfx/Gfx.cpp components/gfx/Gfx.cpp
) )
@ -404,7 +443,7 @@ list(APPEND GRAPHICS_SOURCE_FILES
graphics.cpp graphics.cpp
) )
list(APPEND FACTORY_SOURCE_FILES list(APPEND FACTORYLOADER_SOURCE_FILES
# FreeRTOS # FreeRTOS
FreeRTOS/port.c FreeRTOS/port.c
FreeRTOS/port_cmsis_systick.c FreeRTOS/port_cmsis_systick.c
@ -427,6 +466,7 @@ set(INCLUDE_FILES
logging/Logger.h logging/Logger.h
logging/NrfLogger.h logging/NrfLogger.h
displayapp/DisplayApp.h displayapp/DisplayApp.h
displayapp/Messages.h
displayapp/TouchEvents.h displayapp/TouchEvents.h
displayapp/screens/Screen.h displayapp/screens/Screen.h
displayapp/screens/Clock.h displayapp/screens/Clock.h
@ -481,7 +521,7 @@ set(INCLUDE_FILES
libs/date/includes/date/julian.h libs/date/includes/date/julian.h
libs/date/includes/date/ptz.h libs/date/includes/date/ptz.h
libs/date/includes/date/tz_private.h libs/date/includes/date/tz_private.h
displayapp/LittleVgl.h #displayapp/LittleVgl.h
systemtask/SystemTask.h systemtask/SystemTask.h
systemtask/SystemMonitor.h systemtask/SystemMonitor.h
displayapp/screens/Symbols.h displayapp/screens/Symbols.h
@ -725,12 +765,13 @@ add_custom_command(TARGET ${EXECUTABLE_GRAPHICS_NAME}
COMMENT "post build steps for ${EXECUTABLE_GRAPHICS_FILE_NAME}" COMMENT "post build steps for ${EXECUTABLE_GRAPHICS_FILE_NAME}"
) )
# Build binary that writes the factory image # infinitime-light
set(EXECUTABLE_FACTORY_NAME "pinetime-factory") set(EXECUTABLE_FACTORY_NAME "pinetime-factory")
set(EXECUTABLE_FACTORY_FILE_NAME ${EXECUTABLE_FACTORY_NAME}-${pinetime_VERSION_MAJOR}.${pinetime_VERSION_MINOR}.${pinetime_VERSION_PATCH}) set(EXECUTABLE_FACTORY_FILE_NAME ${EXECUTABLE_FACTORY_NAME}-${pinetime_VERSION_MAJOR}.${pinetime_VERSION_MINOR}.${pinetime_VERSION_PATCH})
add_executable(${EXECUTABLE_FACTORY_NAME} ${FACTORY_SOURCE_FILES}) add_executable(${EXECUTABLE_FACTORY_NAME} ${FACTORY_SOURCE_FILES})
target_link_libraries(${EXECUTABLE_FACTORY_NAME} nrf-sdk) target_link_libraries(${EXECUTABLE_FACTORY_NAME} nimble nrf-sdk)
set_target_properties(${EXECUTABLE_FACTORY_NAME} PROPERTIES OUTPUT_NAME ${EXECUTABLE_FACTORY_FILE_NAME}) set_target_properties(${EXECUTABLE_FACTORY_NAME} PROPERTIES OUTPUT_NAME ${EXECUTABLE_FACTORY_FILE_NAME})
target_compile_definitions(${EXECUTABLE_FACTORY_NAME} PUBLIC "PINETIME_IS_FACTORY")
target_compile_options(${EXECUTABLE_FACTORY_NAME} PUBLIC target_compile_options(${EXECUTABLE_FACTORY_NAME} PUBLIC
$<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:DEBUG>>: ${COMMON_FLAGS} -O0 -g3> $<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:DEBUG>>: ${COMMON_FLAGS} -O0 -g3>
$<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:RELEASE>>: ${COMMON_FLAGS} -O3> $<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:RELEASE>>: ${COMMON_FLAGS} -O3>
@ -754,6 +795,71 @@ add_custom_command(TARGET ${EXECUTABLE_FACTORY_NAME}
COMMENT "post build steps for ${EXECUTABLE_FACTORY_FILE_NAME}" COMMENT "post build steps for ${EXECUTABLE_FACTORY_FILE_NAME}"
) )
# infinitime-light MCUBOOT
set(EXECUTABLE_FACTORY_MCUBOOT_NAME "pinetime-mcuboot-factory")
set(EXECUTABLE_FACTORY_MCUBOOT_FILE_NAME ${EXECUTABLE_FACTORY_MCUBOOT_NAME}-${pinetime_VERSION_MAJOR}.${pinetime_VERSION_MINOR}.${pinetime_VERSION_PATCH})
add_executable(${EXECUTABLE_FACTORY_MCUBOOT_NAME} ${FACTORY_SOURCE_FILES})
target_link_libraries(${EXECUTABLE_FACTORY_MCUBOOT_NAME} nimble nrf-sdk)
set_target_properties(${EXECUTABLE_FACTORY_MCUBOOT_NAME} PROPERTIES OUTPUT_NAME ${EXECUTABLE_FACTORY_MCUBOOT_FILE_NAME})
target_compile_definitions(${EXECUTABLE_FACTORY_MCUBOOT_NAME} PUBLIC "PINETIME_IS_FACTORY")
target_compile_options(${EXECUTABLE_FACTORY_MCUBOOT_NAME} PUBLIC
$<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:DEBUG>>: ${COMMON_FLAGS} -O0 -g3>
$<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:RELEASE>>: ${COMMON_FLAGS} -O3>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CONFIG:DEBUG>>: ${COMMON_FLAGS} -O0 -g3>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CONFIG:RELEASE>>: ${COMMON_FLAGS} -O3>
$<$<COMPILE_LANGUAGE:ASM>: -MP -MD -std=c99 -x assembler-with-cpp>
)
set_target_properties(${EXECUTABLE_FACTORY_MCUBOOT_NAME} PROPERTIES
SUFFIX ".out"
LINK_FLAGS "-mthumb -mabi=aapcs -std=gnu++98 -std=c99 -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT_MCUBOOT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections --specs=nano.specs -lc -lnosys -lm -Wl,-Map=${EXECUTABLE_FACTORY_MCUBOOT_FILE_NAME}.map"
CXX_STANDARD 11
C_STANDARD 99
)
add_custom_command(TARGET ${EXECUTABLE_FACTORY_MCUBOOT_NAME}
POST_BUILD
COMMAND ${CMAKE_SIZE_UTIL} ${EXECUTABLE_FACTORY_MCUBOOT_FILE_NAME}.out
COMMAND ${CMAKE_OBJCOPY} -O binary ${EXECUTABLE_FACTORY_MCUBOOT_FILE_NAME}.out "${EXECUTABLE_FACTORY_MCUBOOT_FILE_NAME}.bin"
COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE_FACTORY_MCUBOOT_FILE_NAME}.out "${EXECUTABLE_FACTORY_MCUBOOT_FILE_NAME}.hex"
COMMAND /home/jf/nrf52/mcuboot/scripts/imgtool.py create --align 4 --version 1.0.0 --header-size 32 --slot-size 475136 --pad-header ${EXECUTABLE_FACTORY_MCUBOOT_FILE_NAME}.bin factoryImage.bin
COMMAND python ${CMAKE_SOURCE_DIR}/tools/bin2c.py factoryImage.bin factoryImage > factoryImage.h
COMMENT "post build steps for ${EXECUTABLE_FACTORY_MCUBOOT_FILE_NAME}"
)
# Build binary that writes the factory image
set(EXECUTABLE_FACTORYLOADER_NAME "pinetime-factory-loader")
set(EXECUTABLE_FACTORYLOADER_FILE_NAME ${EXECUTABLE_FACTORYLOADER_NAME}-${pinetime_VERSION_MAJOR}.${pinetime_VERSION_MINOR}.${pinetime_VERSION_PATCH})
add_executable(${EXECUTABLE_FACTORYLOADER_NAME} ${FACTORYLOADER_SOURCE_FILES})
target_link_libraries(${EXECUTABLE_FACTORYLOADER_NAME} nrf-sdk)
set_target_properties(${EXECUTABLE_FACTORYLOADER_NAME} PROPERTIES OUTPUT_NAME ${EXECUTABLE_FACTORYLOADER_FILE_NAME})
target_compile_options(${EXECUTABLE_FACTORYLOADER_NAME} PUBLIC
$<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:DEBUG>>: ${COMMON_FLAGS} -O0 -g3>
$<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:RELEASE>>: ${COMMON_FLAGS} -O3>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CONFIG:DEBUG>>: ${COMMON_FLAGS} -O0 -g3>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CONFIG:RELEASE>>: ${COMMON_FLAGS} -O3>
$<$<COMPILE_LANGUAGE:ASM>: -MP -MD -std=c99 -x assembler-with-cpp>
)
target_include_directories(${EXECUTABLE_FACTORYLOADER_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/src>
)
add_dependencies(${EXECUTABLE_FACTORYLOADER_NAME} ${EXECUTABLE_FACTORY_MCUBOOT_NAME})
set_target_properties(${EXECUTABLE_FACTORYLOADER_NAME} PROPERTIES
SUFFIX ".out"
LINK_FLAGS "-mthumb -mabi=aapcs -std=gnu++98 -std=c99 -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections --specs=nano.specs -lc -lnosys -lm -Wl,-Map=${EXECUTABLE_FACTORYLOADER_FILE_NAME}.map"
CXX_STANDARD 11
C_STANDARD 99
)
add_custom_command(TARGET ${EXECUTABLE_FACTORYLOADER_NAME}
POST_BUILD
COMMAND ${CMAKE_SIZE_UTIL} ${EXECUTABLE_FACTORYLOADER_FILE_NAME}.out
COMMAND ${CMAKE_OBJCOPY} -O binary ${EXECUTABLE_FACTORYLOADER_FILE_NAME}.out "${EXECUTABLE_FACTORYLOADER_FILE_NAME}.bin"
COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE_FACTORYLOADER_FILE_NAME}.out "${EXECUTABLE_FACTORYLOADER_FILE_NAME}.hex"
COMMENT "post build steps for ${EXECUTABLE_FACTORYLOADER_FILE_NAME}"
)
# FLASH # FLASH
if (USE_JLINK) if (USE_JLINK)
add_custom_target(FLASH_ERASE add_custom_target(FLASH_ERASE

View File

@ -23,6 +23,7 @@
#include "systemtask/SystemTask.h" #include "systemtask/SystemTask.h"
using namespace Pinetime::Applications; using namespace Pinetime::Applications;
using namespace Pinetime::Applications::Display;
DisplayApp::DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Drivers::Cst816S &touchPanel, DisplayApp::DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Drivers::Cst816S &touchPanel,
Controllers::Battery &batteryController, Controllers::Ble &bleController, Controllers::Battery &batteryController, Controllers::Ble &bleController,
@ -218,7 +219,7 @@ void DisplayApp::IdleState() {
} }
void DisplayApp::PushMessage(DisplayApp::Messages msg) { void DisplayApp::PushMessage(Messages msg) {
BaseType_t xHigherPriorityTaskWoken; BaseType_t xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE; xHigherPriorityTaskWoken = pdFALSE;
xQueueSendFromISR(msgQueue, &msg, &xHigherPriorityTaskWoken); xQueueSendFromISR(msgQueue, &msg, &xHigherPriorityTaskWoken);

View File

@ -13,13 +13,14 @@
#include "components/ble/NotificationManager.h" #include "components/ble/NotificationManager.h"
#include "components/firmwarevalidator/FirmwareValidator.h" #include "components/firmwarevalidator/FirmwareValidator.h"
#include "drivers/Cst816s.h" #include "drivers/Cst816s.h"
#include "DummyLittleVgl.h"
#include <date/date.h> #include <date/date.h>
#include "displayapp/screens/Clock.h" #include "displayapp/screens/Clock.h"
#include "displayapp/screens/Modal.h" #include "displayapp/screens/Modal.h"
#include <drivers/Watchdog.h> #include <drivers/Watchdog.h>
#include "TouchEvents.h" #include "TouchEvents.h"
#include "Apps.h" #include "Apps.h"
#include "Messages.h"
#include "LittleVgl.h"
namespace Pinetime { namespace Pinetime {
@ -30,9 +31,6 @@ namespace Pinetime {
class DisplayApp { class DisplayApp {
public: public:
enum class States {Idle, Running}; enum class States {Idle, Running};
enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, ButtonPushed,
NewNotification, BleFirmwareUpdateStarted };
enum class FullRefreshDirections { None, Up, Down }; enum class FullRefreshDirections { None, Up, Down };
enum class TouchModes { Gestures, Polling }; enum class TouchModes { Gestures, Polling };
@ -42,7 +40,7 @@ namespace Pinetime {
System::SystemTask &systemTask, System::SystemTask &systemTask,
Pinetime::Controllers::NotificationManager& notificationManager); Pinetime::Controllers::NotificationManager& notificationManager);
void Start(); void Start();
void PushMessage(Messages msg); void PushMessage(Display::Messages msg);
void StartApp(Apps app); void StartApp(Apps app);

View File

@ -0,0 +1,72 @@
#include "DisplayAppFactory.h"
#include "DisplayAppFactory.h"
#include <FreeRTOS.h>
#include <task.h>
#include <libraries/log/nrf_log.h>
using namespace Pinetime::Applications;
DisplayApp::DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Drivers::Cst816S &,
Controllers::Battery &batteryController, Controllers::Ble &bleController,
Controllers::DateTime &dateTimeController, Drivers::WatchdogView &watchdog,
System::SystemTask &systemTask,
Pinetime::Controllers::NotificationManager& notificationManager) :
lcd{lcd} {
msgQueue = xQueueCreate(queueSize, itemSize);
}
void DisplayApp::Start() {
if (pdPASS != xTaskCreate(DisplayApp::Process, "displayapp", 512, this, 0, &taskHandle))
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}
void DisplayApp::Process(void *instance) {
auto *app = static_cast<DisplayApp *>(instance);
NRF_LOG_INFO("displayapp task started!");
app->InitHw();
// Send a dummy notification to unlock the lvgl display driver for the first iteration
xTaskNotifyGive(xTaskGetCurrentTaskHandle());
while (1) {
app->Refresh();
}
}
void DisplayApp::InitHw() {
}
void DisplayApp::Refresh() {
static bool hello = false;
if(hello) {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
lcd.DrawPixel(j, i, 0xF000);
}
}
}
else {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
lcd.DrawPixel(j, i, 0x0);
}
}
}
hello = !hello;
vTaskDelay(200);
}
void DisplayApp::PushMessage(Display::Messages msg) {
BaseType_t xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE;
xQueueSendFromISR(msgQueue, &msg, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken) {
/* Actual macro used here is port specific. */
// TODO : should I do something here?
}
}

View File

@ -0,0 +1,55 @@
#pragma once
#include <FreeRTOS.h>
#include <task.h>
#include <drivers/St7789.h>
#include <drivers/SpiMaster.h>
#include <bits/unique_ptr.h>
#include <queue.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 <date/date.h>
#include "displayapp/screens/Clock.h"
#include "displayapp/screens/Modal.h"
#include <drivers/Watchdog.h>
#include "TouchEvents.h"
#include "Apps.h"
#include "Messages.h"
#include "DummyLittleVgl.h"
namespace Pinetime {
namespace System {
class SystemTask;
};
namespace Applications {
class DisplayApp {
public:
DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Drivers::Cst816S &,
Controllers::Battery &batteryController, Controllers::Ble &bleController,
Controllers::DateTime &dateTimeController, Drivers::WatchdogView &watchdog,
System::SystemTask &systemTask,
Pinetime::Controllers::NotificationManager& notificationManager);
void Start();
void PushMessage(Pinetime::Applications::Display::Messages msg);
private:
TaskHandle_t taskHandle;
static void Process(void* instance);
void InitHw();
void Refresh();
Pinetime::Drivers::St7789& lcd;
static constexpr uint8_t queueSize = 10;
static constexpr uint8_t itemSize = 1;
QueueHandle_t msgQueue;
};
}
}

11
src/displayapp/Messages.h Normal file
View File

@ -0,0 +1,11 @@
#pragma once
namespace Pinetime {
namespace Applications {
namespace Display {
enum class Messages : uint8_t {
GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, ButtonPushed,
NewNotification, BleFirmwareUpdateStarted
};
}
}
}

View File

@ -6,7 +6,7 @@
#include <libs/lvgl/src/lv_core/lv_style.h> #include <libs/lvgl/src/lv_core/lv_style.h>
#include <libs/lvgl/src/lv_core/lv_obj.h> #include <libs/lvgl/src/lv_core/lv_obj.h>
#include <drivers/St7789.h> #include <drivers/St7789.h>
#include "displayapp/DummyLittleVgl.h" #include <displayapp/LittleVgl.h>
namespace Pinetime { namespace Pinetime {
namespace Applications { namespace Applications {

View File

@ -13,7 +13,8 @@
#include <components/gfx/Gfx.h> #include <components/gfx/Gfx.h>
#include <drivers/St7789.h> #include <drivers/St7789.h>
#include <components/brightness/BrightnessController.h> #include <components/brightness/BrightnessController.h>
#include "../factory/image.h" #include "factoryImage.h"
#if NRF_LOG_ENABLED #if NRF_LOG_ENABLED
#include "logging/NrfLogger.h" #include "logging/NrfLogger.h"
@ -106,7 +107,7 @@ void Process(void* instance) {
static constexpr uint32_t memoryChunkSize = 200; static constexpr uint32_t memoryChunkSize = 200;
uint8_t writeBuffer[memoryChunkSize]; uint8_t writeBuffer[memoryChunkSize];
for(int offset = 0; offset < sizeof(factoryImage); offset+=memoryChunkSize) { for(size_t offset = 0; offset < sizeof(factoryImage); offset+=memoryChunkSize) {
std::memcpy(writeBuffer, &factoryImage[offset], memoryChunkSize); std::memcpy(writeBuffer, &factoryImage[offset], memoryChunkSize);
spiNorFlash.Write(offset, writeBuffer, memoryChunkSize); spiNorFlash.Write(offset, writeBuffer, memoryChunkSize);
} }

View File

@ -7,7 +7,7 @@
#include <os/os_cputime.h> #include <os/os_cputime.h>
#include <libraries/timer/app_timer.h> #include <libraries/timer/app_timer.h>
#include <libraries/gpiote/app_gpiote.h> #include <libraries/gpiote/app_gpiote.h>
#include "displayapp/DisplayApp.h"
#include <softdevice/common/nrf_sdh.h> #include <softdevice/common/nrf_sdh.h>
#include "components/datetime/DateTimeController.h" #include "components/datetime/DateTimeController.h"
#include "components/battery/BatteryController.h" #include "components/battery/BatteryController.h"
@ -16,7 +16,7 @@
#include <drivers/St7789.h> #include <drivers/St7789.h>
#include <drivers/SpiMaster.h> #include <drivers/SpiMaster.h>
#include <drivers/Spi.h> #include <drivers/Spi.h>
#include "displayapp/DummyLittleVgl.h"
#include <systemtask/SystemTask.h> #include <systemtask/SystemTask.h>
#include <nimble/nimble_port_freertos.h> #include <nimble/nimble_port_freertos.h>
#include <nimble/npl_freertos.h> #include <nimble/npl_freertos.h>
@ -70,7 +70,18 @@ Pinetime::Drivers::TwiMaster twiMaster{Pinetime::Drivers::TwiMaster::Modules::TW
Pinetime::Drivers::TwiMaster::Parameters { Pinetime::Drivers::TwiMaster::Parameters {
MaxTwiFrequencyWithoutHardwareBug, pinTwiSda, pinTwiScl}}; MaxTwiFrequencyWithoutHardwareBug, pinTwiSda, pinTwiScl}};
Pinetime::Drivers::Cst816S touchPanel {twiMaster, touchPanelTwiAddress}; Pinetime::Drivers::Cst816S touchPanel {twiMaster, touchPanelTwiAddress};
#ifdef PINETIME_IS_FACTORY
static constexpr bool isFactory = true;
#include "displayapp/DummyLittleVgl.h"
#include "displayapp/DisplayAppFactory.h"
Pinetime::Components::LittleVgl lvgl {lcd, touchPanel}; Pinetime::Components::LittleVgl lvgl {lcd, touchPanel};
#else
static constexpr bool isFactory = false;
#include "displayapp/LittleVgl.h"
#include "displayapp/DisplayApp.h"
Pinetime::Components::LittleVgl lvgl {lcd, touchPanel};
#endif
TimerHandle_t debounceTimer; TimerHandle_t debounceTimer;
@ -84,6 +95,8 @@ std::unique_ptr<Pinetime::System::SystemTask> systemTask;
Pinetime::Controllers::NotificationManager notificationManager; Pinetime::Controllers::NotificationManager notificationManager;
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 == pinTouchIrq) { if(pin == pinTouchIrq) {
systemTask->OnTouchEvent(); systemTask->OnTouchEvent();
@ -97,7 +110,8 @@ void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action
extern "C" { extern "C" {
void vApplicationIdleHook(void) { void vApplicationIdleHook(void) {
lv_tick_inc(1); if(!isFactory)
lv_tick_inc(1);
} }
} }

View File

@ -1,7 +1,6 @@
#include <libraries/log/nrf_log.h> #include <libraries/log/nrf_log.h>
#include <libraries/gpiote/app_gpiote.h> #include <libraries/gpiote/app_gpiote.h>
#include <drivers/Cst816s.h> #include <drivers/Cst816s.h>
#include "displayapp/DummyLittleVgl.h"
#include <hal/nrf_rtc.h> #include <hal/nrf_rtc.h>
#include "components/ble/NotificationManager.h" #include "components/ble/NotificationManager.h"
#include <host/ble_gatt.h> #include <host/ble_gatt.h>
@ -33,7 +32,7 @@ SystemTask::SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd,
Controllers::DateTime &dateTimeController, Controllers::DateTime &dateTimeController,
Pinetime::Controllers::NotificationManager& notificationManager) : Pinetime::Controllers::NotificationManager& notificationManager) :
spi{spi}, lcd{lcd}, spiNorFlash{spiNorFlash}, spi{spi}, lcd{lcd}, spiNorFlash{spiNorFlash},
twiMaster{twiMaster}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController}, gfx{lcd}, twiMaster{twiMaster}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController},
bleController{bleController}, dateTimeController{dateTimeController}, bleController{bleController}, dateTimeController{dateTimeController},
watchdog{}, watchdogView{watchdog}, notificationManager{notificationManager}, watchdog{}, watchdogView{watchdog}, notificationManager{notificationManager},
nimbleController(*this, bleController,dateTimeController, notificationManager, batteryController, spiNorFlash) { nimbleController(*this, bleController,dateTimeController, notificationManager, batteryController, spiNorFlash) {
@ -65,20 +64,16 @@ void SystemTask::Work() {
brightnessController.Init(); brightnessController.Init();
lcd.Init(); lcd.Init();
lcd.VerticalScrollDefinition(0, 240, 0);
lcd.VerticalScrollStartAddress(0);
gfx.Init();
twiMaster.Init(); twiMaster.Init();
touchPanel.Init(); touchPanel.Init();
batteryController.Init(); batteryController.Init();
// displayApp.reset(new Pinetime::Applications::DisplayApp(lcd, lvgl, touchPanel, batteryController, bleController, displayApp.reset(new Pinetime::Applications::DisplayApp(lcd, lvgl, touchPanel, batteryController, bleController,
// dateTimeController, watchdogView, *this, notificationManager)); dateTimeController, watchdogView, *this, notificationManager));
// displayApp->Start(); displayApp->Start();
batteryController.Update(); batteryController.Update();
// displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateBatteryLevel); displayApp->PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel);
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_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);
@ -122,8 +117,8 @@ void SystemTask::Work() {
lcd.Wakeup(); lcd.Wakeup();
touchPanel.Wakeup(); touchPanel.Wakeup();
// displayApp->PushMessage(Applications::DisplayApp::Messages::GoToRunning); displayApp->PushMessage(Pinetime::Applications::Display::Messages::GoToRunning);
// displayApp->PushMessage(Applications::DisplayApp::Messages::UpdateBatteryLevel); displayApp->PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel);
xTimerStart(idleTimer, 0); xTimerStart(idleTimer, 0);
nimbleController.StartAdvertising(); nimbleController.StartAdvertising();
@ -134,15 +129,15 @@ void SystemTask::Work() {
isGoingToSleep = true; isGoingToSleep = true;
NRF_LOG_INFO("[systemtask] Going to sleep"); NRF_LOG_INFO("[systemtask] Going to sleep");
xTimerStop(idleTimer, 0); xTimerStop(idleTimer, 0);
// displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::GoToSleep); displayApp->PushMessage(Pinetime::Applications::Display::Messages::GoToSleep);
break; break;
case Messages::OnNewTime: case Messages::OnNewTime:
ReloadIdleTimer(); ReloadIdleTimer();
// displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateDateTime); displayApp->PushMessage(Pinetime::Applications::Display::Messages::UpdateDateTime);
break; break;
case Messages::OnNewNotification: case Messages::OnNewNotification:
if(isSleeping && !isWakingUp) GoToRunning(); if(isSleeping && !isWakingUp) GoToRunning();
// displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::NewNotification); displayApp->PushMessage(Pinetime::Applications::Display::Messages::NewNotification);
break; break;
case Messages::BleConnected: case Messages::BleConnected:
ReloadIdleTimer(); ReloadIdleTimer();
@ -152,7 +147,7 @@ void SystemTask::Work() {
case Messages::BleFirmwareUpdateStarted: case Messages::BleFirmwareUpdateStarted:
doNotGoToSleep = true; doNotGoToSleep = true;
if(isSleeping && !isWakingUp) GoToRunning(); if(isSleeping && !isWakingUp) GoToRunning();
// displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::BleFirmwareUpdateStarted); displayApp->PushMessage(Pinetime::Applications::Display::Messages::BleFirmwareUpdateStarted);
break; break;
case Messages::BleFirmwareUpdateFinished: case Messages::BleFirmwareUpdateFinished:
doNotGoToSleep = false; doNotGoToSleep = false;
@ -200,25 +195,6 @@ void SystemTask::Work() {
batteryController.Update(); batteryController.Update();
monitor.Process(); monitor.Process();
static bool hello = false;
if(hello) {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
lcd.DrawPixel(j, i, 0xffff);
}
}
}
else {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
lcd.DrawPixel(j, i, 0x0);
}
}
}
hello = !hello;
if(!nrf_gpio_pin_read(pinButton)) if(!nrf_gpio_pin_read(pinButton))
watchdog.Kick(); watchdog.Kick();
@ -232,7 +208,7 @@ void SystemTask::OnButtonPushed() {
if(!isSleeping) { if(!isSleeping) {
NRF_LOG_INFO("[systemtask] Button pushed"); NRF_LOG_INFO("[systemtask] Button pushed");
PushMessage(Messages::OnButtonEvent); PushMessage(Messages::OnButtonEvent);
// displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::ButtonPushed); displayApp->PushMessage(Pinetime::Applications::Display::Messages::ButtonPushed);
} }
else { else {
if(!isWakingUp) { if(!isWakingUp) {
@ -252,7 +228,7 @@ void SystemTask::OnTouchEvent() {
NRF_LOG_INFO("[systemtask] Touch event"); NRF_LOG_INFO("[systemtask] Touch event");
if(!isSleeping) { if(!isSleeping) {
PushMessage(Messages::OnTouchEvent); PushMessage(Messages::OnTouchEvent);
// displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::TouchEvent); displayApp->PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
} }
} }

View File

@ -7,13 +7,21 @@
#include <drivers/SpiMaster.h> #include <drivers/SpiMaster.h>
#include <drivers/St7789.h> #include <drivers/St7789.h>
#include "components/battery/BatteryController.h" #include "components/battery/BatteryController.h"
#ifdef PINETIME_IS_FACTORY
#include "displayapp/DisplayAppFactory.h"
#include "displayapp/DummyLittleVgl.h"
#else
#include "displayapp/DisplayApp.h" #include "displayapp/DisplayApp.h"
#include "displayapp/LittleVgl.h"
#endif
#include <drivers/Watchdog.h> #include <drivers/Watchdog.h>
#include <drivers/SpiNorFlash.h> #include <drivers/SpiNorFlash.h>
#include "SystemMonitor.h" #include "SystemMonitor.h"
#include "components/ble/NimbleController.h" #include "components/ble/NimbleController.h"
#include "timers.h" #include "timers.h"
namespace Pinetime { namespace Pinetime {
namespace System { namespace System {
class SystemTask { class SystemTask {
@ -51,8 +59,7 @@ namespace Pinetime {
Pinetime::Drivers::Cst816S& touchPanel; Pinetime::Drivers::Cst816S& touchPanel;
Pinetime::Components::LittleVgl& lvgl; Pinetime::Components::LittleVgl& lvgl;
Pinetime::Controllers::Battery& batteryController; Pinetime::Controllers::Battery& batteryController;
//std::unique_ptr<Pinetime::Applications::DisplayApp> displayApp; std::unique_ptr<Pinetime::Applications::DisplayApp> displayApp;
Pinetime::Components::Gfx gfx;
Pinetime::Controllers::Ble& bleController; Pinetime::Controllers::Ble& bleController;
Pinetime::Controllers::DateTime& dateTimeController; Pinetime::Controllers::DateTime& dateTimeController;
QueueHandle_t systemTasksMsgQueue; QueueHandle_t systemTasksMsgQueue;