| 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
53 class LIN_Slave_HardwareSerial_ESP32 : public LIN_Slave_Base
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 pSerial->peek(); }
96
98 inline uint8_t _serialRead(void) { return pSerial->read(); }
99
101 inline void _serialWrite(uint8_t buf[], uint8_t num) { 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 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-----------------------------------------------------------------------------*/
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:52
LIN_Slave_Base::version_t
version_t
LIN protocol version.
Definition LIN_slave_Base.h:58
LIN_Slave_Base::LIN_V2
@ LIN_V2
LIN protocol version 2.x.
Definition LIN_slave_Base.h:60
LIN_Slave_HardwareSerial_ESP32
LIN slave node class via ESP32 HardwareSerial.
Definition LIN_slave_HardwareSerial_ESP32.h:54
LIN_Slave_HardwareSerial_ESP32::pinTx
uint8_t pinTx
pin used for transmit
Definition LIN_slave_HardwareSerial_ESP32.h:60
LIN_Slave_HardwareSerial_ESP32::available
bool available(void)
check if a byte is available in Rx buffer
Definition LIN_slave_HardwareSerial_ESP32.h:118
LIN_Slave_HardwareSerial_ESP32::end
void end(void)
Close serial interface.
Definition LIN_slave_HardwareSerial_ESP32.cpp:204
LIN_Slave_HardwareSerial_ESP32::pSerial
HardwareSerial * pSerial
pointer to serial interface used for LIN
Definition LIN_slave_HardwareSerial_ESP32.h:58
LIN_Slave_HardwareSerial_ESP32::flagBreak
static bool flagBreak[LIN_SLAVE_ESP32_MAX_SERIAL]
break flags for Serial0..N
Definition LIN_slave_HardwareSerial_ESP32.h:62
LIN_Slave_HardwareSerial_ESP32::begin
void begin(uint16_t Baudrate=19200)
Open serial interface.
Definition LIN_slave_HardwareSerial_ESP32.cpp:154
LIN_Slave_HardwareSerial_ESP32::_serialPeek
uint8_t _serialPeek(void)
peek next byte from Rx buffer
Definition LIN_slave_HardwareSerial_ESP32.h:95
LIN_Slave_HardwareSerial_ESP32::_serialWrite
void _serialWrite(uint8_t buf[], uint8_t num)
write bytes to Tx buffer
Definition LIN_slave_HardwareSerial_ESP32.h:101
LIN_Slave_HardwareSerial_ESP32::pinRx
uint8_t pinRx
pin used for receive
Definition LIN_slave_HardwareSerial_ESP32.h:59
LIN_Slave_HardwareSerial_ESP32::_getBreakFlag
bool _getBreakFlag(void)
Get break detection flag.
Definition LIN_slave_HardwareSerial_ESP32.cpp:97
LIN_Slave_HardwareSerial_ESP32::_resetBreakFlag
void _resetBreakFlag(void)
Clear break detection flag.
Definition LIN_slave_HardwareSerial_ESP32.cpp:110
LIN_Slave_HardwareSerial_ESP32::idxSerial
uint8_t idxSerial
index to flagBreak[] of this instance
Definition LIN_slave_HardwareSerial_ESP32.h:61
LIN_Slave_HardwareSerial_ESP32::_serialRead
uint8_t _serialRead(void)
read next byte from Rx buffer
Definition LIN_slave_HardwareSerial_ESP32.h:98