summaryrefslogtreecommitdiff
path: root/src/drivers/driver_cache.cpp
blob: 650e6f16cdc137a58ff8472e108c0dfc38a6fe2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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