~aleteoryx/muditaos

ec56afc93393af6c84ba69a2cf9c5ca5d0b83cf2 — Maciej-Mudita 5 years ago f270240
[EGD-5381] Add Low Power Drivers

Peripherals clock synchronization dependent on PLL2
43 files changed, 766 insertions(+), 76 deletions(-)

M config/ProjectConfig.cmake
M module-bsp/CMakeLists.txt
M module-bsp/board/cross/eMMC/eMMC.cpp
M module-bsp/board/cross/eMMC/eMMC.hpp
M module-bsp/board/linux/lpm/LinuxLPM.cpp
M module-bsp/board/linux/lpm/LinuxLPM.h
A module-bsp/board/rt1051/bsp/lpm/ClockState.cpp
A module-bsp/board/rt1051/bsp/lpm/ClockState.hpp
M module-bsp/board/rt1051/bsp/lpm/RT1051LPM.cpp
M module-bsp/board/rt1051/bsp/lpm/RT1051LPM.hpp
A module-bsp/board/rt1051/drivers/RT1051DriverLPSPI.cpp
A module-bsp/board/rt1051/drivers/RT1051DriverLPSPI.hpp
A module-bsp/board/rt1051/drivers/RT1051DriverPLL2.cpp
A module-bsp/board/rt1051/drivers/RT1051DriverPLL2.hpp
A module-bsp/board/rt1051/drivers/RT1051DriverSEMC.cpp
A module-bsp/board/rt1051/drivers/RT1051DriverSEMC.hpp
A module-bsp/board/rt1051/drivers/RT1051DriverUSDHC.cpp
A module-bsp/board/rt1051/drivers/RT1051DriverUSDHC.hpp
M module-bsp/bsp/BoardDefinitions.hpp
M module-bsp/bsp/lpm/bsp_lpm.cpp
M module-bsp/bsp/lpm/bsp_lpm.hpp
A module-bsp/devices/Device.cpp
A module-bsp/devices/Device.hpp
A module-bsp/drivers/lpspi/DriverLPSPI.cpp
A module-bsp/drivers/lpspi/DriverLPSPI.hpp
A module-bsp/drivers/semc/DriverSEMC.cpp
A module-bsp/drivers/semc/DriverSEMC.hpp
A module-bsp/drivers/usdhc/DriverUSDHC.cpp
A module-bsp/drivers/usdhc/DriverUSDHC.hpp
M module-bsp/targets/Target_RT1051.cmake
M module-services/service-eink/EinkDisplay.cpp
M module-services/service-eink/EinkDisplay.hpp
M module-services/service-eink/ServiceEink.cpp
M module-sys/CMakeLists.txt
A module-sys/SystemManager/DeviceManager.cpp
A module-sys/SystemManager/DeviceManager.hpp
M module-sys/SystemManager/PowerManager.cpp
M module-sys/SystemManager/PowerManager.hpp
M module-sys/SystemManager/SystemManager.cpp
M module-sys/SystemManager/SystemManager.hpp
A module-sys/SystemManager/messages/DeviceRegistrationMessage.hpp
M module-utils/Utils.hpp
M source/MessageType.hpp
M config/ProjectConfig.cmake => config/ProjectConfig.cmake +1 -0
@@ 46,6 46,7 @@ set(PROJECT_CONFIG_DEFINITIONS
        PROJECT_CONFIG_USER_DYNMEM_SIZE=9*1024*1024
        USB_DEVICE_VENDOR_ID=${USB_DEVICE_VENDOR_ID}
        USB_DEVICE_PRODUCT_ID=${USB_DEVICE_PRODUCT_ID}
        MAGIC_ENUM_RANGE_MAX=256
        CACHE INTERNAL ""
        )


M module-bsp/CMakeLists.txt => module-bsp/CMakeLists.txt +4 -2
@@ 12,11 12,13 @@ set(SOURCES
        "${CMAKE_CURRENT_SOURCE_DIR}/drivers/dma/DriverDMA.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/drivers/i2c/DriverI2C.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/drivers/pwm/DriverPWM.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/drivers/sai/DriverSAI.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/drivers/lpspi/DriverLPSPI.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/drivers/usdhc/DriverUSDHC.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/drivers/semc/DriverSEMC.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/drivers/gpio/DriverGPIO.cpp"
        board/linux/lpm/LinuxLPM.cpp board/linux/lpm/LinuxLPM.h
        "${CMAKE_CURRENT_SOURCE_DIR}/bsp/bluetooth/Bluetooth.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/bsp/common.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/devices/Device.cpp"    
        )

if (NOT ${PROJECT_TARGET} STREQUAL "TARGET_Linux")

