spi.h File Reference

Low-level SPI peripheral driver interface definition. More...

Detailed Description

Low-level SPI peripheral driver interface definition.

Author
Hauke Petersen hauke.nosp@m..pet.nosp@m.ersen.nosp@m.@fu-.nosp@m.berli.nosp@m.n.de

Definition in file spi.h.

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <limits.h>
#include "periph_cpu.h"
#include "periph_conf.h"
#include "periph/gpio.h"
+ Include dependency graph for spi.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  spi_gpio_mode_t
 SPI gpio mode. More...
 

Macros

#define SPI_DEV(x)   (x)
 Default SPI device access macro.
 
#define SPI_UNDEF   (UINT_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. More...
 

Typedefs

typedef unsigned int 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 = -1, SPI_NOCS = -2, SPI_NOMODE = -3,
  SPI_NOCLK = -4
}
 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. More...
 
void spi_init_pins (spi_t bus)
 Initialize the used SPI bus pins, i.e. More...
 
int spi_init_cs (spi_t bus, spi_cs_t cs)
 Initialize the given chip select pin. More...
 
void spi_deinit_pins (spi_t dev)
 Change the pins of the given SPI bus back to plain GPIO functionality. More...
 
gpio_t spi_pin_miso (spi_t dev)
 Get the MISO pin of the given SPI bus. More...
 
gpio_t spi_pin_mosi (spi_t dev)
 Get the MOSI pin of the given SPI bus. More...
 
gpio_t spi_pin_clk (spi_t dev)
 Get the CLK pin of the given SPI bus. More...
 
int spi_init_with_gpio_mode (spi_t bus, spi_gpio_mode_t mode)
 Initialize MOSI/MISO/SCLK pins with adapted GPIO modes. More...
 
int spi_acquire (spi_t bus, spi_cs_t cs, spi_mode_t mode, spi_clk_t clk)
 Start a new SPI transaction. More...
 
void spi_release (spi_t bus)
 Finish an ongoing SPI transaction by releasing the given SPI bus. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...