Skip to content

Commit 2bafe65

Browse files
committed
Remove CAN setup check for ESP32 TWAI, change extended ID flag format, make twai_transmit non-blocking
1 parent da8960b commit 2bafe65

2 files changed

Lines changed: 5 additions & 14 deletions

File tree

examples/SineWaveCAN/SineWaveCAN.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ bool setupCan() {
208208
return false;
209209
}
210210

211-
can_intf.initialized = true;
212211
return true;
213212
}
214213

src/ODriveESP32TWAI.hpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
// Simple struct to hold TWAI interface state. Unlike other platforms, ESP32's
1010
// TWAI driver uses global functions rather than a class instance.
11-
struct ESP32TWAIIntf {
12-
bool initialized = false;
13-
};
11+
struct ESP32TWAIIntf {};
1412

1513
struct CanMsg {
1614
uint32_t id;
@@ -22,14 +20,11 @@ struct CanMsg {
2220
void onCanMessage(const CanMsg& msg);
2321

2422
static bool sendMsg(ESP32TWAIIntf& intf, uint32_t id, uint8_t length, const uint8_t* data) {
25-
if (!intf.initialized) {
26-
return false;
27-
}
28-
23+
(void)intf;
2924
twai_message_t tx_msg = {};
3025
tx_msg.identifier = id;
3126
tx_msg.data_length_code = length;
32-
tx_msg.extd = (id > 0x7FF) ? 1 : 0;
27+
tx_msg.extd = (id & 0x80000000) ? 1 : 0;
3328
tx_msg.rtr = (data == nullptr) ? 1 : 0;
3429

3530
if (data) {
@@ -38,18 +33,15 @@ static bool sendMsg(ESP32TWAIIntf& intf, uint32_t id, uint8_t length, const uint
3833
}
3934
}
4035

41-
return twai_transmit(&tx_msg, pdMS_TO_TICKS(100)) == ESP_OK;
36+
return twai_transmit(&tx_msg, 0) == ESP_OK;
4237
}
4338

4439
static void onReceive(const CanMsg& msg, ODriveCAN& odrive) {
4540
odrive.onReceive(msg.id, msg.len, msg.buffer);
4641
}
4742

4843
static void pumpEvents(ESP32TWAIIntf& intf, int max_events = 100) {
49-
if (!intf.initialized) {
50-
return;
51-
}
52-
44+
(void)intf;
5345
// max_events prevents an infinite loop if messages come at a high rate
5446
twai_message_t rx_msg;
5547
while (twai_receive(&rx_msg, 0) == ESP_OK && max_events--) {

0 commit comments

Comments
 (0)