| 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
42 class LIN_Slave_NeoHWSerial_AVR : public LIN_Slave_Base
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 this->pSerial->peek(); }
98
100 inline uint8_t _serialRead(void) { return this->pSerial->read(); }
101
103 inline void _serialWrite(uint8_t buf[], uint8_t num) { this->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 this->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-----------------------------------------------------------------------------*/
LIN_slave_Base.h
Base class for LIN slave emulation (non-functional)
LIN_Slave_Base
LIN slave node base class.
Definition LIN_slave_Base.h:106
LIN_Slave_Base::version_t
version_t
LIN protocol version.
Definition LIN_slave_Base.h:112
LIN_Slave_Base::LIN_V2
@ LIN_V2
LIN protocol version 2.x.
Definition LIN_slave_Base.h:114
LIN_Slave_NeoHWSerial_AVR
LIN slave node class via AVR NeoHWSerial.
Definition LIN_slave_NeoHWSerial_AVR.h:43
LIN_Slave_NeoHWSerial_AVR::_getBreakFlag
bool _getBreakFlag(void)
Get break detection flag.
Definition LIN_slave_NeoHWSerial_AVR.cpp:175
LIN_Slave_NeoHWSerial_AVR::_resetBreakFlag
void _resetBreakFlag(void)
Clear break detection flag.
Definition LIN_slave_NeoHWSerial_AVR.cpp:188
LIN_Slave_NeoHWSerial_AVR::_serialWrite
void _serialWrite(uint8_t buf[], uint8_t num)
write bytes to Tx buffer
Definition LIN_slave_NeoHWSerial_AVR.h:103
LIN_Slave_NeoHWSerial_AVR::_serialRead
uint8_t _serialRead(void)
read next byte from Rx buffer
Definition LIN_slave_NeoHWSerial_AVR.h:100
LIN_Slave_NeoHWSerial_AVR::_serialPeek
uint8_t _serialPeek(void)
peek next byte from Rx buffer
Definition LIN_slave_NeoHWSerial_AVR.h:97
LIN_Slave_NeoHWSerial_AVR::begin
void begin(uint16_t Baudrate=19200)
Open serial interface.
Definition LIN_slave_NeoHWSerial_AVR.cpp:228
LIN_Slave_NeoHWSerial_AVR::end
void end(void)
Close serial interface.
Definition LIN_slave_NeoHWSerial_AVR.cpp:290
LIN_Slave_NeoHWSerial_AVR::available
bool available(void)
check if a byte is available in Rx buffer
Definition LIN_slave_NeoHWSerial_AVR.h:120