2018年10月26日 星期五

DIY - ESP32:ESP32 SPI Master 主驅動 API 函數結構件(十七)

DIY - ESP32:ESP32 SPI Master 主驅動 API 函數結構件(十七):

在使用 ESP32 的 ESP-IDF SDK 內的 SPI 的應用程式接口(API)函數 (Function),需要使用到 spi_master 內的結構件(Structure / Struct),這是 SPI 儲存 SPI 的資料和設定數據,也是非常重要的資料。

C語言的結構件(Structure / Struct)
結構件(Structure / Struct):
  1. struct spi_bus_config_t
  2. struct spi_device_interface_config_t
  3. struct spi_transaction_t
  4. struct spi_transaction_ext_t  

1. struct spi_bus_config_t:
This is a configuration structure for a SPI bus。You can use this structure to specify the GPIO pins of the bus. Normally, the driver will use the GPIO matrix to route the signals。An exception is made when all signals either can be routed through the IO_MUX or are -1。 In that case,the IO_MUX is used,allowing for >40MHz speeds。
Public Members
Desription
int mosi_io_num
GPIO pin for Master Out Slave In (=spi_d) signal, or -1 if not used.
int miso_io_num
GPIO pin for Master In Slave Out (=spi_q) signal, or -1 if not used.
int sclk_io_num
GPIO pin for Spi CLocK signal, or -1 if not used.
int quadwp_io_num
GPIO pin for WP (Write Protect) signal which is used as D2 in 4-bit communication modes, or -1 if not used.
int quadhd_io_num
GPIO pin for HD (HolD) signal which is used as D3 in 4-bit communication modes, or -1 if not used.
int max_transfer_sz
Maximum transfer size, in bytes. Defaults to 4094 if 0.
uint32_t flags
Abilities of bus to be checked by the driver. Or-ed value of SPICOMMON_BUSFLAG_* flags.

2. struct spi_device_interface_config_t:
This is a configuration for a SPI slave device that is connected to one of the SPI buses。
Public Members
Desription
uint8_t command_bits
Default amount of bits in command phase (0-16), used when SPI_TRANS_VARIABLE_CMD is not used, otherwise ignored.
uint8_t address_bits
Default amount of bits in address phase (0-64), used when SPI_TRANS_VARIABLE_ADDR is not used, otherwise ignored.
uint8_t dummy_bits
Amount of dummy bits to insert between address and data phase.
uint8_t mode
SPI mode (0-3)
uint8_t duty_cycle_pos
Duty cycle of positive clock, in 1/256th increments (128 = 50%/50% duty). Setting this to 0 (=not setting it) is equivalent to setting this to 128.
uint8_t cs_ena_pretrans
Amount of SPI bit-cycles the cs should be activated before the transmission (0-16). This only works on half-duplex transactions.
uint8_t cs_ena_posttrans
Amount of SPI bit-cycles the cs should stay active after the transmission (0-16)
int clock_speed_hz
Clock speed, divisors of 80MHz, in Hz. See SPI_MASTER_FREQ_*.
int input_delay_ns
Maximum data valid time of slave. The time required between SCLK and MISO valid, including the possible clock delay from slave to master. The driver uses this value to give an extra delay before the MISO is ready on the line. Leave at 0 unless you know you need a delay. For better timing performance at high frequency (over 8MHz), it’s suggest to have the right value.
int spics_io_num
CS GPIO pin for this device, or -1 if not used.
uint32_t flags
Bitwise OR of SPI_DEVICE_* flags.
int queue_size
Transaction queue size. This sets how many transactions can be ‘in the air’ (queued using spi_device_queue_trans but not yet finished using spi_device_get_trans_result) at the same time.
transaction_cb_t pre_cb
Callback to be called before a transmission is started. This callback is called within interrupt context.
transaction_cb_t post_cb
Callback to be called after a transmission has completed. This callback is called within interrupt context.

3. struct spi_transaction_t:
This structure describes one SPI transaction. The descriptor should not be modified until the transaction finishes。
Public Members
Desription
uint32_t flags
Bitwise OR of SPI_TRANS_* flags.
uint16_t cmd
Command data, of which the length is set in the command_bits of spi_device_interface_config_t.
uint64_t addr
Address data, of which the length is set in the address_bits of spi_device_interface_config_t.
size_t length
Total data length, in bits.
size_t rxlength
Total data length received, should be not greater than length in full-duplex mode (0 defaults this to the value of length).
void *user
User-defined variable. Can be used to store eg transaction ID.
const void *tx_buffer
Pointer to transmit buffer, or NULL for no MOSI phase.
uint8_t tx_data[4]
If SPI_USE_TXDATA is set, data set here is sent directly from this variable.
void *rx_buffer
Pointer to receive buffer, or NULL for no MISO phase. Written by 4 bytes-unit if DMA is used.
uint8_t rx_data[4]
If SPI_USE_RXDATA is set, data is received directly to this variable.

4. struct spi_transaction_ext_t: 
This struct is for SPI transactions which may change their address and command length。 Please do set the flags in base to SPI_TRANS_VARIABLE_CMD_ADR to use the bit length here。 
Public Members
Desription
struct spi_transaction_t base
Transaction data, so that pointer to spi_transaction_t can be converted into spi_transaction_ext_t.
uint8_t command_bits
The command length in this transaction, in bits.
uint8_t address_bits
The address length in this transaction, in bits.

相關網址:
※ DIY - ESP32:ESP32 ILI9341 2.4吋 SPI TFT LCD 液晶屏電路(十三)
※ DIY - ESP32:ESP32 ILI9341 2.4吋 SPI TFT LCD 液晶屏程式(十四)
※ DIY - ESP32:ESP32 SPI 驅動 IO 介紹(十五)
※ DIY - ESP32:ESP32 SPI Master 主驅動 API 函數(十六)

2018年 10月 26日 天氣報告
氣溫:27.2@ 21:20
相對濕度:百分之 71%
天氣:大致多雲

沒有留言:

張貼留言