AVR XMEGA USART in SPI mode driver functions.
Copyright (c) 2010-2018 Microchip Technology Inc. and its subsidiaries.
#include "compiler.h"
#include "status_codes.h"
#include "ioport.h"
#include "usart.h"
#include "conf_usart_spi.h"
Data Structures | |
struct | usart_spi_device |
Polled SPI device definition. More... | |
Macros | |
#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... | |
USART in SPI mode Management Configuration | |
#define | CONFIG_USART_SPI_DUMMY 0xFF |
Default Config Spi Master Dummy Field. More... | |
Typedefs | |
typedef uint32_t | board_spi_select_id_t |
typedef uint8_t | spi_flags_t |
Functions | |
void | usart_spi_deselect_device (USART_t *usart, struct usart_spi_device *device) |
Deselect given device on the SPI bus. More... | |
void | usart_spi_disable (USART_t *usart) |
Disables the USART. More... | |
void | usart_spi_enable (USART_t *usart) |
Enables the USART for the specified USART in SPI mode. More... | |
void | usart_spi_init (USART_t *usart) |
Initializes the USART in SPI master mode. More... | |
bool | usart_spi_is_enabled (USART_t *usart) |
Tests if the USART in SPI mode is enabled. More... | |
static bool | usart_spi_is_rx_full (USART_t *usart) |
Tests if the USART in SPI mode contains a received character. More... | |
static bool | usart_spi_is_rx_ready (USART_t *usart) |
Check whether the USART in SPI master mode contains a received character. More... | |
static bool | usart_spi_is_tx_empty (USART_t *usart) |
Check whether there are data in Transmit Holding Register or Transmit Shift Register in SPI master mode. More... | |
static bool | usart_spi_is_tx_ready (USART_t *usart) |
Check if the USART Transmit Register is empty. More... | |
status_code_t | usart_spi_read_packet (USART_t *usart, uint8_t *data, size_t len) |
Receive a sequence of bytes from a USART in SPI mode device. More... | |
static void | usart_spi_read_single (USART_t *usart, uint8_t *data) |
Receive one byte from a SPI device using USART in SPI mode. More... | |
void | usart_spi_select_device (USART_t *usart, struct usart_spi_device *device) |
Select given device on the SPI bus. More... | |
void | usart_spi_setup_device (USART_t *usart, struct usart_spi_device *device, spi_flags_t flags, unsigned long baud_rate, board_spi_select_id_t sel_id) |
Setup a USART in SPI mode device. More... | |
status_code_t | usart_spi_write_packet (USART_t *usart, const uint8_t *data, size_t len) |
Send a sequence of bytes to a SPI device using USART in SPI mode. More... | |
static __always_inline void | usart_spi_write_single (USART_t *usart, uint8_t data) |
Write one byte to a SPI device using USART in SPI mode. More... | |
#define CONFIG_USART_SPI_DUMMY 0xFF |
Default Config Spi Master Dummy Field.
Referenced by usart_spi_read_packet(), and usart_spi_read_single().
#define SPI_CPHA (1 << 0) |
Clock phase.
#define SPI_CPOL (1 << 1) |
Clock polarity.
#define SPI_MODE_0 0 |
SPI mode 0.
Referenced by at25dfx_spi_init(), ili9341_interface_init(), main(), and ssd1306_interface_init().
#define SPI_MODE_1 (SPI_CPHA) |
SPI mode 1.
#define SPI_MODE_2 (SPI_CPOL) |
SPI mode 2.
SPI mode 3.
Referenced by hx8347a_interface_init(), and st7565r_interface_init().
typedef uint32_t board_spi_select_id_t |
typedef uint8_t spi_flags_t |
void usart_spi_deselect_device | ( | USART_t * | usart, |
struct usart_spi_device * | device | ||
) |
Deselect given device on the SPI bus.
Calls board chip deselect.
usart | Base address of the USART instance. |
device | SPI device |
References usart_spi_device::id, and ioport_set_pin_high().
Referenced by at25dfx_spi_deselect_device(), ssd1306_write_command(), ssd1306_write_data(), st7565r_write_command(), and st7565r_write_data().
void usart_spi_disable | ( | USART_t * | usart | ) |
Disables the USART.
Ensures that nothing is transferred while setting up buffers.
usart | Base address of the USART instance. |
void usart_spi_enable | ( | USART_t * | usart | ) |
Enables the USART for the specified USART in SPI mode.
usart | Base address of the USART instance. |
void usart_spi_init | ( | USART_t * | usart | ) |
Initializes the USART in SPI master mode.
usart | Base address of the USART instance. |
References sysclk_enable_module(), SYSCLK_PORT_C, SYSCLK_PORT_D, SYSCLK_PORT_E, and SYSCLK_PORT_F.
Referenced by at25dfx_spi_init(), at45dbx_spi_init(), hx8347a_interface_init(), ili9341_interface_init(), ssd1306_interface_init(), and st7565r_interface_init().
bool usart_spi_is_enabled | ( | USART_t * | usart | ) |
Tests if the USART in SPI mode is enabled.
usart | Base address of the usart instance. |
1
if the usart is enabled, otherwise 0
.
|
inlinestatic |
Tests if the USART in SPI mode contains a received character.
usart | Base address of the USART instance. |
1
if the USART Receive Holding Register is full, otherwise 0
. References usart_rx_is_complete().
|
inlinestatic |
Check whether the USART in SPI master mode contains a received character.
usart | Base address of the USART instance. |
1 | Some data have been received. |
0 | No data has been received. |
References usart_rx_is_complete().
|
inlinestatic |
Check whether there are data in Transmit Holding Register or Transmit Shift Register in SPI master mode.
usart | Base address of the USART instance. |
1 | The two registers are empty. |
0 | One of the two registers contains data. |
References usart_data_register_is_empty().
Referenced by ili9341_wait_for_send_done().
|
inlinestatic |
Check if the USART Transmit Register is empty.
usart | Base address of the USART instance. |
1 | There is no data in the Transmit Holding Register. |
0 | There are data in the Transmit Holding Register. |
References usart_data_register_is_empty().
status_code_t usart_spi_read_packet | ( | USART_t * | usart, |
uint8_t * | data, | ||
size_t | len | ||
) |
Receive a sequence of bytes from a USART in SPI mode device.
All bytes sent out on usart bus are sent as value 0.
usart | Base address of the usart instance. |
data | data buffer to read |
len | Length of data |
References CONFIG_USART_SPI_DUMMY, STATUS_OK, and usart_spi_transmit().
Referenced by at25dfx_spi_read_byte(), at25dfx_spi_read_packet(), and hx8347a_read_byte().
|
inlinestatic |
Receive one byte from a SPI device using USART in SPI mode.
usart | Base address of the USART instance. |
data | Pointer to the data byte where to store the received data. |
References CONFIG_USART_SPI_DUMMY, and usart_spi_transmit().
Referenced by hx8347a_read_byte(), and ili9341_read_byte().
void usart_spi_select_device | ( | USART_t * | usart, |
struct usart_spi_device * | device | ||
) |
Select given device on the SPI bus.
Set device specific setting and calls board chip select.
usart | Base address of the USART instance. |
device | SPI device |
References usart_spi_device::id, and ioport_set_pin_low().
Referenced by at25dfx_spi_select_device(), ssd1306_write_command(), ssd1306_write_data(), st7565r_write_command(), and st7565r_write_data().
void usart_spi_setup_device | ( | USART_t * | usart, |
struct usart_spi_device * | device, | ||
spi_flags_t | flags, | ||
unsigned long | baud_rate, | ||
board_spi_select_id_t | sel_id | ||
) |
Setup a USART in SPI mode device.
The returned device descriptor structure must be passed to the driver whenever that device should be used as current slave device.
usart | Base address of the USART instance. |
device | Pointer to usart device struct that should be initialized. |
flags | USART configuration flags. Common flags for all implementations are the usart modes SPI_MODE_0 ... SPI_MODE_3. |
baud_rate | Baud rate for communication with slave device in Hz. |
sel_id | Board specific select id |
References usart_spi_options::baudrate, usart_spi_options::data_order, usart_spi_options::spimode, and usart_init_spi().
Referenced by at25dfx_spi_init(), hx8347a_interface_init(), ili9341_interface_init(), ssd1306_interface_init(), and st7565r_interface_init().
status_code_t usart_spi_write_packet | ( | USART_t * | usart, |
const uint8_t * | data, | ||
size_t | len | ||
) |
Send a sequence of bytes to a SPI device using USART in SPI mode.
Received bytes on the USART in SPI mode are discarded.
usart | Base address of the USART instance. |
data | Data buffer to write |
len | Length of data |
References STATUS_OK, and usart_spi_transmit().
Referenced by at25dfx_spi_write_byte(), at25dfx_spi_write_packet(), hx8347a_send_byte(), and hx8347a_write_packet().
|
static |
Write one byte to a SPI device using USART in SPI mode.
usart | Base address of the usart instance. |
data | The data byte to be loaded |
References usart_spi_transmit().
Referenced by hx8347a_send_byte(), and ili9341_send_byte().