Microchip® Advanced Software Framework

usart.h File Reference

SAM SERCOM USART Driver.

Copyright (c) 2012-2020 Microchip Technology Inc. and its subsidiaries.

#include <compiler.h>
#include <sercom.h>
#include <pinmux.h>

Data Structures

struct  usart_config
 USART configuration struct. More...
 
struct  usart_module
 SERCOM USART driver software device instance structure. More...
 

Macros

#define PINMUX_DEFAULT   0
 Default pinmux. More...
 
#define PINMUX_UNUSED   0xFFFFFFFF
 Unused pinmux. More...
 
#define USART_TIMEOUT   0xFFFF
 USART timeout value. More...
 

Enumerations

enum  usart_character_size {
  USART_CHARACTER_SIZE_5BIT = SERCOM_USART_CTRLB_CHSIZE(5),
  USART_CHARACTER_SIZE_6BIT = SERCOM_USART_CTRLB_CHSIZE(6),
  USART_CHARACTER_SIZE_7BIT = SERCOM_USART_CTRLB_CHSIZE(7),
  USART_CHARACTER_SIZE_8BIT = SERCOM_USART_CTRLB_CHSIZE(0),
  USART_CHARACTER_SIZE_9BIT = SERCOM_USART_CTRLB_CHSIZE(1)
}
 USART Character Size. More...
 
enum  usart_dataorder {
  USART_DATAORDER_MSB = 0,
  USART_DATAORDER_LSB = SERCOM_USART_CTRLA_DORD
}
 USART Data Order enum. More...
 
enum  usart_parity {
  USART_PARITY_ODD = SERCOM_USART_CTRLB_PMODE,
  USART_PARITY_EVEN = 0,
  USART_PARITY_NONE = 0xFF
}
 USART Parity enum. More...
 
enum  usart_signal_mux_settings {
  USART_RX_0_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(0)),
  USART_RX_0_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(0) | SERCOM_USART_CTRLA_TXPO),
  USART_RX_1_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(1)),
  USART_RX_1_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(1) | SERCOM_USART_CTRLA_TXPO),
  USART_RX_2_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(2)),
  USART_RX_2_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(2) | SERCOM_USART_CTRLA_TXPO),
  USART_RX_3_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(3)),
  USART_RX_3_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(3) | SERCOM_USART_CTRLA_TXPO)
}
 USART signal MUX settings. More...
 
enum  usart_stopbits {
  USART_STOPBITS_1 = 0,
  USART_STOPBITS_2 = SERCOM_USART_CTRLB_SBMODE
}
 USART Stop Bits enum. More...
 
enum  usart_transceiver_type {
  USART_TRANSCEIVER_RX,
  USART_TRANSCEIVER_TX
}
 USART Transceiver. More...
 
enum  usart_transfer_mode {
  USART_TRANSFER_SYNCHRONOUSLY = (SERCOM_USART_CTRLA_CMODE),
  USART_TRANSFER_ASYNCHRONOUSLY = (0x0ul << SERCOM_USART_CTRLA_CMODE_Pos)
}
 USART Transfer mode enum. More...
 

Functions

static void usart_disable (const struct usart_module *const module)
 Disable module. More...
 
static void usart_enable (const struct usart_module *const module)
 Enable the module. More...
 
static void usart_get_config_defaults (struct usart_config *const config)
 Initializes the device to predefined defaults. More...
 
enum status_code usart_init (struct usart_module *const module, Sercom *const hw, const struct usart_config *const config)
 Initializes the device. More...
 
static bool usart_is_syncing (const struct usart_module *const module)
 Check if peripheral is busy syncing registers across clock domains. More...
 
static void usart_reset (const struct usart_module *const module)
 Resets the USART module. More...
 
Lock/Unlock
static enum status_code usart_lock (struct usart_module *const module)
 Attempt to get lock on driver instance. More...
 
static void usart_unlock (struct usart_module *const module)
 Unlock driver instance. More...
 
Writing and Reading
enum status_code usart_write_wait (struct usart_module *const module, const uint16_t tx_data)
 Transmit a character via the USART. More...
 
enum status_code usart_read_wait (struct usart_module *const module, uint16_t *const rx_data)
 Receive a character via the USART. More...
 
enum status_code usart_write_buffer_wait (struct usart_module *const module, const uint8_t *tx_data, uint16_t length)
 Transmit a buffer of characters via the USART. More...
 
enum status_code usart_read_buffer_wait (struct usart_module *const module, uint8_t *rx_data, uint16_t length)
 Receive a buffer of length characters via the USART. More...
 
Enabling/Disabling Receiver and Transmitter
static void usart_enable_transceiver (struct usart_module *const module, enum usart_transceiver_type transceiver_type)
 Enable Transceiver. More...
 
static void usart_disable_transceiver (struct usart_module *const module, enum usart_transceiver_type transceiver_type)
 Disable Transceiver. More...