components/esp_hal_twai/README.md
[!NOTE] This component is currently in beta. Its API, behavior, and compatibility may change at any time and without notice; backward compatibility is not guaranteed. Use caution when integrating into production systems.
The esp_hal_twai component provides a Hardware Abstraction Layer for the TWAI (Two-Wire Automotive Interface) peripheral across all ESP-IDF supported targets. TWAI is Espressif's implementation of the CAN (Controller Area Network) protocol, widely used in automotive and industrial applications for reliable communication between microcontrollers and devices.
The TWAI HAL is structured in two main sub-layers:
HAL Layer (Upper): Defines the operational steps and data structures required to control the TWAI peripheral (e.g., initialization, message transmission/reception, error handling, bus recovery).
Low-Level Layer (Bottom): Serves as a translation layer between the HAL and the register files defined in the soc component, handling target-specific register configurations.
This HAL supports two versions of TWAI controllers depending on the ESP chip:
TWAI Version 1: Standard CAN 2.0 controller supporting standard and extended frame formats
twai_hal_v1.cTWAI Version 2: Enhanced controller with TWAI-FD (CAN-FD) support, enabling flexible data-rate for higher bandwidth communication
twai_hal_v2.cThe HAL functions primarily serve ESP-IDF peripheral drivers such as the esp_driver_twai component.
Advanced developers can use these interfaces directly when implementing custom drivers, with the understanding that API stability is not guaranteed.
soc: Provides chip-specific register definitionshal: Core hardware abstraction utilities and macros