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
37 extern "C" {
38 #endif
39 
43 #define SOFT_UART_FLAG_INVERT_TX 0x1
44 
48 #define SOFT_UART_FLAG_INVERT_RX 0x2
49 
53 typedef struct {
54  gpio_t rx_pin;
55  gpio_t tx_pin;
58  uint32_t timer_freq;
60  uint8_t flags;
62 
66 typedef unsigned soft_uart_t;
67 
92 int soft_uart_init(soft_uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg);
93 
105 int soft_uart_mode(soft_uart_t uart, uart_data_bits_t data_bits, uart_parity_t parity,
106  uart_stop_bits_t stop_bits);
107 
120 void soft_uart_write(soft_uart_t uart, const uint8_t *data, size_t len);
121 
127 void soft_uart_poweron(soft_uart_t uart);
128 
135 
136 #ifdef __cplusplus
137 }
138 #endif
139 
140 #endif /* SOFT_UART_H */
141 
uart_stop_bits_t
uart_stop_bits_t
Definition of possible stop bits lengths in a UART frame.
Definition: uart.h:151
soft_uart_conf_t::rx_timer
tim_t rx_timer
Hardware timer used for RX.
Definition: soft_uart.h:56
timer.h
Low-level timer peripheral driver interface definitions.
soft_uart_write
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.
soft_uart_conf_t::tx_pin
gpio_t tx_pin
TX pin.
Definition: soft_uart.h:55
soft_uart_mode
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.
tim_t
unsigned int tim_t
Default timer type.
Definition: timer.h:69
soft_uart_conf_t::tx_timer
tim_t tx_timer
Hardware timer used for TX.
Definition: soft_uart.h:57
uart_parity_t
uart_parity_t
Definition of possible parity modes.
Definition: uart.h:126
soft_uart_conf_t::flags
uint8_t flags
Soft UART flags.
Definition: soft_uart.h:60
soft_uart_conf_t
Software UART port descriptor.
Definition: soft_uart.h:53
uart.h
Low-level UART peripheral driver interface definition.
soft_uart_poweron
void soft_uart_poweron(soft_uart_t uart)
Power on the given UART device.
soft_uart_init
int soft_uart_init(soft_uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
Initialize a given UART device.
soft_uart_poweroff
void soft_uart_poweroff(soft_uart_t uart)
Power off the given UART device.
soft_uart_conf_t::rx_pin
gpio_t rx_pin
RX pin.
Definition: soft_uart.h:54
gpio.h
Low-level GPIO peripheral driver interface definitions.
soft_uart_t
unsigned soft_uart_t
Software UART type definition.
Definition: soft_uart.h:66
uart_data_bits_t
uart_data_bits_t
Definition of possible data bits lengths in a UART frame.
Definition: uart.h:139
soft_uart_conf_t::timer_freq
uint32_t timer_freq
Operating frequency of the timer.
Definition: soft_uart.h:58
uart_rx_cb_t
void(* uart_rx_cb_t)(void *arg, uint8_t data)
Signature for receive interrupt callback.
Definition: uart.h:99