Loading...
Searching...
No Matches
soft_uart.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 ML!PA Consulting GmbH
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
29#ifndef SOFT_UART_H
30#define SOFT_UART_H
31
32#include "periph/gpio.h"
33#include "periph/uart.h"
34#include "periph/timer.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
43#define SOFT_UART_FLAG_INVERT_TX 0x1
44
48#define SOFT_UART_FLAG_INVERT_RX 0x2
49
53typedef struct {
54 gpio_t rx_pin;
55 gpio_t tx_pin;
58 uint32_t timer_freq;
60 uint8_t flags;
62
66typedef unsigned soft_uart_t;
67
92int soft_uart_init(soft_uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg);
93
106 uart_stop_bits_t stop_bits);
107
120void soft_uart_write(soft_uart_t uart, const uint8_t *data, size_t len);
121
128
135
136#ifdef __cplusplus
137}
138#endif
139
140#endif /* SOFT_UART_H */
Low-level GPIO peripheral driver interface definitions.
Low-level timer peripheral driver interface definitions.
Low-level UART peripheral driver interface definition.
uint_fast8_t tim_t
Default timer type.
Definition timer.h:71
void(* uart_rx_cb_t)(void *arg, uint8_t data)
Signature for receive interrupt callback.
Definition uart.h:108
unsigned soft_uart_t
Software UART type definition.
Definition soft_uart.h:66
void soft_uart_write(soft_uart_t uart, const uint8_t *data, size_t len)
Write data from the given buffer to the specified UART device.
int soft_uart_mode(soft_uart_t uart, uart_data_bits_t data_bits, uart_parity_t parity, uart_stop_bits_t stop_bits)
Setup parity, data and stop bits for a given UART device.
void soft_uart_poweroff(soft_uart_t uart)
Power off the given UART device.
void soft_uart_poweron(soft_uart_t uart)
Power on the given UART device.
int soft_uart_init(soft_uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
Initialize a given UART device.
uart_parity_t
Definition of possible parity modes.
Definition periph_cpu.h:502
uart_stop_bits_t
Definition of possible stop bits lengths.
Definition periph_cpu.h:534
uart_data_bits_t
Definition of possible data bits lengths in a UART frame.
Definition periph_cpu.h:518
Software UART port descriptor.
Definition soft_uart.h:53
gpio_t tx_pin
TX pin.
Definition soft_uart.h:55
gpio_t rx_pin
RX pin.
Definition soft_uart.h:54
uint32_t timer_freq
Operating frequency of the timer.
Definition soft_uart.h:58
tim_t rx_timer
Hardware timer used for RX.
Definition soft_uart.h:56
tim_t tx_timer
Hardware timer used for TX.
Definition soft_uart.h:57
uint8_t flags
Soft UART flags.
Definition soft_uart.h:60