serialport.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 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 
19 #ifndef ARDUINO_SERIAL_H
20 #define ARDUINO_SERIAL_H
21 
22 extern "C" {
23 #include "ringbuffer.h"
24 #include "periph/uart.h"
25 }
26 
30 #define SERIAL_RX_BUFSIZE (64)
31 
36  BIN,
37  OCT,
38  DEC,
39  HEX
40 };
41 
45 class SerialPort {
46 
47 private:
48  uart_t dev;
49  char rx_mem[SERIAL_RX_BUFSIZE];
50  ringbuffer_t rx_buf;
51 
52 public:
58  explicit SerialPort(uart_t dev);
59 
72  int available(void);
73 
87  void begin(long speed);
88 
97  void end(void);
98 
114  size_t print(int val);
115 
126  size_t print(int val, SerialFormat format);
127 
135  size_t print(float val);
136 
147  size_t print(float val, int format);
148 
158  size_t print(char val);
159 
169  size_t print(const char *val);
170 
184  size_t println(int val);
185 
198  size_t println(int val, SerialFormat format);
199 
211  size_t println(float val);
212 
225  size_t println(float val, int format);
226 
238  size_t println(char val);
239 
251  size_t println(const char *val);
252 
261  int read(void);
262 
275  int write(int val);
276 
286  int write(const char *str);
287 
297  int write(char *buf, int len);
298 };
299 
300 #endif /* ARDUINO_SERIAL_H */
301 
Ringbuffer header.
Low-level UART peripheral driver interface definition.
format to binary representation
Definition: serialport.hpp:36
size_t println(int val)
Prints data to the serial port as human-readable ASCII text followed by a carriage return character (...
unsigned int uart_t
Define default UART type identifier.
Definition: uart.h:66
SerialFormat
Formatting options for Serial.print(int, format)
Definition: serialport.hpp:35
void begin(long speed)
Sets the data rate in bits per second (baud) for serial data transmission.
format to decimal representation
Definition: serialport.hpp:38
int available(void)
Get the number of bytes (characters) available for reading from the serial port.
Ringbuffer.
Definition: ringbuffer.h:30
int write(int val)
Writes binary data to the serial port.
int read(void)
Reads incoming serial data.
SerialPort(uart_t dev)
Constructor maps the serial port to a RIOT UART device.
size_t print(int val)
Prints data to the serial port as human-readable ASCII text.
void end(void)
Disables serial communication, allowing the RX and TX pins to be used for general input and output...
#define SERIAL_RX_BUFSIZE
Default RX buffer size - same as the original Arduino...
Definition: serialport.hpp:30
format to hex representation
Definition: serialport.hpp:39
format to octal representation
Definition: serialport.hpp:37
Arduino Serial Interface.
Definition: serialport.hpp:45