56#include "px_spi_cfg.h"
59#if ( !defined(PX_SPI_CFG_SPI0_EN ) \
60 || !defined(PX_SPI_CFG_SPCR ) \
61 || !defined(PX_SPI_CFG_USE_SPI2X ) \
62 || !defined(PX_SPI_CFG_DEFAULT_BAUD ) \
63 || !defined(PX_SPI_CFG_DEFAULT_MODE ) \
64 || !defined(PX_SPI_CFG_DEFAULT_DATA_ORDER) \
65 || !defined(PX_SPI_CFG_CS_LO ) \
66 || !defined(PX_SPI_CFG_CS_HI ) )
68#error
"One or more options not defined in 'px_uart_cfg.h'"
72#error "PX_SPI_CFG_SPIx_EN must be 0 or 1"
76#define PX_SPI_CFG_PER_COUNT (PX_SPI_CFG_SPI0_EN)
77#if (PX_SPI_CFG_PER_COUNT == 0)
78#error "No peripherals enabled"
125#define PX_SPI_FLAG_START (1 << 0)
127#define PX_SPI_FLAG_STOP (1 << 1)
129#define PX_SPI_FLAG_START_AND_STOP (PX_SPI_FLAG_START + PX_SPI_FLAG_STOP)
135 struct px_spi_per_s * spi_per;
139 uint8_t mo_dummy_byte;
185 uint8_t mo_dummy_byte);
277 const void * data_wr,
#define PX_SPI_CFG_SPI0_EN
Enable/disable support for SPI0 peripheral.
@ PX_SPI_MODE0
CPOL=0, CPHA=0; SCLK idle polarity low; data sampled on first (rising) edge.
@ PX_SPI_MODE3
CPOL=1, CPHA=1; SCLK idle polarity high; data sampled on second (rising) edge.
@ PX_SPI_MODE1
CPOL=0, CPHA=1; SCLK idle polarity low; data sampled on second (falling) edge.
@ PX_SPI_MODE2
CPOL=1, CPHA=0; SCLK idle polarity high; data sampled on first (falling) edge.
@ PX_SPI_DATA_ORDER_LSB
Data order is Least Significant Bit first (D0, D1, ..., D7)
@ PX_SPI_DATA_ORDER_MSB
Data order is Most Significant Bit first (D7, D6, ..., D0)
@ PX_SPI_BAUD_CLK_DIV_128
F_PCLK / 128.
@ PX_SPI_BAUD_CLK_DIV_8
F_PCLK / 8.
@ PX_SPI_BAUD_CLK_DIV_4
F_PCLK / 4.
@ PX_SPI_BAUD_CLK_DIV_64
F_PCLK / 64.
@ PX_SPI_BAUD_CLK_DIV_16
F_PCLK / 16.
@ PX_SPI_BAUD_CLK_DIV_2
F_PCLK / 2.
@ PX_SPI_BAUD_CLK_DIV_32
F_PCLK / 32.
bool use_spi2x
Use 2X clock rate.
uint8_t spcr
SPI Control Register value.
bool px_spi_close(px_spi_handle_t *handle)
Close specified device.
px_spi_mode_t
Specify SPI Clock polarity / Clock phase.
void px_spi_init(void)
Initialise SPI driver.
bool px_spi_open2(px_spi_handle_t *handle, px_spi_nr_t spi_nr, uint8_t cs_id, px_spi_baud_t baud, px_spi_mode_t mode, px_spi_dord_t data_order, uint8_t mo_dummy_byte)
Open SPI peripheral using specified parameters.
px_spi_dord_t
Specify SPI Data order.
void px_spi_xc(px_spi_handle_t *handle, const void *data_wr, void *data_rd, size_t nr_of_bytes, uint8_t flags)
Perform an SPI exchange (write and read) transaction with an SPI slave.
void px_spi_wr(px_spi_handle_t *handle, const void *data, size_t nr_of_bytes, uint8_t flags)
Perform an SPI write transaction with an SPI slave.
void px_spi_rd(px_spi_handle_t *handle, void *data, size_t nr_of_bytes, uint8_t flags)
Perform an SPI read transaction with an SPI slave.
px_spi_nr_t
Specify SPI peripheral number.
void px_spi_change_baud(px_spi_handle_t *handle, px_spi_baud_t baud)
Change SPI peripheral baud.
uint32_t px_spi_util_clk_div_to_baud_hz(px_spi_baud_t baud)
Calculate the actual BAUD (in Hz) from the specified division.
bool px_spi_open(px_spi_handle_t *handle, px_spi_nr_t spi_nr, uint8_t cs_id)
Open SPI peripheral using predefined (default) parameters.
px_spi_baud_t
Specify SPI baud rate as a ratio of the peripheral clock.
px_spi_baud_t px_spi_util_baud_hz_to_clk_div(uint32_t baud_hz)
Calculate clock divisor that will yield closest frequency equal to or less than specified baud rate (...