LIN_slave_portable_Arduino 1.4
Arduino library for Local Interconnect Network slave node emulation
Loading...
Searching...
No Matches
LIN_slave_HardwareSerial_ESP32.h
Go to the documentation of this file.
1
10// assert ESP32 platform
11#if defined(ARDUINO_ARCH_ESP32)
12
13/*-----------------------------------------------------------------------------
14 MODULE DEFINITION FOR MULTIPLE INCLUSION
15-----------------------------------------------------------------------------*/
16#ifndef _LIN_SLAVE_HW_SERIAL_ESP32_H_
17#define _LIN_SLAVE_HW_SERIAL_ESP32_H_
18
19
20/*-----------------------------------------------------------------------------
21 INCLUDE FILES
22-----------------------------------------------------------------------------*/
23
24// include required libraries
25#include <LIN_slave_Base.h>
26
27
28/*-----------------------------------------------------------------------------
29 GLOBAL MACROS
30-----------------------------------------------------------------------------*/
31
33#if !defined(LIN_SLAVE_ESP32_MAX_SERIAL)
34 #define LIN_SLAVE_ESP32_MAX_SERIAL 3
35#endif
36
38#ifdef ARDUINO_ESP32S2
39 #undef LIN_SLAVE_ESP32_MAX_SERIAL
40 #define LIN_SLAVE_ESP32_MAX_SERIAL 2
41#endif
42
43
44/*-----------------------------------------------------------------------------
45 GLOBAL CLASS
46-----------------------------------------------------------------------------*/
47
54{
55 // PRIVATE VARIABLES
56 public:
57
58 HardwareSerial *pSerial;
59 uint8_t pinRx;
60 uint8_t pinTx;
61 uint8_t idxSerial;
62 static bool flagBreak[LIN_SLAVE_ESP32_MAX_SERIAL];
63
64
65 // PRIVATE METHODS
66 private:
67
68 #if (LIN_SLAVE_ESP32_MAX_SERIAL >= 1)
70 static void _onSerialReceiveError0(hardwareSerial_error_t Err);
71 #else
72 #error no HardwareSerial available for this board
73 #endif
74 #if (LIN_SLAVE_ESP32_MAX_SERIAL >= 2)
76 static void _onSerialReceiveError1(hardwareSerial_error_t Err);
77 #endif
78 #if (LIN_SLAVE_ESP32_MAX_SERIAL >= 3)
80 static void _onSerialReceiveError2(hardwareSerial_error_t Err);
81 #endif
82
83
84 // PROTECTED METHODS
85 protected:
86
88 bool _getBreakFlag(void);
89
91 void _resetBreakFlag(void);
92
93
95 inline uint8_t _serialPeek(void) { return this->pSerial->peek(); }
96
98 inline uint8_t _serialRead(void) { return this->pSerial->read(); }
99
101 inline void _serialWrite(uint8_t buf[], uint8_t num) { this->pSerial->write(buf, num); }
102
103
104 // PUBLIC METHODS
105 public:
106
108 LIN_Slave_HardwareSerial_ESP32(HardwareSerial &Interface, uint8_t PinRx, uint8_t PinTx,
109 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);
110
112 void begin(uint16_t Baudrate = 19200);
113
115 void end(void);
116
118 inline bool available(void) { return this->pSerial->available(); }
119
120}; // class LIN_Slave_HardwareSerial_ESP32
121
122
123/*-----------------------------------------------------------------------------
124 END OF MODULE DEFINITION FOR MULTIPLE INLUSION
125-----------------------------------------------------------------------------*/
126#endif // _LIN_SLAVE_HW_SERIAL_ESP32_H_
127
128#endif // ARDUINO_ARCH_ESP32
129
130/*-----------------------------------------------------------------------------
131 END OF FILE
132-----------------------------------------------------------------------------*/
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 ESP32 HardwareSerial.
bool available(void)
check if a byte is available in Rx buffer
HardwareSerial * pSerial
pointer to serial interface used for LIN
static bool flagBreak[LIN_SLAVE_ESP32_MAX_SERIAL]
break flags for Serial0..N
void begin(uint16_t Baudrate=19200)
Open serial interface.
uint8_t _serialPeek(void)
peek next byte from Rx buffer
void _serialWrite(uint8_t buf[], uint8_t num)
write bytes to Tx buffer
bool _getBreakFlag(void)
Get break detection flag.
void _resetBreakFlag(void)
Clear break detection flag.
uint8_t idxSerial
index to flagBreak[] of this instance
uint8_t _serialRead(void)
read next byte from Rx buffer