M module-bsp/board/cross/eMMC/eMMC.cpp => module-bsp/board/cross/eMMC/eMMC.cpp +9 -1
@@ 20,6 20,8 @@ namespace bsp

    RetCode eMMC::Init()
    {
        driverUSDHC = drivers::DriverUSDHC::Create(
            "EMMC", static_cast<drivers::USDHCInstances>(BoardDefinitions::EMMC_USDHC_INSTANCE));
#if defined(TARGET_RT1051)

        // pll = DriverPLL::Create(static_cast<PLLInstances >(BoardDefinitions ::EMMC_PLL),DriverPLLParams{});


@@ 56,7 58,9 @@ namespace bsp
    RetCode eMMC::ReadBlocks(uint8_t *buffer, uint32_t startBlock, uint32_t blockCount)
    {
#if defined(TARGET_RT1051)
        driverUSDHC->Enable();
        auto ret = MMC_ReadBlocks(&mmcCard, buffer, startBlock, blockCount);
        driverUSDHC->Disable();
        if (ret != kStatus_Success) {
            return RetCode::Failure;
        }


@@ 71,7 75,9 @@ namespace bsp
    RetCode eMMC::WriteBlocks(const uint8_t *buffer, uint32_t startBlock, uint32_t blockCount)
    {
#if defined(TARGET_RT1051)
        driverUSDHC->Enable();
        auto ret = MMC_WriteBlocks(&mmcCard, buffer, startBlock, blockCount);
        driverUSDHC->Disable();
        if (ret != kStatus_Success) {
            return RetCode::Failure;
        }


@@ 86,7 92,9 @@ namespace bsp
    RetCode eMMC::SwitchPartition(eMMC::Partition partition)
    {
#if defined(TARGET_RT1051)
        driverUSDHC->Enable();
        auto ret = MMC_SelectPartition(&mmcCard, static_cast<mmc_access_partition_t>(partition));
        driverUSDHC->Disable();
        if (ret != kStatus_Success) {
            return RetCode::Failure;
        }


@@ 98,4 106,4 @@ namespace bsp
#endif
    }

} // namespace bsp
\ No newline at end of file
} // namespace bsp

M module-bsp/board/cross/eMMC/eMMC.hpp => module-bsp/board/cross/eMMC/eMMC.hpp +2 -0
@@ 15,6 15,7 @@
#endif

#include "bsp/common.hpp"
#include "drivers/usdhc/DriverUSDHC.hpp"

namespace bsp
{


@@ 55,6 56,7 @@ namespace bsp
#else
#error "Unsupported target"
#endif
        std::shared_ptr<drivers::DriverUSDHC> driverUSDHC;
    };

} // namespace bsp

M module-bsp/board/linux/lpm/LinuxLPM.cpp => module-bsp/board/linux/lpm/LinuxLPM.cpp +0 -4
@@ 30,8 30,4 @@ namespace bsp
        currentOscSource = source;
    }

    void LinuxLPM::SwitchPll2State(bsp::LowPowerMode::Pll2State state)
    {
        currentPll2State = state;
    }
} // namespace bsp

M module-bsp/board/linux/lpm/LinuxLPM.h => module-bsp/board/linux/lpm/LinuxLPM.h +0 -1
@@ 16,7 16,6 @@ namespace bsp
        int32_t Reboot() override final;
        void SetCpuFrequency(CpuFrequency freq) final;
        void SwitchOscillatorSource(OscillatorSource source) final;
        void SwitchPll2State(Pll2State state) final;
    };

} // namespace bsp

A module-bsp/board/rt1051/bsp/lpm/ClockState.cpp => module-bsp/board/rt1051/bsp/lpm/ClockState.cpp +19 -0
@@ 0,0 1,19 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "ClockState.hpp"

namespace bsp
{
    inline constexpr uint8_t CCM_TupleShift{8};
    inline constexpr uint8_t CCM_TupleMask{0x1F};
    inline constexpr uint32_t ClockNeededRunWaitMode{kCLOCK_ClockNeededRunWait};

    bool IsClockEnabled(clock_ip_name_t name)
    {
        const auto index = static_cast<uint32_t>(name) >> CCM_TupleShift;
        const auto shift = static_cast<uint32_t>(name) & CCM_TupleMask;

        return ((*reinterpret_cast<volatile uint32_t *>(&CCM->CCGR0 + index)) & (ClockNeededRunWaitMode << shift));
    }
}; // namespace bsp

A module-bsp/board/rt1051/bsp/lpm/ClockState.hpp => module-bsp/board/rt1051/bsp/lpm/ClockState.hpp +11 -0
@@ 0,0 1,11 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <fsl_clock.h>

namespace bsp
{
    [[nodiscard]] bool IsClockEnabled(clock_ip_name_t name);
}

M module-bsp/board/rt1051/bsp/lpm/RT1051LPM.cpp => module-bsp/board/rt1051/bsp/lpm/RT1051LPM.cpp +1 -31
@@ 10,6 10,7 @@
#include <clock_config.h>
#include <fsl_clock.h>
#include <fsl_dcdc.h>
#include "ClockState.hpp"

namespace bsp
{


@@ 102,35 103,4 @@ namespace bsp
        currentOscSource = source;
    }

    void RT1051LPM::SwitchPll2State(bsp::LowPowerMode::Pll2State state)
    {
        if (state == bsp::LowPowerMode::Pll2State::Disable) {
            if (IsClockEnabled(kCLOCK_Lpspi1) || IsClockEnabled(kCLOCK_Lpspi2) || IsClockEnabled(kCLOCK_Lpspi3) ||
                IsClockEnabled(kCLOCK_Lpspi4) || IsClockEnabled(kCLOCK_Usdhc1) || IsClockEnabled(kCLOCK_Usdhc2)) {
                return;
            }

            /// First switch external RAM clock
            CLOCK_SetMux(kCLOCK_SemcMux, 0);
            /// Then turn off PLL2
            clkPLL2setup(CLK_DISABLE);
        }
        else {
            /// First turn on PLL2
            clkPLL2setup(CLK_ENABLE);
            /// Then switch external RAM clock
            CLOCK_SetMux(kCLOCK_SemcMux, 1);
        }

        currentPll2State = state;
    }

    bool RT1051LPM::IsClockEnabled(clock_ip_name_t name) const noexcept
    {
        const auto index = static_cast<uint32_t>(name) >> CCM_TupleShift;
        const auto shift = static_cast<uint32_t>(name) & CCM_TupleMask;

        return ((*reinterpret_cast<volatile uint32_t *>(&CCM->CCGR0 + index)) & (ClockNeededRunWaitMode << shift));
    }

} // namespace bsp

M module-bsp/board/rt1051/bsp/lpm/RT1051LPM.hpp => module-bsp/board/rt1051/bsp/lpm/RT1051LPM.hpp +0 -7
@@ 7,14 7,10 @@
#include "bsp/lpm/bsp_lpm.hpp"
#include "drivers/gpio/DriverGPIO.hpp"
#include "CpuFreqLPM.hpp"
#include <fsl_clock.h>

