diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-04-26 08:49:02 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-04-26 08:49:02 +1000 |
| commit | 7972bd4567a99179338259e9e6ce19168c2c0db3 (patch) | |
| tree | f46642afd36011d3d064e022232e77744b82c6ae /src/drivers/driver_cache.cpp | |
| parent | 4887f3789817f87bf1272af0b52684e3364270c2 (diff) | |
| parent | 5575378c1c8171cd716b79d3ab89df1e56ceb9d3 (diff) | |
| download | tangara-fw-7972bd4567a99179338259e9e6ce19168c2c0db3.tar.gz | |
Merge branch 'main' into leveldb
Diffstat (limited to 'src/drivers/driver_cache.cpp')
| -rw-r--r-- | src/drivers/driver_cache.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/drivers/driver_cache.cpp b/src/drivers/driver_cache.cpp new file mode 100644 index 00000000..650e6f16 --- /dev/null +++ b/src/drivers/driver_cache.cpp @@ -0,0 +1,43 @@ +#include "driver_cache.hpp" + +#include <memory> +#include <mutex> + +#include "display.hpp" +#include "display_init.hpp" +#include "storage.hpp" +#include "touchwheel.hpp" + +namespace drivers { + +DriverCache::DriverCache() : gpios_(std::make_unique<GpioExpander>()) {} +DriverCache::~DriverCache() {} + +auto DriverCache::AcquireGpios() -> GpioExpander* { + return gpios_.get(); +} + +auto DriverCache::AcquireDac() -> std::shared_ptr<AudioDac> { + return Acquire(dac_, [&]() -> AudioDac* { + return AudioDac::create(AcquireGpios()).value_or(nullptr); + }); +} + +auto DriverCache::AcquireDisplay() -> std::shared_ptr<Display> { + return Acquire(display_, [&]() -> Display* { + return Display::create(AcquireGpios(), displays::kST7735R); + }); +} + +auto DriverCache::AcquireStorage() -> std::shared_ptr<SdStorage> { + return Acquire(storage_, [&]() -> SdStorage* { + return SdStorage::create(AcquireGpios()).value_or(nullptr); + }); +} + +auto DriverCache::AcquireTouchWheel() -> std::shared_ptr<TouchWheel> { + return Acquire(touchwheel_, + [&]() -> TouchWheel* { return new TouchWheel(); }); +} + +} // namespace drivers |
