GaIA BIOS Library
Loading...
Searching...
No Matches
spi.h File Reference

SPI Peripheral Driver. More...

#include <stdint.h>

Data Structures

struct  spi_t
 SPI Peripheral Descriptor. More...

Macros

#define SPI_TRANSFER_COMPLETE   0
 SPI transfer complete without errors.
#define SPI_TRANSFER_ERROR   1
 SPI transfer had errors.
#define SPI_DIV_2   0
 SPI Baudrate = SPI clock / 2.
#define SPI_DIV_4   1
 SPI Baudrate = SPI clock / 4.
#define SPI_DIV_8   2
 SPI Baudrate = SPI clock / 8.
#define SPI_DIV_16   3
 SPI Baudrate = SPI clock / 16.
#define SPI_DIV_32   4
 SPI Baudrate = SPI clock / 32.
#define SPI_DIV_64   5
 SPI Baudrate = SPI clock / 64.
#define SPI_DIV_128   6
 SPI Baudrate = SPI clock / 128.
#define SPI_DIV_256   7
 SPI Baudrate = SPI clock / 256.

Typedefs

typedef void(* spi_callback_t) (uint32_t event)
 SPI callback on transfer complete or on transfer error.

Functions

void spi_init (uint8_t spi_id, uint32_t div, spi_callback_t callback)
 Initializes the given SPI.
void spi_transfer (uint8_t spi_id, uint8_t *src, uint8_t *dst, uint16_t len)
 Transfers the block of data requested.

Detailed Description

SPI Peripheral Driver.

Provides functions to initialize the SPI peripheral and to initiate a transfer.

Author
Tecnologix, 2014

Typedef Documentation

◆ spi_callback_t

typedef void(* spi_callback_t) (uint32_t event)

SPI callback on transfer complete or on transfer error.

Parameters
eventtype of event. It can be:
  • SPI_TRANSFER_COMPLETE
  • SPI_TRANSFER_ERROR

Function Documentation

◆ spi_init()

void spi_init ( uint8_t spi_id,
uint32_t div,
spi_callback_t callback )

Initializes the given SPI.

Parameters
spi_id- SPI identifier
div- Divider for the baudrate value. It can be one of: SPI_DIV_2, SPI_DIV_4, SPI_DIV_8, SPI_DIV_16, SPI_DIV_32, SPI_DIV_64, SPI_DIV_128, SPI_DIV_256.
callback- function to be called at the end of the tranfer or in case of errors.

◆ spi_transfer()

void spi_transfer ( uint8_t spi_id,
uint8_t * src,
uint8_t * dst,
uint16_t len )

Transfers the block of data requested.

Parameters
spi_id- SPI identifier.
src- source buffer. It can be NULL if it is a send-only transfer.
dst- destination buffer. It can be NULL if it is a send-only transfer.
len- buffers length.