Skip to content

Commit

Permalink
[adruino-CAN] Update to latest library code
Browse files Browse the repository at this point in the history
  • Loading branch information
TD-er committed Sep 22, 2024
1 parent 0bc2b45 commit 44f2f69
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/arduino-CAN/src/CANController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 1 addition & 8 deletions lib/arduino-CAN/src/CANController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 5 additions & 12 deletions lib/arduino-CAN/src/ESP32SJA1000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion lib/arduino-CAN/src/ESP32SJA1000.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 2 additions & 0 deletions lib/arduino-CAN/src/MCP2515.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 } },
Expand All @@ -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 } },
Expand Down

0 comments on commit 44f2f69

Please sign in to comment.