ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
esphome::mcp251xfd::MCP251XFD Class Reference

#include <mcp251xfd.h>

Inheritance diagram for esphome::mcp251xfd::MCP251XFD:
esphome::canbus::Canbus esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_8MHZ > esphome::Component esphome::spi::SPIClient

Public Member Functions

 MCP251XFD (CanClock clock, CanMode mode, uint32_t nominal_bit_timing, uint32_t data_bit_timing, uint32_t transmitter_delay_compensation)
 
void dump_config () override
 
void set_interrupt_pin (InternalGPIOPin *pin)
 
canbus::CanStatus get_status () override
 
- Public Member Functions inherited from esphome::canbus::Canbus
 Canbus ()
 
void setup () override
 
float get_setup_priority () const override
 
void loop () override
 
canbus::Error send_data (const CanFrame &frame)
 Validates the frame and passes it to the driver.
 
canbus::Error send_data (uint32_t can_id, bool use_extended_id, bool remote_transmission_request, const uint8_t *data, size_t len, bool fd=false, bool bit_rate_switch=false, bool pad_data=false)
 Sends up to 8 bytes as a classic frame, longer data is cut.
 
canbus::Error send_data (uint32_t can_id, bool use_extended_id, bool remote_transmission_request, const uint8_t *data, size_t len)
 Sends up to 8 bytes as a classic frame, longer data is cut.
 
canbus::Error send_data (uint32_t can_id, bool use_extended_id, bool remote_transmission_request, const std::vector< uint8_t > &data)
 
canbus::Error send_data (uint32_t can_id, bool use_extended_id, const std::vector< uint8_t > &data)
 
void set_can_id (uint32_t can_id)
 
void set_use_extended_id (bool use_extended_id)
 
void set_bitrate (CanSpeed bit_rate)
 
void set_max_frames_per_loop (uint32_t max_frames_per_loop)
 
void set_default_fd (bool default_fd)
 
void set_default_bit_rate_switch (bool default_bit_rate_switch)
 
void set_default_pad_data (bool default_pad_data)
 
void set_supports_fd (bool supports_fd)
 
bool supports_fd () const
 Whether this bus sends and receives CAN FD frames; a classic bus can share a build with a CAN FD one.
 
template<typename F >
void add_frame_callback (F &&callback)
 The frame is only valid during the call.
 
template<typename F >
 ESPDEPRECATED ("Use add_frame_callback(), which does not copy the payload. Removed in 2027.5.0.", "2026.11.0") void add_callback(F &&callback)
 Add a callback to be called when a CAN message is received.
 
- Public Member Functions inherited from esphome::Component
float get_actual_setup_priority () const
 
void set_setup_priority (float priority)
 
void call ()
 
virtual void on_shutdown ()
 
virtual void on_safe_shutdown ()
 
virtual bool teardown ()
 Called during teardown to allow component to gracefully finish operations.
 
virtual void on_powerdown ()
 Called last before a reboot or deep sleep to power down hardware.
 
uint8_t get_component_state () const
 
void reset_to_construction_state ()
 Reset this component back to the construction state to allow setup to run again.
 
bool is_in_loop_state () const
 Check if this component has completed setup and is in the loop state.
 
bool is_idle () const
 Check if this component is idle.
 
void mark_failed ()
 Mark this component as failed.
 
void mark_failed (const LogString *message)
 
bool ESPHOME_ALWAYS_INLINE setup_check (bool ok)
 Marks the component failed with message (default "Communication failed") unless ok; returns ok.
 
bool ESPHOME_ALWAYS_INLINE setup_check (bool ok, const LogString *message)
 
void disable_loop ()
 Disable this component's loop.
 
void enable_loop ()
 Enable this component's loop.
 
void enable_loop_soon_any_context ()
 Thread and ISR-safe version of enable_loop() that can be called from any context.
 
bool is_failed () const
 
bool is_ready () const
 
virtual bool can_proceed ()
 
bool status_has_warning () const
 
bool status_has_error () const
 
