mirror of
https://github.com/usatiuk/cardboy.git
synced 2025-10-28 23:27:49 +01:00
74 lines
2.2 KiB
C++
74 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include "cardboy/sdk/display_spec.hpp"
|
|
#include "cardboy/sdk/platform.hpp"
|
|
#include "config.hpp"
|
|
|
|
#include <buttons.hpp>
|
|
#include <disp_tools.hpp>
|
|
#include <power_helper.hpp>
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
|
|
class PlatformFramebuffer final : public cardboy::sdk::IFramebuffer {
|
|
public:
|
|
int width() const override { return cardboy::sdk::kDisplayWidth; }
|
|
int height() const override { return cardboy::sdk::kDisplayHeight; }
|
|
|
|
void drawPixel(int x, int y, bool on) override {
|
|
if (x < 0 || y < 0 || x >= width() || y >= height())
|
|
return;
|
|
DispTools::set_pixel(x, y, on);
|
|
}
|
|
|
|
void clear(bool on) override {
|
|
for (int y = 0; y < height(); ++y)
|
|
for (int x = 0; x < width(); ++x)
|
|
DispTools::set_pixel(x, y, on);
|
|
}
|
|
|
|
void beginFrame() override { DispTools::draw_to_display_async_wait(); }
|
|
void endFrame() override { DispTools::draw_to_display_async_start(); }
|
|
bool isFrameInFlight() const override { return DispTools::draw_to_display_async_busy(); }
|
|
};
|
|
|
|
class PlatformInput final : public cardboy::sdk::IInput {
|
|
public:
|
|
cardboy::sdk::InputState readState() override {
|
|
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::IClock {
|
|
public:
|
|
std::uint32_t millis() override {
|
|
TickType_t ticks = xTaskGetTickCount();
|
|
return static_cast<std::uint32_t>((static_cast<std::uint64_t>(ticks) * 1000ULL) / configTICK_RATE_HZ);
|
|
}
|
|
|
|
void sleep_ms(std::uint32_t ms) override {
|
|
if (ms == 0)
|
|
return;
|
|
PowerHelper::get().delay(static_cast<int>(ms), static_cast<int>(ms));
|
|
}
|
|
};
|