namespace bsp
{
    inline constexpr uint8_t OscillatorReadyCounterValue{127};
    inline constexpr uint8_t CCM_TupleShift{8};
    inline constexpr uint8_t CCM_TupleMask{0x1F};
    inline constexpr uint32_t ClockNeededRunWaitMode{kCLOCK_ClockNeededRunWait};

    class RT1051LPM : public LowPowerMode
    {


@@ 24,11 20,8 @@ namespace bsp
        int32_t Reboot() override final;
        void SetCpuFrequency(CpuFrequency freq) final;
        void SwitchOscillatorSource(OscillatorSource source) final;
        void SwitchPll2State(Pll2State state) final;

      private:
        [[nodiscard]] bool IsClockEnabled(clock_ip_name_t name) const noexcept;

        std::shared_ptr<drivers::DriverGPIO> gpio;
        std::unique_ptr<bsp::CpuFreqLPM> CpuFreq;
    };

A module-bsp/board/rt1051/drivers/RT1051DriverLPSPI.cpp => module-bsp/board/rt1051/drivers/RT1051DriverLPSPI.cpp +51 -0
@@ 0,0 1,51 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "RT1051DriverLPSPI.hpp"
#include "critical.hpp"
#include "board/rt1051/bsp/lpm/ClockState.hpp"

namespace drivers
{

    RT1051DriverLPSPI::RT1051DriverLPSPI(std::string name, LPSPIInstances inst) : DriverLPSPI(std::move(name), inst)
    {
        switch (instance) {
        case LPSPIInstances::LPSPI_1:
            lpspiClock = kCLOCK_Lpspi1;
            break;
        case LPSPIInstances::LPSPI_2:
            lpspiClock = kCLOCK_Lpspi2;
            break;
        case LPSPIInstances::LPSPI_3:
            lpspiClock = kCLOCK_Lpspi3;
            break;
        case LPSPIInstances::LPSPI_4:
            lpspiClock = kCLOCK_Lpspi4;
            break;
        }
    }

    void RT1051DriverLPSPI::Enable()
    {
        cpp_freertos::CriticalSection::Enter();
        if (!pll2Driver) {
            pll2Driver = std::make_shared<RT1051DriverPLL2>();
        }
        if (!bsp::IsClockEnabled(lpspiClock)) {
            CLOCK_EnableClock(lpspiClock);
        }
        cpp_freertos::CriticalSection::Exit();
    }

    void RT1051DriverLPSPI::Disable()
    {
        cpp_freertos::CriticalSection::Enter();
        if (bsp::IsClockEnabled(lpspiClock)) {
            CLOCK_DisableClock(lpspiClock);
        }
        pll2Driver.reset();
        cpp_freertos::CriticalSection::Exit();
    }

} // namespace drivers

A module-bsp/board/rt1051/drivers/RT1051DriverLPSPI.hpp => module-bsp/board/rt1051/drivers/RT1051DriverLPSPI.hpp +25 -0
@@ 0,0 1,25 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "drivers/lpspi/DriverLPSPI.hpp"
#include "RT1051DriverPLL2.hpp"
#include "board/rt1051/common/clock_config.h"

namespace drivers
{
    class RT1051DriverLPSPI : public DriverLPSPI
    {
      public:
        explicit RT1051DriverLPSPI(std::string name, LPSPIInstances inst);

        void Enable() final;
        void Disable() final;

      private:
        std::shared_ptr<RT1051DriverPLL2> pll2Driver;
        clock_ip_name_t lpspiClock;
    };

} // namespace drivers

A module-bsp/board/rt1051/drivers/RT1051DriverPLL2.cpp => module-bsp/board/rt1051/drivers/RT1051DriverPLL2.cpp +33 -0
@@ 0,0 1,33 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "RT1051DriverPLL2.hpp"
#include "board/rt1051/bsp/lpm/ClockState.hpp"

namespace drivers
{

    RT1051DriverPLL2::RT1051DriverPLL2() noexcept
    {
        if (!IsPLL2Enabled()) {
            clkPLL2setup(CLK_ENABLE);
        }
    }

    RT1051DriverPLL2::~RT1051DriverPLL2()
    {
        if ((CLOCK_GetMux(kCLOCK_SemcMux) == SemcMuxPeripheralClock) && !bsp::IsClockEnabled(kCLOCK_Lpspi1) &&
            !bsp::IsClockEnabled(kCLOCK_Lpspi2) && !bsp::IsClockEnabled(kCLOCK_Lpspi3) &&
            !bsp::IsClockEnabled(kCLOCK_Lpspi4) && !bsp::IsClockEnabled(kCLOCK_Usdhc1) &&
            !bsp::IsClockEnabled(kCLOCK_Usdhc2)) {

            clkPLL2setup(CLK_DISABLE);
        }
    }

    bool RT1051DriverPLL2::IsPLL2Enabled() const noexcept
    {
        return !(CCM_ANALOG->PLL_SYS & CCM_ANALOG_PLL_SYS_POWERDOWN_MASK);
    }

} // namespace drivers

A module-bsp/board/rt1051/drivers/RT1051DriverPLL2.hpp => module-bsp/board/rt1051/drivers/RT1051DriverPLL2.hpp +23 -0
@@ 0,0 1,23 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "board/rt1051/common/clock_config.h"

namespace drivers
{
    inline constexpr uint32_t SemcMuxPLL2Clock{1};
    inline constexpr uint32_t SemcMuxPeripheralClock{0};

    class RT1051DriverPLL2
    {
      public:
        RT1051DriverPLL2() noexcept;
        ~RT1051DriverPLL2();

      private:
        [[nodiscard]] bool IsPLL2Enabled() const noexcept;
    };

} // namespace drivers

A module-bsp/board/rt1051/drivers/RT1051DriverSEMC.cpp => module-bsp/board/rt1051/drivers/RT1051DriverSEMC.cpp +40 -0
@@ 0,0 1,40 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "RT1051DriverSEMC.hpp"
#include "critical.hpp"
#include "board/rt1051/common/clock_config.h"

namespace drivers
{

