LIN_slave_portable_Arduino 1.3
Arduino library for Local Interconnect Network slave node emulation
Loading...
Searching...
No Matches
LIN_slave_SoftwareSerial.h
Go to the documentation of this file.
1
10// assert platform which supports SoftwareSerial. Note: ARDUINO_ARCH_ESP32 requires library ESPSoftwareSerial
11#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) || \
12 defined(ARDUINO_ARCH_MEGAAVR) || defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_RENESAS)
13
14/*-----------------------------------------------------------------------------
15 MODULE DEFINITION FOR MULTIPLE INCLUSION
16-----------------------------------------------------------------------------*/
17#ifndef _LIN_SLAVE_SW_SERIAL_H_
18#define _LIN_SLAVE_SW_SERIAL_H_
19
20
21/*-----------------------------------------------------------------------------
22 INCLUDE FILES
23-----------------------------------------------------------------------------*/
24
25// include required libraries
26#include <LIN_slave_Base.h>
27#include <SoftwareSerial.h>
28
29
30/*-----------------------------------------------------------------------------
31 GLOBAL CLASS
32-----------------------------------------------------------------------------*/
33
40{
41 // PRIVATE VARIABLES
42 private:
43
44 SoftwareSerial SWSerial;
45 uint8_t pinRx;
46 uint8_t pinTx;
47 bool inverseLogic;
48 bool flagBreak;
49 uint16_t minFramePause;
50
51
52 // PROTECTED METHODS
53 protected:
54
56 bool _getBreakFlag(void);
57
59 void _resetBreakFlag(void);
60
61
63 inline uint8_t _serialPeek(void) { return this->SWSerial.peek(); }
64
66 inline uint8_t _serialRead(void) { return this->SWSerial.read(); }
67
69 inline void _serialWrite(uint8_t buf[], uint8_t num)
70 {
71 // Renesas does not support stopListening()/listen()
72 #if defined(ARDUINO_ARCH_RENESAS)
73 this->SWSerial.write(buf, num);
74 this->SWSerial.flush();
75
76 // Disable receive to avoid inter-byte pauses on AVR
77 #else
78 this->SWSerial.stopListening();
79 this->SWSerial.write(buf, num);
80 this->SWSerial.flush();
81 this->SWSerial.listen();
82 #endif
83 }
84
85
86 // PUBLIC METHODS
87 public:
88
90 LIN_Slave_SoftwareSerial(uint8_t PinRx, uint8_t PinTx, bool InverseLogic = false, uint16_t MinFramePause=1000L,
91 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);
92
94 void begin(uint16_t Baudrate = 19200);
95
97 void end(void);
98
100 inline bool available(void) { return this->SWSerial.available(); }
101
103 virtual void handler(void);
104
105}; // class LIN_Slave_SoftwareSerial
106
107
108/*-----------------------------------------------------------------------------
109 END OF MODULE DEFINITION FOR MULTIPLE INLUSION
110-----------------------------------------------------------------------------*/
111#endif // _LIN_MASTER_SW_SERIAL_H_
112
113#else // ARDUINO_ARCH_AVR || ARDUINO_ARCH_ESP8266 || ARDUINO_ARCH_ESP32 || ARDUINO_ARCH_MEGAAVR || ARDUINO_ARCH_STM32 || ARDUINO_ARCH_RENESAS
114
115 #error architecture not yet supported
116
117#endif
118
119/*-----------------------------------------------------------------------------
120 END OF FILE
121-----------------------------------------------------------------------------*/
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 generic SoftwareSerial.
uint8_t _serialPeek(void)
peek next byte from Rx buffer
virtual void handler(void)
Handle LIN protocol and call user-defined frame handlers.
void begin(uint16_t Baudrate=19200)
Open serial interface.
void _resetBreakFlag(void)
Clear break detection flag.
void end(void)
Close serial interface.
uint8_t _serialRead(void)
read next byte from Rx buffer
bool available(void)
check if a byte is available in Rx buffer
void _serialWrite(uint8_t buf[], uint8_t num)
write bytes to Tx buffer (blocking)
bool _getBreakFlag(void)
Get break detection flag.