Tetsuya Yamamoto / Mbed 2 deprecated MD-Tutorial

Dependencies:   mbed

Committer:
tetsu_0207
Date:
Wed Dec 02 08:06:45 2020 +0000
Revision:
7:0bc2bc07f2fe
Parent:
6:17e3a28338dc
[Debug] success buffer serial library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tetsu_0207 6:17e3a28338dc 1 #ifndef BUFFER_SERIAL_H
tetsu_0207 6:17e3a28338dc 2 #define BUHHER_SERIAL_H
tetsu_0207 6:17e3a28338dc 3
tetsu_0207 6:17e3a28338dc 4 // include
tetsu_0207 6:17e3a28338dc 5 #include "mbed.h"
tetsu_0207 6:17e3a28338dc 6
tetsu_0207 6:17e3a28338dc 7 #ifndef SERIAL_RX_BUFFER_SIZE
tetsu_0207 6:17e3a28338dc 8 // RX Buffer Max Size
tetsu_0207 7:0bc2bc07f2fe 9 #define SERIAL_RX_BUFFER_SIZE 64
tetsu_0207 6:17e3a28338dc 10 #endif
tetsu_0207 6:17e3a28338dc 11
tetsu_0207 6:17e3a28338dc 12 #if (SERIAL_RX_BUFFER_SIZE>256)
tetsu_0207 6:17e3a28338dc 13 typedef uint16_t rx_buffer_index_t;
tetsu_0207 6:17e3a28338dc 14 #else
tetsu_0207 6:17e3a28338dc 15 typedef uint8_t rx_buffer_index_t;
tetsu_0207 6:17e3a28338dc 16 #endif
tetsu_0207 6:17e3a28338dc 17
tetsu_0207 6:17e3a28338dc 18 class BufferSerial : public RawSerial
tetsu_0207 6:17e3a28338dc 19 {
tetsu_0207 6:17e3a28338dc 20 public:
tetsu_0207 6:17e3a28338dc 21 // constructor
tetsu_0207 6:17e3a28338dc 22 BufferSerial(PinName tx, PinName rx,int baud,int timeout);
tetsu_0207 6:17e3a28338dc 23
tetsu_0207 6:17e3a28338dc 24 // function of arduino serial
tetsu_0207 6:17e3a28338dc 25 int available(void);
tetsu_0207 6:17e3a28338dc 26 // return number of bytes available to read.
tetsu_0207 6:17e3a28338dc 27 int read(void);
tetsu_0207 6:17e3a28338dc 28 // return first byte of incoming data available (or -1 if no data is available)
tetsu_0207 6:17e3a28338dc 29 size_t readBytesUntil(char charactor,char *buffer,int length);
tetsu_0207 6:17e3a28338dc 30 // return number of bytes placed in the buffer
tetsu_0207 6:17e3a28338dc 31
tetsu_0207 6:17e3a28338dc 32 unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE];
tetsu_0207 6:17e3a28338dc 33 private:
tetsu_0207 6:17e3a28338dc 34 // rx buffer array
tetsu_0207 6:17e3a28338dc 35 //unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE];
tetsu_0207 6:17e3a28338dc 36 // head index
tetsu_0207 6:17e3a28338dc 37 volatile rx_buffer_index_t _rx_buffer_head;
tetsu_0207 6:17e3a28338dc 38 volatile rx_buffer_index_t _rx_buffer_tail;
tetsu_0207 6:17e3a28338dc 39 int timer_ms;
tetsu_0207 6:17e3a28338dc 40 // attach rx
tetsu_0207 6:17e3a28338dc 41 void serial_rx(void);
tetsu_0207 6:17e3a28338dc 42
tetsu_0207 6:17e3a28338dc 43 int timedRead();
tetsu_0207 6:17e3a28338dc 44 Timer timer;
tetsu_0207 6:17e3a28338dc 45 unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
tetsu_0207 6:17e3a28338dc 46 unsigned long _startMillis; // used for timeout measurement
tetsu_0207 6:17e3a28338dc 47 };
tetsu_0207 6:17e3a28338dc 48
tetsu_0207 6:17e3a28338dc 49 #endif