mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-04-21 07:28:21 -04:00
Remove system dependency from charger driver implementation. Remove circular, lambda driven dependency between charger and brownout detector. Remove event manager dependency in driver as well. Encapsulate some of charger logic in introduced battery controller. Extract path configuration to the separate target to decouple charger from vfs middleware. Signed-off-by: Marcin Smoczyński <smoczynski.marcin@gmail.com>
25 lines
737 B
C++
25 lines
737 B
C++
// 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 <module-os/CriticalSectionGuard.hpp>
|
|
|
|
#include <memory>
|
|
|
|
namespace hal::impl
|
|
{
|
|
template <typename TDerived, typename TInterface, typename... Args>
|
|
inline std::shared_ptr<TInterface> factory(Args... args)
|
|
{
|
|
const auto criticalSection = cpp_freertos::CriticalSectionGuard{};
|
|
static std::weak_ptr<TDerived> singleton;
|
|
auto inst = singleton.lock();
|
|
if (not inst) {
|
|
inst = std::make_shared<TDerived>(std::forward<Args>(args)...);
|
|
singleton = inst;
|
|
}
|
|
return inst;
|
|
}
|
|
} // namespace hal::impl
|