main: configure SPI for LCD frame recording

This commit is contained in:
King Kévin 2023-03-13 19:38:15 +01:00
parent 102bc6d038
commit 66a6149fdf
1 changed files with 39 additions and 1 deletions

View File

@ -21,6 +21,20 @@
// GPIO for on-board LED (WEMOS S2 mini, source on)
#define LED_BOARD 15
/* GM1352 test pads:
* - CS: LCD chip select, to start data communication
* - DATA: LCD data bits
* - WR: LCD data clock (not periodic)
* - S: ??? (low)
* - 1: HOLD button (press low)
* - 2: MIN/MAX button (press low)
* - 3: POWER button (press low)
*/
#define GPIO_POWER (35U)
#define GPIO_MOSI (16U)
#define GPIO_SCLK (33U)
#define GPIO_CS (18U)
static const char *TAG = "main";
/**
@ -85,10 +99,34 @@ void app_main(void)
tinyusb_config_cdcacm_t amc_cfg = { 0 }; // the configuration uses default values
ESP_ERROR_CHECK( tusb_cdc_acm_init(&amc_cfg) ); // configure CDC ACM
ESP_ERROR_CHECK( tusb_dfu_rf_init() ); // configure DFU runtime (ensures we can use it)
esp_tusb_init_console(TINYUSB_CDC_ACM_0); // log to USB
ESP_LOGI(TAG, "USB initialized");
// configure SPI for GM1352 LCD data frame reading
const spi_bus_config_t buscfg = { // SPI bus configuration
.mosi_io_num = GPIO_MOSI,
.miso_io_num = -1,
.sclk_io_num = GPIO_SCLK,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
};
spi_slave_interface_config_t slvcfg={
.mode = 0,
.spics_io_num = GPIO_CS,
.queue_size = 3,
.flags = 0,
.post_setup_cb = NULL,
.post_trans_cb = post_trans_cb,
};
ESP_ERROR_CHECK( spi_slave_initialize(SPI2_HOST, &buscfg, &slvcfg, SPI_DMA_CH_AUTO) );
spi_slave_transaction_t t; // for the SPI transaction
memset(&t, 0, sizeof(t)); // clear transaction
t.length = FRAME_SIZE * 8; // transaction size
WORD_ALIGNED_ATTR uint8_t recvbuf[FRAME_SIZE]; // SPI receive buffer must be word aligned for DMA
t.rx_buffer = recvbuf; // set buffer
spi_slave_queue_trans(SPI2_HOST, &t, portMAX_DELAY);
ESP_LOGI(TAG, "application ready");
esp_tusb_init_console(TINYUSB_CDC_ACM_0); // log to USB
gpio_set_level(LED_BOARD, 0); // switch running LED on to indicate all is ready
while (1) {
vTaskDelay(1000 / portTICK_PERIOD_MS);