Esp32c6 dual can support with canio#10670
Conversation
Implement display initialization for Waveshare ESP32-C6 Touch LCD.
Add comment for Micropython setup specific to Waveshare ESP32-C6 Touch LCD 1.47.
Added twai_driver_handle and instance fields to canio_can_obj_t structure.
tannewt
left a comment
There was a problem hiding this comment.
Thanks for these tweaks! I didn't realize the C6 had two TWAI!
| if (self->instance==0){ | ||
| reserved_can_instance&=0x02; /* free first instance - clear 1st bit */ | ||
| }else if (self->instance==1){ | ||
| reserved_can_instance&=0x01; /* free second instance - clear 2nd bit */ | ||
| } |
There was a problem hiding this comment.
| if (self->instance==0){ | |
| reserved_can_instance&=0x02; /* free first instance - clear 1st bit */ | |
| }else if (self->instance==1){ | |
| reserved_can_instance&=0x01; /* free second instance - clear 2nd bit */ | |
| } | |
| reserved_can_instance &= ~(1 << self->instance); |
This sets the bit and then ~ inverts them.
| byte this_can_instance=0; | ||
| if (reserved_can_instance==0x00){ /* None assigned */ | ||
| reserved_can_instance=0x01; /* First instance is assigned*/ | ||
| this_can_instance=0; /* Idx of selected instance */ | ||
| } | ||
| else if (reserved_can_instance==0x01) /* First instance allready assigned */ | ||
| { | ||
| reserved_can_instance=0x03; /* Second instance also assigned */ | ||
| this_can_instance=1; /* Idx of selected instance */ | ||
|
|
||
| }else if (reserved_can_instance==0x02) /* Second instance is assigned */ | ||
| { | ||
| reserved_can_instance=0x03; /* first instance also assigned*/ | ||
| this_can_instance=0; /* Idx of selected instance */ | ||
| } |
There was a problem hiding this comment.
Use a loop for this. That way it'll work if a chip with more than 2 comes along. The compiler can unroll if desired.
| #define TWAI0 REG_TWAI_BASE(0) /**< \brief (CAN0) APB Base Address */ | ||
| #define TWAI1 REG_TWAI_BASE(1) /**< \brief (CAN1) APB Base Address */ | ||
| #define TWAI_INST_NUM 2 /**< \brief (CAN) Number of instances */ | ||
|
|
||
| static twai_handle_t twai_bus_0; | ||
| static twai_handle_t twai_bus_1; | ||
| static twai_handle_t *const twai_insts[TWAI_INST_NUM] = { &twai_bus_0, &twai_bus_1 }; |
There was a problem hiding this comment.
Guard this based on some defines the IDF provides for the number of TWAI. Otherwise, chips with only 1 instance won't work.
|
|
||
| # Board was originally defined with a 2MB firmware, almost 2MB user filesystem. Leave it that way. | ||
| CIRCUITPY_4MB_FLASH_LARGE_USER_FS_LAYOUT = 1 |
There was a problem hiding this comment.
Remove this since it is a new board.
| @@ -0,0 +1,11 @@ | |||
| CIRCUITPY_CREATOR_ID = 0x1BBB0000 | |||
| CIRCUITPY_CREATION_ID = 0x00C60002 | |||
There was a problem hiding this comment.
Please grab a new id here for the touch version: https://github.com/creationid/creators/blob/main/creations/waveshare.md
|
@ericbaril72 Are you still interested in working on this? Thanks. |
I refactored the common-hal/canio/can.c to alloy for use of both CAN controllers in the ESP32C6.
Having purchased the "TOUCH" version of waveshare_esp32_c6 with LCD, I also had to create this new board that uses way different pinouts.
Only tested without filters as I am using it as a CAN-to-CAN bridge.
Listener.c DOES need to be modified to select the proper &TWAI if filters are to be used ( MATCH )