Skip to content

Conversation

ericbaril72
Copy link

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 )

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.
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these tweaks! I didn't realize the C6 had two TWAI!

Comment on lines +296 to +300
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 */
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines +119 to +133
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 */
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +21 to +27
#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 };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guard this based on some defines the IDF provides for the number of TWAI. Otherwise, chips with only 1 instance won't work.

Comment on lines +9 to +11

# Board was originally defined with a 2MB firmware, almost 2MB user filesystem. Leave it that way.
CIRCUITPY_4MB_FLASH_LARGE_USER_FS_LAYOUT = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this since it is a new board.

@@ -0,0 +1,11 @@
CIRCUITPY_CREATOR_ID = 0x1BBB0000
CIRCUITPY_CREATION_ID = 0x00C60002
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please grab a new id here for the touch version: https://github.com/creationid/creators/blob/main/creations/waveshare.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants