mirror of
https://github.com/usatiuk/cardboy.git
synced 2025-10-28 23:27:49 +01:00
90 lines
2.6 KiB
C++
90 lines
2.6 KiB
C++
#pragma once
|
|
|
|
#include <cardboy/sdk/display_spec.hpp>
|
|
#include "cardboy/backend/esp/display.hpp"
|
|
#include "cardboy/backend/esp/event_bus.hpp"
|
|
#include "cardboy/sdk/platform.hpp"
|
|
#include "cardboy/sdk/services.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <memory>
|
|
|
|
namespace cardboy::backend::esp {
|
|
|
|
class EspRuntime;
|
|
|
|
class EspFramebuffer final : public cardboy::sdk::FramebufferFacade<EspFramebuffer> {
|
|
public:
|
|
EspFramebuffer() = default;
|
|
|
|
[[nodiscard]] int width_impl() const { return cardboy::sdk::kDisplayWidth; }
|
|
[[nodiscard]] int height_impl() const { return cardboy::sdk::kDisplayHeight; }
|
|
void __attribute__((always_inline)) drawPixel_impl(int x, int y, bool on) { SMD::set_pixel(x, y, on); }
|
|
void __attribute__((always_inline)) drawBits8_impl(int x, int y, std::uint8_t bits) {
|
|
SMD::set_pixel_8(x, y, bits);
|
|
}
|
|
void clear_impl(bool on);
|
|
void frameReady_impl();
|
|
void sendFrame_impl(bool clearAfterSend);
|
|
[[nodiscard]] bool frameInFlight_impl() const;
|
|
};
|
|
|
|
class EspInput final : public cardboy::sdk::InputFacade<EspInput> {
|
|
public:
|
|
cardboy::sdk::InputState readState_impl();
|
|
};
|
|
|
|
class EspClock final : public cardboy::sdk::ClockFacade<EspClock> {
|
|
public:
|
|
std::uint32_t millis_impl();
|
|
void sleep_ms_impl(std::uint32_t ms);
|
|
};
|
|
|
|
class EspRuntime {
|
|
public:
|
|
EspRuntime();
|
|
~EspRuntime();
|
|
|
|
cardboy::sdk::Services& serviceRegistry();
|
|
|
|
EspFramebuffer framebuffer;
|
|
EspInput input;
|
|
EspClock clock;
|
|
|
|
private:
|
|
void initializeHardware();
|
|
|
|
class BuzzerService;
|
|
class BatteryService;
|
|
class StorageService;
|
|
class RandomService;
|
|
class HighResClockService;
|
|
class FilesystemService;
|
|
class LoopHooksService;
|
|
class NotificationService;
|
|
|
|
std::unique_ptr<BuzzerService> buzzerService;
|
|
std::unique_ptr<BatteryService> batteryService;
|
|
std::unique_ptr<StorageService> storageService;
|
|
std::unique_ptr<RandomService> randomService;
|
|
std::unique_ptr<HighResClockService> highResClockService;
|
|
std::unique_ptr<FilesystemService> filesystemService;
|
|
std::unique_ptr<EventBus> eventBus;
|
|
std::unique_ptr<LoopHooksService> loopHooksService;
|
|
std::unique_ptr<NotificationService> notificationService;
|
|
|
|
cardboy::sdk::Services services{};
|
|
};
|
|
|
|
struct Backend {
|
|
using Framebuffer = EspFramebuffer;
|
|
using Input = EspInput;
|
|
using Clock = EspClock;
|
|
};
|
|
|
|
} // namespace cardboy::backend::esp
|
|
|
|
namespace cardboy::backend {
|
|
using EspBackend = esp::Backend;
|
|
} // namespace cardboy::backend
|