    RT1051DriverSEMC::RT1051DriverSEMC(std::string name) : DriverSEMC(std::move(name))
    {
        SwitchToPLL2ClockSource();
    }

    void RT1051DriverSEMC::Enable()
    {}

    void RT1051DriverSEMC::Disable()
    {}

    void RT1051DriverSEMC::SwitchToPLL2ClockSource()
    {
        cpp_freertos::CriticalSection::Enter();
        if (!pll2Driver) {
            pll2Driver = std::make_shared<RT1051DriverPLL2>();
        }
        CLOCK_SetMux(kCLOCK_SemcMux, SemcMuxPLL2Clock);
        cpp_freertos::CriticalSection::Exit();
    }

    void RT1051DriverSEMC::SwitchToPeripheralClockSource()
    {
        cpp_freertos::CriticalSection::Enter();
        CLOCK_SetMux(kCLOCK_SemcMux, SemcMuxPeripheralClock);
        pll2Driver.reset();
        cpp_freertos::CriticalSection::Exit();
    }

} // namespace drivers

A module-bsp/board/rt1051/drivers/RT1051DriverSEMC.hpp => module-bsp/board/rt1051/drivers/RT1051DriverSEMC.hpp +26 -0
@@ 0,0 1,26 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "drivers/semc/DriverSEMC.hpp"
#include "RT1051DriverPLL2.hpp"

namespace drivers
{
    class RT1051DriverSEMC : public DriverSEMC
    {
      public:
        explicit RT1051DriverSEMC(std::string name);

        void Enable() final;
        void Disable() final;

        void SwitchToPLL2ClockSource() final;
        void SwitchToPeripheralClockSource() final;

      private:
        std::shared_ptr<RT1051DriverPLL2> pll2Driver;
    };

} // namespace drivers

A module-bsp/board/rt1051/drivers/RT1051DriverUSDHC.cpp => module-bsp/board/rt1051/drivers/RT1051DriverUSDHC.cpp +45 -0
@@ 0,0 1,45 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "RT1051DriverUSDHC.hpp"
#include "critical.hpp"
#include "board/rt1051/bsp/lpm/ClockState.hpp"

namespace drivers
{

    RT1051DriverUSDHC::RT1051DriverUSDHC(std::string name, USDHCInstances inst) : DriverUSDHC(std::move(name), inst)
    {
        switch (instance) {
        case USDHCInstances::USDHC_1:
            usdhcClock = kCLOCK_Usdhc1;
            break;
        case USDHCInstances::USDHC_2:
            usdhcClock = kCLOCK_Usdhc2;
            break;
        }
    }

    void RT1051DriverUSDHC::Enable()
    {
        cpp_freertos::CriticalSection::Enter();
        if (!pll2Driver) {
            pll2Driver = std::make_shared<RT1051DriverPLL2>();
        }
        if (!bsp::IsClockEnabled(usdhcClock)) {
            CLOCK_EnableClock(usdhcClock);
        }
        cpp_freertos::CriticalSection::Exit();
    }

    void RT1051DriverUSDHC::Disable()
    {
        cpp_freertos::CriticalSection::Enter();
        if (bsp::IsClockEnabled(usdhcClock)) {
            CLOCK_DisableClock(usdhcClock);
        }
        pll2Driver.reset();
        cpp_freertos::CriticalSection::Exit();
    }

} // namespace drivers

A module-bsp/board/rt1051/drivers/RT1051DriverUSDHC.hpp => module-bsp/board/rt1051/drivers/RT1051DriverUSDHC.hpp +25 -0
@@ 0,0 1,25 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "drivers/usdhc/DriverUSDHC.hpp"
#include "RT1051DriverPLL2.hpp"
#include "board/rt1051/common/clock_config.h"

namespace drivers
{
    class RT1051DriverUSDHC : public DriverUSDHC
    {
      public:
        explicit RT1051DriverUSDHC(std::string name, USDHCInstances inst);

        void Enable() final;
        void Disable() final;

      private:
        std::shared_ptr<RT1051DriverPLL2> pll2Driver;
        clock_ip_name_t usdhcClock;
    };

} // namespace drivers

M module-bsp/bsp/BoardDefinitions.hpp => module-bsp/bsp/BoardDefinitions.hpp +4 -0
@@ 6,6 6,8 @@
#include "drivers/i2c/DriverI2C.hpp"
#include "drivers/pll/DriverPLL.hpp"
#include "drivers/gpio/DriverGPIO.hpp"
#include "drivers/lpspi/DriverLPSPI.hpp"
#include "drivers/usdhc/DriverUSDHC.hpp"

enum class BoardDefinitions
{


@@ 84,6 86,7 @@ enum class BoardDefinitions
    EINK_RESET_PIN=16,
    EINK_BUSY_PIN=17,
    EINK_PLL = static_cast<int >(drivers::PLLInstances::PLL2_PFD2),
    EINK_LPSPI_INSTANCE = static_cast<int >(drivers::LPSPIInstances::LPSPI_1),

    BLUETOOTH_DMA = static_cast<int >(drivers::DMAInstances ::DMA_0),
    BLUETOOTH_DMAMUX = static_cast<int >(drivers::DMAMuxInstances ::DMAMUX0),


@@ 91,6 94,7 @@ enum class BoardDefinitions
    BLUETOOTH_RX_DMA_CHANNEL = 8,

    EMMC_PLL = static_cast<int >(drivers::PLLInstances::PLL2_PFD2),
    EMMC_USDHC_INSTANCE = static_cast<int >(drivers::USDHCInstances::USDHC_2),

