Skip to content

Commit 40c8ef5

Browse files
committed
Specify rx and tx pin in the constructor
1 parent 51b6060 commit 40c8ef5

File tree

2 files changed

+5
-44
lines changed

2 files changed

+5
-44
lines changed

src/TJA1020.cpp

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,57 +13,18 @@
1313
#include <Lin_Interface.hpp>
1414
// #include <Arduino.h>
1515

16-
//-----------------------------------------------------------------------------
17-
// Pin definitions, we need the TX Pin to control the TJA1020 statemachine
18-
// See "HardwareSerial.cpp"
19-
#ifdef ESP32
20-
#ifndef TX0
21-
#define TX0 1
22-
#endif
23-
24-
#ifndef TX1
25-
#define TX1 10
26-
#endif
27-
28-
#ifndef TX2
29-
#define TX2 17
30-
#endif
31-
#elif ESP8266
32-
#ifndef TX0
33-
#define TX0 1
34-
#endif
35-
36-
#ifndef TX1
37-
#define TX1 15
38-
#endif
39-
#else
40-
#error "Need Pin definitions for LIN Transceiver"
41-
#endif
42-
4316
//-----------------------------------------------------------------------------
4417
// constructor
4518

4619
/// Provides HW UART via TJA1020 Chip
47-
Lin_TJA1020::Lin_TJA1020(int uart_nr, uint32_t _baud, int8_t nslpPin) : Lin_Interface(uart_nr)
20+
Lin_TJA1020::Lin_TJA1020(int uart_nr, uint32_t _baud, int8_t rxPin, int8_t txPin, int8_t nslpPin) : Lin_Interface(uart_nr)
4821
{
49-
// Use typical pin configuration if interfaced by uart_nr
50-
//############
51-
// See "HardwareSerial.cpp"
52-
if(uart_nr == 0) {
53-
_tx_pin = TX0;
54-
}
55-
if(uart_nr == 1) {
56-
_tx_pin = TX1;
57-
}
58-
#ifdef ESP32
59-
if(uart_nr == 2) {
60-
_tx_pin = TX2;
61-
}
62-
#endif
63-
//############
22+
_tx_pin = txPin;
6423

6524
// use default baud rate, if not specified
6625
Lin_Interface::baud = _baud ? _baud : 19200;
26+
Lin_Interface::rxPin = rxPin;
27+
Lin_Interface::txPin = txPin;
6728

6829
_nslp_pin = nslpPin;
6930
}

src/TJA1020.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Lin_TJA1020 : public Lin_Interface
2121
/// @param uart_nr Index of HW UART to be used (0..2)
2222
/// @param baud Baud rate for RX/TX (0 = default 19200 baud)
2323
/// @param nslpPin /SLP Pin to control TJA1020
24-
Lin_TJA1020(int uart_nr, uint32_t _baud, int8_t nslpPin);
24+
Lin_TJA1020(int uart_nr, uint32_t _baud, int8_t rxPin, int8_t txPin, int8_t nslpPin);
2525

2626
bool readFrame(uint8_t FrameID);
2727
void writeFrame(uint8_t FrameID, size_t size);

0 commit comments

Comments
 (0)