This is the API for SPI master service on MEGARF.
See Quick Start Guide for the SPI Master Driver
Data Structures | |
struct | spi_device |
Variables | |
port_pin_t | spi_device::id |
Spi Master Management Configuration | |
typedef uint8_t | spi_flags_t |
typedef uint32_t | board_spi_select_id_t |
void | spi_master_init (volatile void *spi) |
Initializes the SPI in master mode. More... | |
void | spi_master_setup_device (volatile void *spi, struct spi_device *device, spi_flags_t flags, unsigned long baud_rate, board_spi_select_id_t sel_id) |
Setup a SPI device. More... | |
void | spi_select_device (volatile void *spi, struct spi_device *device) |
Select given device on the SPI bus. More... | |
void | spi_deselect_device (volatile void *spi, struct spi_device *device) |
Deselect given device on the SPI bus. More... | |
status_code_t | spi_write_packet (volatile void *spi, const uint8_t *data, size_t len) |
Send a sequence of bytes to a SPI device. More... | |
status_code_t | spi_read_packet (volatile void *spi, uint8_t *data, size_t len) |
Receive a sequence of bytes from a SPI device. More... | |
static void | spi_read_single (volatile void *spi, uint8_t *data) |
Receive one byte from a SPI device. More... | |
static __always_inline void | spi_write_single (volatile void *spi, uint8_t data) |
Write one byte to a SPI device. More... | |
static bool | spi_is_tx_empty (volatile void *spi) |
Checks if all transmissions are complete. More... | |
static bool | spi_is_tx_ready (volatile void *spi) |
Checks if all transmissions is ready. More... | |
static bool | spi_is_rx_full (volatile void *spi) |
Tests if the SPI contains a received character. More... | |
static bool | spi_is_rx_ready (volatile void *spi) |
Checks if all reception is ready. More... | |
#define | CONFIG_SPI_MASTER_DUMMY 0xFF |
#define | SPI_CPHA (1 << 0) |
Clock phase. More... | |
#define | SPI_CPOL (1 << 1) |
Clock polarity. More... | |
#define | SPI_MODE_0 0 |
SPI mode 0. More... | |
#define | SPI_MODE_1 (SPI_CPHA) |
SPI mode 1. More... | |
#define | SPI_MODE_2 (SPI_CPOL) |
SPI mode 2. More... | |
#define | SPI_MODE_3 (SPI_CPOL | SPI_CPHA) |
SPI mode 3. More... | |
The SPI module will be set up as master:
Add to application C-file (e.g. main.c):
Add to, e.g., the main loop in the application C-file:
#define CONFIG_SPI_MASTER_DUMMY 0xFF |
Referenced by spi_read_packet().
#define SPI_CPHA (1 << 0) |
Clock phase.
#define SPI_CPOL (1 << 1) |
Clock polarity.
#define SPI_MODE_0 0 |
SPI mode 0.
#define SPI_MODE_1 (SPI_CPHA) |
SPI mode 1.
#define SPI_MODE_2 (SPI_CPOL) |
SPI mode 2.
typedef uint32_t board_spi_select_id_t |
typedef uint8_t spi_flags_t |
void spi_deselect_device | ( | volatile void * | spi, |
struct spi_device * | device | ||
) |
Deselect given device on the SPI bus.
Calls board chip deselect.
spi | Base address of the SPI instance. |
device | SPI device |
References spi_device::id, and ioport_set_pin_high().
|
inlinestatic |
Tests if the SPI contains a received character.
spi | Base address of the SPI instance. |
1
if the SPI Receive Holding Register is full, otherwise 0
. References spi_is_tx_ok().
Referenced by epd_spi_read(), and spi_read_packet().
|
inlinestatic |
Checks if all reception is ready.
spi | Base address of the SPI instance. |
1
if the SPI Receiver is ready, otherwise 0
. References spi_is_tx_ok().
|
inlinestatic |
Checks if all transmissions are complete.
spi | Base address of the SPI instance. |
1 | All transmissions complete. |
0 | Transmissions not complete. |
References spi_is_tx_ok().
Referenced by epd_spi_write(), and spi_write_packet().
|
inlinestatic |
Checks if all transmissions is ready.
spi | Base address of the SPI instance. |
1 | All transmissions complete. |
0 | Transmissions not complete. |
References spi_is_tx_ok().
void spi_master_init | ( | volatile void * | spi | ) |
Initializes the SPI in master mode.
spi | Base address of the SPI instance. |
References PRSPI_bm, spi_enable_master_mode(), and sysclk_enable_module().
Referenced by at45dbx_spi_init(), epd_spi_init(), and main().
void spi_master_setup_device | ( | volatile void * | spi, |
struct spi_device * | device, | ||
spi_flags_t | flags, | ||
unsigned long | baud_rate, | ||
board_spi_select_id_t | sel_id | ||
) |
Setup a SPI device.
The returned device descriptor structure must be passed to the driver whenever that device should be used as current slave device.
spi | Base address of the SPI instance. |
device | Pointer to SPI device struct that should be initialized. |
flags | SPI configuration flags. Common flags for all implementations are the SPI modes SPI_MODE_0 ... SPI_MODE_3. |
baud_rate | Divider for Baud rate setting. |
sel_id | Board specific select id |
status_code_t spi_read_packet | ( | volatile void * | spi, |
uint8_t * | data, | ||
size_t | len | ||
) |
Receive a sequence of bytes from a SPI device.
All bytes sent out on SPI bus are sent as value 0.
spi | Base address of the SPI instance. |
data | data buffer to read |
len | Length of data |
References CONFIG_SPI_MASTER_DUMMY, spi_is_rx_full(), spi_write_single(), and STATUS_OK.
Referenced by spi_at45dbx_mem_check().
|
inlinestatic |
Receive one byte from a SPI device.
spi | Base address of the SPI instance. |
data | Pointer to the data byte where to store the received data. |
References spi_get().
void spi_select_device | ( | volatile void * | spi, |
struct spi_device * | device | ||
) |
Select given device on the SPI bus.
Set device specific setting and calls board chip select.
spi | Base address of the SPI instance. |
device | SPI device |
References spi_device::id, and ioport_set_pin_low().
status_code_t spi_write_packet | ( | volatile void * | spi, |
const uint8_t * | data, | ||
size_t | len | ||
) |
Send a sequence of bytes to a SPI device.
Received bytes on the SPI bus are discarded.
spi | Base address of the SPI instance. |
data | data buffer to write |
len | Length of data |
References spi_is_tx_empty(), spi_write_single(), and STATUS_OK.
Referenced by spi_at45dbx_mem_check().
|
static |
Write one byte to a SPI device.
spi | Base address of the SPI instance. |
data | The data byte to be loaded |
References spi_put().
Referenced by epd_spi_read(), epd_spi_write(), spi_read_packet(), and spi_write_packet().
port_pin_t spi_device::id |
Referenced by spi_deselect_device(), and spi_select_device().