void status_set_warning ()
 
void status_set_warning (const char *message)
 
void status_set_warning (const LogString *message)
 
bool status_comm_result (bool ok)
 Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok.
 
bool status_comm_result (bool ok, const LogString *message)
 
bool status_comm_check (bool ok)
 Sets the warning ("Communication failed") when not ok but never clears it; returns ok.
 
void status_set_error ()
 
void status_set_error (const LogString *message)
 
void status_clear_warning ()
 
void status_clear_error ()
 
 ESPDEPRECATED ("Use status_momentary_warning() without a name. Removed in 2027.5.0", "2026.11.0") void status_momentary_warning(const char *name
 
void status_momentary_warning (uint32_t length=5000)
 Set warning status flag and clear it after length ms.
 
void status_momentary_warning (const LogString *message, uint32_t length=5000)
 
 ESPDEPRECATED ("Use status_momentary_error() without a name. Removed in 2027.5.0", "2026.11.0") void status_momentary_error(const char *name
 
void status_momentary_error (uint32_t length=5000)
 Set error status flag and clear it after length ms.
 
void status_momentary_error (const LogString *message, uint32_t length=5000)
 
bool has_overridden_loop () const
 
const LogString * get_component_log_str () const ESPHOME_ALWAYS_INLINE
 Get the integration where this component was declared as a LogString for logging.
 
bool should_warn_of_blocking (uint32_t blocking_time, uint32_t &threshold_ms_out)
 
- Public Member Functions inherited from esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_8MHZ >
 SPIDevice ()
 
 SPIDevice (SPIComponent *parent, GPIOPin *cs_pin)
 
void spi_setup () override
 
void spi_teardown () override
 
void set_spi_parent (SPIComponent *parent)
 
void set_cs_pin (GPIOPin *cs)
 
void set_data_rate (uint32_t data_rate)
 
void set_bit_order (SPIBitOrder order)
 
void set_mode (SPIMode mode)
 
uint8_t read_byte ()
 
void read_array (uint8_t *data, size_t length)
 
void write (uint16_t data, size_t num_bits)
 Write a single data item, up to 32 bits.
 
void write_cmd_addr_data (size_t cmd_bits, uint32_t cmd, size_t addr_bits, uint32_t address, const uint8_t *data, size_t length, uint8_t bus_width=1)
 
void write_byte (uint8_t data)
 
void transfer_array (uint8_t *data, size_t length)
 Write the array data, replace with received data.
 
void transfer_array (std::array< uint8_t, N > &data)
 
uint8_t transfer_byte (uint8_t data)
 
void write_byte16 (uint16_t data)
 Write 16 bit data.
 
void write_array16 (const uint16_t *data, size_t length)
 Write an array of data as 16 bit values, byte-swapping if required.
 
void enable ()
 
void disable ()
 
void write_array (const uint8_t *data, size_t length)
 
void write_array (const std::array< uint8_t, N > &data)
 
void write_array (const std::vector< uint8_t > &data)
 
- Public Member Functions inherited from esphome::spi::SPIClient
 SPIClient (SPIBitOrder bit_order, SPIMode mode, uint32_t data_rate)
 
bool spi_is_ready ()
 
void set_release_device (bool release)
 
void set_write_only (bool write_only)
 
void set_psram_dma (bool enable)
 

Protected Member Functions

bool setup_internal () override
 
canbus::CanEventFlags get_events () override
 
canbus::Error send_message (canbus::CanFrame *frame) override
 
canbus::Error read_message (canbus::CanFrame *frame) override
 
bool configure_ ()
 
bool reset_ ()
 
bool configure_clock_ ()
 
bool set_mode_ (CanMode mode, uint16_t timeout_ms=100)
 
bool wait_for_register_ (uint16_t address, uint8_t mask, uint8_t expected, uint16_t timeout_ms=100)
 
bool read_registers_ (uint16_t address, uint8_t *data, size_t length)
 
bool read_register_ (uint16_t address, uint32_t &value)
 
bool set_comm_fault_ (const LogString *reason)
 
bool should_log_fault_ (uint32_t now)
 
bool recover_mode_if_needed_ (bool bus_off, bool retry_due)
 
void write_transfer_ (uint16_t address, uint8_t *transfer, size_t length)
 
void write_registers_ (uint16_t address, const uint8_t *data, size_t length)
 
void write_register_ (uint16_t address, uint32_t value)
 
void write_byte_ (uint16_t address, uint8_t value)
 
bool validate_fifo_address_ (uint32_t offset, uint32_t start, uint32_t depth, uint16_t &address)
 
bool classic_ () const
 
uint32_t message_size_ () const
 
uint32_t rx_fifo_depth_ () const
 
- Protected Member Functions inherited from esphome::canbus::Canbus
void log_events_ (CanEventFlags events, uint32_t now)
 
canbus::Error send_frame_ (const CanFrame &frame)
 Logs and sends a frame that is already valid.
 
bool lambda_payload_fits_ (const CanPayload &payload, bool fd)
 For a canbus.send lambda: a CAN FD frame that did not fit is refused, a classic one is cut to 8 bytes.
 
- Protected Member Functions inherited from esphome::Component
friend void::setup ()
 
friend void::original_setup ()
 
void set_component_source_ (uint8_t index)
 Set where this component was loaded from for some debug messages.
 
virtual void call_setup ()
 
void call_dump_config_ ()
 
void enable_loop_slow_path_ ()
 
void set_component_state_ (uint8_t state)
 Helper to set component state (clears state bits and sets new state)
 
bool set_status_flag_ (uint8_t flag)
 Helper to set a status LED flag on both this component and the app.
 
bool set_error_flag_ (const LogString *message)
 Set the error flag and log it; true when it was not set before.
 
void set_interval (const char *name, uint32_t interval, std::function< void()> &&f)
 Set an interval function with a const char* name.
 
void set_interval (uint32_t id, uint32_t interval, std::function< void()> &&f)
 Set an interval function with a numeric ID (zero heap allocation).
 
void set_interval (InternalSchedulerID id, uint32_t interval, std::function< void()> &&f)
 
void set_interval (uint32_t interval, std::function< void()> &&f)
 
bool cancel_interval (const char *name)
 Cancel an interval function.
 
bool cancel_interval (uint32_t id)
 
bool cancel_interval (InternalSchedulerID id)
 
void set_timeout (const char *name, uint32_t timeout, std::function< void()> &&f)
 Set a timeout function with a const char* name.
 
void set_timeout (uint32_t id, uint32_t timeout, std::function< void()> &&f)
 Set a timeout function with a numeric ID (zero heap allocation).
 
void set_timeout (InternalSchedulerID id, uint32_t timeout, std::function< void()> &&f)
 
void set_timeout (uint32_t timeout, std::function< void()> &&f)
 
bool cancel_timeout (const char *name)
 Cancel a timeout function.
 
bool cancel_timeout (uint32_t id)
 
bool cancel_timeout (InternalSchedulerID id)
 
void defer (const char *name, std::function< void()> &&f)
 Defer a callback to the next loop() call with a const char* name.
 
void defer (std::function< void()> &&f)
 Defer a callback to the next loop() call.
 
void defer (uint32_t id, std::function< void()> &&f)
 Defer a callback with a numeric ID (zero heap allocation)
 
bool cancel_defer (const char *name)
 Cancel a defer callback using the specified name, name must not be empty.
 
bool cancel_defer (uint32_t id)
 
void status_clear_warning_slow_path_ ()
 
void status_comm_check_slow_path_ ()
 
void status_clear_error_slow_path_ ()
 

Protected Attributes

InternalGPIOPin * interrupt_pin_ {nullptr}
 
uint32_t nominal_bit_timing_
 
uint32_t data_bit_timing_
 
uint32_t transmitter_delay_compensation_
 
uint32_t last_trec_ {0}
 
uint32_t last_fault_log_time_ {0u - FAULT_LOG_INTERVAL_MS}
 
uint32_t last_mode_check_time_ {0u - MODE_RECOVERY_INTERVAL_MS}
 
uint32_t rx_overrun_count_ {0}
 
uint32_t bus_error_count_ {0}
 
CanClock mcp_clock_
 
CanMode mcp_mode_
 
uint8_t last_error_flags_ {0}
 
bool comm_fault_active_ {false}
 
bool mode_fault_active_ {false}
 
- Protected Attributes inherited from esphome::canbus::Canbus
uint32_t can_id_
 
uint32_t max_frames_per_loop_ {50}
 
CanSpeed bit_rate_ {CAN_125KBPS}
 
bool use_extended_id_ {false}
 
bool default_fd_ {false}
 
bool default_bit_rate_switch_ {false}
 
bool default_pad_data_ {false}
 
bool supports_fd_ {false}
 
uint8_t events_to_log_ {0}
 
bool bus_off_ {false}
 
CallbackManager< void(const CanFrame &frame)> frame_callbacks_ {}
 
uint32_t last_event_check_time_ {0}
 
uint32_t last_event_log_time_ {0}
 
uint32_t last_bus_off_time_ {0}
 
uint32_t last_state_log_time_ {0}
 
- Protected Attributes inherited from esphome::Component
uint8_t component_source_index_ {0}
 Index into component source PROGMEM lookup table (0 = not set)
 
uint8_t warn_if_blocking_over_ {WARN_IF_BLOCKING_OVER_CS}
 Warn threshold in centiseconds (max 2550ms)
 
uint8_t component_state_ {0x00}
 State of this component - each bit has a purpose: Bits 0-2: Component state (0x00=CONSTRUCTION, 0x01=SETUP, 0x02=LOOP, 0x03=FAILED, 0x04=LOOP_DONE) Bit 3: STATUS_LED_WARNING Bit 4: STATUS_LED_ERROR Bit 5: Has overridden loop() (set at registration time) Bits 6-7: Unused - reserved for future expansion.
 
volatile bool pending_enable_loop_ {false}
 ISR-safe flag for enable_loop_soon_any_context.
 
ComponentRuntimeStats runtime_stats_
 
- Protected Attributes inherited from esphome::spi::SPIClient
SPIBitOrder bit_order_ {BIT_ORDER_MSB_FIRST}
 
SPIMode mode_ {MODE0}
 
uint32_t data_rate_ {1000000}
 
SPIComponent * parent_ {nullptr}
 
GPIOPin * cs_ {nullptr}
 
bool release_device_ {false}
 
bool write_only_ {false}
 
bool psram_dma_ {false}
 
SPIDelegate * delegate_ {SPIDelegate::NULL_DELEGATE}
 

Additional Inherited Members

- Data Fields inherited from esphome::Component
uint32_t length = 5000)
 
- Static Protected Attributes inherited from esphome::canbus::Canbus
static constexpr uint32_t EVENT_CHECK_INTERVAL_MS = 100
 
static constexpr uint32_t EVENT_LOG_THROTTLE_MS = 1000
 
static constexpr uint32_t EVENT_LOG_BUS_OFF_HOLDOFF_MS = 1000
 
static constexpr uint32_t STATE_LOG_INTERVAL_MS = 1000
 

Detailed Description

Definition at line 10 of file mcp251xfd.h.

Constructor & Destructor Documentation

◆ MCP251XFD()

esphome::mcp251xfd::MCP251XFD::MCP251XFD ( CanClock clock,
CanMode mode,
uint32_t nominal_bit_timing,
uint32_t data_bit_timing,
uint32_t transmitter_delay_compensation )
inline

Definition at line 14 of file mcp251xfd.h.

Member Function Documentation

◆ classic_()

bool esphome::mcp251xfd::MCP251XFD::classic_ ( ) const
inlineprotected

Definition at line 67 of file mcp251xfd.h.

◆ configure_()

bool esphome::mcp251xfd::MCP251XFD::configure_ ( )
protected

Definition at line 27 of file mcp251xfd.cpp.

◆ configure_clock_()

bool esphome::mcp251xfd::MCP251XFD::configure_clock_ ( )
protected

Definition at line 121 of file mcp251xfd.cpp.

◆ dump_config()

void esphome::mcp251xfd::MCP251XFD::dump_config ( )
overridevirtual

Reimplemented from esphome::canbus::Canbus.

Definition at line 91 of file mcp251xfd.cpp.

◆ get_events()

canbus::CanEventFlags esphome::mcp251xfd::MCP251XFD::get_events ( )
overrideprotectedvirtual

Reimplemented from esphome::canbus::Canbus.

Definition at line 400 of file mcp251xfd.cpp.

◆ get_status()

canbus::CanStatus esphome::mcp251xfd::MCP251XFD::get_status ( )
overridevirtual

Reimplemented from esphome::canbus::Canbus.

Definition at line 388 of file mcp251xfd.cpp.

◆ message_size_()

uint32_t esphome::mcp251xfd::MCP251XFD::message_size_ ( ) const
inlineprotected

Definition at line 75 of file mcp251xfd.h.

◆ read_message()

canbus::Error esphome::mcp251xfd::MCP251XFD::read_message ( canbus::CanFrame * frame)
overrideprotectedvirtual

Implements esphome::canbus::Canbus.

Definition at line 327 of file mcp251xfd.cpp.

◆ read_register_()

bool esphome::mcp251xfd::MCP251XFD::read_register_ ( uint16_t address,
uint32_t & value )
protected

Definition at line 191 of file mcp251xfd.cpp.

◆ read_registers_()

bool esphome::mcp251xfd::MCP251XFD::read_registers_ ( uint16_t address,
uint8_t * data,
size_t length )
protected

Definition at line 151 of file mcp251xfd.cpp.

◆ recover_mode_if_needed_()

bool esphome::mcp251xfd::MCP251XFD::recover_mode_if_needed_ ( bool bus_off,
bool retry_due )
protected

Definition at line 206 of file mcp251xfd.cpp.

◆ reset_()

bool esphome::mcp251xfd::MCP251XFD::reset_ ( )
protected

Definition at line 106 of file mcp251xfd.cpp.

◆ rx_fifo_depth_()

uint32_t esphome::mcp251xfd::MCP251XFD::rx_fifo_depth_ ( ) const
inlineprotected

Definition at line 76 of file mcp251xfd.h.

◆ send_message()

canbus::Error esphome::mcp251xfd::MCP251XFD::send_message ( canbus::CanFrame * frame)
overrideprotectedvirtual

Implements esphome::canbus::Canbus.

Definition at line 289 of file mcp251xfd.cpp.

◆ set_comm_fault_()

bool esphome::mcp251xfd::MCP251XFD::set_comm_fault_ ( const LogString * reason)
protected

Definition at line 185 of file mcp251xfd.cpp.

◆ set_interrupt_pin()

void esphome::mcp251xfd::MCP251XFD::set_interrupt_pin ( InternalGPIOPin * pin)
inline

Definition at line 24 of file mcp251xfd.h.

◆ set_mode_()

bool esphome::mcp251xfd::MCP251XFD::set_mode_ ( CanMode mode,
uint16_t timeout_ms = 100 )
protected

Definition at line 144 of file mcp251xfd.cpp.

◆ setup_internal()

bool esphome::mcp251xfd::MCP251XFD::setup_internal ( )
overrideprotectedvirtual

Implements esphome::canbus::Canbus.

Definition at line 22 of file mcp251xfd.cpp.

◆ should_log_fault_()

bool esphome::mcp251xfd::MCP251XFD::should_log_fault_ ( uint32_t now)
protected

Definition at line 199 of file mcp251xfd.cpp.

◆ validate_fifo_address_()

bool esphome::mcp251xfd::MCP251XFD::validate_fifo_address_ ( uint32_t offset,
uint32_t start,
uint32_t depth,
uint16_t & address )
protected

Definition at line 280 of file mcp251xfd.cpp.

◆ wait_for_register_()

bool esphome::mcp251xfd::MCP251XFD::wait_for_register_ ( uint16_t address,
uint8_t mask,
uint8_t expected,
uint16_t timeout_ms = 100 )
protected

Definition at line 131 of file mcp251xfd.cpp.

◆ write_byte_()

void esphome::mcp251xfd::MCP251XFD::write_byte_ ( uint16_t address,
uint8_t value )
protected

Definition at line 278 of file mcp251xfd.cpp.

◆ write_register_()

void esphome::mcp251xfd::MCP251XFD::write_register_ ( uint16_t address,
uint32_t value )
protected

Definition at line 272 of file mcp251xfd.cpp.

◆ write_registers_()

void esphome::mcp251xfd::MCP251XFD::write_registers_ ( uint16_t address,
const uint8_t * data,
size_t length )
protected

Definition at line 266 of file mcp251xfd.cpp.

◆ write_transfer_()

void esphome::mcp251xfd::MCP251XFD::write_transfer_ ( uint16_t address,
uint8_t * transfer,
size_t length )
protected

Definition at line 258 of file mcp251xfd.cpp.

Field Documentation

◆ bus_error_count_

uint32_t esphome::mcp251xfd::MCP251XFD::bus_error_count_ {0}
protected

Definition at line 38 of file mcp251xfd.h.

◆ comm_fault_active_

bool esphome::mcp251xfd::MCP251XFD::comm_fault_active_ {false}
protected

Definition at line 42 of file mcp251xfd.h.

◆ data_bit_timing_

uint32_t esphome::mcp251xfd::MCP251XFD::data_bit_timing_
protected

Definition at line 30 of file mcp251xfd.h.

◆ interrupt_pin_

InternalGPIOPin* esphome::mcp251xfd::MCP251XFD::interrupt_pin_ {nullptr}
protected

Definition at line 28 of file mcp251xfd.h.

◆ last_error_flags_

uint8_t esphome::mcp251xfd::MCP251XFD::last_error_flags_ {0}
protected

Definition at line 41 of file mcp251xfd.h.

◆ last_fault_log_time_

uint32_t esphome::mcp251xfd::MCP251XFD::last_fault_log_time_ {0u - FAULT_LOG_INTERVAL_MS}
protected

Definition at line 34 of file mcp251xfd.h.

◆ last_mode_check_time_

uint32_t esphome::mcp251xfd::MCP251XFD::last_mode_check_time_ {0u - MODE_RECOVERY_INTERVAL_MS}
protected

Definition at line 35 of file mcp251xfd.h.

◆ last_trec_

uint32_t esphome::mcp251xfd::MCP251XFD::last_trec_ {0}
protected

Definition at line 32 of file mcp251xfd.h.

◆ mcp_clock_

CanClock esphome::mcp251xfd::MCP251XFD::mcp_clock_
protected

Definition at line 39 of file mcp251xfd.h.

◆ mcp_mode_

CanMode esphome::mcp251xfd::MCP251XFD::mcp_mode_
protected

Definition at line 40 of file mcp251xfd.h.

◆ mode_fault_active_

bool esphome::mcp251xfd::MCP251XFD::mode_fault_active_ {false}
protected

Definition at line 43 of file mcp251xfd.h.

◆ nominal_bit_timing_

uint32_t esphome::mcp251xfd::MCP251XFD::nominal_bit_timing_
protected

Definition at line 29 of file mcp251xfd.h.

◆ rx_overrun_count_

uint32_t esphome::mcp251xfd::MCP251XFD::rx_overrun_count_ {0}
protected

Definition at line 37 of file mcp251xfd.h.

◆ transmitter_delay_compensation_

uint32_t esphome::mcp251xfd::MCP251XFD::transmitter_delay_compensation_
protected

Definition at line 31 of file mcp251xfd.h.


The documentation for this class was generated from the following files: