Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openmrn_arduino::Esp32HardwareTwai Class Reference

ESP32 Hardware TWAI (CAN) driver interface. More...

#include <Esp32HardwareTwai.hxx>

Inheritance diagram for openmrn_arduino::Esp32HardwareTwai:
Singleton< Esp32HardwareTwai >

Public Member Functions

 Esp32HardwareTwai (int rx, int tx, bool report=true, size_t rx_buffer_size=config_can_rx_buffer_size(), size_t tx_buffer_size=config_can_tx_buffer_size(), const char *path="/dev/twai", int clock_out=GPIO_NUM_NC, int bus_status=GPIO_NUM_NC, uint32_t isr_preferred_core=DEFAULT_ISR_CORE)
 
 ~Esp32HardwareTwai ()
 Destructor.
 
void hw_init ()
 Initializes the TWAI hardware and VFS adapter.
 
void get_driver_stats (esp32_twai_stats_t *stats)
 Retrieves the current driver statistics.
 

Private Member Functions

 Esp32HardwareTwai ()
 Default constructor.
 
 DISALLOW_COPY_AND_ASSIGN (Esp32HardwareTwai)
 

Private Attributes

const int rxPin_
 GPIO pin connected to the external transceiver RX pin.
 
const int txPin_
 GPIO pin connected to the external transceiver TX pin.
 
const int extClockPin_
 GPIO pin that generates an external clock signal.
 
const int busStatusPin_
 GPIO pin connected to an external bus status indicator.
 
const uint32_t preferredIsrCore_
 Core which the TWAI ISR should be bound to.
 
const char * vfsPath_
 VFS Mount point.
 

Static Private Attributes

static constexpr uint32_t DEFAULT_ISR_CORE = PRO_CPU_NUM
 Default core for running the TWAI ISR.
 

Additional Inherited Members

- Static Public Member Functions inherited from Singleton< Esp32HardwareTwai >
static Esp32HardwareTwai * instance ()
 
static bool exists ()
 

Detailed Description

ESP32 Hardware TWAI (CAN) driver interface.

The ESP32 has a hardware TWAI controller that requires an external CAN transceiver connected via two GPIO pins (RX and TX). SPI connected CAN transceivers are not supported by this interface.

Example of usage (async API):

void setup() {
...
twai.hw_init();
openmrn.begin();
openmrn.add_can_port_async("/dev/twai/twai0");
...
}
ESP32 Hardware TWAI (CAN) driver interface.
void hw_init()
Initializes the TWAI hardware and VFS adapter.

Example of usage (select API):

void setup() {
...
twai.hw_init();
openmrn.begin();
openmrn.add_can_port_select("/dev/twai/twai0");
openmrn.start_executor_thread();
...
}

NOTE: For the select API it is necessary to start the executor thread in the setup() method.

NOTE: The select API is not be usable without CONFIG_VFS_SUPPORT_SELECT being enabled in sdkconfig, this option is disabled automatically when CONFIG_LWIP_USE_ONLY_LWIP_SELECT is enabled. CONFIG_VFS_SUPPORT_SELECT is enabled by default in arduino-esp32.

Definition at line 128 of file Esp32HardwareTwai.hxx.

Member Function Documentation

◆ get_driver_stats()

void openmrn_arduino::Esp32HardwareTwai::get_driver_stats ( esp32_twai_stats_t stats)

Retrieves the current driver statistics.

Parameters
statsesp32_twai_stats_t buffer to be filled with the current statistics.

◆ hw_init()

void openmrn_arduino::Esp32HardwareTwai::hw_init ( )

Initializes the TWAI hardware and VFS adapter.

NOTE: This must be called prior to adding the TWAI driver to the SimpleCanStack.

Member Data Documentation

◆ busStatusPin_

const int openmrn_arduino::Esp32HardwareTwai::busStatusPin_
private

GPIO pin connected to an external bus status indicator.

Definition at line 195 of file Esp32HardwareTwai.hxx.

◆ DEFAULT_ISR_CORE

constexpr uint32_t openmrn_arduino::Esp32HardwareTwai::DEFAULT_ISR_CORE = PRO_CPU_NUM
staticconstexprprivate

Default core for running the TWAI ISR.

Definition at line 205 of file Esp32HardwareTwai.hxx.

◆ extClockPin_

const int openmrn_arduino::Esp32HardwareTwai::extClockPin_
private

GPIO pin that generates an external clock signal.

Definition at line 192 of file Esp32HardwareTwai.hxx.

◆ preferredIsrCore_

const uint32_t openmrn_arduino::Esp32HardwareTwai::preferredIsrCore_
private

Core which the TWAI ISR should be bound to.

Definition at line 198 of file Esp32HardwareTwai.hxx.

◆ rxPin_

const int openmrn_arduino::Esp32HardwareTwai::rxPin_
private

GPIO pin connected to the external transceiver RX pin.

Definition at line 186 of file Esp32HardwareTwai.hxx.

◆ txPin_

const int openmrn_arduino::Esp32HardwareTwai::txPin_
private

GPIO pin connected to the external transceiver TX pin.

Definition at line 189 of file Esp32HardwareTwai.hxx.

◆ vfsPath_

const char* openmrn_arduino::Esp32HardwareTwai::vfsPath_
private

VFS Mount point.

Definition at line 209 of file Esp32HardwareTwai.hxx.


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