Modified spi_master driver and example

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Modified spi_master driver and example

Postby loboris » Fri Mar 24, 2017 3:01 pm

https://github.com/loboris/ESP32_NEW_SPI_MASTER_EXAMPLE

Driver modifications
  • Number of the devices attached to the bus which uses hw CS can be 3 (NO_CS) as in original driver
  • Additional devices which does not use hw CS can be attached to the bus, up to NO_DEV
  • Additional parameter spics_ext_io_num is added to spi_device_interface_config_t, it is automatically handled by spi_device_select / spi_device_deselect functions
  • Devices can have individual bus_configs, so different mosi, miso, sck pins can be configured for each device
  • Because of that, spi_bus_add_device() function has added parameter bus_config
  • Reconfiguring the bus is done automaticaly when using spi_device_select() function
  • Device select/deselect functions spi_device_select / spi_device_deselect are added
  • Added NonDMA/no Transactions mode for direct transfer on the spi bus
  • Added some helper functions
Non Queued mode without DMA

Direct transfer to SPI device is possible which can coexist with queued data transfer.
Non queued transfers uses the semaphore (taken in select function & given in deselect function) to protect the transfer.

Main function in this mode is spi_transfer_data()
  • it has trans parameter which has to be configured the same way as for spi_device_transmit() function.
  • uses devices pre_cb and post_cb
  • transfer data bit size must be 8-bit multiples
  • if the divice is configured for half duplex mode (cfg.flags = SPI_DEVICE_HALFDUPLEX) data is read after sending (if any), otherwise, data is read while sending
  • if device uses hw CS (spics_io_num > 0), CS is activated before transfer and deactivated after transfer
  • if device uses external CS (spics_io_num <= 0 & spics_ext_io_num > 0) CS must be handled with spi_device_select / spi_device_deselect
  • there is no limit for transmit/receive buffer size
Complete function decsriptions are available in the header file spi_master.h

This mode is very useful when executing large amount of small transactions. Displayig individual pixels is more than 10 times faster when using NonDMA mode.

Complete example is available which demonstrate the usage with ILI9341 display and compares DMA / NonDMA preformance and advantages.
As an example of using NonDMA transfer mode, low level display functions are provided in tftfunc.c

Who is online

Users browsing this forum: No registered users and 46 guests