#pragma once #include #include "GLOBALS.h" #include "program.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 = 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 x, short y, short size_x, short size_y, short color); void draw_rect(short x, short y, short size_x, short size_y, short thickness, short color); void draw_line(short x1, short y1, short x2, short y2, short color); void draw_text(short x, short y, const std::string& str, short color, short size); void draw_button(short x, short y, short size_x, short size_y, short color, bool pressed, std::string str); void fill_screen(short color); void push_sprite(); void get_text_bounds(const std::string& str, short size, short& width, short& height); void draw_scrollable_textbox(const ScrollableTextBox& box); };