33
33
#include "shared-bindings/microcontroller/Pin.h"
34
34
#include "shared-bindings/util.h"
35
35
#include "supervisor/port.h"
36
- #include "hal/twai_ll.h"
37
36
38
37
#include "hal/twai_types.h"
39
38
@@ -43,6 +42,10 @@ twai_timing_config_t get_t_config(int baudrate) {
43
42
switch (baudrate ) {
44
43
case 1000000 :
45
44
{
45
+ // TWAI_TIMING_CONFIG_abc expands to a C designated initializer list
46
+ // { .brp = 4, ...}. This is only acceptable to the compiler as an
47
+ // initializer and 'return TWAI_TIMING_CONFIG_1MBITS()` is not valid.
48
+ // Instead, introduce a temporary, named variable and return it.
46
49
twai_timing_config_t t_config = TWAI_TIMING_CONFIG_1MBITS ();
47
50
return t_config ;
48
51
}
@@ -116,7 +119,6 @@ twai_timing_config_t get_t_config(int baudrate) {
116
119
}
117
120
}
118
121
119
- __attribute__((optimize ("O0" )))
120
122
void common_hal_canio_can_construct (canio_can_obj_t * self , mcu_pin_obj_t * tx , mcu_pin_obj_t * rx , int baudrate , bool loopback , bool silent )
121
123
{
122
124
#define DIV_ROUND (a , b ) (((a) + (b)/2) / (b))
@@ -129,7 +131,7 @@ void common_hal_canio_can_construct(canio_can_obj_t *self, mcu_pin_obj_t *tx, mc
129
131
mp_raise_ValueError (translate ("loopback + silent mode not supported by peripheral" ));
130
132
}
131
133
132
- self -> t_config = get_t_config (baudrate ); ;
134
+ twai_timing_config_t t_config = get_t_config (baudrate );
133
135
twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT (-1 , -1 , TWAI_MODE_NORMAL );
134
136
g_config .tx_io = tx -> number ;
135
137
g_config .rx_io = rx -> number ;
@@ -139,14 +141,10 @@ void common_hal_canio_can_construct(canio_can_obj_t *self, mcu_pin_obj_t *tx, mc
139
141
if (silent ) {
140
142
g_config .mode = TWAI_MODE_LISTEN_ONLY ;
141
143
}
142
- self -> g_config = g_config ;
143
144
144
- {
145
145
twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL ();
146
- self -> f_config = f_config ;
147
- }
148
146
149
- esp_err_t result = twai_driver_install (& self -> g_config , & self -> t_config , & self -> f_config );
147
+ esp_err_t result = twai_driver_install (& g_config , & t_config , & f_config );
150
148
if (result == ESP_ERR_NO_MEM ) {
151
149
mp_raise_msg (& mp_type_MemoryError , translate ("ESP-IDF memory allocation failed" ));
152
150
} else if (result == ESP_ERR_INVALID_ARG ) {
0 commit comments