16
16
* Simply declare your rx and tx frames using 'CanFrame' structures and you are good to go!
17
17
*
18
18
*/
19
-
19
+ # ifdef ARDUINO
20
20
#include < Arduino.h>
21
+ #else
22
+ #include " inttypes.h"
23
+ #endif
21
24
#include " driver/twai.h"
22
25
26
+
23
27
// Uncomment or declare before importing header
24
28
// #define LOG_TWAI log_e
25
29
// #define LOG_TWAI_TX log_e
@@ -67,7 +71,7 @@ class TwaiCAN {
67
71
void setSpeed (TwaiSpeed);
68
72
TwaiSpeed getSpeed () { return speed; };
69
73
70
- // Converts from numeric CAN speed to enum values setSpeed(convertSpeed(500));
74
+ // Converts from numeric CAN speed to enum values: setSpeed(convertSpeed(500));
71
75
TwaiSpeed convertSpeed (uint16_t canSpeed = 0 );
72
76
73
77
// Size of queues for TWAI-CAN driver - remember about memory constrains!
@@ -83,16 +87,16 @@ class TwaiCAN {
83
87
84
88
// Everything is defaulted so you can just call .begin() or .begin(TwaiSpeed)
85
89
// 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 ,
87
91
int8_t txPin = -1 , int8_t rxPin = -1 ,
88
92
uint16_t txQueue = 0xFFFF , uint16_t rxQueue = 0xFFFF ,
89
93
twai_filter_config_t * fConfig = nullptr ,
90
94
twai_general_config_t * gConfig = nullptr ,
91
95
twai_timing_config_t * tConfig = nullptr );
92
96
93
97
// 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 ) {
96
100
bool ret = false ;
97
101
if ((frame) && twai_receive (frame, pdMS_TO_TICKS (timeout)) == ESP_OK) {
98
102
LOG_TWAI_RX (" Frame received %03X" , frame->identifier );
@@ -102,8 +106,8 @@ class TwaiCAN {
102
106
}
103
107
104
108
// 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 ) {
107
111
bool ret = false ;
108
112
if ((frame) && twai_transmit (frame, pdMS_TO_TICKS (timeout)) == ESP_OK) {
109
113
LOG_TWAI_TX (" Frame sent %03X" , frame->identifier );
0 commit comments