- // Pin configuration for ST7789
- #define ST7789_MISO_PIN -1 // Not used
- #define ST7789_MOSI_PIN 11 // Master Out Slave In pin
- #define ST7789_CLK_PIN 12 // Clock pin
- #define ST7789_DC_PIN 2 // Data/Command pin
- #define ST7789_RST_PIN 6 // Reset pin
- #define ST7789_BCKL_PIN 1 // Backlight pin
- esp_err_t display_init(void) {
- esp_err_t ret;
- // Configuration for the SPI bus
- spi_bus_config_t buscfg = {
- .miso_io_num = ST7789_MISO_PIN,
- .mosi_io_num = ST7789_MOSI_PIN,
- .sclk_io_num = ST7789_CLK_PIN,
- .quadwp_io_num = -1,
- .quadhd_io_num = -1,
- .max_transfer_sz = 16 * 320 * 2 + 8
- };
- ESP_LOGI(TAG, "Initializing SPI bus...");
- ret = spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO);
- if (ret != ESP_OK) {
- ESP_LOGE(TAG, "Failed to initialize SPI bus: %s", esp_err_to_name(ret));
- return ret;
- }
- ESP_LOGI(TAG, "SPI bus initialized successfully");
- // Configuration for the SPI device on the bus
- spi_device_interface_config_t devcfg = {
- .clock_speed_hz = 1 * 1000 * 1000, // Clock out at 10 MHz
- .mode = 3, // SPI mode 3
- .spics_io_num = 42, // No CS pin
- .queue_size = 7,
- .flags = SPI_DEVICE_NO_DUMMY, // No dummy phase
- .pre_cb = NULL,
- };
- ESP_LOGI(TAG, "Adding device to SPI bus...");
- ret = spi_bus_add_device(SPI2_HOST, &devcfg, &spi);
- if (ret != ESP_OK) {
- ESP_LOGE(TAG, "Failed to add device to SPI bus: %s", esp_err_to_name(ret));
- return ret;
- }
- ESP_LOGI(TAG, "Device added to SPI bus successfully");
My code below: