From 44f2f694aa9694ca81da03a50e929825ff85060c Mon Sep 17 00:00:00 2001 From: TD-er Date: Sun, 22 Sep 2024 15:21:27 +0200 Subject: [PATCH] [adruino-CAN] Update to latest library code --- lib/arduino-CAN/src/CANController.cpp | 2 +- lib/arduino-CAN/src/CANController.h | 9 +-------- lib/arduino-CAN/src/ESP32SJA1000.cpp | 17 +++++------------ lib/arduino-CAN/src/ESP32SJA1000.h | 2 +- lib/arduino-CAN/src/MCP2515.cpp | 2 ++ 5 files changed, 10 insertions(+), 22 deletions(-) diff --git a/lib/arduino-CAN/src/CANController.cpp b/lib/arduino-CAN/src/CANController.cpp index 8bd34ed920..0890eec867 100644 --- a/lib/arduino-CAN/src/CANController.cpp +++ b/lib/arduino-CAN/src/CANController.cpp @@ -93,7 +93,7 @@ int CANControllerClass::beginExtendedPacket(long id, int dlc, bool rtr) return 1; } -int CANControllerClass::endPacket(unsigned long timeoutMs) +int CANControllerClass::endPacket() { if (!_packetBegun) { return 0; diff --git a/lib/arduino-CAN/src/CANController.h b/lib/arduino-CAN/src/CANController.h index 311c2f8be5..cdaeb94b0e 100644 --- a/lib/arduino-CAN/src/CANController.h +++ b/lib/arduino-CAN/src/CANController.h @@ -9,19 +9,12 @@ class CANControllerClass : public Stream { public: - enum { - SEND_OK, - SEND_BEGIN, - SEND_TIMEOUT, - SEND_ACK, - }; - virtual int begin(long baudRate); virtual void end(); int beginPacket(int id, int dlc = -1, bool rtr = false); int beginExtendedPacket(long id, int dlc = -1, bool rtr = false); - virtual int endPacket(unsigned long timeoutMs = 0); + virtual int endPacket(); virtual int parsePacket(); long packetId(); diff --git a/lib/arduino-CAN/src/ESP32SJA1000.cpp b/lib/arduino-CAN/src/ESP32SJA1000.cpp index 30e39e984a..309e0302e1 100644 --- a/lib/arduino-CAN/src/ESP32SJA1000.cpp +++ b/lib/arduino-CAN/src/ESP32SJA1000.cpp @@ -162,19 +162,14 @@ void ESP32SJA1000Class::end() CANControllerClass::end(); } -int ESP32SJA1000Class::endPacket(unsigned long timeoutMs) +int ESP32SJA1000Class::endPacket() { - unsigned long maxTime = millis() + timeoutMs; - - if (!CANControllerClass::endPacket(timeoutMs)) { - return SEND_BEGIN; + if (!CANControllerClass::endPacket()) { + return 0; } // wait for TX buffer to free while ((readRegister(REG_SR) & 0x04) != 0x04) { - if (timeoutMs && (millis() > maxTime)) { - return SEND_TIMEOUT; - } yield(); } @@ -212,14 +207,12 @@ int ESP32SJA1000Class::endPacket(unsigned long timeoutMs) while ((readRegister(REG_SR) & 0x08) != 0x08) { if (readRegister(REG_ECC) == 0xd9) { modifyRegister(REG_CMR, 0x1f, 0x02); // error, abort - return SEND_ACK; - } else if (timeoutMs && (millis() > maxTime)) { - return SEND_TIMEOUT; + return 0; } yield(); } - return SEND_OK; + return 1; } int ESP32SJA1000Class::parsePacket() diff --git a/lib/arduino-CAN/src/ESP32SJA1000.h b/lib/arduino-CAN/src/ESP32SJA1000.h index b1a0d306ce..b83cddc675 100644 --- a/lib/arduino-CAN/src/ESP32SJA1000.h +++ b/lib/arduino-CAN/src/ESP32SJA1000.h @@ -20,7 +20,7 @@ class ESP32SJA1000Class : public CANControllerClass { virtual int begin(long baudRate); virtual void end(); - virtual int endPacket(unsigned long timeoutMs = 0); + virtual int endPacket(); virtual int parsePacket(); diff --git a/lib/arduino-CAN/src/MCP2515.cpp b/lib/arduino-CAN/src/MCP2515.cpp index a153a7693b..36c160d37b 100644 --- a/lib/arduino-CAN/src/MCP2515.cpp +++ b/lib/arduino-CAN/src/MCP2515.cpp @@ -91,6 +91,7 @@ int MCP2515Class::begin(long baudRate) uint8_t cnf[3]; } CNF_MAPPER[] = { { (long)8E6, (long)1000E3, { 0x00, 0x80, 0x00 } }, + { (long)8E6, (long)666666, { 0xC0, 0xB8, 0x01 } }, { (long)8E6, (long)500E3, { 0x00, 0x90, 0x02 } }, { (long)8E6, (long)250E3, { 0x00, 0xb1, 0x05 } }, { (long)8E6, (long)200E3, { 0x00, 0xb4, 0x06 } }, @@ -104,6 +105,7 @@ int MCP2515Class::begin(long baudRate) { (long)8E6, (long)5E3, { 0x1f, 0xbf, 0x07 } }, { (long)16E6, (long)1000E3, { 0x00, 0xd0, 0x82 } }, + { (long)16E6, (long)666666, { 0xC0, 0xF8, 0x81 } }, { (long)16E6, (long)500E3, { 0x00, 0xf0, 0x86 } }, { (long)16E6, (long)250E3, { 0x41, 0xf1, 0x85 } }, { (long)16E6, (long)200E3, { 0x01, 0xfa, 0x87 } },