    AUDIO_PLL = static_cast<int >(drivers::PLLInstances::PLL4_Audio),


M module-bsp/bsp/lpm/bsp_lpm.cpp => module-bsp/bsp/lpm/bsp_lpm.cpp +0 -5
@@ 35,9 35,4 @@ namespace bsp{
    {
    	return currentOscSource;
    }

    LowPowerMode::Pll2State LowPowerMode::GetCurrentPll2State() const noexcept
    {
    	return currentPll2State;
    }
}

M module-bsp/bsp/lpm/bsp_lpm.hpp => module-bsp/bsp/lpm/bsp_lpm.hpp +0 -9
@@ 23,11 23,6 @@ namespace bsp {
            External,
            Internal
        };
        enum class Pll2State
        {
            Enable,
            Disable
        };

        LowPowerMode()          = default;
        virtual ~LowPowerMode() = default;


@@ 43,13 38,9 @@ namespace bsp {
        virtual void SwitchOscillatorSource(OscillatorSource source) = 0;
        [[nodiscard]] OscillatorSource GetCurrentOscillatorSource() const noexcept;

        virtual void SwitchPll2State(Pll2State state) = 0;
        [[nodiscard]] Pll2State GetCurrentPll2State() const noexcept;

    protected:
        CpuFrequency currentFrequency = CpuFrequency::Level_6;
        OscillatorSource currentOscSource = OscillatorSource::External;
        Pll2State currentPll2State = Pll2State::Enable;
    };
} // namespace bsp


A module-bsp/devices/Device.cpp => module-bsp/devices/Device.cpp +22 -0
@@ 0,0 1,22 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "Device.hpp"

namespace devices
{

    Device::Device(std::string name) : name(std::move(name))
    {}

    bool Device::IsEnabled() const noexcept
    {
        return isEnabled;
    }

    [[nodiscard]] auto Device::GetName() const noexcept -> std::string
    {
        return name;
    }

} // namespace devices

A module-bsp/devices/Device.hpp => module-bsp/devices/Device.hpp +27 -0
@@ 0,0 1,27 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <string>

namespace devices
{
    class Device
    {
      public:
        explicit Device(std::string name);
        virtual ~Device() = default;

        virtual void Enable()  = 0;
        virtual void Disable() = 0;
        [[nodiscard]] bool IsEnabled() const noexcept;
        [[nodiscard]] auto GetName() const noexcept -> std::string;

      protected:
        bool isEnabled{false};

        const std::string name;
    };

} // namespace devices

A module-bsp/drivers/lpspi/DriverLPSPI.cpp => module-bsp/drivers/lpspi/DriverLPSPI.cpp +41 -0
@@ 0,0 1,41 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "DriverLPSPI.hpp"
#include "critical.hpp"

#if defined(TARGET_RT1051)
#include "board/rt1051/drivers/RT1051DriverLPSPI.hpp"
#elif defined(TARGET_Linux)

#else
#error "Unsupported target"
#endif

namespace drivers
{

    std::weak_ptr<DriverLPSPI> DriverLPSPI::singleton[magic_enum::enum_count<LPSPIInstances>()];

    std::shared_ptr<DriverLPSPI> DriverLPSPI::Create(std::string name, const drivers::LPSPIInstances instance)
    {
        cpp_freertos::CriticalSection::Enter();
        std::shared_ptr<DriverLPSPI> inst = singleton[static_cast<uint32_t>(instance)].lock();

        if (!inst) {
#if defined(TARGET_RT1051)
            inst = std::make_shared<RT1051DriverLPSPI>(std::move(name), instance);
#elif defined(TARGET_Linux)
#else
#error "Unsupported target"
#endif

            singleton[static_cast<uint32_t>(instance)] = std::move(inst);
        }

        cpp_freertos::CriticalSection::Exit();

        return inst;
    }

} // namespace drivers

A module-bsp/drivers/lpspi/DriverLPSPI.hpp => module-bsp/drivers/lpspi/DriverLPSPI.hpp +36 -0
@@ 0,0 1,36 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <memory>
#include <devices/Device.hpp>
#include <magic_enum.hpp>

namespace drivers
{

    enum class LPSPIInstances
    {
        LPSPI_1,
        LPSPI_2,
        LPSPI_3,
        LPSPI_4
    };

    class DriverLPSPI : public devices::Device
    {
      public:
        static std::shared_ptr<DriverLPSPI> Create(std::string name, const LPSPIInstances inst);

        explicit DriverLPSPI(std::string name, LPSPIInstances inst) : devices::Device(std::move(name)), instance(inst)
        {}

      protected:
        LPSPIInstances instance;

      private:
        static std::weak_ptr<DriverLPSPI> singleton[magic_enum::enum_count<LPSPIInstances>()];
    };

} // namespace drivers

A module-bsp/drivers/semc/DriverSEMC.cpp => module-bsp/drivers/semc/DriverSEMC.cpp +42 -0
@@ 0,0 1,42 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "DriverSEMC.hpp"
#include "critical.hpp"

#if defined(TARGET_RT1051)
#include "board/rt1051/drivers/RT1051DriverSEMC.hpp"
#elif defined(TARGET_Linux)

#else
#error "Unsupported target"
#endif

namespace drivers
{

    std::weak_ptr<DriverSEMC> DriverSEMC::singleton;

    std::shared_ptr<DriverSEMC> DriverSEMC::Create(std::string name)
    {

        cpp_freertos::CriticalSection::Enter();
        std::shared_ptr<DriverSEMC> inst = singleton.lock();

        if (!inst) {
#if defined(TARGET_RT1051)
            inst = std::make_shared<RT1051DriverSEMC>(std::move(name));
#elif defined(TARGET_Linux)
#else
#error "Unsupported target"
#endif

            singleton = std::move(inst);
        }

        cpp_freertos::CriticalSection::Exit();

        return inst;
    }

} // namespace drivers

A module-bsp/drivers/semc/DriverSEMC.hpp => module-bsp/drivers/semc/DriverSEMC.hpp +27 -0
@@ 0,0 1,27 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <memory>
#include <devices/Device.hpp>

namespace drivers
{

