20 #ifndef MBED_SPI_API_H 21 #define MBED_SPI_API_H 25 #include "hal/dma_api.h" 26 #include "hal/buffer.h" 30 #define SPI_EVENT_ERROR (1 << 1) 31 #define SPI_EVENT_COMPLETE (1 << 2) 32 #define SPI_EVENT_RX_OVERFLOW (1 << 3) 33 #define SPI_EVENT_ALL (SPI_EVENT_ERROR | SPI_EVENT_COMPLETE | SPI_EVENT_RX_OVERFLOW) 35 #define SPI_EVENT_INTERNAL_TRANSFER_COMPLETE (1 << 30) // Internal flag to report that an event occurred 37 #define SPI_FILL_WORD (0xFFFF) 38 #define SPI_FILL_CHAR (0xFF) 52 typedef struct spi_s
spi_t;
156 #ifdef DEVICE_SPI_COUNT 164 SPIName spi_get_peripheral_name(PinName mosi, PinName miso, PinName mclk);
189 void spi_init(
spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel);
366 #if DEVICE_SPI_ASYNCH 384 void spi_master_transfer(
spi_t *obj,
const void *tx,
size_t tx_length,
void *rx,
size_t rx_length, uint8_t bit_width, uint32_t handler, uint32_t event, DMAUsage hint);
421 #endif // __cplusplus 425 #endif // MBED_SPI_API_H uint8_t spi_active(spi_t *obj)
Attempts to determine if the SPI peripheral is already in use.
const PinMap * spi_master_mosi_pinmap(void)
Get the pins that support SPI MOSI.
bool hw_cs_handle
If true, in SPI master mode Chip Select can be handled by hardware.
Generic buffer structure.
bool tx_rx_buffers_equal_length
If true, rx and tx buffers must have the same length.
uint32_t spi_irq_handler_asynch(spi_t *obj)
The asynchronous IRQ handler.
void spi_slave_write(spi_t *obj, int value)
Write a value to the SPI peripheral in slave mode.
bool support_slave_mode
If true, the device can handle SPI slave mode using hardware management on the specified ssel pin...
void spi_format(spi_t *obj, int bits, int mode, int slave)
Configure the SPI format.
void spi_frequency(spi_t *obj, int hz)
Set the SPI baud rate.
void spi_get_capabilities(PinName ssel, bool slave, spi_capabilities_t *cap)
Fills the given spi_capabilities_t structure with the capabilities of the given peripheral.
uint32_t minimum_frequency
Minimum frequency supported must be set by target device and it will be assessed during testing...
void spi_master_transfer(spi_t *obj, const void *tx, size_t tx_length, void *rx, size_t rx_length, uint8_t bit_width, uint32_t handler, uint32_t event, DMAUsage hint)
Begin the SPI transfer.
uint32_t maximum_frequency
Maximum frequency supported must be set by target device and it will be assessed during testing...
uint8_t clk_modes
specifies supported modes from spi_mode_t.
const PinMap * spi_master_miso_pinmap(void)
Get the pins that support SPI MISO.
const PinMap * spi_master_cs_pinmap(void)
Get the pins that support SPI CS.
const PinMap * spi_master_clk_pinmap(void)
Get the pins that support SPI CLK.
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
Initialize the SPI peripheral.
int spi_slave_read(spi_t *obj)
Get a received value out of the SPI receive buffer in slave mode.
void spi_free(spi_t *obj)
Release a SPI object.
void spi_init_direct(spi_t *obj, const spi_pinmap_t *pinmap)
Initialize the SPI peripheral.
Describes the capabilities of a SPI peripherals.
bool async_mode
If true, in async mode is supported.
int spi_master_write(spi_t *obj, int value)
Write a byte out in master mode and receive a value.
uint16_t slave_delay_between_symbols_ns
specifies required number of ns between transmission of successive symbols in slave mode...
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, char write_fill)
Write a block out in master mode and receive a value.
const PinMap * spi_slave_cs_pinmap(void)
Get the pins that support SPI CS.
const PinMap * spi_slave_mosi_pinmap(void)
Get the pins that support SPI MOSI.
void spi_abort_asynch(spi_t *obj)
Abort an SPI transfer.
int spi_slave_receive(spi_t *obj)
Check if a value is available to read.
const PinMap * spi_slave_clk_pinmap(void)
Get the pins that support SPI CLK.
uint8_t spi_get_module(spi_t *obj)
Get the module number.
const PinMap * spi_slave_miso_pinmap(void)
Get the pins that support SPI MISO.
int spi_busy(spi_t *obj)
Checks if the specified SPI peripheral is in use.
Asynch SPI HAL structure.
uint32_t word_length
Each bit represents the corresponding word length.