Files
cardboy/Firmware/main/include/app_platform.hpp
2025-10-09 09:26:34 +02:00

65 lines
1.6 KiB
C++

#pragma once
#include "config.hpp"
#include "input_state.hpp"
#include <buttons.hpp>
#include <disp_tools.hpp>
#include <power_helper.hpp>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
class PlatformFramebuffer {
public:
int width() const { return DISP_WIDTH; }
int height() const { return DISP_HEIGHT; }
void drawPixel(int x, int y, bool on) {
if (x < 0 || y < 0 || x >= width() || y >= height())
return;
DispTools::set_pixel(x, y, on);
}
void clear(bool on) {
for (int y = 0; y < height(); ++y)
for (int x = 0; x < width(); ++x)
DispTools::set_pixel(x, y, on);
}
};
class PlatformInput {
public:
InputState readState() {
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 {
public:
uint32_t millis() {
TickType_t ticks = xTaskGetTickCount();
return static_cast<uint32_t>((static_cast<uint64_t>(ticks) * 1000ULL) / configTICK_RATE_HZ);
}
void sleep_ms(uint32_t ms) { PowerHelper::get().delay(static_cast<int>(ms), static_cast<int>(ms)); }
};