2021-05-23 19:50:04 -04:00
/*
* SPDX - FileCopyrightText : 2010 - 2021 Espressif Systems ( Shanghai ) CO LTD
*
* SPDX - License - Identifier : Apache - 2.0
*/
2017-01-06 01:20:32 -05:00
2019-06-25 01:36:24 -04:00
# pragma once
2017-01-06 01:20:32 -05:00
# include "esp_err.h"
# include "freertos/FreeRTOS.h"
2019-06-25 01:36:24 -04:00
//for spi_bus_initialization funcions. to be back-compatible
2017-03-31 03:05:25 -04:00
# include "driver/spi_common.h"
2017-01-06 01:20:32 -05:00
2017-09-28 08:19:18 -04:00
/** SPI master clock is divided by 80MHz apb clock. Below defines are example frequencies, and are accurate. Be free to specify a random frequency, it will be rounded to closest frequency (to macros below if above 8MHz).
* 8 MHz
*/
# define SPI_MASTER_FREQ_8M (APB_CLK_FREQ / 10)
# define SPI_MASTER_FREQ_9M (APB_CLK_FREQ / 9) ///< 8.89MHz
# define SPI_MASTER_FREQ_10M (APB_CLK_FREQ / 8) ///< 10MHz
# define SPI_MASTER_FREQ_11M (APB_CLK_FREQ / 7) ///< 11.43MHz
# define SPI_MASTER_FREQ_13M (APB_CLK_FREQ / 6) ///< 13.33MHz
# define SPI_MASTER_FREQ_16M (APB_CLK_FREQ / 5) ///< 16MHz
# define SPI_MASTER_FREQ_20M (APB_CLK_FREQ / 4) ///< 20MHz
# define SPI_MASTER_FREQ_26M (APB_CLK_FREQ / 3) ///< 26.67MHz
# define SPI_MASTER_FREQ_40M (APB_CLK_FREQ / 2) ///< 40MHz
# define SPI_MASTER_FREQ_80M (APB_CLK_FREQ / 1) ///< 80MHz
2017-01-06 01:20:32 -05:00
# ifdef __cplusplus
extern " C "
{
# endif
# define SPI_DEVICE_TXBIT_LSBFIRST (1<<0) ///< Transmit command/address/data LSB first instead of the default MSB first
# define SPI_DEVICE_RXBIT_LSBFIRST (1<<1) ///< Receive data LSB first instead of the default MSB first
2018-01-14 22:46:33 -05:00
# define SPI_DEVICE_BIT_LSBFIRST (SPI_DEVICE_TXBIT_LSBFIRST|SPI_DEVICE_RXBIT_LSBFIRST) ///< Transmit and receive LSB first
2017-04-26 23:24:44 -04:00
# define SPI_DEVICE_3WIRE (1<<2) ///< Use MOSI (=spid) for both sending and receiving data
2017-01-06 01:20:32 -05:00
# define SPI_DEVICE_POSITIVE_CS (1<<3) ///< Make CS positive during a transaction instead of negative
# define SPI_DEVICE_HALFDUPLEX (1<<4) ///< Transmit data before receiving it, instead of simultaneously
# define SPI_DEVICE_CLK_AS_CS (1<<5) ///< Output clock on CS line if CS is active
2018-06-05 13:36:01 -04:00
/** There are timing issue when reading at high frequency (the frequency is related to whether iomux pins are used, valid time after slave sees the clock).
2018-03-27 03:20:15 -04:00
* - In half - duplex mode , the driver automatically inserts dummy bits before reading phase to fix the timing issue . Set this flag to disable this feature .
* - In full - duplex mode , however , the hardware cannot use dummy bits , so there is no way to prevent data being read from getting corrupted .
* Set this flag to confirm that you ' re going to work with output only , or read without dummy bits at your own risk .
*/
2017-09-28 08:19:18 -04:00
# define SPI_DEVICE_NO_DUMMY (1<<6)
2019-06-05 22:57:29 -04:00
# define SPI_DEVICE_DDRCLK (1<<7)
2022-06-12 16:10:42 -04:00
# define SPI_DEVICE_NO_RETURN_RESULT (1<<8) ///< Don't return the descriptor to the host on completion (use post_cb to notify instead)
2017-01-06 01:20:32 -05:00
typedef struct spi_transaction_t spi_transaction_t ;
typedef void ( * transaction_cb_t ) ( spi_transaction_t * trans ) ;
/**
* @ brief This is a configuration for a SPI slave device that is connected to one of the SPI buses .
*/
typedef struct {
2017-09-27 08:16:37 -04:00
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.
2017-01-06 01:20:32 -05:00
uint8_t dummy_bits ; ///< Amount of dummy bits to insert between address and data phase
2021-02-03 08:56:53 -05:00
uint8_t mode ; /**< SPI mode, representing a pair of (CPOL, CPHA) configuration:
- 0 : ( 0 , 0 )
- 1 : ( 0 , 1 )
- 2 : ( 1 , 0 )
- 3 : ( 1 , 1 )
*/
2019-06-05 22:57:29 -04:00
uint16_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.
uint16_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.
2017-01-06 01:20:32 -05:00
uint8_t cs_ena_posttrans ; ///< Amount of SPI bit-cycles the cs should stay active after the transmission (0-16)
2017-09-28 08:19:18 -04:00
int clock_speed_hz ; ///< Clock speed, divisors of 80MHz, in Hz. See ``SPI_MASTER_FREQ_*``.
2018-01-30 22:15:23 -05:00
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
2017-09-28 08:19:18 -04:00
performance at high frequency ( over 8 MHz ) , it ' s suggest to have the right value .
*/
2017-01-06 01:20:32 -05:00
int spics_io_num ; ///< CS GPIO pin for this device, or -1 if not used
uint32_t flags ; ///< Bitwise OR of SPI_DEVICE_* flags
2017-01-10 22:25:56 -05:00
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
2018-10-23 04:57:32 -04:00
transaction_cb_t pre_cb ; /**< Callback to be called before a transmission is started.
*
* This callback is called within interrupt
* context should be in IRAM for best
* performance , see " Transferring Speed "
* section in the SPI Master documentation for
* full details . If not , the callback may crash
* during flash operation when the driver is
* initialized with ESP_INTR_FLAG_IRAM .
*/
transaction_cb_t post_cb ; /**< Callback to be called after a transmission has completed.
*
* This callback is called within interrupt
* context should be in IRAM for best
* performance , see " Transferring Speed "
* section in the SPI Master documentation for
* full details . If not , the callback may crash
* during flash operation when the driver is
* initialized with ESP_INTR_FLAG_IRAM .
*/
2017-01-06 01:20:32 -05:00
} spi_device_interface_config_t ;
2017-01-10 01:41:12 -05:00
# define SPI_TRANS_MODE_DIO (1<<0) ///< Transmit/receive data in 2-bit mode
# define SPI_TRANS_MODE_QIO (1<<1) ///< Transmit/receive data in 4-bit mode
# define SPI_TRANS_USE_RXDATA (1<<2) ///< Receive into rx_data member of spi_transaction_t instead into memory at rx_buffer.
# define SPI_TRANS_USE_TXDATA (1<<3) ///< Transmit tx_data member of spi_transaction_t instead of data at tx_buffer. Do not set tx_buffer when using this.
2017-12-12 04:50:21 -05:00
# define SPI_TRANS_MODE_DIOQIO_ADDR (1<<4) ///< Also transmit address in mode selected by SPI_MODE_DIO/SPI_MODE_QIO
# define SPI_TRANS_VARIABLE_CMD (1<<5) ///< Use the ``command_bits`` in ``spi_transaction_ext_t`` rather than default value in ``spi_device_interface_config_t``.
# define SPI_TRANS_VARIABLE_ADDR (1<<6) ///< Use the ``address_bits`` in ``spi_transaction_ext_t`` rather than default value in ``spi_device_interface_config_t``.
2019-02-26 13:09:36 -05:00
# define SPI_TRANS_VARIABLE_DUMMY (1<<7) ///< Use the ``dummy_bits`` in ``spi_transaction_ext_t`` rather than default value in ``spi_device_interface_config_t``.
2021-05-12 23:53:44 -04:00
# define SPI_TRANS_CS_KEEP_ACTIVE (1<<8) ///< Keep CS active after data transfer
2021-08-18 07:19:55 -04:00
# define SPI_TRANS_MULTILINE_CMD (1<<9) ///< The data lines used at command phase is the same as data phase (otherwise, only one data line is used at command phase)
# define SPI_TRANS_MODE_OCT (1<<10) ///< Transmit/receive data in 8-bit mode
# define SPI_TRANS_MULTILINE_ADDR SPI_TRANS_MODE_DIOQIO_ADDR ///< The data lines used at address phase is the same as data phase (otherwise, only one data line is used at address phase)
2021-07-09 04:46:27 -04:00
2017-01-06 01:20:32 -05:00
/**
2017-07-16 23:37:32 -04:00
* This structure describes one SPI transaction . The descriptor should not be modified until the transaction finishes .
2017-01-06 01:20:32 -05:00
*/
struct spi_transaction_t {
uint32_t flags ; ///< Bitwise OR of SPI_TRANS_* flags
2018-03-27 03:20:15 -04:00
uint16_t cmd ; /**< Command data, of which the length is set in the ``command_bits`` of spi_device_interface_config_t.
*
* < b > NOTE : this field , used to be " command " in ESP - IDF 2.1 and before , is re - written to be used in a new way in ESP - IDF 3.0 . < / b >
*
* Example : write 0x0123 and command_bits = 12 to send command 0x12 , 0x3 _ ( in previous version , you may have to write 0x3 _12 ) .
*/
uint64_t addr ; /**< Address data, of which the length is set in the ``address_bits`` of spi_device_interface_config_t.
*
2017-09-28 08:19:18 -04:00
* < b > NOTE : this field , used to be " address " in ESP - IDF 2.1 and before , is re - written to be used in a new way in ESP - IDF3 .0 . < / b >
2018-03-27 03:20:15 -04:00
*
2017-09-28 08:19:18 -04:00
* Example : write 0x123400 and address_bits = 24 to send address of 0x12 , 0x34 , 0x00 ( in previous version , you may have to write 0x12340000 ) .
2018-03-27 03:20:15 -04:00
*/
2017-01-06 01:20:32 -05:00
size_t length ; ///< Total data length, in bits
2017-08-14 23:00:33 -04:00
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``).
2017-01-06 01:20:32 -05:00
void * user ; ///< User-defined variable. Can be used to store eg transaction ID.
union {
const void * tx_buffer ; ///< Pointer to transmit buffer, or NULL for no MOSI phase
2018-12-07 02:34:15 -05:00
uint8_t tx_data [ 4 ] ; ///< If SPI_TRANS_USE_TXDATA is set, data set here is sent directly from this variable.
2017-01-06 01:20:32 -05:00
} ;
union {
2017-07-16 23:37:32 -04:00
void * rx_buffer ; ///< Pointer to receive buffer, or NULL for no MISO phase. Written by 4 bytes-unit if DMA is used.
2018-12-07 02:34:15 -05:00
uint8_t rx_data [ 4 ] ; ///< If SPI_TRANS_USE_RXDATA is set, data is received directly to this variable
2017-01-06 01:20:32 -05:00
} ;
2017-08-15 00:46:21 -04:00
} ; //the rx data should start from a 32-bit aligned address to get around dma issue.
2017-01-06 01:20:32 -05:00
2017-09-27 08:16:37 -04:00
/**
* 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 .
*/
typedef struct {
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.
2019-02-26 13:09:36 -05:00
uint8_t dummy_bits ; ///< The dummy length in this transaction, in bits.
2017-09-27 08:16:37 -04:00
} spi_transaction_ext_t ;
2017-01-06 01:20:32 -05:00
2021-08-18 07:19:55 -04:00
typedef struct spi_device_t * spi_device_handle_t ; ///< Handle for a device on a SPI bus
2017-01-06 01:20:32 -05:00
/**
* @ brief Allocate a device on a SPI bus
*
* This initializes the internal structures for a device , plus allocates a CS pin on the indicated SPI master
* peripheral and routes it to the indicated GPIO . All SPI master devices have three CS pins and can thus control
* up to three devices .
*
2017-03-02 05:46:59 -05:00
* @ note While in general , speeds up to 80 MHz on the dedicated SPI pins and 40 MHz on GPIO - matrix - routed pins are
* supported , full - duplex transfers routed over the GPIO matrix only support speeds up to 26 MHz .
*
2019-10-24 07:00:26 -04:00
* @ param host_id SPI peripheral to allocate device on
2017-01-06 01:20:32 -05:00
* @ param dev_config SPI interface protocol config for the device
* @ param handle Pointer to variable to hold the device handle
2017-09-28 08:19:18 -04:00
* @ return
2022-08-17 03:03:56 -04:00
* - ESP_ERR_INVALID_ARG if parameter is invalid or configuration combination is not supported ( e . g .
* ` dev_config - > post_cb ` isn ' t set while flag ` SPI_DEVICE_NO_RETURN_RESULT ` is enabled )
2017-01-06 01:20:32 -05:00
* - ESP_ERR_NOT_FOUND if host doesn ' t have any free CS slots
* - ESP_ERR_NO_MEM if out of memory
* - ESP_OK on success
2017-09-28 08:19:18 -04:00
*/
2019-10-24 07:00:26 -04:00
esp_err_t spi_bus_add_device ( spi_host_device_t host_id , const spi_device_interface_config_t * dev_config , spi_device_handle_t * handle ) ;
2017-01-06 01:20:32 -05:00
/**
* @ brief Remove a device from the SPI bus
*
* @ param handle Device handle to free
2017-09-28 08:19:18 -04:00
* @ return
2017-01-06 01:20:32 -05:00
* - ESP_ERR_INVALID_ARG if parameter is invalid
* - ESP_ERR_INVALID_STATE if device already is freed
* - ESP_OK on success
*/
esp_err_t spi_bus_remove_device ( spi_device_handle_t handle ) ;
/**
2018-01-30 22:15:23 -05:00
* @ brief Queue a SPI transaction for interrupt transaction execution . Get the result by ` ` spi_device_get_trans_result ` ` .
*
* @ note Normally a device cannot start ( queue ) polling and interrupt
* transactions simultaneously .
2017-01-06 01:20:32 -05:00
*
* @ param handle Device handle obtained using spi_host_add_dev
* @ param trans_desc Description of transaction to execute
* @ param ticks_to_wait Ticks to wait until there ' s room in the queue ; use portMAX_DELAY to
* never time out .
2017-11-16 18:52:21 -05:00
* @ return
2021-12-13 00:17:17 -05:00
* - ESP_ERR_INVALID_ARG if parameter is invalid . This can happen if SPI_TRANS_CS_KEEP_ACTIVE flag is specified while
2021-05-12 23:53:44 -04:00
* the bus was not acquired ( ` spi_device_acquire_bus ( ) ` should be called first )
2017-11-08 07:36:37 -05:00
* - ESP_ERR_TIMEOUT if there was no room in the queue before ticks_to_wait expired
2017-11-16 18:52:21 -05:00
* - ESP_ERR_NO_MEM if allocating DMA - capable temporary buffer failed
2018-01-30 22:15:23 -05:00
* - ESP_ERR_INVALID_STATE if previous transactions are not finished
2017-01-06 01:20:32 -05:00
* - ESP_OK on success
*/
esp_err_t spi_device_queue_trans ( spi_device_handle_t handle , spi_transaction_t * trans_desc , TickType_t ticks_to_wait ) ;
/**
2018-01-30 22:15:23 -05:00
* @ brief Get the result of a SPI transaction queued earlier by ` ` spi_device_queue_trans ` ` .
2017-01-06 01:20:32 -05:00
*
2018-01-30 22:15:23 -05:00
* This routine will wait until a transaction to the given device
* succesfully completed . It will then return the description of the
2017-09-28 08:19:18 -04:00
* completed transaction so software can inspect the result and e . g . free the memory or
2017-01-06 01:20:32 -05:00
* re - use the buffers .
*
* @ param handle Device handle obtained using spi_host_add_dev
2017-09-28 08:19:18 -04:00
* @ param trans_desc Pointer to variable able to contain a pointer to the description of the transaction
that is executed . The descriptor should not be modified until the descriptor is returned by
2017-07-16 23:37:32 -04:00
spi_device_get_trans_result .
2017-01-06 01:20:32 -05:00
* @ param ticks_to_wait Ticks to wait until there ' s a returned item ; use portMAX_DELAY to never time
out .
2017-09-28 08:19:18 -04:00
* @ return
2017-01-06 01:20:32 -05:00
* - ESP_ERR_INVALID_ARG if parameter is invalid
2022-09-15 03:56:25 -04:00
* - ESP_ERR_NOT_SUPPORTED if flag ` SPI_DEVICE_NO_RETURN_RESULT ` is set
2017-11-08 07:36:37 -05:00
* - ESP_ERR_TIMEOUT if there was no completed transaction before ticks_to_wait expired
2017-01-06 01:20:32 -05:00
* - ESP_OK on success
*/
esp_err_t spi_device_get_trans_result ( spi_device_handle_t handle , spi_transaction_t * * trans_desc , TickType_t ticks_to_wait ) ;
/**
2018-05-06 21:03:48 -04:00
* @ brief Send a SPI transaction , wait for it to complete , and return the result
2017-01-06 01:20:32 -05:00
*
2018-05-06 21:03:48 -04:00
* This function is the equivalent of calling spi_device_queue_trans ( ) followed by spi_device_get_trans_result ( ) .
2018-01-30 22:15:23 -05:00
* Do not use this when there is still a transaction separately queued ( started ) from spi_device_queue_trans ( ) or polling_start / transmit that hasn ' t been finalized .
2018-05-06 21:03:48 -04:00
*
* @ note This function is not thread safe when multiple tasks access the same SPI device .
2018-01-30 22:15:23 -05:00
* Normally a device cannot start ( queue ) polling and interrupt
* transactions simutanuously .
2017-01-06 01:20:32 -05:00
*
* @ param handle Device handle obtained using spi_host_add_dev
2017-08-25 03:45:04 -04:00
* @ param trans_desc Description of transaction to execute
2018-05-06 21:03:48 -04:00
* @ return
2017-01-06 01:20:32 -05:00
* - ESP_ERR_INVALID_ARG if parameter is invalid
* - ESP_OK on success
*/
esp_err_t spi_device_transmit ( spi_device_handle_t handle , spi_transaction_t * trans_desc ) ;
2018-01-30 22:15:23 -05:00
/**
* @ brief Immediately start a polling transaction .
*
* @ note Normally a device cannot start ( queue ) polling and interrupt
* transactions simutanuously . Moreover , a device cannot start a new polling
* transaction if another polling transaction is not finished .
*
* @ param handle Device handle obtained using spi_host_add_dev
* @ param trans_desc Description of transaction to execute
* @ param ticks_to_wait Ticks to wait until there ' s room in the queue ;
* currently only portMAX_DELAY is supported .
*
* @ return
2021-12-13 00:17:17 -05:00
* - ESP_ERR_INVALID_ARG if parameter is invalid . This can happen if SPI_TRANS_CS_KEEP_ACTIVE flag is specified while
2021-05-12 23:53:44 -04:00
* the bus was not acquired ( ` spi_device_acquire_bus ( ) ` should be called first )
2018-01-30 22:15:23 -05:00
* - ESP_ERR_TIMEOUT if the device cannot get control of the bus before ` ` ticks_to_wait ` ` expired
* - ESP_ERR_NO_MEM if allocating DMA - capable temporary buffer failed
* - ESP_ERR_INVALID_STATE if previous transactions are not finished
* - ESP_OK on success
*/
esp_err_t spi_device_polling_start ( spi_device_handle_t handle , spi_transaction_t * trans_desc , TickType_t ticks_to_wait ) ;
/**
* @ brief Poll until the polling transaction ends .
*
* This routine will not return until the transaction to the given device has
* succesfully completed . The task is not blocked , but actively busy - spins for
* the transaction to be completed .
*
* @ param handle Device handle obtained using spi_host_add_dev
* @ param ticks_to_wait Ticks to wait until there ' s a returned item ; use portMAX_DELAY to never time
out .
* @ return
* - ESP_ERR_INVALID_ARG if parameter is invalid
* - ESP_ERR_TIMEOUT if the transaction cannot finish before ticks_to_wait expired
* - ESP_OK on success
*/
esp_err_t spi_device_polling_end ( spi_device_handle_t handle , TickType_t ticks_to_wait ) ;
/**
* @ brief Send a polling transaction , wait for it to complete , and return the result
*
* This function is the equivalent of calling spi_device_polling_start ( ) followed by spi_device_polling_end ( ) .
* Do not use this when there is still a transaction that hasn ' t been finalized .
*
* @ note This function is not thread safe when multiple tasks access the same SPI device .
* Normally a device cannot start ( queue ) polling and interrupt
* transactions simutanuously .
*
* @ param handle Device handle obtained using spi_host_add_dev
* @ param trans_desc Description of transaction to execute
* @ return
* - ESP_ERR_INVALID_ARG if parameter is invalid
* - ESP_OK on success
*/
esp_err_t spi_device_polling_transmit ( spi_device_handle_t handle , spi_transaction_t * trans_desc ) ;
/**
* @ brief Occupy the SPI bus for a device to do continuous transactions .
*
* Transactions to all other devices will be put off until ` ` spi_device_release_bus ` ` is called .
*
* @ note The function will wait until all the existing transactions have been sent .
*
* @ param device The device to occupy the bus .
* @ param wait Time to wait before the the bus is occupied by the device . Currently MUST set to portMAX_DELAY .
*
* @ return
* - ESP_ERR_INVALID_ARG : ` ` wait ` ` is not set to portMAX_DELAY .
* - ESP_OK : Success .
*/
esp_err_t spi_device_acquire_bus ( spi_device_handle_t device , TickType_t wait ) ;
/**
* @ brief Release the SPI bus occupied by the device . All other devices can start sending transactions .
*
* @ param dev The device to release the bus .
*/
void spi_device_release_bus ( spi_device_handle_t dev ) ;
2022-07-12 18:00:46 -04:00
/**
* @ brief Calculate working frequency for specific device
*
* @ param handle SPI device handle
* @ param [ out ] freq_khz output parameter to hold calculated frequency in kHz
*
* @ return
* - ESP_ERR_INVALID_ARG : ` ` handle ` ` or ` ` freq_khz ` ` parameter is NULL
* - ESP_OK : Success
*/
esp_err_t spi_device_get_actual_freq ( spi_device_handle_t handle , int * freq_khz ) ;
2019-01-23 04:07:03 -05:00
/**
* @ brief Calculate the working frequency that is most close to desired frequency .
*
* @ param fapb The frequency of apb clock , should be ` ` APB_CLK_FREQ ` ` .
* @ param hz Desired working frequency
* @ param duty_cycle Duty cycle of the spi clock
*
2017-12-14 03:08:13 -05:00
* @ return Actual working frequency that most fit .
*/
2019-01-23 04:07:03 -05:00
int spi_get_actual_clock ( int fapb , int hz , int duty_cycle ) ;
2017-12-14 03:08:13 -05:00
2017-09-28 08:19:18 -04:00
/**
* @ brief Calculate the timing settings of specified frequency and settings .
*
2018-06-05 13:36:01 -04:00
* @ param gpio_is_used True if using GPIO matrix , or False if iomux pins are used .
2017-09-28 08:19:18 -04:00
* @ param input_delay_ns Input delay from SCLK launch edge to MISO data valid .
2022-05-14 07:12:13 -04:00
* @ param eff_clk Effective clock frequency ( in Hz ) from ` spi_get_actual_clock ( ) ` .
2017-09-28 08:19:18 -04:00
* @ param dummy_o Address of dummy bits used output . Set to NULL if not needed .
* @ param cycles_remain_o Address of cycles remaining ( after dummy bits are used ) output .
* - - 1 If too many cycles remaining , suggest to compensate half a clock .
* - 0 If no remaining cycles or dummy bits are not used .
* - positive value : cycles suggest to compensate .
2018-01-30 22:15:23 -05:00
*
2017-09-28 08:19:18 -04:00
* @ note If * * dummy_o * is not zero , it means dummy bits should be applied in half duplex mode , and full duplex mode may not work .
*/
2021-08-18 07:19:55 -04:00
void spi_get_timing ( bool gpio_is_used , int input_delay_ns , int eff_clk , int * dummy_o , int * cycles_remain_o ) ;
2017-09-28 08:19:18 -04:00
/**
* @ brief Get the frequency limit of current configurations .
* SPI master working at this limit is OK , while above the limit , full duplex mode and DMA will not work ,
* and dummy bits will be aplied in the half duplex mode .
2018-01-30 22:15:23 -05:00
*
2017-09-28 08:19:18 -04:00
* @ param gpio_is_used True if using GPIO matrix , or False if native pins are used .
* @ param input_delay_ns Input delay from SCLK launch edge to MISO data valid .
* @ return Frequency limit of current configurations .
*/
int spi_get_freq_limit ( bool gpio_is_used , int input_delay_ns ) ;
2017-01-06 01:20:32 -05:00
# ifdef __cplusplus
}
# endif