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
9#pragma once
10
30
31#include "periph/gpio.h"
32#include "periph/uart.h"
33#include "periph/timer.h"
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
42#define SOFT_UART_FLAG_INVERT_TX 0x1
43
47#define SOFT_UART_FLAG_INVERT_RX 0x2
48
52typedef struct {
53 gpio_t rx_pin;
54 gpio_t tx_pin;
57 uint32_t timer_freq;
59 uint8_t flags;
61
65typedef unsigned soft_uart_t;
66
91int soft_uart_init(soft_uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg);
92
105 uart_stop_bits_t stop_bits);
106
119void soft_uart_write(soft_uart_t uart, const uint8_t *data, size_t len);
120
127
134
135#ifdef __cplusplus
136}
137#endif
138
Low-level timer peripheral driver interface definitions.
Low-level GPIO peripheral driver interface definitions.
uint_fast8_t tim_t
Default timer type.
Definition timer.h:70
void(* uart_rx_cb_t)(void *arg, uint8_t data)
Signature for receive interrupt callback.
Definition uart.h:107
unsigned soft_uart_t
Software UART type definition.
Definition soft_uart.h:65
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:501
uart_stop_bits_t
Definition of possible stop bits lengths.
Definition periph_cpu.h:533
uart_data_bits_t
Definition of possible data bits lengths in a UART frame.
Definition periph_cpu.h:517
Software UART port descriptor.
Definition soft_uart.h:52
gpio_t tx_pin
TX pin.
Definition soft_uart.h:54
gpio_t rx_pin
RX pin.
Definition soft_uart.h:53
uint32_t timer_freq
Operating frequency of the timer.
Definition soft_uart.h:57
tim_t rx_timer
Hardware timer used for RX.
Definition soft_uart.h:55
tim_t tx_timer
Hardware timer used for TX.
Definition soft_uart.h:56
uint8_t flags
Soft UART flags.
Definition soft_uart.h:59
Low-level UART peripheral driver interface definition.