Skip to content

Commit af4fb06

Browse files
author
sorek
committed
Added IRAM_ATTR for faster (?) processing; made begin() not override set CAN speed
1 parent 3df1a38 commit af4fb06

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "ESP32-TWAI-CAN",
33
"keywords": "can, twai, esp32, esp32-s3, esp32-s2, driver, arduino",
44
"description": "ESP32 driver for TWAI / CAN for Adruino using ESP-IDF drivers.",
5-
"version": "1.0.0",
5+
"version": "1.0.1",
66
"repository":
77
{
88
"type": "git",

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=ESP32-TWAI-CAN
2-
version=1.0.0
2+
version=1.0.1
33
author=sorek.uk
44
maintainer=sorek <contact@sorek.uk>
55
sentence=ESP32 driver for TWAI / CAN for Adruino using ESP-IDF drivers.
66
paragraph=Supporting ESP32, ESP32-S2, ESP32-S3, ESP32-C3
7-
category=driver
7+
category=Communication
88
url=https://github.com/handmade0octopus/ESP32-TWAI-CAN
99
architectures=*

src/ESP32-TWAI-CAN.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616
* Simply declare your rx and tx frames using 'CanFrame' structures and you are good to go!
1717
*
1818
*/
19-
19+
#ifdef ARDUINO
2020
#include <Arduino.h>
21+
#else
22+
#include "inttypes.h"
23+
#endif
2124
#include "driver/twai.h"
2225

26+
2327
// Uncomment or declare before importing header
2428
//#define LOG_TWAI log_e
2529
//#define LOG_TWAI_TX log_e
@@ -67,7 +71,7 @@ class TwaiCAN {
6771
void setSpeed(TwaiSpeed);
6872
TwaiSpeed getSpeed() { return speed; };
6973

70-
// Converts from numeric CAN speed to enum values setSpeed(convertSpeed(500));
74+
// Converts from numeric CAN speed to enum values: setSpeed(convertSpeed(500));
7175
TwaiSpeed convertSpeed(uint16_t canSpeed = 0);
7276

7377
// Size of queues for TWAI-CAN driver - remember about memory constrains!
@@ -83,16 +87,16 @@ class TwaiCAN {
8387

8488
// Everything is defaulted so you can just call .begin() or .begin(TwaiSpeed)
8589
// Calling begin() to change speed works, it will disable current driver first
86-
bool begin(TwaiSpeed twaiSpeed = TWAI_SPEED_500KBPS,
90+
bool begin(TwaiSpeed twaiSpeed = TWAI_SPEED_SIZE,
8791
int8_t txPin = -1, int8_t rxPin = -1,
8892
uint16_t txQueue = 0xFFFF, uint16_t rxQueue = 0xFFFF,
8993
twai_filter_config_t* fConfig = nullptr,
9094
twai_general_config_t* gConfig = nullptr,
9195
twai_timing_config_t* tConfig = nullptr);
9296

9397
// Pass frame either by reference or pointer; timeout in ms, you can pass 0 for non blocking
94-
inline bool readFrame(CanFrame& frame, uint32_t timeout = 1000) { return readFrame(&frame, timeout); }
95-
inline bool readFrame(CanFrame* frame, uint32_t timeout = 1000) {
98+
inline bool IRAM_ATTR readFrame(CanFrame& frame, uint32_t timeout = 1000) { return readFrame(&frame, timeout); }
99+
inline bool IRAM_ATTR readFrame(CanFrame* frame, uint32_t timeout = 1000) {
96100
bool ret = false;
97101
if((frame) && twai_receive(frame, pdMS_TO_TICKS(timeout)) == ESP_OK) {
98102
LOG_TWAI_RX("Frame received %03X", frame->identifier);
@@ -102,8 +106,8 @@ class TwaiCAN {
102106
}
103107

104108
// Pass frame either by reference or pointer; timeout in ms, you can pass 0 for non blocking
105-
inline bool writeFrame(CanFrame& frame, uint32_t timeout = 1) { return writeFrame(&frame, timeout); }
106-
inline bool writeFrame(CanFrame* frame, uint32_t timeout = 1) {
109+
inline bool IRAM_ATTR writeFrame(CanFrame& frame, uint32_t timeout = 1) { return writeFrame(&frame, timeout); }
110+
inline bool IRAM_ATTR writeFrame(CanFrame* frame, uint32_t timeout = 1) {
107111
bool ret = false;
108112
if((frame) && twai_transmit(frame, pdMS_TO_TICKS(timeout)) == ESP_OK) {
109113
LOG_TWAI_TX("Frame sent %03X", frame->identifier);

0 commit comments

Comments
 (0)