spi.h File Reference
#include "pico.h"
#include "hardware/structs/spi.h"
#include "hardware/regs/dreq.h"
Include dependency graph for spi.h:

Go to the source code of this file.

Macros

#define PARAM_ASSERTIONS_ENABLED_SPI   0
 
#define spi0   ((spi_inst_t *)spi0_hw)
 
#define spi1   ((spi_inst_t *)spi1_hw)
 

Typedefs

typedef struct spi_inst spi_inst_t
 

Enumerations

enum  spi_cpha_t { SPI_CPHA_0 = 0, SPI_CPHA_1 = 1 }
 Enumeration of SPI CPHA (clock phase) values.
 
enum  spi_cpol_t { SPI_CPOL_0 = 0, SPI_CPOL_1 = 1 }
 Enumeration of SPI CPOL (clock polarity) values.
 
enum  spi_order_t { SPI_LSB_FIRST = 0, SPI_MSB_FIRST = 1 }
 Enumeration of SPI bit-order values.
 

Functions

uint spi_init (spi_inst_t *spi, uint baudrate)
 Initialise SPI instances. More...
 
void spi_deinit (spi_inst_t *spi)
 Deinitialise SPI instances. More...
 
uint spi_set_baudrate (spi_inst_t *spi, uint baudrate)
 Set SPI baudrate. More...
 
uint spi_get_baudrate (const spi_inst_t *spi)
 Get SPI baudrate. More...
 
static uint spi_get_index (const spi_inst_t *spi)
 Convert SPI instance to hardware instance number. More...
 
static spi_hw_tspi_get_hw (spi_inst_t *spi)
 
static const spi_hw_tspi_get_const_hw (const spi_inst_t *spi)
 
static void spi_set_format (spi_inst_t *spi, uint data_bits, spi_cpol_t cpol, spi_cpha_t cpha, __unused spi_order_t order)
 Configure SPI. More...
 
static void spi_set_slave (spi_inst_t *spi, bool slave)
 Set SPI master/slave. More...
 
static bool spi_is_writable (const spi_inst_t *spi)
 Check whether a write can be done on SPI device. More...
 
static bool spi_is_readable (const spi_inst_t *spi)
 Check whether a read can be done on SPI device. More...
 
static bool spi_is_busy (const spi_inst_t *spi)
 Check whether SPI is busy. More...
 
int spi_write_read_blocking (spi_inst_t *spi, const uint8_t *src, uint8_t *dst, size_t len)
 Write/Read to/from an SPI device. More...
 
int spi_write_blocking (spi_inst_t *spi, const uint8_t *src, size_t len)
 Write to an SPI device, blocking. More...
 
int spi_read_blocking (spi_inst_t *spi, uint8_t repeated_tx_data, uint8_t *dst, size_t len)
 Read from an SPI device. More...
 
int spi_write16_read16_blocking (spi_inst_t *spi, const uint16_t *src, uint16_t *dst, size_t len)
 Write/Read half words to/from an SPI device. More...
 
int spi_write16_blocking (spi_inst_t *spi, const uint16_t *src, size_t len)
 Write to an SPI device. More...
 
int spi_read16_blocking (spi_inst_t *spi, uint16_t repeated_tx_data, uint16_t *dst, size_t len)
 Read from an SPI device. More...
 
static uint spi_get_dreq (spi_inst_t *spi, bool is_tx)
 Return the DREQ to use for pacing transfers to/from a particular SPI instance. More...
 

Typedef Documentation

◆ spi_inst_t

typedef struct spi_inst spi_inst_t

Opaque type representing an SPI instance.