|
| | EspCan (const hf_esp_can_config_t &config) noexcept |
| | Constructor with TWAI node configuration.
|
| |
| | ~EspCan () noexcept override |
| | Destructor - ensures proper cleanup and resource deallocation.
|
| |
| hf_can_err_t | Initialize () noexcept override |
| | Initialize the TWAI node and allocate resources.
|
| |
| hf_can_err_t | Deinitialize () noexcept override |
| | Deinitialize the TWAI node and free resources.
|
| |
| hf_can_err_t | SendMessage (const hf_can_message_t &message, uint32_t timeout_ms=1000) noexcept override |
| | Queue a CAN message for transmission.
|
| |
| hf_can_err_t | ReceiveMessage (hf_can_message_t &message, uint32_t timeout_ms=0) noexcept override |
| | Take the oldest frame from the RX ring.
|
| |
| hf_can_err_t | SetReceiveCallback (hf_can_receive_callback_t callback) noexcept override |
| | Set the BaseCan receive callback.
|
| |
| void | ClearReceiveCallback () noexcept override |
| | Clear the BaseCan receive callback.
|
| |
| hf_can_err_t | SetReceiveCallbackEx (hf_esp_can_receive_callback_t cb, void *user_data=nullptr) noexcept |
| |
| void | ClearReceiveCallbackEx () noexcept |
| |
| hf_can_err_t | SetErrorCallback (hf_esp_can_error_callback_t cb, void *user_data=nullptr) noexcept |
| |
| void | ClearErrorCallback () noexcept |
| |
| hf_can_err_t | SetStateChangeCallback (hf_esp_can_state_callback_t cb, void *user_data=nullptr) noexcept |
| |
| void | ClearStateChangeCallback () noexcept |
| |
| hf_can_err_t | SetTxCompleteCallback (hf_esp_can_tx_callback_t cb, void *user_data=nullptr) noexcept |
| |
| void | ClearTxCompleteCallback () noexcept |
| |
| hf_can_err_t | GetStatus (hf_can_status_t &status) noexcept override |
| | Get current CAN bus status.
|
| |
| hf_can_err_t | Reset () noexcept override |
| | Reset the CAN controller.
|
| |
| hf_can_err_t | SetAcceptanceFilter (uint32_t id, uint32_t mask, bool extended=false) noexcept override |
| | Set acceptance filter for incoming messages.
|
| |
| hf_can_err_t | ClearAcceptanceFilter () noexcept override |
| | Clear all acceptance filters (accept all messages).
|
| |
| hf_can_err_t | GetStatistics (hf_can_statistics_t &stats) noexcept override |
| | Get detailed statistics.
|
| |
| hf_can_err_t | ResetStatistics () noexcept override |
| | Reset statistics counters.
|
| |
| hf_can_err_t | GetDiagnostics (hf_can_diagnostics_t &diagnostics) noexcept override |
| | Get diagnostic information.
|
| |
| hf_can_err_t | ConfigureAdvancedTiming (const hf_esp_can_timing_config_t &timing_config) noexcept |
| | Configure advanced bit timing parameters.
|
| |
| hf_can_err_t | ConfigureAdvancedFilter (const hf_esp_can_filter_config_t &filter_config) noexcept |
| | Configure hardware acceptance filter with advanced options.
|
| |
| hf_can_err_t | InitiateBusRecovery () noexcept |
| | Initiate bus recovery from bus-off state (same as RequestBusRecovery()).
|
| |
| hf_can_err_t | GetBusStatus (hf_can_bus_status_t &status) noexcept override |
| | Error state, TEC/REC, RX overruns, TX-queue-full and bus-off counters.
|
| |
| hf_can_err_t | RequestBusRecovery () noexcept override |
| | Start bus-off recovery; returns without waiting (see BaseCan).
|
| |
| hf_can_err_t | GetNodeInfo (twai_node_record_t &node_info) noexcept |
| | Get detailed node information including error states.
|
| |
| uint32_t | SendMessageBatch (const hf_can_message_t *messages, uint32_t count, uint32_t timeout_ms=1000) noexcept |
| | Send multiple messages in a batch for improved performance.
|
| |
| virtual | ~BaseCan () noexcept=default |
| | Virtual destructor ensures proper cleanup in derived classes.
|
| |
| | BaseCan (const BaseCan &)=delete |
| |
| BaseCan & | operator= (const BaseCan &)=delete |
| |
| | BaseCan (BaseCan &&)=delete |
| |
| BaseCan & | operator= (BaseCan &&)=delete |
| |
| bool | EnsureInitialized () noexcept |
| | Ensures that the CAN bus is initialized (lazy initialization).
|
| |
| bool | EnsureDeinitialized () noexcept |
| | Ensures that the CAN bus is deinitialized.
|
| |
| bool | IsInitialized () const noexcept |
| | Checks if the class is initialized.
|
| |
| hf_can_err_t | TrySendMessage (const hf_can_message_t &message) noexcept |
| | Queue a message for transmission without blocking.
|
| |
| virtual hf_can_err_t | SetReceiveCallbackFD (hf_can_fd_receive_callback_t callback) noexcept |
| | Set CAN-FD receive callback with enhanced information.
|
| |
| virtual bool | SupportsCanFD () const noexcept |
| | Check if CAN-FD is supported by this controller.
|
| |
| virtual bool | SetCanFDMode (bool enable, hf_u32_t data_baudrate=2000000, hf_u32_t timeout_ms=1000) noexcept |
| | Enable or disable CAN-FD mode.
|
| |
| virtual bool | ConfigureCanFDTiming (hf_u16_t nominal_prescaler, hf_u8_t nominal_tseg1, hf_u8_t nominal_tseg2, hf_u16_t data_prescaler, hf_u8_t data_tseg1, hf_u8_t data_tseg2, hf_u8_t sjw=1) noexcept |
| | Configure CAN-FD timing parameters.
|
| |
| virtual bool | SetTransmitterDelayCompensation (hf_u8_t tdc_offset, hf_u8_t tdc_filter) noexcept |
| | Set transmitter delay compensation (CAN-FD feature).
|
| |
| virtual hf_u32_t | ReceiveMessageBatch (hf_can_message_t *messages, hf_u32_t max_count, hf_u32_t timeout_ms=100) noexcept |
| | Receive multiple messages in a batch.
|
| |
| virtual hf_can_err_t | ResetDiagnostics () noexcept |
| | Reset CAN diagnostic information.
|
| |
ESP32 CAN (TWAI) implementation using ESP-IDF v5.5+ node-based API.
This class provides clean, comprehensive CAN communication using the ESP32's TWAI (Two-Wire Automotive Interface) controllers with modern ESP-IDF v5.5+ node-based APIs. The implementation supports ESP32 and external SN65 CAN transceivers.
Key Features:
- ESP-IDF v5.5+ handle-based TWAI node API
- ESP32 compatible TWAI controller support
- Event-driven callback-based message reception
- Advanced acceptance filtering (single/dual mask modes)
- Comprehensive error detection and bus recovery
- Advanced bit timing configuration for various baud rates
- Thread-safe operations with proper resource management
- Support for external SN65 CAN transceivers
- Comprehensive diagnostics and performance monitoring
- Note
- This implementation requires ESP-IDF v5.5 or later
-
Each EspCan instance represents a single TWAI node