-
Notifications
You must be signed in to change notification settings - Fork 23
Modified library for ESP32 native TWAI driver #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BWV999-MTL
wants to merge
10
commits into
odriverobotics:master
Choose a base branch
from
BWV999-MTL:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
32d9092
Add files via upload
BWV999-MTL d98eea3
Add files via upload
BWV999-MTL 5b93388
Add files via upload
BWV999-MTL 8a92e32
Update SineWaveCAN.ino
BWV999-MTL 46ecde3
Update SineWaveCAN.ino
BWV999-MTL 53d97d2
Update ODriveESP32TWAI.hpp
BWV999-MTL 70b668b
Update TWAI_CAN_Class.h
BWV999-MTL c0bb4a7
Update SineWaveCAN.ino
BWV999-MTL 9df8fd5
Update TWAI_CAN_Class.h
BWV999-MTL fde3d5d
Update TWAI_CAN_Class.h
BWV999-MTL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#pragma once | ||
|
||
#include "TWAI_CAN_Class.h" // Include your custom TWAIClass header | ||
#include "ODriveCAN.h" | ||
|
||
// This is a convenience struct because the TWAIClass doesn't have a | ||
// native message type. | ||
struct CanMsg { | ||
uint32_t id; | ||
uint8_t len; | ||
uint8_t buffer[8]; | ||
}; | ||
|
||
// Must be defined by the application if you want to use defaultCanReceiveCallback(). | ||
void onCanMessage(const CanMsg& msg); | ||
|
||
|
||
static bool sendMsg(TWAIClass& can_intf, uint32_t id, uint8_t length, const uint8_t* data) { | ||
BWV999-MTL marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Send CAN message | ||
can_intf.prepareMessage(id, length, !data); | ||
if (data) { | ||
for (int i = 0; i < length; ++i) { | ||
can_intf.write(data[i], i); | ||
} | ||
} | ||
return can_intf.endPacket(); | ||
} | ||
|
||
static void onReceive(const CanMsg& msg, ODriveCAN& odrive) { | ||
odrive.onReceive(msg.id, msg.len, msg.buffer); | ||
} | ||
|
||
static void pumpEvents(TWAIClass& intf) { | ||
CanMsg msg; | ||
int length = intf.parsePacket(); // Check if a packet is available | ||
|
||
if (length > 0) { | ||
msg.id = intf.packetId(); // Retrieve the ID of the received message | ||
// Debug print to check if ID is read correctly | ||
//Serial.print("Received Raw Frame ID: 0x"); // DEBUG PRINT uncomment to print all messages to serial console ********************************** | ||
//Serial.println(msg.id, HEX); // DEBUG PRINT uncomment to print all messages to serial console ********************************** | ||
msg.len = length; | ||
intf.readBytes(msg.buffer, length); // Retrieve the data from the message | ||
onCanMessage(msg); // Call the user-defined callback | ||
} | ||
} | ||
|
||
CREATE_CAN_INTF_WRAPPER(TWAIClass) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.