72 lines
2.0 KiB
C++
72 lines
2.0 KiB
C++
#pragma once
|
|
#include <LovyanGFX.hpp>
|
|
#include "GLOBALS.h"
|
|
#include <string>
|
|
|
|
#define MAX_X 480
|
|
#define MAX_Y 320
|
|
|
|
// https://github.com/lovyan03/LovyanGFX/issues/714#issuecomment-2968349655
|
|
// https://github.com/lovyan03/LovyanGFX/issues/734
|
|
class LGFX : public lgfx::LGFX_Device {
|
|
public:
|
|
lgfx::Panel_ILI9488 panel;
|
|
lgfx::Bus_SPI spi;
|
|
|
|
LGFX() {
|
|
|
|
// ---- SPI BUS CONFIG ----
|
|
{
|
|
auto cfg = spi.config(); // *** GET STRUCT ***
|
|
cfg.spi_host = SPI2_HOST;
|
|
cfg.pin_sclk = 12;
|
|
cfg.pin_mosi = 11;
|
|
cfg.pin_dc = 21;
|
|
cfg.pin_miso = -1;
|
|
cfg.freq_write = 60000000;
|
|
cfg.freq_read = 16000000;
|
|
cfg.use_lock = true;
|
|
cfg.dma_channel = 1;
|
|
spi.config(cfg); // *** APPLY CONFIG ***
|
|
}
|
|
|
|
// ---- PANEL CONFIG ----
|
|
{
|
|
auto cfg = panel.config(); // *** GET STRUCT ***
|
|
cfg.pin_cs = 10;
|
|
cfg.pin_rst = 15;
|
|
|
|
cfg.memory_width = 320;
|
|
cfg.memory_height = 480;
|
|
cfg.panel_width = 320;
|
|
cfg.panel_height = 480;
|
|
cfg.offset_x = 0;
|
|
cfg.offset_y = 0;
|
|
|
|
panel.config(cfg); // *** APPLY CONFIG ***
|
|
}
|
|
|
|
panel.setBus(&spi);
|
|
setPanel(&panel);
|
|
}
|
|
};
|
|
|
|
class TFT_Handler {
|
|
public:
|
|
LGFX tft;
|
|
DISPLAY_STATE* _display_state;
|
|
LGFX_Sprite sprite;
|
|
|
|
TFT_Handler() : sprite(&tft) {}
|
|
|
|
void init(DISPLAY_STATE* display_state);
|
|
|
|
void draw_box(short int x, short int y, short int size_x, short int size_y, int color);
|
|
void draw_rect(short int x, short int y, short int size_x, short int size_y, short int thickness, int color);
|
|
void draw_line(short int x1, short int y1, short int x2, short int y2, int color);
|
|
void draw_text(short int x, short int y, const std::string& str, int color, short int size);
|
|
void fill_screen(int color);
|
|
void push_sprite();
|
|
|
|
};
|