Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new hardware abstraction from InfiniTime using C++20 concepts. #73

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
46 changes: 23 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ project(InfiniSim VERSION ${PROJECT_VERSION} LANGUAGES C CXX)
# https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html
string(COMPARE EQUAL "${CMAKE_CXX_STANDARD}" "" no_cmake_cxx_standard_set)
if(no_cmake_cxx_standard_set)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
message(STATUS "Using default C++ standard ${CMAKE_CXX_STANDARD}")
Expand Down Expand Up @@ -134,20 +134,23 @@ target_sources(infinisim PUBLIC
sim/components/heartrate/HeartRateController.cpp
sim/components/motion/MotionController.h
sim/components/motion/MotionController.cpp
sim/drivers/Watchdog.h
sim/drivers/Watchdog.cpp
sim/drivers/Bma421.h
sim/drivers/Bma421.cpp
sim/drivers/Cst816s.h
sim/drivers/Cst816s.cpp
sim/drivers/Hrs3300.h
sim/drivers/Hrs3300.cpp
sim/drivers/SpiMaster.h
sim/drivers/SpiMaster.cpp
sim/drivers/TwiMaster.h
sim/drivers/TwiMaster.cpp
sim/drivers/SpiNorFlash.h
sim/drivers/SpiNorFlash.cpp
sim/drivers/infinisim/Watchdog.h
sim/drivers/infinisim/Watchdog.cpp
sim/drivers/infinisim/Bma421.h
sim/drivers/infinisim/Bma421.cpp
sim/drivers/infinisim/SdlTouchPanel.h
sim/drivers/infinisim/SdlTouchPanel.cpp
sim/drivers/infinisim/Hrs3300.h
sim/drivers/infinisim/Hrs3300.cpp
sim/drivers/infinisim/SpiMaster.h
sim/drivers/infinisim/Spi.h
sim/drivers/infinisim/Spi.cpp
sim/drivers/infinisim/TwiMaster.h
sim/drivers/infinisim/TwiMaster.cpp
sim/drivers/infinisim/SpiNorFlash.h
sim/drivers/infinisim/SpiNorFlash.cpp
sim/drivers/infinisim/St7789.cpp
sim/drivers/infinisim/St7789.h
sim/heartratetask/HeartRateTask.h
sim/heartratetask/HeartRateTask.cpp
)
Expand Down Expand Up @@ -214,9 +217,6 @@ target_sources(infinisim PUBLIC
${InfiniTime_DIR}/src/components/timer/TimerController.cpp
${InfiniTime_DIR}/src/drivers/PinMap.h
${InfiniTime_DIR}/src/drivers/Spi.h
${InfiniTime_DIR}/src/drivers/Spi.cpp
${InfiniTime_DIR}/src/drivers/St7789.h
${InfiniTime_DIR}/src/drivers/St7789.cpp
${InfiniTime_DIR}/src/touchhandler/TouchHandler.h
${InfiniTime_DIR}/src/touchhandler/TouchHandler.cpp
${InfiniTime_DIR}/src/systemtask/SystemTask.h
Expand Down Expand Up @@ -335,13 +335,13 @@ add_executable(littlefs-do
${InfiniTime_DIR}/src/components/fs/FS.h
${InfiniTime_DIR}/src/components/fs/FS.cpp
# dependencies for FS.h
sim/drivers/SpiNorFlash.h
sim/drivers/SpiNorFlash.cpp
sim/drivers/infinisim/SpiNorFlash.h
sim/drivers/infinisim/SpiNorFlash.cpp
# dependencies for SpiNorFlash.h
${InfiniTime_DIR}/src/drivers/Spi.h
${InfiniTime_DIR}/src/drivers/Spi.cpp
sim/drivers/SpiMaster.h
sim/drivers/SpiMaster.cpp
sim/drivers/infinisim/SpiMaster.h
sim/drivers/infinisim/Spi.h
sim/drivers/infinisim/Spi.cpp

${InfiniTime_DIR}/src/components/settings/Settings.h
${InfiniTime_DIR}/src/components/settings/Settings.cpp
Expand Down
2 changes: 1 addition & 1 deletion littlefs-do-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "components/fs/FS.h"
#include "components/settings/Settings.h"
#include "drivers/SpiNorFlash.h"
#include "drivers/infinisim/SpiNorFlash.h"

#include "nlohmann/json.hpp"
#include "miniz.h"
Expand Down
101 changes: 48 additions & 53 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,31 @@
#else
#include "displayapp/lv_pinetime_theme.h"
#endif
#include <drivers/Hrs3300.h>
#include <drivers/Bma421.h>
#include "sim/drivers/infinisim/Bma421.h"
#include "sim/drivers/infinisim/Hrs3300.h"

#include "BootloaderVersion.h"
#include "buttonhandler/ButtonHandler.h"
#include "components/battery/BatteryController.h"
#include "components/ble/BleController.h"
#include "components/ble/NotificationManager.h"
#include "components/brightness/BrightnessController.h"
#include "components/motor/MotorController.h"
#include "components/datetime/DateTimeController.h"
#include "components/heartrate/HeartRateController.h"
#include "components/fs/FS.h"
#include "drivers/Spi.h"
#include "drivers/SpiMaster.h"
#include "drivers/SpiNorFlash.h"
#include "drivers/St7789.h"
#include "drivers/TwiMaster.h"
#include "drivers/Cst816s.h"
#include "components/heartrate/HeartRateController.h"
#include "components/motor/MotorController.h"
#include "drivers/PinMap.h"
#include "drivers/Spi.h"
#include "drivers/Display.h"
#include "drivers/Watchdog.h"
#include "drivers/WatchdogView.h"
#include "sim/drivers/infinisim/SdlTouchPanel.h"
#include "sim/drivers/infinisim/SpiMaster.h"
#include "sim/drivers/infinisim/SpiNorFlash.h"
#include "sim/drivers/infinisim/TwiMaster.h"
#include "sim/drivers/infinisim/Watchdog.h"
#include "systemtask/SystemTask.h"
#include "drivers/PinMap.h"
#include "touchhandler/TouchHandler.h"
#include "buttonhandler/ButtonHandler.h"

// get the simulator-headers
#include "displayapp/DisplayApp.h"
Expand All @@ -70,6 +72,14 @@
#endif
#include <gif.h>

#include "port/Spi.h"
#include "port/SpiMaster.h"
#include "port/SpiNorFlash.h"
#include "port/TwiMaster.h"
#include "port/TouchPanel.h"
#include "port/Watchdog.h"
#include "port/Display.h"

/*********************
* DEFINES
*********************/
Expand Down Expand Up @@ -283,44 +293,28 @@ void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action
/**********************
* GLOBAL FUNCTIONS
**********************/
constexpr NRF_TWIM_Type *NRF_TWIM1 = nullptr;


static constexpr uint8_t touchPanelTwiAddress = 0x15;
static constexpr uint8_t motionSensorTwiAddress = 0x18;
static constexpr uint8_t heartRateSensorTwiAddress = 0x44;

Pinetime::Drivers::SpiMaster spi {Pinetime::Drivers::SpiMaster::SpiModule::SPI0,
{Pinetime::Drivers::SpiMaster::BitOrder::Msb_Lsb,
Pinetime::Drivers::SpiMaster::Modes::Mode3,
Pinetime::Drivers::SpiMaster::Frequencies::Freq8Mhz,
Pinetime::PinMap::SpiSck,
Pinetime::PinMap::SpiMosi,
Pinetime::PinMap::SpiMiso}};

Pinetime::Drivers::Spi lcdSpi {spi, Pinetime::PinMap::SpiLcdCsn};
Pinetime::Drivers::St7789 lcd {lcdSpi, Pinetime::PinMap::LcdDataCommand};

Pinetime::Drivers::Spi flashSpi {spi, Pinetime::PinMap::SpiFlashCsn};
Pinetime::Drivers::SpiNorFlash spiNorFlash {"spiNorFlash.raw"};

// 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
// at ~390Khz with correct timings.
static constexpr uint32_t MaxTwiFrequencyWithoutHardwareBug {0x06200000};
Pinetime::Drivers::TwiMaster twiMaster {NRF_TWIM1, MaxTwiFrequencyWithoutHardwareBug, Pinetime::PinMap::TwiSda, Pinetime::PinMap::TwiScl};
Pinetime::Drivers::Cst816S touchPanel; // {twiMaster, touchPanelTwiAddress};
//#ifdef PINETIME_IS_RECOVERY
// #include "displayapp/DummyLittleVgl.h"
// #include "displayapp/DisplayAppRecovery.h"
//#else
// #include "displayapp/LittleVgl.h"
// #include "displayapp/DisplayApp.h"
//#endif

Pinetime::Drivers::Infinisim::SpiMaster spiImpl {};
Pinetime::Drivers::SpiMaster spi {spiImpl};

Pinetime::Drivers::Infinisim::Displays::St7789 lcdImpl;
Pinetime::Drivers::Display lcd {lcdImpl};

Pinetime::Drivers::Infinisim::SpiNorFlash spiNorFlashImpl {"spiNorFlash.raw"};
Pinetime::Drivers::SpiNorFlash spiNorFlash {spiNorFlashImpl};

Pinetime::Drivers::Infinisim::TwiMaster twiMasterImpl {};
Pinetime::Drivers::TwiMaster twiMaster{twiMasterImpl};

Pinetime::Drivers::Infinisim::TouchPanels::SdlTouchPanel touchPanelImpl;
Pinetime::Drivers::TouchPanel touchPanel {touchPanelImpl};

Pinetime::Components::LittleVgl lvgl {lcd, touchPanel};

Pinetime::Drivers::Bma421 motionSensor {twiMaster, motionSensorTwiAddress};
Pinetime::Drivers::Hrs3300 heartRateSensor {twiMaster, heartRateSensorTwiAddress};
Pinetime::Drivers::Infinisim::MotionSensors::Bma421 motionSensorImpl{};
Pinetime::Drivers::MotionSensor motionSensor{motionSensorImpl};
Pinetime::Drivers::Infinisim::HeartRateSensors::Hrs3300 heartRateSensorImpl;
Pinetime::Drivers::HeartRateSensor heartRateSensor{heartRateSensorImpl};

TimerHandle_t debounceTimer;
TimerHandle_t debounceChargeTimer;
Expand All @@ -335,7 +329,8 @@ Pinetime::Controllers::Settings settingsController {fs};
Pinetime::Controllers::MotorController motorController {};

Pinetime::Controllers::DateTime dateTimeController {settingsController};
Pinetime::Drivers::Watchdog watchdog;
Pinetime::Drivers::Infinisim::Watchdogs::Watchdog watchdogImpl;
Pinetime::Drivers::Watchdog watchdog{watchdogImpl};
Pinetime::Drivers::WatchdogView watchdogView(watchdog);
Pinetime::Controllers::NotificationManager notificationManager;
Pinetime::Controllers::MotionController motionController;
Expand Down Expand Up @@ -686,12 +681,12 @@ class Framework {
} else if (key == 'P') {
this->print_memory_usage = false;
} else if (key == 's') {
motionSensor.steps += 500;
motionSensorImpl.steps += 500;
} else if (key == 'S') {
if (motionSensor.steps > 500) {
motionSensor.steps -= 500;
if (motionSensorImpl.steps > 500) {
motionSensorImpl.steps -= 500;
} else {
motionSensor.steps = 0;
motionSensorImpl.steps = 0;
}
} else if (key == 'h') {
if (heartRateController.State() == Pinetime::Controllers::HeartRateController::States::Stopped) {
Expand Down
4 changes: 0 additions & 4 deletions sim/components/ble/NimbleController.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
//#include "components/ble/FSService.h"

namespace Pinetime {
namespace Drivers {
class SpiNorFlash;
}

namespace System {
class SystemTask;
}
Expand Down
6 changes: 3 additions & 3 deletions sim/components/motion/MotionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ int32_t MotionController::currentShakeSpeed() {
void MotionController::IsSensorOk(bool isOk) {
isSensorOk = isOk;
}
void MotionController::Init(Pinetime::Drivers::Bma421::DeviceTypes types) {
void MotionController::Init(Pinetime::Drivers::MotionSensors::DeviceTypes types) {
switch (types) {
case Drivers::Bma421::DeviceTypes::BMA421:
case Drivers::MotionSensors::DeviceTypes::BMA421:
this->deviceType = DeviceTypes::BMA421;
break;
case Drivers::Bma421::DeviceTypes::BMA425:
case Drivers::MotionSensors::DeviceTypes::BMA425:
this->deviceType = DeviceTypes::BMA425;
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions sim/components/motion/MotionController.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "drivers/MotionSensor.h"
#include <cstdint>
#include <drivers/Bma421.h>
//#include <components/ble/MotionService.h>

namespace Pinetime {
Expand Down Expand Up @@ -48,7 +48,7 @@ namespace Pinetime {
return deviceType;
}

void Init(Pinetime::Drivers::Bma421::DeviceTypes types);
void Init(Pinetime::Drivers::MotionSensors::DeviceTypes types);
// void SetService(Pinetime::Controllers::MotionService* service);

private:
Expand Down
8 changes: 5 additions & 3 deletions sim/displayapp/LittleVgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#include <task.h>
#include <timers.h>
////#include <projdefs.h>
#include "drivers/Cst816s.h"
#include "drivers/St7789.h"
#include "drivers/TouchPanel.h"
#include "drivers/Display.h"
#include "port/Display.h"


// lv-sim monitor display driver for monitor_flush() function
#include "lv_drivers/display/monitor.h"
Expand Down Expand Up @@ -41,7 +43,7 @@ bool touchpad_read(lv_indev_drv_t* indev_drv, lv_indev_data_t* data) {
return lvgl->GetTouchPadInfo(data);
}

LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Drivers::Cst816S& touchPanel)
LittleVgl::LittleVgl(Pinetime::Drivers::Display& lcd, Pinetime::Drivers::TouchPanel& touchPanel)
: lcd {lcd}, touchPanel {touchPanel} {
}

Expand Down
13 changes: 5 additions & 8 deletions sim/displayapp/LittleVgl.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
#pragma once

#include "port/TouchPanel.h"
#include "port/Display.h"
#include <lvgl/lvgl.h>

namespace Pinetime {
namespace Drivers {
class Cst816S;
class St7789;
}

namespace Components {
class LittleVgl {
public:
enum class FullRefreshDirections { None, Up, Down, Left, Right, LeftAnim, RightAnim };
LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Drivers::Cst816S& touchPanel);
LittleVgl(Pinetime::Drivers::Display& lcd, Pinetime::Drivers::TouchPanel& touchPanel);

LittleVgl(const LittleVgl&) = delete;
LittleVgl& operator=(const LittleVgl&) = delete;
Expand All @@ -39,8 +36,8 @@ namespace Pinetime {
void InitTouchpad();
void InitTheme();

Pinetime::Drivers::St7789& lcd;
Pinetime::Drivers::Cst816S& touchPanel;
Pinetime::Drivers::Display& lcd;
Pinetime::Drivers::TouchPanel& touchPanel;

lv_disp_buf_t disp_buf_2;
lv_color_t buf2_1[LV_HOR_RES_MAX * 4];
Expand Down
Loading