1、SPI配置
Code:
- void SPI_3Wire_Interface_Init( esp_err_t* ret,
- spi_device_handle_t* spi,
- spi_bus_config_t* buscfg,
- spi_device_interface_config_t* devcfg)
- {
- buscfg->miso_io_num=-1;
- buscfg->mosi_io_num=PIN_NUM_SPI_3WIRE_SDA_IO;
- buscfg->sclk_io_num=PIN_NUM_SPI_3WIRE_SCLK_O;
- buscfg->quadwp_io_num=-1;
- buscfg->quadhd_io_num=-1;
- //buscfg.data4_io_num=-1;
- //buscfg.data5_io_num=-1;
- //buscfg.data6_io_num=-1;
- //buscfg.data7_io_num=-1;
- buscfg->max_transfer_sz=xSPI_Max_transfer_size;
- buscfg->flags=SPICOMMON_BUSFLAG_DUAL;
- //buscfg.intr_flags=;
-
- devcfg->command_bits=1;
- //devcfg.address_bits=24;
- //devcfg.dummy_bits=;
- devcfg->mode=xSPI_CPOL_CPHA_mode; //CPOL, CPHA
- //devcfg.duty_cycle_pos;
- //devcfg.cs_ena_pretrans;
- //devcfg.cs_ena_posttrans;
- devcfg->clock_speed_hz=xSPI_Clock_Speed_For_DM_Initial;
- //devcfg.input_delay_ns=;
- //devcfg->spics_io_num=PIN_NUM_SPI_4WIRE_2_CS_O;
- devcfg->flags=SPI_DEVICE_3WIRE | SPI_DEVICE_HALFDUPLEX;
- devcfg->queue_size=7;
- //*devcfg.pre_cb=RS_transfer_callback; //D/C(RS)处理
- //devcfg.post_cb=;
-
- //Initialize the SPI bus
- *ret=spi_bus_initialize(LCD_HOST, buscfg, SPI_DMA_CH_AUTO);
- ESP_ERROR_CHECK(*ret);
- //Attach the LCD to the SPI bus
- *ret=spi_bus_add_device(LCD_HOST, devcfg, spi);
- ESP_ERROR_CHECK(*ret);
- }
2、发送事务
Code:
- void DM_Display_Color(uint16_t u16Color)
- {
- uint32_t i,j= 0;
- uint32_t u32TxBuffer = 0;
- uint32_t u32temp = 0;
- //uint16_t u16Color = 0xF800; //16bit 565 红色
-
- u32temp = (1 << 17) | (1 << 8) | ((u16Color & 0xFF00) << 1) | ((u16Color & 0x00FF) << 1); //增加D/Cx标识位
- u32TxBuffer = SPI_SWAP_DATA_TX(u32temp,18);
-
-
- ICNA3310_write_1R4D(0x2A, 0x00, 0x00, 0x01, 0x67); // paritial update
- ICNA3310_write_1R4D(0x2B, 0x00, 0x00, 0x01, 0x67); // partial update
- ICNA3310_write_1R0D(0x2C);
-
- devcfg.command_bits=0;
- ret=spi_bus_add_device(LCD_HOST, &devcfg, &spi);
- ESP_ERROR_CHECK(ret);
-
- DM_CS(0);
-
- for(i=0; i<360; i++)
- {
- for(j=0; j<360; j++)
- {
- //发送data
- memset(&sendcfg, 0, sizeof(sendcfg));
- sendcfg.length = 18;
- sendcfg.tx_buffer = &u32TxBuffer;
- ret=spi_device_polling_transmit(spi, &sendcfg);
- assert(ret==ESP_OK);
- }
-
- }
-
- DM_CS(1);
-
- }
|
|
2023-3-3 14:45:21
评论
举报
|
|
|