This commit is contained in:
2025-12-31 13:16:23 +03:00
parent 8534bb505a
commit 3620b54406
11 changed files with 666 additions and 3 deletions

37
README.md Normal file → Executable file
View File

@@ -1,3 +1,36 @@
# esp_component_template
#include "zh_mcp23s17.h"
esp_component_template
#define SPI_HOST (SPI_HOST_MAX - 1)
spi_device_handle_t mcp23s17_handle = NULL;
// To speed up transfers, every SPI transfer sends a bunch of lines. This define specifies how many. More means more memory use,
// but less overhead for setting up / finishing transfers. Make sure 240 is dividable by this.
#define PARALLEL_LINES 16
void app_main(void)
{
esp_err_t ret;
spi_device_handle_t spi;
spi_bus_config_t buscfg = {
.miso_io_num = 25,
.mosi_io_num = 23,
.sclk_io_num = 19,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = 16 * 320 * 2 + 8};
spi_device_interface_config_t devcfg = {
.clock_speed_hz = 10 * 1000 * 1000, // Clock out at 10 MHz
.mode = 0, // SPI mode 0
.spics_io_num = 22, // CS pin
.queue_size = 7, // We want to be able to queue 7 transactions at a time
// .pre_cb = lcd_spi_pre_transfer_callback, // Specify pre-transfer callback to handle D/C line
};
// Initialize the SPI bus
ret = spi_bus_initialize(SPI_HOST, &buscfg, SPI_DMA_CH_AUTO);
ESP_ERROR_CHECK(ret);
// Attach the LCD to the SPI bus
ret = spi_bus_add_device(SPI_HOST, &devcfg, &mcp23s17_handle);
ESP_ERROR_CHECK(ret);
}