Refactor SPI handling in cat-medication-tracker to use ESP-IDF API for improved performance and reliability
This commit is contained in:
@@ -15,17 +15,27 @@ esphome:
|
||||
then:
|
||||
- lambda: |-
|
||||
// Send MADCTL 0x88: MY=1, BGR=1 — correct portrait for this board
|
||||
// Uses raw HSPI to bypass ESPHome's buffered display layer
|
||||
SPIClass spi2(HSPI);
|
||||
spi2.begin(14, 12, 13, -1); // SCK, MISO, MOSI, SS
|
||||
spi2.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
|
||||
digitalWrite(15, LOW); // CS assert
|
||||
digitalWrite(2, LOW); // DC = command
|
||||
spi2.transfer(0x36); // MADCTL register
|
||||
digitalWrite(2, HIGH); // DC = data
|
||||
spi2.transfer(0x88); // MY=1, BGR=1: correct vertical, no horizontal mirror
|
||||
digitalWrite(15, HIGH); // CS deassert
|
||||
spi2.endTransaction();
|
||||
// Uses ESP-IDF SPI master API to bypass ESPHome's buffered display layer
|
||||
spi_device_handle_t disp_fix;
|
||||
spi_device_interface_config_t cfg = {};
|
||||
cfg.clock_speed_hz = 1000000;
|
||||
cfg.mode = 0;
|
||||
cfg.spics_io_num = -1; // manual CS
|
||||
cfg.queue_size = 1;
|
||||
if (spi_bus_add_device(SPI2_HOST, &cfg, &disp_fix) == ESP_OK) {
|
||||
gpio_set_level((gpio_num_t)15, 0); // CS low
|
||||
gpio_set_level((gpio_num_t)2, 0); // DC = command
|
||||
spi_transaction_t t = {};
|
||||
t.length = 8;
|
||||
t.flags = SPI_TRANS_USE_TXDATA;
|
||||
t.tx_data[0] = 0x36; // MADCTL register
|
||||
spi_device_polling_transmit(disp_fix, &t);
|
||||
gpio_set_level((gpio_num_t)2, 1); // DC = data
|
||||
t.tx_data[0] = 0x88; // MY=1, BGR=1
|
||||
spi_device_polling_transmit(disp_fix, &t);
|
||||
gpio_set_level((gpio_num_t)15, 1); // CS high
|
||||
spi_bus_remove_device(disp_fix);
|
||||
}
|
||||
- component.update: my_display
|
||||
|
||||
esp32:
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
#pragma once
|
||||
#include <SPI.h>
|
||||
#include "driver/spi_master.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
Reference in New Issue
Block a user