46 #ifndef _SPI_MASTER_H_ 47 #define _SPI_MASTER_H_ 114 spi->CTRL |= SPI_ENABLE_bm;
127 spi->CTRL &= ~SPI_ENABLE_bm;
138 return spi->CTRL & SPI_ENABLE_bm ?
true :
false;
147 static inline void spi_put(SPI_t *spi, uint8_t data)
171 return spi->STATUS & SPI_IF_bm ?
true :
false;
182 spi->CTRL |= SPI_MASTER_bm;
214 #ifndef CONFIG_SPI_MASTER_DUMMY 215 #define CONFIG_SPI_MASTER_DUMMY 0xFF 222 #define SPI_CPHA (1 << 0) 227 #define SPI_CPOL (1 << 1) 236 #define SPI_MODE_1 (SPI_CPHA) 240 #define SPI_MODE_2 (SPI_CPOL) 244 #define SPI_MODE_3 (SPI_CPOL | SPI_CPHA) 246 typedef uint8_t spi_flags_t;
247 typedef uint32_t board_spi_select_id_t;
277 spi_flags_t flags,
unsigned long baud_rate,
278 board_spi_select_id_t sel_id);
350 extern status_code_t
spi_write_packet(SPI_t *spi,
const uint8_t *data,
size_t len);
375 extern status_code_t
spi_read_packet(SPI_t *spi, uint8_t *data,
size_t len);
430 #endif // _SPI_MASTER_H_ static bool spi_is_rx_full(SPI_t *spi)
Tests if the SPI contains a received character.
static void spi_disable(SPI_t *spi)
Disables the SPI.
static void spi_enable_master_mode(SPI_t *spi)
Activate SPI master mode of a SPI peripheral.
Data format not recognized.
static bool spi_is_enabled(SPI_t *spi)
Tests if the SPI is enabled.
Polled SPI device definition.
Request flushed from queue.
port_pin_t id
Board specific select id.
Commonly used includes, types and macros.
static void spi_read_single(SPI_t *spi, uint8_t *data)
Receive one byte from a SPI device.
void spi_master_init(SPI_t *spi)
Initializes the SPI in master mode.
static void spi_put(SPI_t *spi, uint8_t data)
Put one data byte to a SPI peripheral.
static void spi_enable(SPI_t *spi)
Enables the SPI.
XMEGA I/O Port driver header file.
status_code_t spi_read_packet(SPI_t *spi, uint8_t *data, size_t len)
Receive a sequence of bytes from a SPI device.
static bool spi_is_rx_ready(SPI_t *spi)
Checks if all reception is ready.
static uint8_t spi_get(SPI_t *spi)
Get one data byte to a SPI peripheral.
static __always_inline void spi_write_single(SPI_t *spi, uint8_t data)
Write one byte to a SPI device.
Data integrity check failed.
static bool spi_is_tx_ok(SPI_t *spi)
Tests if the SPI contains a received character.
void spi_master_setup_device(SPI_t *spi, struct spi_device *device, spi_flags_t flags, unsigned long baud_rate, board_spi_select_id_t sel_id)
Setup a SPI device.
int8_t spi_xmega_set_baud_div(SPI_t *spi, uint32_t baudrate, uint32_t clkper_hz)
Calculates the SPI baudrate divider.
static bool spi_is_tx_empty(SPI_t *spi)
Checks if all transmissions are complete.
static bool spi_is_tx_ready(SPI_t *spi)
Checks if all transmissions is ready.
void spi_select_device(SPI_t *spi, struct spi_device *device)
Select given device on the SPI bus.
void spi_deselect_device(SPI_t *spi, struct spi_device *device)
Deselect given device on the SPI bus.
status_code_t spi_write_packet(SPI_t *spi, const uint8_t *data, size_t len)
Send a sequence of bytes to a SPI device.
#define __always_inline
The function should always be inlined.