    class DriverSEMC : public devices::Device
    {
      public:
        static std::shared_ptr<DriverSEMC> Create(std::string name);

        explicit DriverSEMC(std::string name) : devices::Device(std::move(name))
        {}

        virtual void SwitchToPLL2ClockSource()       = 0;
        virtual void SwitchToPeripheralClockSource() = 0;

      private:
        static std::weak_ptr<DriverSEMC> singleton;
    };

} // namespace drivers

A module-bsp/drivers/usdhc/DriverUSDHC.cpp => module-bsp/drivers/usdhc/DriverUSDHC.cpp +42 -0
@@ 0,0 1,42 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "DriverUSDHC.hpp"
#include "critical.hpp"

#if defined(TARGET_RT1051)
#include "board/rt1051/drivers/RT1051DriverUSDHC.hpp"
#elif defined(TARGET_Linux)

#else
#error "Unsupported target"
#endif

namespace drivers
{

    std::weak_ptr<DriverUSDHC> DriverUSDHC::singleton[magic_enum::enum_count<USDHCInstances>()];

    std::shared_ptr<DriverUSDHC> DriverUSDHC::Create(std::string name, const drivers::USDHCInstances instance)
    {

        cpp_freertos::CriticalSection::Enter();
        std::shared_ptr<DriverUSDHC> inst = singleton[static_cast<uint32_t>(instance)].lock();

        if (!inst) {
#if defined(TARGET_RT1051)
            inst = std::make_shared<RT1051DriverUSDHC>(std::move(name), instance);
#elif defined(TARGET_Linux)
#else
#error "Unsupported target"
#endif

            singleton[static_cast<uint32_t>(instance)] = std::move(inst);
        }

        cpp_freertos::CriticalSection::Exit();

        return inst;
    }

} // namespace drivers

A module-bsp/drivers/usdhc/DriverUSDHC.hpp => module-bsp/drivers/usdhc/DriverUSDHC.hpp +34 -0
@@ 0,0 1,34 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <memory>
#include <devices/Device.hpp>
#include <magic_enum.hpp>

namespace drivers
{

    enum class USDHCInstances
    {
        USDHC_1,
        USDHC_2
    };

    class DriverUSDHC : public devices::Device
    {
      public:
        static std::shared_ptr<DriverUSDHC> Create(std::string name, const USDHCInstances inst);

        explicit DriverUSDHC(std::string name, USDHCInstances inst) : devices::Device(std::move(name)), instance(inst)
        {}

      protected:
        USDHCInstances instance;

      private:
        static std::weak_ptr<DriverUSDHC> singleton[magic_enum::enum_count<USDHCInstances>()];
    };

} // namespace drivers

M module-bsp/targets/Target_RT1051.cmake => module-bsp/targets/Target_RT1051.cmake +5 -0
@@ 52,6 52,7 @@ set(BOARD_SOURCES ${BOARD_SOURCES}
	"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/bsp/watchdog/watchdog.cpp"
	"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/bsp/lpm/RT1051LPM.cpp"
	"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/bsp/lpm/CpuFreqLPM.cpp"
	"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/bsp/lpm/ClockState.cpp"	
	"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/bluetooth/BluetoothCommon.cpp"
	"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/bluetooth/BlueKitchen.cpp"
	"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/bsp/rtc/rtc.cpp"


@@ 63,6 64,10 @@ set(BOARD_SOURCES ${BOARD_SOURCES}
	"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/bsp/audio/qfilter.c"
	"${USB_SRC}"
	"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/drivers/RT1051DriverPLL.cpp"
	"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/drivers/RT1051DriverPLL2.cpp"
	"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/drivers/RT1051DriverLPSPI.cpp"
	"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/drivers/RT1051DriverUSDHC.cpp"
	"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/drivers/RT1051DriverSEMC.cpp"
	"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/drivers/RT1051DriverI2C.cpp"
	"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/drivers/RT1051DriverPWM.cpp"
	"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/drivers/RT1051DriverDMAMux.cpp"

M module-services/service-eink/EinkDisplay.cpp => module-services/service-eink/EinkDisplay.cpp +17 -2
@@ 5,7 5,7 @@

#include <gui/core/Color.hpp>
#include <gsl/gsl_util>

#include <bsp/BoardDefinitions.hpp>
#include <cstdio>
#include <cstring>



@@ 45,7 45,10 @@ namespace service::eink
    EinkDisplay::EinkDisplay(::gui::Size screenSize)
        : size{screenSize}, currentWaveform{createDefaultWaveFormSettings(EinkWaveformGC16)},
          displayMode{EinkDisplayColorMode_e::EinkDisplayColorModeStandard}
    {}
    {
        driverLPSPI = drivers::DriverLPSPI::Create(
            "EInk", static_cast<drivers::LPSPIInstances>(BoardDefinitions::EINK_LPSPI_INSTANCE));
    }

    EinkDisplay::~EinkDisplay() noexcept
    {


@@ 65,12 68,18 @@ namespace service::eink

    void EinkDisplay::powerOn()
    {
        if (driverLPSPI) {
            driverLPSPI->Enable();
        }
        EinkPowerOn();
    }

    void EinkDisplay::powerOff()
    {
        EinkPowerOff();
        if (driverLPSPI) {
            driverLPSPI->Disable();
        }
    }

    void EinkDisplay::shutdown()


@@ 241,4 250,10 @@ namespace service::eink
    {
        return size;
    }

    [[nodiscard]] auto EinkDisplay::getDevice() const noexcept -> std::shared_ptr<devices::Device>
    {
        return driverLPSPI;
    }

} // namespace service::eink

M module-services/service-eink/EinkDisplay.hpp => module-services/service-eink/EinkDisplay.hpp +4 -0
@@ 10,6 10,7 @@

#include <cstdint>
#include <memory>
#include "drivers/lpspi/DriverLPSPI.hpp"

namespace service::eink
{


@@ 38,6 39,8 @@ namespace service::eink
        std::int32_t getLastTemperature() const noexcept;
        ::gui::Size getSize() const noexcept;

        [[nodiscard]] auto getDevice() const noexcept -> std::shared_ptr<devices::Device>;

      private:
        static unsigned int toWaveformTemperatureOffset(std::int32_t temperature) noexcept;
        static unsigned int toWaveformOffset(unsigned short LUTbank, unsigned int temperatureOffset) noexcept;


@@ 50,5 53,6 @@ namespace service::eink
        const ::gui::Size size;
        EinkWaveformSettings_t currentWaveform;
        EinkDisplayColorMode_e displayMode;
        std::shared_ptr<drivers::DriverLPSPI> driverLPSPI;
    };
} // namespace service::eink

M module-services/service-eink/ServiceEink.cpp => module-services/service-eink/ServiceEink.cpp +5 -0
@@ 11,6 11,8 @@
#include <log/log.hpp>
#include <messages/EinkMessage.hpp>
#include <messages/ImageMessage.hpp>
#include <SystemManager/messages/DeviceRegistrationMessage.hpp>
#include <SystemManager/Constants.hpp>

#include <cstring>
#include <memory>


@@ 48,6 50,9 @@ namespace service::eink
            return sys::ReturnCodes::Failure;
        }

