mirror of
https://github.com/usatiuk/cardboy.git
synced 2025-10-28 15:17:48 +01:00
74 lines
2.4 KiB
C++
74 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include "cardboy/sdk/display_spec.hpp"
|
|
#include "cardboy/sdk/platform.hpp"
|
|
#include "config.hpp"
|
|
|
|
#include <buttons.hpp>
|
|
#include <display.hpp>
|
|
#include <power_helper.hpp>
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
|
|
class PlatformFramebuffer final : public cardboy::sdk::FramebufferFacade<PlatformFramebuffer> {
|
|
public:
|
|
[[nodiscard]] int width_impl() const { return cardboy::sdk::kDisplayWidth; }
|
|
[[nodiscard]] int height_impl() const { return cardboy::sdk::kDisplayHeight; }
|
|
|
|
__attribute__((always_inline)) void drawPixel_impl(int x, int y, bool on) {
|
|
if (x < 0 || y < 0 || x >= width() || y >= height())
|
|
return;
|
|
SMD::set_pixel(x, y, on);
|
|
}
|
|
|
|
void clear_impl(bool on) {
|
|
for (int y = 0; y < height(); ++y)
|
|
for (int x = 0; x < width(); ++x)
|
|
SMD::set_pixel(x, y, on);
|
|
}
|
|
|
|
__attribute__((always_inline)) void frameReady_impl() { SMD::frame_ready(); }
|
|
__attribute__((always_inline)) void sendFrame_impl(bool clear) { SMD::send_frame(clear); }
|
|
__attribute__((always_inline)) [[nodiscard]] bool frameInFlight_impl() const { return SMD::frame_transfer_in_flight(); }
|
|
};
|
|
|
|
class PlatformInput final : public cardboy::sdk::InputFacade<PlatformInput> {
|
|
public:
|
|
cardboy::sdk::InputState readState_impl() {
|
|
cardboy::sdk::InputState state{};
|
|
const uint8_t pressed = Buttons::get().get_pressed();
|
|
if (pressed & BTN_UP)
|
|
state.up = true;
|
|
if (pressed & BTN_LEFT)
|
|
state.left = true;
|
|
if (pressed & BTN_RIGHT)
|
|
state.right = true;
|
|
if (pressed & BTN_DOWN)
|
|
state.down = true;
|
|
if (pressed & BTN_A)
|
|
state.a = true;
|
|
if (pressed & BTN_B)
|
|
state.b = true;
|
|
if (pressed & BTN_SELECT)
|
|
state.select = true;
|
|
if (pressed & BTN_START)
|
|
state.start = true;
|
|
return state;
|
|
}
|
|
};
|
|
|
|
class PlatformClock final : public cardboy::sdk::ClockFacade<PlatformClock> {
|
|
public:
|
|
std::uint32_t millis_impl() {
|
|
TickType_t ticks = xTaskGetTickCount();
|
|
return static_cast<std::uint32_t>((static_cast<std::uint64_t>(ticks) * 1000ULL) / configTICK_RATE_HZ);
|
|
}
|
|
|
|
void sleep_ms_impl(std::uint32_t ms) {
|
|
if (ms == 0)
|
|
return;
|
|
PowerHelper::get().delay(static_cast<int>(ms), static_cast<int>(ms));
|
|
}
|
|
};
|