PebbleOS v4.43.0-108-gde23235b2
Loading...
Searching...
No Matches
spi.h File Reference
#include <stddef.h>
#include <stdint.h>
#include <pbl/device.h>
#include <pbl/drivers/gpio.h>
#include <pbl/kernel/sem.h>
#include <pbl/util/bits.h>
#include <pbl/util/size.h>

Data Structures

struct  pbl_spi_xfer
 A full-duplex transfer. More...
 
struct  pbl_spi_bus_ops
 Bus driver operations. More...
 
struct  pbl_spi_bus
 An SPI controller. More...
 
struct  pbl_spi_dev
 A peripheral on a bus. More...
 

Macros

#define PBL_SPI_DEV(_bus, _cs, _max_hz, _mode)    {.bus = (_bus), .cs = (_cs), .mode = (_mode), .max_hz = (_max_hz)}
 Initializer for a struct pbl_spi_dev.
 
#define PBL_SPI_BUS_STATE_DEFINE(sym, ...)
 Define the class state of bus sym, for the PBL_SPI_*_DEFINE() macro of a driver.
 
#define PBL_SPI_BUS_INIT(sym, _name, _ops, _deps)
 Initializer for the struct pbl_spi_bus of bus sym.
 
Mode flags
#define PBL_SPI_CPHA   PBL_BIT(0)
 Sample on the trailing clock edge.
 
#define PBL_SPI_CPOL   PBL_BIT(1)
 Clock idles high.
 
#define PBL_SPI_MODE_0   0U
 Mode 0: clock idles low, sample on the leading edge.
 
#define PBL_SPI_MODE_1   PBL_SPI_CPHA
 Mode 1: clock idles low, sample on the trailing edge.
 
#define PBL_SPI_MODE_2   PBL_SPI_CPOL
 Mode 2: clock idles high, sample on the leading edge.
 
#define PBL_SPI_MODE_3   (PBL_SPI_CPOL | PBL_SPI_CPHA)
 Mode 3: clock idles high, sample on the trailing edge.
 
#define PBL_SPI_CS_HIGH   PBL_BIT(2)
 Chip select is active high.
 
#define PBL_SPI_LSB_FIRST   PBL_BIT(3)
 Send the least significant bit of each byte first.
 

Typedefs

typedef void(* pbl_spi_callback_t) (int status, void *arg)
 Completion callback of pbl_spi_transfer_async().
 

Functions

int pbl_spi_bus_init (const struct pbl_device *dev)
 Device init of every bus: sets the class state up, then calls the driver's init.
 
void pbl_spi_bus_complete (const struct pbl_spi_bus *bus, int status)
 Report the outcome of the transfer in flight.
 
int pbl_spi_setup (const struct pbl_spi_dev *dev)
 Set a device up: checks its chip select and mode, and drives its chip select inactive.
 
int pbl_spi_transfer_async (const struct pbl_spi_dev *dev, const struct pbl_spi_xfer *xfers, size_t num_xfers, pbl_spi_callback_t cb, void *arg)
 Run transfers with a device, returning once they have started.
 
int pbl_spi_transfer (const struct pbl_spi_dev *dev, const struct pbl_spi_xfer *xfers, size_t num_xfers)
 Run transfers with a device.
 
static int pbl_spi_write (const struct pbl_spi_dev *dev, const void *buf, uint32_t len)
 Write data.
 
static int pbl_spi_read (const struct pbl_spi_dev *dev, void *buf, uint32_t len)
 Read data, writing zeros.
 
static int pbl_spi_write_read (const struct pbl_spi_dev *dev, const void *wbuf, uint32_t wlen, void *rbuf, uint32_t rlen)
 Write data, then read data.
 

Variables

const struct pbl_device_class pbl_spi_bus_class
 Class of the SPI buses.