#pragma once #include #include "GLOBALS.h" #include #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 = 40000000; cfg.freq_read = 16000000; 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; void init(DISPLAY_STATE* display_state); void start_draw(); void end_draw(); void draw_box(int x, int y, int size_x, int size_y, int color); void draw_rect(int x, int y, int size_x, int size_y, int thickness, int color); void draw_line(int x1, int y1, int x2, int y2, int color); void draw_text(int x, int y, std::string str); void fill_screen(int color); void draw_box_sprite(int x, int y, int size_x, int size_y, int color); };