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  template<typename T> size_t _println(T val);
52  template<typename T> size_t _println(T val, SerialFormat format);
53 
54 public:
60  explicit SerialPort(uart_t dev);
61 
74  int available(void);
75 
89  void begin(long speed);
90 
99  void end(void);
100 
116  size_t print(int val);
117 
128  size_t print(int val, SerialFormat format);
129 
145  size_t print(unsigned int val);
146 
157  size_t print(unsigned int val, SerialFormat format);
158 
174  size_t print(long val);
175 
186  size_t print(long val, SerialFormat format);
187 
203  size_t print(unsigned long val);
204 
215  size_t print(unsigned long val, SerialFormat format);
216 
224  size_t print(float val);
225 
236  size_t print(float val, int format);
237 
247  size_t print(char val);
248 
258  size_t print(const char *val);
259 
273  size_t println(int val);
274 
287  size_t println(int val, SerialFormat format);
288 
302  size_t println(unsigned int val);
303 
316  size_t println(unsigned int val, SerialFormat format);
317 
331  size_t println(long val);
332 
345  size_t println(long val, SerialFormat format);
346 
360  size_t println(unsigned long val);
361 
374  size_t println(unsigned long val, SerialFormat format);
375 
387  size_t println(float val);
388 
401  size_t println(float val, int format);
402 
414  size_t println(char val);
415 
427  size_t println(const char *val);
428 
437  size_t println(void);
438 
447  int read(void);
448 
461  int write(int val);
462 
472  int write(const char *str);
473 
483  int write(char *buf, int len);
484 };
485 
486 #endif /* ARDUINO_SERIAL_H */
487 
A utility for storing and retrieving byte data using a ring buffer.
Low-level UART peripheral driver interface definition.
format to binary representation
Definition: serialport.hpp:36
unsigned int uart_t
Define default UART type identifier.
Definition: uart.h:78
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:36
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.
size_t println(void)
Prints a carriage return character (ASCII 13, or "\r") and a newline character (ASCII 10...
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