|
18 | 18 | #include "esp_heap_caps.h" |
19 | 19 | #include "esp_clk_tree.h" |
20 | 20 | #include "clk_ctrl_os.h" |
21 | | -#include "driver/gpio.h" |
22 | 21 | #include "esp_private/periph_ctrl.h" |
23 | 22 | #include "esp_private/esp_clk.h" |
| 23 | +#include "esp_private/gpio.h" |
24 | 24 | #include "driver/twai.h" |
25 | 25 | #include "soc/soc_caps.h" |
26 | 26 | #include "soc/soc.h" |
| 27 | +#include "soc/io_mux_reg.h" |
27 | 28 | #include "soc/twai_periph.h" |
28 | | -#include "soc/gpio_sig_map.h" |
29 | 29 | #include "hal/twai_hal.h" |
30 | 30 | #include "esp_rom_gpio.h" |
31 | 31 | #if SOC_TWAI_SUPPORT_SLEEP_RETENTION |
|
34 | 34 |
|
35 | 35 | /* ---------------------------- Definitions --------------------------------- */ |
36 | 36 | //Internal Macros |
| 37 | +#define TWAI_TAG "TWAI" |
37 | 38 | #define TWAI_CHECK(cond, ret_val) ({ \ |
38 | 39 | if (!(cond)) { \ |
39 | 40 | return (ret_val); \ |
|
46 | 47 | #ifdef CONFIG_TWAI_ISR_IN_IRAM |
47 | 48 | #define TWAI_MALLOC_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT) |
48 | 49 | #else |
49 | | -#define TWAI_TAG "TWAI" |
50 | 50 | #define TWAI_MALLOC_CAPS MALLOC_CAP_DEFAULT |
51 | 51 | #endif //CONFIG_TWAI_ISR_IN_IRAM |
52 | 52 |
|
@@ -289,37 +289,26 @@ static void twai_configure_gpio(int controller_id, gpio_num_t tx, gpio_num_t rx, |
289 | 289 | { |
290 | 290 | // assert the GPIO number is not a negative number (shift operation on a negative number is undefined) |
291 | 291 | assert(tx >= 0 && rx >= 0); |
292 | | - // if TX and RX set to the same GPIO, which means we want to create a loop-back in the GPIO matrix |
293 | | - bool io_loop_back = (tx == rx); |
294 | | - gpio_config_t gpio_conf = { |
295 | | - .intr_type = GPIO_INTR_DISABLE, |
296 | | - .pull_down_en = false, |
297 | | - .pull_up_en = false, |
298 | | - }; |
| 292 | + |
299 | 293 | //Set RX pin |
300 | | - gpio_conf.mode = GPIO_MODE_INPUT | (io_loop_back ? GPIO_MODE_OUTPUT : 0); |
301 | | - gpio_conf.pin_bit_mask = 1ULL << rx; |
302 | | - gpio_config(&gpio_conf); |
| 294 | + gpio_func_sel(rx, PIN_FUNC_GPIO); |
| 295 | + gpio_input_enable(rx); |
303 | 296 | esp_rom_gpio_connect_in_signal(rx, twai_controller_periph_signals.controllers[controller_id].rx_sig, false); |
304 | 297 |
|
305 | 298 | //Set TX pin |
306 | | - gpio_conf.mode = GPIO_MODE_OUTPUT | (io_loop_back ? GPIO_MODE_INPUT : 0); |
307 | | - gpio_conf.pin_bit_mask = 1ULL << tx; |
308 | | - gpio_config(&gpio_conf); |
| 299 | + gpio_func_sel(tx, PIN_FUNC_GPIO); |
309 | 300 | esp_rom_gpio_connect_out_signal(tx, twai_controller_periph_signals.controllers[controller_id].tx_sig, false, false); |
310 | 301 |
|
311 | 302 | //Configure output clock pin (Optional) |
312 | 303 | if (clkout >= 0 && clkout < GPIO_NUM_MAX) { |
313 | | - gpio_set_pull_mode(clkout, GPIO_FLOATING); |
| 304 | + gpio_func_sel(clkout, PIN_FUNC_GPIO); |
314 | 305 | esp_rom_gpio_connect_out_signal(clkout, twai_controller_periph_signals.controllers[controller_id].clk_out_sig, false, false); |
315 | | - esp_rom_gpio_pad_select_gpio(clkout); |
316 | 306 | } |
317 | 307 |
|
318 | 308 | //Configure bus status pin (Optional) |
319 | 309 | if (bus_status >= 0 && bus_status < GPIO_NUM_MAX) { |
320 | | - gpio_set_pull_mode(bus_status, GPIO_FLOATING); |
| 310 | + gpio_func_sel(bus_status, PIN_FUNC_GPIO); |
321 | 311 | esp_rom_gpio_connect_out_signal(bus_status, twai_controller_periph_signals.controllers[controller_id].bus_off_sig, false, false); |
322 | | - esp_rom_gpio_pad_select_gpio(bus_status); |
323 | 312 | } |
324 | 313 | } |
325 | 314 |
|
|
0 commit comments