Loading...
Searching...
No Matches
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
22extern "C" {
23#include "ringbuffer.h"
24#include "periph/uart.h"
25}
26
30#define SERIAL_RX_BUFSIZE (64)
31
41
46
47private:
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
54public:
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 */
Arduino Serial Interface.
int write(const char *str)
Writes binary data to the serial port.
size_t print(long val)
Prints data to the serial port as human-readable ASCII text.
size_t print(const char *val)
Prints data to the serial port as human-readable ASCII text.
size_t println(unsigned long val)
Prints data to the serial port as human-readable ASCII text followed by a carriage return character (...
size_t println(long val)
Prints data to the serial port as human-readable ASCII text followed by a carriage return character (...
size_t print(unsigned int val, SerialFormat format)
Prints data to the serial port as human-readable ASCII text.
int write(int val)
Writes binary data to the serial port.
size_t print(float val, int format)
Prints data to the serial port as human-readable ASCII text.
size_t print(long val, SerialFormat format)
Prints data to the serial port as human-readable ASCII text.
size_t print(char val)
Prints data to the serial port as human-readable ASCII text.
int read(void)
Reads incoming serial data.
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.
int available(void)
Get the number of bytes (characters) available for reading from the serial port.
size_t println(float val)
Prints data to the serial port as human-readable ASCII text followed by a carriage return character (...
size_t print(unsigned int val)
Prints data to the serial port as human-readable ASCII text.
size_t println(long val, SerialFormat format)
Prints data to the serial port as human-readable ASCII text followed by a carriage return character (...
size_t println(int val, SerialFormat format)
Prints data to the serial port as human-readable ASCII text followed by a carriage return character (...
size_t println(unsigned int val)
Prints data to the serial port as human-readable ASCII text followed by a carriage return character (...
size_t print(int val, SerialFormat format)
Prints data to the serial port as human-readable ASCII text.
size_t println(char val)
Prints data to the serial port as human-readable ASCII text followed by a carriage return character (...
void begin(long speed)
Sets the data rate in bits per second (baud) for serial data transmission.
int write(char *buf, int len)
Writes binary data to the serial port.
size_t println(int val)
Prints data to the serial port as human-readable ASCII text followed by a carriage return character (...
size_t println(unsigned int val, SerialFormat format)
Prints data to the serial port as human-readable ASCII text followed by a carriage return character (...
size_t println(float val, int format)
Prints data to the serial port as human-readable ASCII text followed by a carriage return character (...
size_t print(unsigned long val, SerialFormat format)
Prints data to the serial port as human-readable ASCII text.
SerialPort(uart_t dev)
Constructor maps the serial port to a RIOT UART device.
size_t print(unsigned long val)
Prints data to the serial port as human-readable ASCII text.
size_t println(unsigned long val, SerialFormat format)
Prints data to the serial port as human-readable ASCII text followed by a carriage return character (...
size_t print(float val)
Prints data to the serial port as human-readable ASCII text.
size_t println(const char *val)
Prints data to the serial port as human-readable ASCII text followed by a carriage return character (...
Low-level UART peripheral driver interface definition.
uint_fast8_t uart_t
Define default UART type identifier.
Definition uart.h:85
A utility for storing and retrieving byte data using a ring buffer.
SerialFormat
Formatting options for Serial.print(int, format)
@ BIN
format to binary representation
@ OCT
format to octal representation
@ DEC
format to decimal representation
@ HEX
format to hex representation
#define SERIAL_RX_BUFSIZE
Default RX buffer size - same as the original Arduino...
Ringbuffer.
Definition ringbuffer.h:36