        auto deviceRegistrationMsg = std::make_shared<sys::DeviceRegistrationMessage>(display.getDevice());
        bus.sendUnicast(deviceRegistrationMsg, service::name::system_manager);

        display.powerOn();

        auto msg = std::make_shared<service::gui::EinkInitialized>(display.getSize());

M module-sys/CMakeLists.txt => module-sys/CMakeLists.txt +1 -0
@@ 16,6 16,7 @@ set(SOURCES
        ${CMAKE_CURRENT_SOURCE_DIR}/SystemManager/SystemManager.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/SystemManager/PowerManager.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/SystemManager/CpuStatistics.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/SystemManager/DeviceManager.cpp

        )


A module-sys/SystemManager/DeviceManager.cpp => module-sys/SystemManager/DeviceManager.cpp +47 -0
@@ 0,0 1,47 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "DeviceManager.hpp"
#include <algorithm>
#include <log/log.hpp>

namespace sys
{

    void DeviceManager::RegisterNewDevice(std::shared_ptr<devices::Device> newDevice)
    {
        if (newDevice) {
            devices.push_back(newDevice);
        }
    }

    void DeviceManager::PrintAllDevices() const noexcept
    {
        std::for_each(std::begin(devices), std::end(devices), PrintName);
    }

    void DeviceManager::DisableAllDevices() const noexcept
    {
        std::for_each(std::begin(devices), std::end(devices), DisableDevice);
    }

    void DeviceManager::PrintName(const DevicePointer &element)
    {
        if (!element.expired()) {
            std::shared_ptr<devices::Device> sharedResource = element.lock();
            LOG_INFO("Device %s", sharedResource->GetName().c_str());
        }
    }

    void DeviceManager::DisableDevice(const DevicePointer &element)
    {
        if (!element.expired()) {
            std::shared_ptr<devices::Device> sharedResource = element.lock();
            if (sharedResource->IsEnabled()) {
                sharedResource->Disable();
                LOG_DEBUG("Device %s has been disabled", sharedResource->GetName().c_str());
            }
        }
    }

} // namespace sys

A module-sys/SystemManager/DeviceManager.hpp => module-sys/SystemManager/DeviceManager.hpp +30 -0
@@ 0,0 1,30 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <memory>
#include <vector>
#include "devices/Device.hpp"

namespace sys
{
    using DevicePointer = std::weak_ptr<devices::Device>;
    using DeviceVector  = std::vector<DevicePointer>;

    class DeviceManager
    {

      public:
        void RegisterNewDevice(std::shared_ptr<devices::Device> newDevice);
        void PrintAllDevices() const noexcept;
        void DisableAllDevices() const noexcept;

      private:
        static void PrintName(const DevicePointer &element);
        static void DisableDevice(const DevicePointer &element);

        DeviceVector devices;
    };

} // namespace sys

M module-sys/SystemManager/PowerManager.cpp => module-sys/SystemManager/PowerManager.cpp +19 -13
@@ 10,6 10,7 @@ namespace sys
    PowerManager::PowerManager()
    {
        lowPowerControl = bsp::LowPowerMode::Create().value_or(nullptr);
        driverSEMC      = drivers::DriverSEMC::Create("ExternalRAM");
    }

