ATmega328P HAL Driver
hal_usart.h
Go to the documentation of this file.
1 
7 /*
8  * MIT License
9  *
10  * Copyright (c) 2023 Ceyhun Şen
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy
13  * of this software and associated documentation files (the "Software"), to deal
14  * in the Software without restriction, including without limitation the rights
15  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16  * copies of the Software, and to permit persons to whom the Software is
17  * furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included in all
20  * copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28  * SOFTWARE.
29  * */
30 
31 #ifndef __HAL_USART_H
32 #define __HAL_USART_H
33 
34 #include <stdint.h>
35 
40  usart_success = 0,
41  usart_error,
42  usart_error_overrun,
43  usart_error_underrun,
44  usart_error_framing,
45  usart_error_parity,
46 };
47 
52  usart_direction_transmit,
53  usart_direction_receive,
54  usart_direction_transmit_and_receive
55 };
56 
60 enum usart_mode {
61  usart_mode_asynchronous_normal,
62  usart_mode_asynchronous_double_speed,
63  usart_mode_synchronous_master
64 };
65 
70  usart_parity_disabled,
71  usart_parity_even,
72  usart_parity_odd
73 };
74 
103 struct usart_t {
104  uint32_t baud_rate;
105  uint8_t data_bits;
106  uint8_t stop_bits;
107  enum usart_direction direction;
108  enum usart_mode mode;
109  enum usart_parity parity;
110 };
111 
112 // Core functions.
113 enum usart_result usart_init(struct usart_t *usart);
114 enum usart_result usart_transmit(struct usart_t *usart, uint8_t *data, uint16_t len);
115 enum usart_result usart_receive(struct usart_t *usart, uint8_t *data, uint16_t len);
116 
117 // Extras.
118 void usart_stdio_init();
119 
120 #endif // __HAL_USART_H
usart_mode
Definition: hal_usart.h:60
enum usart_result usart_transmit(struct usart_t *usart, uint8_t *data, uint16_t len)
Transmit data over USART.
Definition: hal_usart.c:240
usart_result
Definition: hal_usart.h:39
enum usart_result usart_receive(struct usart_t *usart, uint8_t *data, uint16_t len)
Receive data over USART.
Definition: hal_usart.c:259
usart_parity
Definition: hal_usart.h:69
usart_direction
Definition: hal_usart.h:51
enum usart_result usart_init(struct usart_t *usart)
Initialize USART.
Definition: hal_usart.c:202
void usart_stdio_init()
Initialize standart I/O stream.
Definition: hal_usart_extra.c:83
Definition: hal_usart.h:103