gossamer 0.0.1
a very lightweight app framework for SAMD and SAML chips
Loading...
Searching...
No Matches
uart.h
1
2/*
3 * MIT License
4 *
5 * Copyright (c) 2024 Joey Castillo
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26#pragma once
27
28#include <stdint.h>
29#include <stdbool.h>
30#include <stddef.h>
31
48typedef enum {
49 UART_TXPO_0 = 0,
50 UART_TXPO_2,
51 UART_TXPO_0_FLOW_CONTROL,
52 UART_TXPO_NONE = 0xff
54
56typedef enum {
57 UART_RXPO_0 = 0,
58 UART_RXPO_1,
59 UART_RXPO_2,
60 UART_RXPO_3,
61 UART_RXPO_NONE = 0xff
63
68void uart_init(uint32_t baud);
69
73void uart_enable(void);
74
79bool uart_is_enabled(void);
80
85void uart_set_run_in_standby(bool run_in_standby);
86
91void uart_set_irda_mode(bool irda);
92
98void uart_write(char *data, size_t length);
99
106size_t uart_read(char *data, size_t max_length);
107
113bool uart_read_byte(char *byte);
114
118void uart_disable(void);
119
127void uart_init_instance(uint8_t sercom, uart_txpo_t txpo, uart_rxpo_t rxpo, uint32_t baud);
128
133void uart_set_run_in_standby_instance(uint8_t sercom, bool run_in_standby);
134
140void uart_set_irda_mode_instance(uint8_t sercom, bool irda);
141
146void uart_enable_instance(uint8_t sercom);
147
153bool uart_is_enabled_instance(uint8_t sercom);
154
161void uart_write_instance(uint8_t sercom, char *data, size_t length);
162
170size_t uart_read_instance(uint8_t sercom, char *data, size_t max_length);
171
178bool uart_read_byte_instance(uint8_t sercom, char *byte);
179
184void uart_disable_instance(uint8_t sercom);
185
195void uart_irq_handler(uint8_t sercom);
196
size_t uart_read(char *data, size_t max_length)
Reads data from the UART peripheral for a board with a defined UART_SERCOM.
bool uart_is_enabled(void)
Checks if the UART peripheral is currently enabled for a board with a defined UART_SERCOM.
uart_txpo_t
UART transmit pinout options.
Definition uart.h:48
void uart_disable_instance(uint8_t sercom)
Disables a specific SERCOM UART instance.
Definition uart.c:208
void uart_irq_handler(uint8_t sercom)
UART IRQ handler.
Definition uart.c:212
bool uart_read_byte_instance(uint8_t sercom, char *byte)
Reads a single byte from a specific SERCOM UART instance.
Definition uart.c:191
uart_rxpo_t
UART receive pinout options.
Definition uart.h:56
void uart_set_irda_mode_instance(uint8_t sercom, bool irda)
Sets IRDA mode for a specific SERCOM instance.
Definition uart.c:163
void uart_set_run_in_standby_instance(uint8_t sercom, bool run_in_standby)
Enables a specific SERCOM UART instance.
Definition uart.c:159
bool uart_is_enabled_instance(uint8_t sercom)
Checks if the UART peripheral on the given SERCOM is currently enabled.
Definition uart.c:172
void uart_disable(void)
Disables the UART peripheral for a board with a defined UART_SERCOM.
void uart_init_instance(uint8_t sercom, uart_txpo_t txpo, uart_rxpo_t rxpo, uint32_t baud)
initializes a specific SERCOM UART instance.
Definition uart.c:109
void uart_set_run_in_standby(bool run_in_standby)
Sets whether the UART_SERCOM should run in standby mode.
void uart_enable_instance(uint8_t sercom)
Enables a specific SERCOM UART instance.
Definition uart.c:168
void uart_init(uint32_t baud)
Initializes the UART peripheral for a board with a defined UART_SERCOM.
bool uart_read_byte(char *byte)
Reads a single byte from the UART peripheral for a board with a defined UART_SERCOM.
size_t uart_read_instance(uint8_t sercom, char *data, size_t max_length)
Reads data from a specific SERCOM UART instance.
Definition uart.c:182
void uart_write_instance(uint8_t sercom, char *data, size_t length)
Writes data to a specific SERCOM UART instance.
Definition uart.c:176
void uart_write(char *data, size_t length)
Writes data to the UART peripheral for a board with a defined UART_SERCOM.
void uart_set_irda_mode(bool irda)
Sets IRDA mode for the UART_SERCOM.
void uart_enable(void)
Enables the UART peripheral for a board with a defined UART_SERCOM.