Skip to content

Commit bdc5999

Browse files
committed
spi: code clean up
1 parent 953b7d4 commit bdc5999

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

main/src/chip/spi.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ spi_device_handle_t hspi;
1919

2020
void hspi_init(void)
2121
{
22-
spi_bus_config_t buscfg={
22+
spi_bus_config_t buscfg = {
2323
.miso_io_num = -1,
2424
.mosi_io_num = CONFIG_SPI_MOSI_PIN,
2525
.sclk_io_num = CONFIG_SPI_SCLK_PIN,
@@ -31,21 +31,20 @@ void hspi_init(void)
3131
.max_transfer_sz = ST7789_SCREEN_WIDTH*ST7789_SCREEN_HEIGHT*2
3232
#endif
3333
};
34-
spi_device_interface_config_t devcfg={
34+
ESP_ERROR_CHECK(spi_bus_initialize(HSPI_HOST, &buscfg, 1));
35+
36+
spi_device_interface_config_t devcfg = {
3537
.mode = 0, // SPI mode 0
3638
.spics_io_num = CONFIG_SPI_CS_PIN, // CS pin
39+
.clock_speed_hz = 40000000, // Clock out at 40 MHz
3740
#ifdef CONFIG_SCREEN_PANEL_ST7735
38-
.clock_speed_hz = 26000000, // Clock out at 26 MHz
39-
.queue_size = 6, // We want to be able to queue 6 transactions at a time
4041
.pre_cb = st7735_setpin_dc, // Specify pre-transfer callback to handle D/C line
4142
#elif defined(CONFIG_SCREEN_PANEL_ST7789)
42-
.clock_speed_hz = 40000000, // Clock out at 40 MHz
43-
.queue_size = 6, // We want to be able to queue 6 transactions at a time
4443
.pre_cb = st7789_setpin_dc, // Specify pre-transfer callback to handle D/C line
4544
#endif
45+
.queue_size = 2, // We want to be able to queue 2 transactions at a time
4646
.flags = SPI_DEVICE_3WIRE | SPI_DEVICE_HALFDUPLEX
4747
};
48-
ESP_ERROR_CHECK(spi_bus_initialize(HSPI_HOST, &buscfg, 1));
4948
ESP_ERROR_CHECK(spi_bus_add_device(HSPI_HOST, &devcfg, &hspi));
5049

5150
ESP_LOGI(HSPI_TAG, "initialized, sclk: %d, mosi: %d, miso: %d, cs: %d",

0 commit comments

Comments
 (0)