mirror of
https://github.com/usatiuk/cardboy.git
synced 2025-10-28 23:27:49 +01:00
71 lines
1.7 KiB
C++
71 lines
1.7 KiB
C++
//
|
|
// Created by Stepan Usatiuk on 02.03.2025.
|
|
//
|
|
|
|
#ifndef CB_DISPLAY_HPP
|
|
#define CB_DISPLAY_HPP
|
|
|
|
#include "config.hpp"
|
|
|
|
#include "driver/spi_master.h"
|
|
|
|
#include <array>
|
|
#include <bitset>
|
|
|
|
#include "Surface.hpp"
|
|
#include "Window.hpp"
|
|
|
|
class SMD {
|
|
public:
|
|
using disp_line_t = std::bitset<400>;
|
|
using disp_frame_t = std::array<disp_line_t, 240>;
|
|
|
|
static SMD& get();
|
|
void clear();
|
|
void draw(const disp_frame_t& frame);
|
|
|
|
private:
|
|
SMD();
|
|
static inline spi_device_interface_config_t _devcfg = {
|
|
.mode = 0, // SPI mode 0
|
|
.clock_speed_hz = 2 * 1000 * 1000, // Clock out at 10 MHz
|
|
.spics_io_num = SPI_DISP_CS, // CS pin
|
|
.flags = SPI_DEVICE_POSITIVE_CS,
|
|
.queue_size = 3,
|
|
// .pre_cb = lcd_spi_pre_transfer_callback, //Specify pre-transfer callback to handle D/C line
|
|
};
|
|
static constexpr size_t kLineBytes = DISP_WIDTH / 8;
|
|
spi_device_handle_t _spi;
|
|
bool _vcom = false;
|
|
|
|
static constexpr size_t kLineData = (kLineBytes + 4);
|
|
std::array<uint8_t, kLineData> buf{};
|
|
|
|
std::array<uint8_t, kLineBytes> prep_line(const SMD::disp_line_t& line);
|
|
};
|
|
|
|
class SMDSurface : public Surface<SMDSurface, BwPixel>, public StandardEventQueue<SMDSurface> {
|
|
public:
|
|
SMDSurface(EventLoop* loop);
|
|
|
|
~SMDSurface() override;
|
|
|
|
void draw_pixel_impl(unsigned x, unsigned y, const BwPixel& pixel);
|
|
|
|
void clear_impl();
|
|
|
|
int get_width_impl() const;
|
|
|
|
int get_height_impl() const;
|
|
|
|
template<typename T>
|
|
EventHandlingResult handle(const T& event) {
|
|
return _window->handle(event);
|
|
}
|
|
|
|
EventHandlingResult handle(SurfaceResizeEvent event);
|
|
};
|
|
|
|
|
|
#endif // DISPLAY_HPP
|