blob: 9c21b83cd51081865bb52635e72ae81161cf5576 (
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
44
45
46
47
48
49
|
/*
* Copyright 2023 jacqueline <me@jacqueline.id.au>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
#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
|