    PowerManager::~PowerManager()


@@ 55,17 56,17 @@ namespace sys
    {
        const auto freq      = lowPowerControl->GetCurrentFrequency();
        const auto oscSource = lowPowerControl->GetCurrentOscillatorSource();
        const auto pll2State = lowPowerControl->GetCurrentPll2State();

        // switch osc source first
        if (freq == bsp::LowPowerMode::CpuFrequency::Level_1 &&
            oscSource == bsp::LowPowerMode::OscillatorSource::Internal) {
            lowPowerControl->SwitchOscillatorSource(bsp::LowPowerMode::OscillatorSource::External);
        }
        if (freq == bsp::LowPowerMode::CpuFrequency::Level_1) {
            // switch osc source first
            if (oscSource == bsp::LowPowerMode::OscillatorSource::Internal) {
                lowPowerControl->SwitchOscillatorSource(bsp::LowPowerMode::OscillatorSource::External);
            }

        // then turn on pll2
        if (pll2State == bsp::LowPowerMode::Pll2State::Disable) {
            lowPowerControl->SwitchPll2State(bsp::LowPowerMode::Pll2State::Enable);
            // then switch external RAM clock source
            if (driverSEMC) {
                driverSEMC->SwitchToPLL2ClockSource();
            }
        }

        // and increase frequency


@@ 97,16 98,15 @@ namespace sys

        if (level == bsp::LowPowerMode::CpuFrequency::Level_1) {
            const auto oscSource = lowPowerControl->GetCurrentOscillatorSource();
            const auto pll2State = lowPowerControl->GetCurrentPll2State();

            // then switch osc source
            if (oscSource == bsp::LowPowerMode::OscillatorSource::External) {
                lowPowerControl->SwitchOscillatorSource(bsp::LowPowerMode::OscillatorSource::Internal);
            }

            // and turn off pll2
            if (pll2State == bsp::LowPowerMode::Pll2State::Enable) {
                lowPowerControl->SwitchPll2State(bsp::LowPowerMode::Pll2State::Disable);
            // and switch external RAM clock source
            if (driverSEMC) {
                driverSEMC->SwitchToPeripheralClockSource();
            }
        }
    }


@@ 116,4 116,10 @@ namespace sys
        aboveThresholdCounter = 0;
        belowThresholdCounter = 0;
    }

    [[nodiscard]] auto PowerManager::getExternalRamDevice() const noexcept -> std::shared_ptr<devices::Device>
    {
        return driverSEMC;
    }

} // namespace sys

M module-sys/SystemManager/PowerManager.hpp => module-sys/SystemManager/PowerManager.hpp +4 -0
@@ 7,6 7,7 @@
#include <functional>

#include "bsp/lpm/bsp_lpm.hpp"
#include "drivers/semc/DriverSEMC.hpp"

namespace sys
{


@@ 42,6 43,8 @@ namespace sys
        /// @note the frequency is always reduced by one step
        void DecreaseCpuFrequency() const;

        [[nodiscard]] auto getExternalRamDevice() const noexcept -> std::shared_ptr<devices::Device>;

      private:
        void ResetFrequencyShiftCounter();



@@ 49,6 52,7 @@ namespace sys
        uint32_t aboveThresholdCounter{0};

        std::unique_ptr<bsp::LowPowerMode> lowPowerControl;
        std::shared_ptr<drivers::DriverSEMC> driverSEMC;
    };

} // namespace sys

M module-sys/SystemManager/SystemManager.cpp => module-sys/SystemManager/SystemManager.cpp +12 -0
@@ 17,6 17,7 @@
#include <service-cellular/CellularMessage.hpp>
#include <service-appmgr/model/ApplicationManager.hpp>
#include "messages/CpuFrequencyMessage.hpp"
#include "messages/DeviceRegistrationMessage.hpp"

const inline size_t systemManagerStack = 4096 * 2;



@@ 106,6 107,7 @@ namespace sys
    {
        powerManager  = std::make_unique<PowerManager>();
        cpuStatistics = std::make_unique<CpuStatistics>();
        deviceManager = std::make_unique<DeviceManager>();

        userInit = init;



@@ 299,6 301,15 @@ namespace sys
            return sys::MessageNone{};
        });

        connect(typeid(sys::DeviceRegistrationMessage), [this](sys::Message *message) -> sys::MessagePointer {
            auto msg = static_cast<sys::DeviceRegistrationMessage *>(message);
            deviceManager->RegisterNewDevice(msg->getDevice());

            return sys::MessageNone{};
        });

        deviceManager->RegisterNewDevice(powerManager->getExternalRamDevice());

        return ReturnCodes::Success;
    }



@@ 361,5 372,6 @@ namespace sys
    cpp_freertos::MutexStandard SystemManager::destroyMutex;
    std::unique_ptr<PowerManager> SystemManager::powerManager;
    std::unique_ptr<CpuStatistics> SystemManager::cpuStatistics;
    std::unique_ptr<DeviceManager> SystemManager::deviceManager;

} // namespace sys

M module-sys/SystemManager/SystemManager.hpp => module-sys/SystemManager/SystemManager.hpp +2 -0
@@ 21,6 21,7 @@
#include "PowerManager.hpp"
#include "Constants.hpp"
#include "CpuStatistics.hpp"
#include "DeviceManager.hpp"
#include <chrono>

namespace sys


@@ 142,6 143,7 @@ namespace sys
        static cpp_freertos::MutexStandard destroyMutex;
        static std::unique_ptr<PowerManager> powerManager;
        static std::unique_ptr<CpuStatistics> cpuStatistics;
        static std::unique_ptr<DeviceManager> deviceManager;
    };

} // namespace sys

A module-sys/SystemManager/messages/DeviceRegistrationMessage.hpp => module-sys/SystemManager/messages/DeviceRegistrationMessage.hpp +28 -0
@@ 0,0 1,28 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "devices/Device.hpp"

namespace sys
{
    class DeviceRegistrationMessage : public sys::DataMessage
    {
      public:
        explicit DeviceRegistrationMessage(std::shared_ptr<devices::Device> devicePtr)
            : sys::DataMessage(MessageType::DeviceRegistration), device(devicePtr)
        {}

        [[nodiscard]] auto getDevice() const noexcept -> std::shared_ptr<devices::Device>
        {
            return device;
        };

      private:
        std::shared_ptr<devices::Device> device;
    };
} // namespace sys

M module-utils/Utils.hpp => module-utils/Utils.hpp +0 -1
@@ 12,7 12,6 @@
#include <random>
#include "time/time_conversion.hpp"

#define MAGIC_ENUM_RANGE_MAX 256
#include <magic_enum.hpp>

namespace utils

M source/MessageType.hpp => source/MessageType.hpp +2 -0
@@ 166,6 166,8 @@ enum class MessageType

    // Power manager
    PMChangePowerMode,
    // System manager
    DeviceRegistration,

    // battery charger messages
    EVMBatteryLevel,