LIN_slave_portable_Arduino 1.4
Arduino library for Local Interconnect Network slave node emulation
Loading...
Searching...
No Matches
LIN_slave_NeoHWSerial_AVR.h
Go to the documentation of this file.
1
10// comment out to use HardwareSerial (sync on inter-frame pause) instead of NeoHWSerial (sync on BREAK)
11#define USE_NEOSERIAL
12
13// for AVR platform use NeoHWSerial or comment out USE_NEOSERIAL above
14#if defined(ARDUINO_ARCH_AVR) && defined (USE_NEOSERIAL) && !defined(ARDUINO_AVR_TRINKET3) && !defined(ARDUINO_AVR_TRINKET5)
15
16
17/*-----------------------------------------------------------------------------
18 MODULE DEFINITION FOR MULTIPLE INCLUSION
19-----------------------------------------------------------------------------*/
20#ifndef _LIN_SLAVE_NEOHWSERIAL_AVR_H_
21#define _LIN_SLAVE_NEOHWSERIAL_AVR_H_
22
23
24/*-----------------------------------------------------------------------------
25 INCLUDE FILES
26-----------------------------------------------------------------------------*/
27
28// include required libraries
29#include <NeoHWSerial.h>
30#include <LIN_slave_Base.h>
31
32
33/*-----------------------------------------------------------------------------
34 GLOBAL CLASS
35-----------------------------------------------------------------------------*/
36
43{
44 // PRIVATE VARIABLES
45 private:
46
47 NeoHWSerial *pSerial;
48 uint8_t idxSerial;
49 #if defined(HAVE_HWSERIAL3)
50 static bool flagBreak[4];
51 #elif defined(HAVE_HWSERIAL2)
52 static bool flagBreak[3];
53 #elif defined(HAVE_HWSERIAL1)
54 static bool flagBreak[2];
55 #elif defined(HAVE_HWSERIAL0)
56 static bool flagBreak[1];
57 #else
58 #error no HardwareSerial available for this board
59 #endif
60
61
62 // PRIVATE METHODS
63 private:
64
65 #if defined(HAVE_HWSERIAL0)
67 static bool _onSerialReceive0(uint8_t byte, uint8_t status);
68 #endif
69
70 #if defined(HAVE_HWSERIAL1)
72 static bool _onSerialReceive1(uint8_t byte, uint8_t status);
73 #endif
74
75 #if defined(HAVE_HWSERIAL2)
77 static bool _onSerialReceive2(uint8_t byte, uint8_t status);
78 #endif
79
80 #if defined(HAVE_HWSERIAL3)
82 static bool _onSerialReceive3(uint8_t byte, uint8_t status);
83 #endif
84
85
86 // PROTECTED METHODS
87 protected:
88
90 bool _getBreakFlag(void);
91
93 void _resetBreakFlag(void);
94
95
97 inline uint8_t _serialPeek(void) { return pSerial->peek(); }
98
100 inline uint8_t _serialRead(void) { return pSerial->read(); }
101
103 inline void _serialWrite(uint8_t buf[], uint8_t num) { pSerial->write(buf, num); }
104
105
106 // PUBLIC METHODS
107 public:
108
110 LIN_Slave_NeoHWSerial_AVR(NeoHWSerial &Interface,
111 LIN_Slave_Base::version_t Version = LIN_Slave_Base::LIN_V2, const char NameLIN[] = "Slave", uint32_t TimeoutRx = 1500L, const int8_t PinTxEN = INT8_MIN);
112
114 void begin(uint16_t Baudrate = 19200);
115
117 void end(void);
118
120 inline bool available(void) { return pSerial->available(); }
121
122}; // class LIN_Slave_NeoHWSerial_AVR
123
124
125/*-----------------------------------------------------------------------------
126 END OF MODULE DEFINITION FOR MULTIPLE INLUSION
127-----------------------------------------------------------------------------*/
128#endif // _LIN_SLAVE_NEOHWSERIAL_AVR_H_
129
130#endif // ARDUINO_ARCH_AVR && USE_NEOSERIAL
131
132
133/*-----------------------------------------------------------------------------
134 END OF FILE
135-----------------------------------------------------------------------------*/
Base class for LIN slave emulation (non-functional)
LIN slave node base class.
version_t
LIN protocol version.
@ LIN_V2
LIN protocol version 2.x.
LIN slave node class via AVR NeoHWSerial.
bool _getBreakFlag(void)
Get break detection flag.
void _resetBreakFlag(void)
Clear break detection flag.
void _serialWrite(uint8_t buf[], uint8_t num)
write bytes to Tx buffer
uint8_t _serialRead(void)
read next byte from Rx buffer
uint8_t _serialPeek(void)
peek next byte from Rx buffer
void begin(uint16_t Baudrate=19200)
Open serial interface.
void end(void)
Close serial interface.
bool available(void)
check if a byte is available in Rx buffer