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 instancesPuts the SPI into a known state, and enable it. Must be called before other functions. More...
 
void spi_deinit (spi_inst_t *spi)
 Deinitialise SPI instancesPuts the SPI into a disabled state. Init will need to be called to reenable the device functions. More...
 
uint spi_set_baudrate (spi_inst_t *spi, uint baudrate)
 Set SPI baudrateSet SPI frequency as close as possible to baudrate, and return the actual achieved rate. More...
 
uint spi_get_baudrate (const spi_inst_t *spi)
 Get SPI baudrateGet SPI baudrate which was set by. 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 SPIConfigure how the SPI serialises and deserialises data on the wire. More...
 
static void spi_set_slave (spi_inst_t *spi, bool slave)
 Set SPI master/slaveConfigure the SPI for master- or slave-mode operation. By default, spi_init() sets master-mode. 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 deviceWrite len bytes from src to SPI. Simultaneously read len bytes from SPI to dst. Blocks until all data is transferred. No timeout, as SPI hardware always transfers at a known data rate. More...
 
int spi_write_blocking (spi_inst_t *spi, const uint8_t *src, size_t len)
 Write to an SPI device, blockingWrite len bytes from src to SPI, and discard any data received back Blocks until all data is transferred. No timeout, as SPI hardware always transfers at a known data rate. More...
 
int spi_read_blocking (spi_inst_t *spi, uint8_t repeated_tx_data, uint8_t *dst, size_t len)
 Read from an SPI deviceRead len bytes from SPI to dst. Blocks until all data is transferred. No timeout, as SPI hardware always transfers at a known data rate. repeated_tx_data is output repeatedly on TX as data is read in from RX. Generally this can be 0, but some devices require a specific value here, e.g. SD cards expect 0xff. 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 deviceWrite len halfwords from src to SPI. Simultaneously read len halfwords from SPI to dst. Blocks until all data is transferred. No timeout, as SPI hardware always transfers at a known data rate. More...
 
int spi_write16_blocking (spi_inst_t *spi, const uint16_t *src, size_t len)
 Write to an SPI deviceWrite len halfwords from src to SPI. Discard any data received back. Blocks until all data is transferred. No timeout, as SPI hardware always transfers at a known data rate. More...
 
int spi_read16_blocking (spi_inst_t *spi, uint16_t repeated_tx_data, uint16_t *dst, size_t len)
 Read from an SPI deviceRead len halfwords from SPI to dst. Blocks until all data is transferred. No timeout, as SPI hardware always transfers at a known data rate. repeated_tx_data is output repeatedly on TX as data is read in from RX. Generally this can be 0, but some devices require a specific value here, e.g. SD cards expect 0xff. 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.