Microchip® Advanced Software Framework

usart_spi.c File Reference

AVR XMEGA USART in SPI mode driver functions.

Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.

#include "usart_spi.h"
#include "sysclk.h"

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_init (USART_t *usart)
 Initializes the USART in SPI master mode. 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...
 
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...
 

void usart_spi_deselect_device ( USART_t *  usart,
struct usart_spi_device device 
)

Deselect given device on the SPI bus.

Calls board chip deselect.

Parameters
usartBase address of the USART instance.
deviceSPI device
Precondition
SPI device must be selected with usart_spi_select_device() first

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_init ( USART_t *  usart)

Initializes the USART in SPI master mode.

Parameters
usartBase 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().

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.

Parameters
usartBase address of the usart instance.
datadata buffer to read
lenLength of data
Precondition
usart device must be selected with usart_spi_select_device() first

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().

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.

Parameters
usartBase address of the USART instance.
deviceSPI 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.

Parameters
usartBase address of the USART instance.
devicePointer to usart device struct that should be initialized.
flagsUSART configuration flags. Common flags for all implementations are the usart modes SPI_MODE_0 ... SPI_MODE_3.
baud_rateBaud rate for communication with slave device in Hz.
sel_idBoard 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.

Parameters
usartBase address of the USART instance.
dataData buffer to write
lenLength of data
Precondition
usart device must be selected with usart_spi_select_device() first

References STATUS_OK, and usart_spi_transmit().

Referenced by at25dfx_spi_write_byte(), at25dfx_spi_write_packet(), hx8347a_send_byte(), and hx8347a_write_packet().