Low-level SPI peripheral driver interface definition. More...
Low-level SPI peripheral driver interface definition.
Definition in file spi.h.
#include <endian.h>
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "periph_cpu.h"
#include "periph_conf.h"
#include "periph/gpio.h"
Go to the source code of this file.
Data Structures | |
struct | spi_gpio_mode_t |
SPI gpio mode. More... | |
Macros | |
#define | CONFIG_SPI_DMA_THRESHOLD_BYTES 16 |
Threshold under which polling transfers are used instead of DMA TODO: determine at run-time based on SPI clock. | |
#define | SPI_DEV(x) (x) |
Default SPI device access macro. | |
#define | SPI_UNDEF (UINT_FAST8_MAX) |
Define global value for undefined SPI device. | |
#define | SPI_CS_UNDEF (GPIO_UNDEF) |
Define value for unused CS line. | |
#define | SPI_HWCS(x) (SPI_CS_UNDEF) |
Default SPI hardware chip select access macro. | |
Typedefs | |
typedef uint_fast8_t | spi_t |
Default type for SPI devices. | |
typedef gpio_t | spi_cs_t |
Chip select pin type overlaps with gpio_t so it can be casted to this. | |
Enumerations | |
enum | { SPI_OK = 0 , SPI_NODEV = -ENXIO , SPI_NOCS = -EINVAL , SPI_NOMODE = -EINVAL , SPI_NOCLK = -EINVAL } |
Status codes used by the SPI driver interface. More... | |
enum | spi_mode_t { SPI_MODE_0 = 0 , SPI_MODE_1 , SPI_MODE_2 , SPI_MODE_3 } |
Available SPI modes, defining the configuration of clock polarity and clock phase. More... | |
enum | spi_clk_t { SPI_CLK_100KHZ = 0 , SPI_CLK_400KHZ , SPI_CLK_1MHZ , SPI_CLK_5MHZ , SPI_CLK_10MHZ } |
Available SPI clock speeds. More... | |
Functions | |
void | spi_init (spi_t bus) |
Basic initialization of the given SPI bus. | |
void | spi_init_pins (spi_t bus) |
Initialize the used SPI bus pins, i.e. | |
int | spi_init_cs (spi_t bus, spi_cs_t cs) |
Initialize the given chip select pin. | |
void | spi_deinit_pins (spi_t dev) |
Change the pins of the given SPI bus back to plain GPIO functionality. | |
gpio_t | spi_pin_miso (spi_t dev) |
Get the MISO pin of the given SPI bus. | |
gpio_t | spi_pin_mosi (spi_t dev) |
Get the MOSI pin of the given SPI bus. | |
gpio_t | spi_pin_clk (spi_t dev) |
Get the CLK pin of the given SPI bus. | |
int | spi_init_with_gpio_mode (spi_t bus, const spi_gpio_mode_t *mode) |
Initialize MOSI/MISO/SCLK pins with adapted GPIO modes. | |
void | spi_acquire (spi_t bus, spi_cs_t cs, spi_mode_t mode, spi_clk_t clk) |
Start a new SPI transaction. | |
void | spi_release (spi_t bus) |
Finish an ongoing SPI transaction by releasing the given SPI bus. | |
uint8_t | spi_transfer_byte (spi_t bus, spi_cs_t cs, bool cont, uint8_t out) |
Transfer one byte on the given SPI bus. | |
void | spi_transfer_bytes (spi_t bus, spi_cs_t cs, bool cont, const void *out, void *in, size_t len) |
Transfer a number bytes using the given SPI bus. | |
uint8_t | spi_transfer_reg (spi_t bus, spi_cs_t cs, uint8_t reg, uint8_t out) |
Transfer one byte to/from a given register address. | |
void | spi_transfer_regs (spi_t bus, spi_cs_t cs, uint8_t reg, const void *out, void *in, size_t len) |
Transfer a number of bytes to/from a given register address. | |
static uint16_t | spi_transfer_u16_be (spi_t bus, spi_cs_t cs, bool cont, uint16_t host_number) |
Transfer a 16 bit number in big endian byte order. | |