summaryrefslogtreecommitdiff
path: root/src/drivers/include/driver_cache.hpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-05-19 21:21:27 +1000
committerjacqueline <me@jacqueline.id.au>2023-05-19 21:21:27 +1000
commita6ab1504058304012791281f9eb42c262745888f (patch)
treef82379cd1e66a8ae2f1afbae5cf083a8ab7acc53 /src/drivers/include/driver_cache.hpp
parentb320a6a863cf1c10dc79254af41f573730935564 (diff)
downloadtangara-fw-a6ab1504058304012791281f9eb42c262745888f.tar.gz
Add tinyfsm, start converting core functions to an FSM-based event loop
Diffstat (limited to 'src/drivers/include/driver_cache.hpp')
-rw-r--r--src/drivers/include/driver_cache.hpp54
1 files changed, 0 insertions, 54 deletions
diff --git a/src/drivers/include/driver_cache.hpp b/src/drivers/include/driver_cache.hpp
deleted file mode 100644
index c56ebc3f..00000000
--- a/src/drivers/include/driver_cache.hpp
+++ /dev/null
@@ -1,54 +0,0 @@
-#pragma once
-
-#include <memory>
-#include <mutex>
-
-#include "dac.hpp"
-#include "display.hpp"
-#include "gpio_expander.hpp"
-#include "storage.hpp"
-#include "touchwheel.hpp"
-
-namespace drivers {
-
-class DriverCache {
- private:
- std::unique_ptr<GpioExpander> gpios_;
- std::weak_ptr<AudioDac> dac_;
- std::weak_ptr<Display> display_;
- std::weak_ptr<SdStorage> storage_;
- std::weak_ptr<TouchWheel> touchwheel_;
- // TODO(jacqueline): Haptics, samd
-
- std::mutex mutex_;
-
- template <typename T, typename F>
- auto Acquire(std::weak_ptr<T> ptr, F factory) -> std::shared_ptr<T> {
- std::shared_ptr<T> acquired = ptr.lock();
- if (acquired) {
- return acquired;
- }
-
- std::lock_guard<std::mutex> lock(mutex_);
-
- acquired = ptr.lock();
- if (acquired) {
- return acquired;
- }
- acquired.reset(factory());
- ptr = acquired;
- return acquired;
- }
-
- public:
- DriverCache();
- ~DriverCache();
-
- auto AcquireGpios() -> GpioExpander*;
- auto AcquireDac() -> std::shared_ptr<AudioDac>;
- auto AcquireDisplay() -> std::shared_ptr<Display>;
- auto AcquireStorage() -> std::shared_ptr<SdStorage>;
- auto AcquireTouchWheel() -> std::shared_ptr<TouchWheel>;
-};
-
-} // namespace drivers