Skip to content

Instantly share code, notes, and snippets.

@sukesh-ak
Last active November 13, 2022 06:31
Show Gist options
  • Save sukesh-ak/92b1cd6a6a746d95b9fbed09e3d034a4 to your computer and use it in GitHub Desktop.
Save sukesh-ak/92b1cd6a6a746d95b9fbed09e3d034a4 to your computer and use it in GitHub Desktop.
Makerfabs GC9A01 1.28 Inch Round LCD LovyanGFX config
/*
Simple Touch Drawing sample for Makerfabs GC9A01 1.28 Inch Round LCD Module
Requirements:
- Development board : ESP32-S3 based
- Arduino Library - Display/Touch : LovyanGFX
- Board selected in Arduino : ESP32S3 Dev Module
*/
// Portrait
#define TFT_WIDTH 240
#define TFT_HEIGHT 240
#define TFT_MOSI GPIO_NUM_8
#define TFT_MISO -1 // Set this PIN for using shared SPI option
#define TFT_SCLK GPIO_NUM_9
#define TFT_DC GPIO_NUM_11
#define TFT_CS GPIO_NUM_10
#define TFT_RST GPIO_NUM_45 //???
#define TFT_BKLT GPIO_NUM_45 //???
#define LGFX_USE_V1 // set to use new version of library
#include <LovyanGFX.hpp> // main library
class LGFX : public lgfx::LGFX_Device
{
// provide an instance that matches the type of panel you want to connect to.
lgfx::Panel_GC9A01 _panel_instance;
// provide an instance that matches the type of bus to which the panel is connected.
lgfx::Bus_SPI _bus_instance; // Instances of spi buses
lgfx::Light_PWM _light_instance;
public:
LGFX(void)
{
{
// set up bus control.
auto cfg = _bus_instance.config(); // gets the structure for bus settings.
// SPI bus settings
cfg.spi_host = SPI2_HOST; // Select SPI to use ESP32-S2,C3: SPI2_HOST or SPI3_HOST / ESP32: VSPI_HOST or HSPI_HOST
//* Due to the ESP-IDF upgrade, the description of VSPI_HOST , HSPI_HOST will be deprecated, so if you get an error, use SPI2_HOST , SPI3_HOST instead.
cfg.spi_mode = 0; // Set SPI communication mode (0-3)
cfg.freq_write = 80000000; // SPI clock on transmission (up to 80MHz, rounded to 80MHz divided by integer)
cfg.freq_read = 16000000; // SPI clock on reception
cfg.spi_3wire = true; // Set true when receiving on the MOSI pin
cfg.use_lock = true; // set true if transaction lock is used
// * With the ESP-IDF version upgrade, SPI_DMA_CH_AUTO (automatic setting) of DMA channels is recommended.
cfg.dma_channel = SPI_DMA_CH_AUTO; // Set DMA channel to be used (0=DMA not used / 1=1ch / 2=ch / SPI_DMA_CH_AUTO=Auto setting)
cfg.pin_sclk = TFT_SCLK; // Set SCLK pin number for SPI
cfg.pin_mosi = TFT_MOSI; // Set SPI MOSI pin number
// When using the SPI bus, which is common to the SD card, be sure to set MISO without omitting it.
cfg.pin_miso = TFT_MISO; // Set THE MSO pin number of spi (-1 = disable)
cfg.pin_dc = TFT_DC; // Set THE D/C pin number of SPI (-1 = disable)
_bus_instance.config(cfg); // reflects the setting value on the bus.
_panel_instance.setBus(&_bus_instance); // Set the bus to the panel.
}
{
// set the display panel control.
auto cfg = _panel_instance.config(); // gets the structure for display panel settings.
cfg.pin_cs = TFT_CS; // Pin number to which CS is connected (-1 = disable)
cfg.pin_rst = TFT_RST; // Pin number to which RST is connected (-1 = disable)
cfg.pin_busy = -1; // Pin number to which BUSY is connected (-1 = disable)
// the following setting values are set to a general initial value for each panel,
cfg.panel_width = TFT_WIDTH; // actual visible width
cfg.panel_height = TFT_HEIGHT; // actually visible height
cfg.offset_x = 0; // Panel X-direction offset amount
cfg.offset_y = 0; // Panel Y offset amount
cfg.offset_rotation = 0; // offset of rotational values from 0 to 7 (4 to 7 upside down)
cfg.dummy_read_pixel = 8; // number of bits in dummy leads before pixel read
cfg.dummy_read_bits = 1; // number of bits in dummy leads before reading non-pixel data
cfg.readable = false; // set to true if data can be read
cfg.invert = false; // set to true if the light and dark of the panel is reversed
cfg.rgb_order = false; // set to true if the red and blue of the panel are swapped
cfg.dlen_16bit = false; // Set to true for panels that transmit data lengths in 16-bit increments in 16-bit parallel or SPI
cfg.bus_shared = true; // Set to true when sharing the bus with sd card (bus control is performed with drawJpgFile, etc.)
_panel_instance.config(cfg);
}
{
auto cfg = _light_instance.config();
cfg.pin_bl = TFT_BKLT;
cfg.invert = false;
cfg.freq = 44100;
cfg.pwm_channel = 7;
_light_instance.config(cfg);
_panel_instance.setLight(&_light_instance);
}
setPanel(&_panel_instance); // Set the panel to be used.
}
};
static LGFX lcd; // declare display variable
void setup(void)
{
lcd.init();
lcd.setCursor(0,0);
lcd.printf("Hello World!");
}
void loop()
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment