-
-
Notifications
You must be signed in to change notification settings - Fork 725
/
Copy pathboard_driver_serial.h
89 lines (75 loc) · 2.61 KB
/
board_driver_serial.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
Copyright (c) 2015 Arduino LLC. All right reserved.
Copyright (c) 2015 Atmel Corporation/Thibaut VIARD. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef UART_DRIVER_H
#define UART_DRIVER_H
#include <stdio.h>
#include <stdbool.h>
#include <sam.h>
#define PINMUX_UNUSED 0xFFFFFFFF
/* SERCOM UART available pad settings */
enum uart_pad_settings {
UART_RX_PAD0_TX_PAD2 = SERCOM_USART_CTRLA_RXPO(0) | SERCOM_USART_CTRLA_TXPO(1),
UART_RX_PAD1_TX_PAD2 = SERCOM_USART_CTRLA_RXPO(1) | SERCOM_USART_CTRLA_TXPO(1),
UART_RX_PAD2_TX_PAD0 = SERCOM_USART_CTRLA_RXPO(2),
UART_RX_PAD3_TX_PAD0 = SERCOM_USART_CTRLA_RXPO(3),
UART_RX_PAD1_TX_PAD0 = SERCOM_USART_CTRLA_RXPO(1),
UART_RX_PAD3_TX_PAD2 = SERCOM_USART_CTRLA_RXPO(3) | SERCOM_USART_CTRLA_TXPO(1),
};
/**
* \brief Initializes the UART
*
* \param Pointer to SERCOM instance
* \param Baud value corresponding to the desired baudrate
* \param SERCOM pad settings
*/
void uart_basic_init(Sercom *sercom, uint16_t baud_val, enum uart_pad_settings pad_conf);
/**
* \brief Disables UART interface
*
* \param Pointer to SERCOM instance
*/
void uart_disable(Sercom *sercom);
/**
* \brief Sends a single byte through UART interface
*
* \param Pointer to SERCOM instance
* \param Data to send
*/
void uart_write_byte(Sercom *sercom, uint8_t data);
/**
* \brief Reads a single character from UART interface
*
* \param Pointer to SERCOM instance
* \return Data byte read
*/
uint8_t uart_read_byte(Sercom *sercom);
/**
* \brief Sends buffer on UART interface
*
* \param Pointer to SERCOM instance
* \param Pointer to data to send
* \param Number of bytes to send
*/
void uart_write_buffer_polled(Sercom *sercom, uint8_t *ptr, uint16_t length);
/**
* \brief Reads data on UART interface
*
* \param Pointer to SERCOM instance
* \param Pointer to store read data
* \param Number of bytes to read
*/
void uart_read_buffer_polled(Sercom *sercom, uint8_t *ptr, uint16_t length);
#endif