uart.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2015 Freie Universit├Ąt Berlin
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 
58 #ifndef PERIPH_UART_H
59 #define PERIPH_UART_H
60 
61 #include <errno.h>
62 #include <limits.h>
63 #include <stddef.h>
64 #include <stdint.h>
65 
66 #include "periph_cpu.h"
67 #include "periph_conf.h"
68 
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72 
76 #ifndef HAVE_UART_T
77 typedef unsigned int uart_t;
78 #endif
79 
83 #ifndef UART_UNDEF
84 #define UART_UNDEF (UINT_MAX)
85 #endif
86 
90 #ifndef UART_DEV
91 #define UART_DEV(x) (x)
92 #endif
93 
100 typedef void(*uart_rx_cb_t)(void *arg, uint8_t data);
101 
107 typedef void(*uart_rxstart_cb_t)(void *arg);
108 
112 #ifndef HAVE_UART_ISR_CTX_T
113 typedef struct {
115  void *arg;
116 #ifdef MODULE_PERIPH_UART_RXSTART_IRQ
117  uart_rxstart_cb_t rxs_cb;
118  void *rxs_arg;
119 #endif
121 #endif
122 
128 enum {
129  UART_OK = 0,
134 };
135 
139 #ifndef HAVE_UART_PARITY_T
140 typedef enum {
147 #endif
148 
152 #ifndef HAVE_UART_DATA_BITS_T
153 typedef enum {
159 #endif
160 
164 #ifndef HAVE_UART_STOP_BITS_T
165 typedef enum {
169 #endif
170 
195 int uart_init(uart_t uart, uint32_t baud, uart_rx_cb_t rx_cb, void *arg);
196 
197 #if defined(MODULE_PERIPH_UART_RECONFIGURE) || DOXYGEN
214 
231 
232 #if DOXYGEN
243 gpio_t uart_pin_rx(uart_t uart);
244 
255 gpio_t uart_pin_tx(uart_t uart);
256 
257 #endif /* DOXYGEN */
258 #endif /* MODULE_PERIPH_UART_RECONFIGURE */
259 
260 #if defined(MODULE_PERIPH_UART_RXSTART_IRQ) || DOXYGEN
261 
277 
287 
297 #endif /* MODULE_PERIPH_UART_RXSTART_IRQ */
298 
311 int uart_mode(uart_t uart, uart_data_bits_t data_bits, uart_parity_t parity,
312  uart_stop_bits_t stop_bits);
313 
326 void uart_write(uart_t uart, const uint8_t *data, size_t len);
327 
333 void uart_poweron(uart_t uart);
334 
341 
342 #ifdef __cplusplus
343 }
344 #endif
345 
346 #endif /* PERIPH_UART_H */
#define EIO
I/O error.
Definition: errno.h:98
#define ENOTSUP
Not supported (may be the same value as [EOPNOTSUPP]).
Definition: errno.h:130
#define ENODEV
No such device.
Definition: errno.h:113
void uart_poweroff(uart_t uart)
Power off the given UART device.
void uart_rxstart_irq_configure(uart_t uart, uart_rxstart_cb_t cb, void *arg)
Configure the function that will be called when a start condition is detected.
void uart_deinit_pins(uart_t uart)
Change the pins of the given UART back to plain GPIO functionality.
void(* uart_rxstart_cb_t)(void *arg)
Signature for receive start condition interrupt callback.
Definition: uart.h:107
int uart_init(uart_t uart, uint32_t baud, uart_rx_cb_t rx_cb, void *arg)
Initialize a given UART device.
void uart_rxstart_irq_disable(uart_t uart)
Disable the RX start interrupt.
uart_parity_t
Definition of possible parity modes.
Definition: uart.h:140
uart_stop_bits_t
Definition of possible stop bits lengths in a UART frame.
Definition: uart.h:165
void uart_poweron(uart_t uart)
Power on the given UART device.
gpio_t uart_pin_tx(uart_t uart)
Get the TX pin of the given UART.
void uart_init_pins(uart_t uart)
Initialize the used UART pins, i.e.
void(* uart_rx_cb_t)(void *arg, uint8_t data)
Signature for receive interrupt callback.
Definition: uart.h:100
void uart_rxstart_irq_enable(uart_t uart)
Enable the RX start interrupt.
gpio_t uart_pin_rx(uart_t uart)
Get the RX pin of the given UART.
uart_data_bits_t
Definition of possible data bits lengths in a UART frame.
Definition: uart.h:153
void uart_write(uart_t uart, const uint8_t *data, size_t len)
Write data from the given buffer to the specified UART device.
int uart_mode(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.
unsigned int uart_t
Define default UART type identifier.
Definition: uart.h:77
@ UART_PARITY_SPACE
space parity
Definition: uart.h:145
@ UART_PARITY_NONE
no parity
Definition: uart.h:141
@ UART_PARITY_EVEN
even parity
Definition: uart.h:142
@ UART_PARITY_ODD
odd parity
Definition: uart.h:143
@ UART_PARITY_MARK
mark parity
Definition: uart.h:144
@ UART_STOP_BITS_2
2 stop bits
Definition: uart.h:167
@ UART_STOP_BITS_1
1 stop bit
Definition: uart.h:166
@ UART_NOBAUD
given symbol rate is not applicable
Definition: uart.h:131
@ UART_OK
everything in order
Definition: uart.h:129
@ UART_NODEV
invalid UART device given
Definition: uart.h:130
@ UART_INTERR
all other internal errors
Definition: uart.h:133
@ UART_NOMODE
given mode is not applicable
Definition: uart.h:132
@ UART_DATA_BITS_6
6 data bits
Definition: uart.h:155
@ UART_DATA_BITS_5
5 data bits
Definition: uart.h:154
@ UART_DATA_BITS_7
7 data bits
Definition: uart.h:156
@ UART_DATA_BITS_8
8 data bits
Definition: uart.h:157
uart_parity_t
Definition of possible parity modes.
Definition: periph_cpu.h:499
uart_stop_bits_t
Definition of possible stop bits lengths.
Definition: periph_cpu.h:531
uart_data_bits_t
Definition of possible data bits lengths in a UART frame.
Definition: periph_cpu.h:515
Interrupt context for a UART device.
Definition: uart.h:113
uart_rx_cb_t rx_cb
data received interrupt callback
Definition: uart.h:114
void * arg
argument to data received callback
Definition: uart.h:115