SAM USART in SPI mode driver functions.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
Data Structures | |
struct | usart_spi_device |
Polled SPI device definition. More... | |
Macros | |
#define | SPI_TYPE_DEFS |
USART in SPI mode Management Configuration. | |
#define | CONFIG_USART_SPI_DUMMY 0xFF |
Default Configuration of SPI Master Dummy Field. More... | |
Typedefs | |
typedef uint32_t | board_spi_select_id_t |
Board SPI Select Id Definition. More... | |
typedef uint8_t | port_pin_t |
typedef uint8_t | spi_flags_t |
SPI Flags Definition. More... | |
Functions | |
void | usart_spi_deselect_device (Usart *p_usart, struct usart_spi_device *device) |
De-select the given device on the SPI bus. More... | |
void | usart_spi_disable (Usart *p_usart) |
Disable the USART for the specified USART in SPI mode. More... | |
void | usart_spi_enable (Usart *p_usart) |
Enable the USART for the specified USART in SPI mode. More... | |
void | usart_spi_init (Usart *p_usart) |
Enable the USART system clock in SPI master mode. More... | |
uint32_t | usart_spi_is_rx_full (Usart *p_usart) |
Check if both receive buffers are full. More... | |
uint32_t | usart_spi_is_rx_ready (Usart *p_usart) |
Check whether the USART in SPI master mode contains a received character. More... | |
uint32_t | usart_spi_is_tx_empty (Usart *p_usart) |
Check whether there are data in Transmit Holding Register or Transmit Shift Register in SPI master mode. More... | |
uint32_t | usart_spi_is_tx_ready (Usart *p_usart) |
Check if the USART Transmit Holding Register is empty or not in SPI mode. More... | |
uint32_t | usart_spi_read_packet (Usart *p_usart, uint8_t *data, size_t len) |
Receive a sequence of bytes from a USART in SPI mode device. More... | |
void | usart_spi_read_single (Usart *p_usart, uint8_t *data) |
Receive one byte from an SPI device using USART in SPI mode. More... | |
void | usart_spi_select_device (Usart *p_usart, struct usart_spi_device *device) |
Select the given device on the SPI bus. More... | |
void | usart_spi_setup_device (Usart *p_usart, struct usart_spi_device *device, spi_flags_t flags, unsigned long baud_rate, board_spi_select_id_t sel_id) |
Set up a USART in SPI master mode device. More... | |
uint32_t | usart_spi_write_packet (Usart *p_usart, const uint8_t *data, size_t len) |
Send a sequence of bytes to an SPI device using USART in SPI mode. More... | |
void | usart_spi_write_single (Usart *p_usart, uint8_t data) |
Write one byte to an SPI device using USART in SPI mode. More... | |
#define CONFIG_USART_SPI_DUMMY 0xFF |
Default Configuration of SPI Master Dummy Field.
Referenced by usart_spi_read_packet(), and usart_spi_read_single().
#define SPI_TYPE_DEFS |
typedef uint32_t board_spi_select_id_t |
Board SPI Select Id Definition.
typedef uint8_t port_pin_t |
typedef uint8_t spi_flags_t |
SPI Flags Definition.
void usart_spi_deselect_device | ( | Usart * | p_usart, |
struct usart_spi_device * | device | ||
) |
De-select the given device on the SPI bus.
p_usart | Base address of the USART instance. |
device | SPI device. |
References UNUSED, and usart_spi_release_chip_select().
Referenced by at25dfx_spi_deselect_device(), ssd1306_write_command(), and ssd1306_write_data().
void usart_spi_disable | ( | Usart * | p_usart | ) |
Disable the USART for the specified USART in SPI mode.
Ensure that nothing is transferred while setting up buffers.
p_usart | Base address of the USART instance. |
References usart_disable_rx(), and usart_disable_tx().
void usart_spi_enable | ( | Usart * | p_usart | ) |
Enable the USART for the specified USART in SPI mode.
p_usart | Base address of the USART instance. |
References usart_enable_rx(), and usart_enable_tx().
void usart_spi_init | ( | Usart * | p_usart | ) |
Enable the USART system clock in SPI master mode.
p_usart | Pointer to Base address of the USART instance. |
References sysclk_enable_peripheral_clock().
Referenced by at25dfx_spi_init(), at45dbx_spi_init(), and ssd1306_interface_init().
uint32_t usart_spi_is_rx_full | ( | Usart * | p_usart | ) |
Check if both receive buffers are full.
p_usart | Base address of the USART instance. |
1 | Receive buffers are full. |
0 | Receive buffers are not full. |
References usart_is_rx_buf_full().
uint32_t usart_spi_is_rx_ready | ( | Usart * | p_usart | ) |
Check whether the USART in SPI master mode contains a received character.
p_usart | Base address of the USART instance. |
1 | Some data have been received. |
0 | No data has been received. |
References usart_is_rx_ready().
uint32_t usart_spi_is_tx_empty | ( | Usart * | p_usart | ) |
Check whether there are data in Transmit Holding Register or Transmit Shift Register in SPI master mode.
p_usart | Base address of the USART instance. |
1 | The two registers are empty. |
0 | One of the two registers contains data. |
References usart_is_tx_empty().
uint32_t usart_spi_is_tx_ready | ( | Usart * | p_usart | ) |
Check if the USART Transmit Holding Register is empty or not in SPI mode.
p_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_is_tx_ready().
uint32_t usart_spi_read_packet | ( | Usart * | p_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.
p_usart | Base address of the usart instance. |
data | Data buffer to put read data. |
len | Length of data. |
References CONFIG_USART_SPI_DUMMY, usart_getchar(), and usart_putchar().
Referenced by at25dfx_spi_read_byte(), and at25dfx_spi_read_packet().
void usart_spi_read_single | ( | Usart * | p_usart, |
uint8_t * | data | ||
) |
Receive one byte from an SPI device using USART in SPI mode.
p_usart | Base address of the USART instance. |
data | Pointer to the data byte where to store the received data. |
References CONFIG_USART_SPI_DUMMY, usart_getchar(), and usart_putchar().
void usart_spi_select_device | ( | Usart * | p_usart, |
struct usart_spi_device * | device | ||
) |
Select the given device on the SPI bus.
p_usart | Base address of the USART instance. |
device | SPI device. |
References UNUSED, and usart_spi_force_chip_select().
Referenced by at25dfx_spi_select_device(), ssd1306_write_command(), and ssd1306_write_data().
void usart_spi_setup_device | ( | Usart * | p_usart, |
struct usart_spi_device * | device, | ||
spi_flags_t | flags, | ||
unsigned long | baud_rate, | ||
board_spi_select_id_t | sel_id | ||
) |
Set up a USART in SPI master mode device.
The returned device descriptor structure must be passed to the driver whenever that device should be used as current slave device.
p_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, which should be SPI_MODE_0, SPI_MODE_1, SPI_MODE_2, SPI_MODE_3. |
baud_rate | Baud rate for communication with slave device in Hz. |
sel_id | Board specific select id. |
References usart_spi_opt_t::baudrate, usart_spi_opt_t::channel_mode, usart_spi_opt_t::char_length, usart_spi_opt_t::spi_mode, sysclk_get_pba_hz(), UNUSED, usart_enable_rx(), usart_enable_tx(), and usart_init_spi_master().
Referenced by at25dfx_spi_init(), and ssd1306_interface_init().
uint32_t usart_spi_write_packet | ( | Usart * | p_usart, |
const uint8_t * | data, | ||
size_t | len | ||
) |
Send a sequence of bytes to an SPI device using USART in SPI mode.
Received bytes on the USART in SPI mode are discarded.
p_usart | Base address of the USART instance. |
data | Data buffer to write. |
len | Length of data. |
References usart_getchar(), and usart_putchar().
Referenced by at25dfx_spi_write_byte(), and at25dfx_spi_write_packet().
void usart_spi_write_single | ( | Usart * | p_usart, |
uint8_t | data | ||
) |
Write one byte to an SPI device using USART in SPI mode.
p_usart | Base address of the USART instance. |
data | The data to be sent out. |
References usart_putchar().