48#include "px_spi_cfg.h"
51#if ( !defined(PX_SPI_CFG_SPI1_EN ) \
52 || !defined(PX_SPI_CFG_SPI2_EN ) \
53 || !defined(PX_SPI_CFG_DEFAULT_BAUD ) \
54 || !defined(PX_SPI_CFG_DEFAULT_MODE ) \
55 || !defined(PX_SPI_CFG_DEFAULT_DATA_ORDER) \
56 || !defined(PX_SPI_CFG_CS_LO ) \
57 || !defined(PX_SPI_CFG_CS_HI ) )
58#error "One or more options not defined in 'px_spi_cfg.h'"
60#if ( (PX_SPI_CFG_SPI1_EN > 1) \
61 ||(PX_SPI_CFG_SPI2_EN > 1) )
62#error "PX_SPI_CFG_SPIx_EN must be 0 or 1"
66#define PX_SPI_CFG_PER_COUNT (PX_SPI_CFG_SPI1_EN + PX_SPI_CFG_SPI2_EN )
67#if (PX_SPI_CFG_PER_COUNT == 0)
68#error "No peripherals enabled"
117#define PX_SPI_FLAG_START (1 << 0)
119#define PX_SPI_FLAG_STOP (1 << 1)
121#define PX_SPI_FLAG_START_AND_STOP (PX_SPI_FLAG_START + PX_SPI_FLAG_STOP)
176 uint8_t mo_dummy_byte);
268 const void * data_wr,
@ 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_256
F_PCLK / 256.
@ 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.
uint8_t cs_id
Chip Select GPIO ID.
uint8_t mo_dummy_byte
Master Out dummy byte when data is read from Master In.
uint32_t spi_cr1_val
SPI Control Register 1 value (SPI_CR1)
struct px_spi_per_s * spi_per
SPI peripheral.
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 (...