|
libxr
1.0
Want to be the best embedded framework
|
Public Member Functions | |
| ESP32SPI (spi_host_device_t host, int sclk_pin, int miso_pin, int mosi_pin, RawData dma_rx, RawData dma_tx, SPI::Configuration config={ SPI::ClockPolarity::LOW, SPI::ClockPhase::EDGE_1, SPI::Prescaler::DIV_8, false, }, uint32_t dma_enable_min_size=3U, bool enable_dma=true) | |
| ErrorCode | ReadAndWrite (RawData read_data, ConstRawData write_data, OperationRW &op, bool in_isr=false) override |
| 进行 SPI 读写操作。Performs SPI read and write operations. | |
| ErrorCode | SetConfig (SPI::Configuration config) override |
| 设置 SPI 配置参数。Sets SPI configuration parameters. | |
| ErrorCode | MemRead (uint16_t reg, RawData read_data, OperationRW &op, bool in_isr=false) override |
| 从 SPI 设备的寄存器读取数据。 Reads data from a specific register of the SPI device. | |
| ErrorCode | MemWrite (uint16_t reg, ConstRawData write_data, OperationRW &op, bool in_isr=false) override |
| 向 SPI 设备的寄存器写入数据。 Writes data to a specific register of the SPI device. | |
| ErrorCode | Transfer (size_t size, OperationRW &op, bool in_isr=false) override |
| 进行一次SPI传输(使用当前缓冲区数据,零拷贝,支持双缓冲)。 Performs a SPI transfer (zero-copy, supports double buffering). | |
| uint32_t | GetMaxBusSpeed () const override |
| 获取 SPI 设备的最大时钟速度。Gets the maximum clock speed of the SPI device. | |
| Prescaler | GetMaxPrescaler () const override |
| 获取 SPI 设备的最大分频系数。Gets the maximum prescaler of the SPI device. | |
| RawData | GetRxBuffer () |
| RawData | GetTxBuffer () |
Public Member Functions inherited from LibXR::SPI | |
| SPI (RawData rx_buffer, RawData tx_buffer) | |
| 构造函数。Constructor. | |
| virtual ErrorCode | Read (RawData read_data, OperationRW &op, bool in_isr=false) |
| 进行 SPI 读取操作。Performs SPI read operation. | |
| virtual ErrorCode | Write (ConstRawData write_data, OperationRW &op, bool in_isr=false) |
| 进行 SPI 写入操作。Performs SPI write operation. | |
| uint32_t | GetBusSpeed () const |
| 获取 SPI 设备的当前总线速度。Gets the current bus speed of the SPI device. | |
| Prescaler | CalcPrescaler (uint32_t target_max_bus_speed, uint32_t target_min_bus_speed, bool increase) |
| 计算 SPI 分频系数。Calculates the SPI prescaler. | |
| RawData | GetRxBuffer () |
| 获取接收数据的缓冲区。Gets the buffer for storing received data. | |
| RawData | GetTxBuffer () |
| 获取发送数据的缓冲区。Gets the buffer for storing data to be sent. | |
| void | SwitchBuffer () |
| 切换缓冲区。Switches the buffer. | |
| void | SetActiveLength (size_t len) |
| 设置缓冲区的有效数据长度。Sets the length of valid data in the buffer. | |
| size_t | GetActiveLength () const |
| 获取缓冲区的有效数据长度。Gets the length of valid data in the buffer. | |
| Configuration & | GetConfig () |
| 获取 SPI 配置参数。Gets the SPI configuration parameters. | |
| bool | IsDoubleBuffer () const |
| 检查是否使用双缓冲区。Checks if double buffering is enabled. | |
Private Member Functions | |
| bool | Acquire () |
| void | Release () |
| ErrorCode | InitializeHardware () |
| ErrorCode | ConfigurePins () |
| ErrorCode | ResolveClockSource (uint32_t &source_hz) |
| ErrorCode | InstallInterrupt () |
| ErrorCode | InitDmaBackend () |
| void | HandleInterrupt () |
| void | FinishAsync (bool in_isr, ErrorCode ec) |
| bool | CanUseDma (size_t size) const |
| ErrorCode | EnsureReadyAndAcquire () |
| ErrorCode | ReturnAsyncStartResult (ErrorCode ec, bool started) |
| ErrorCode | StartAsyncTransfer (const uint8_t *tx, uint8_t *rx, size_t size, bool enable_rx, RawData read_back, bool mem_read, OperationRW &op, bool &started) |
| void | ConfigureTransferRegisters (size_t size) |
| ErrorCode | ExecuteChunk (const uint8_t *tx, uint8_t *rx, size_t size, bool enable_rx) |
| ErrorCode | ExecuteTransfer (const uint8_t *tx, uint8_t *rx, size_t size, bool enable_rx) |
| bool | UseLocalDoubleBuffer () const |
| void | SwitchBufferLocal () |
Static Private Member Functions | |
| static void | SpiIsrEntry (void *arg) |
| static ErrorCode | FinalizeSyncResult (OperationRW &op, bool in_isr, ErrorCode ec) |
| static ErrorCode | CompleteZeroSize (OperationRW &op, bool in_isr) |
Private Attributes | |
| spi_host_device_t | host_ |
| spi_dev_t * | hw_ = nullptr |
| int | sclk_pin_ |
| int | miso_pin_ |
| int | mosi_pin_ |
| uint32_t | source_clock_hz_ = 0 |
| std::atomic< bool > | busy_ {false} |
| bool | initialized_ = false |
| uint32_t | dma_enable_min_size_ = 3U |
| bool | dma_requested_ = true |
| RawData | dma_rx_raw_ = {nullptr, 0} |
| RawData | dma_tx_raw_ = {nullptr, 0} |
| size_t | dbuf_rx_block_size_ = 0 |
| size_t | dbuf_tx_block_size_ = 0 |
| uint8_t | dbuf_active_block_ = 0 |
| bool | dbuf_enabled_ = false |
| intr_handle_t | intr_handle_ = nullptr |
| bool | intr_installed_ = false |
| bool | dma_enabled_ = false |
| void * | dma_ctx_ = nullptr |
| size_t | dma_max_transfer_bytes_ = 0 |
| bool | async_running_ = false |
| size_t | async_dma_size_ = 0 |
| bool | async_dma_rx_enabled_ = false |
| bool | mem_read_ = false |
| RawData | read_back_ = {nullptr, 0} |
| OperationRW | rw_op_ |
Static Private Attributes | |
| static constexpr size_t | kMaxPollingTransferBytes = SOC_SPI_MAXIMUM_BUFFER_SIZE |
| static constexpr size_t | kMaxDmaTransferBytes = SPI_LL_DMA_MAX_BIT_LEN / 8U |
Additional Inherited Members | |
Public Types inherited from LibXR::SPI | |
| enum class | ClockPolarity : uint8_t { LOW = 0 , HIGH = 1 } |
| 定义 SPI 时钟极性。Defines the SPI clock polarity. More... | |
| enum class | ClockPhase : uint8_t { EDGE_1 = 0 , EDGE_2 = 1 } |
| 定义 SPI 时钟相位。Defines the SPI clock phase. More... | |
| enum class | Prescaler : uint8_t { DIV_1 = 0 , DIV_2 = 1 , DIV_4 = 2 , DIV_8 = 3 , DIV_16 = 4 , DIV_32 = 5 , DIV_64 = 6 , DIV_128 = 7 , DIV_256 = 8 , DIV_512 = 9 , DIV_1024 = 10 , DIV_2048 = 11 , DIV_4096 = 12 , DIV_8192 = 13 , DIV_16384 = 14 , DIV_32768 = 15 , DIV_65536 = 16 , UNKNOWN = 0xFF } |
| using | OperationRW = WriteOperation |
| 定义读写操作类型的别名。Defines an alias for the read/write operation type. | |
Static Public Member Functions inherited from LibXR::SPI | |
| static constexpr uint32_t | PrescalerToDiv (Prescaler prescaler) |
| 将分频系数转换为除数。Converts a prescaler to a divisor. | |
Definition at line 19 of file esp_spi.hpp.
| LibXR::ESP32SPI::ESP32SPI | ( | spi_host_device_t | host, |
| int | sclk_pin, | ||
| int | miso_pin, | ||
| int | mosi_pin, | ||
| RawData | dma_rx, | ||
| RawData | dma_tx, | ||
| SPI::Configuration | config = { SPI::ClockPolarity::LOW, SPI::ClockPhase::EDGE_1, SPI::Prescaler::DIV_8, false, }, | ||
| uint32_t | dma_enable_min_size = 3U, | ||
| bool | enable_dma = true ) |
Definition at line 113 of file esp_spi.cpp.
|
private |
Definition at line 171 of file esp_spi.cpp.
|
private |
Definition at line 538 of file esp_spi.cpp.
|
staticprivate |
Definition at line 566 of file esp_spi.cpp.
|
private |
Definition at line 241 of file esp_spi.cpp.
|
private |
Definition at line 580 of file esp_spi.cpp.
|
private |
Definition at line 544 of file esp_spi.cpp.
|
private |
Definition at line 692 of file esp_spi.cpp.
|
private |
Definition at line 729 of file esp_spi.cpp.
|
staticprivate |
Definition at line 557 of file esp_spi.cpp.
|
private |
Definition at line 385 of file esp_spi.cpp.
|
overridevirtual |
获取 SPI 设备的最大时钟速度。Gets the maximum clock speed of the SPI device.
Implements LibXR::SPI.
Definition at line 927 of file esp_spi.cpp.
|
overridevirtual |
获取 SPI 设备的最大分频系数。Gets the maximum prescaler of the SPI device.
Implements LibXR::SPI.
Definition at line 929 of file esp_spi.cpp.
| RawData LibXR::ESP32SPI::GetRxBuffer | ( | ) |
Definition at line 508 of file esp_spi.cpp.
| RawData LibXR::ESP32SPI::GetTxBuffer | ( | ) |
Definition at line 519 of file esp_spi.cpp.
|
private |
Definition at line 364 of file esp_spi.cpp.
|
private |
Definition at line 319 of file esp_spi.cpp.
|
private |
Definition at line 180 of file esp_spi.cpp.
|
private |
Definition at line 300 of file esp_spi.cpp.
|
overridevirtual |
从 SPI 设备的寄存器读取数据。 Reads data from a specific register of the SPI device.
| reg | 寄存器地址。Register address. |
| read_data | 读取的数据缓冲区。Buffer to store read data. |
| op | 操作类型(同步/异步)。Operation mode (sync/async). |
| in_isr | 是否在中断中进行操作。Whether the operation is performed in an ISR. |
Implements LibXR::SPI.
Definition at line 804 of file esp_spi.cpp.
|
overridevirtual |
向 SPI 设备的寄存器写入数据。 Writes data to a specific register of the SPI device.
| reg | 寄存器地址。Register address. |
| write_data | 写入的数据缓冲区。Buffer containing data to write. |
| op | 操作类型(同步/异步)。Operation mode (sync/async). |
| in_isr | 是否在中断中进行操作。Whether the operation is performed in an ISR. |
Implements LibXR::SPI.
Definition at line 849 of file esp_spi.cpp.
|
overridevirtual |
进行 SPI 读写操作。Performs SPI read and write operations.
| read_data | 存储读取数据的缓冲区。Buffer to store the read data. |
| write_data | 需要写入的数据缓冲区。Buffer containing the data to be written. |
| op | 读写操作类型。Type of read/write operation. |
| in_isr | 是否在中断中进行操作。Whether the operation is performed in an ISR. |
Implements LibXR::SPI.
Definition at line 751 of file esp_spi.cpp.
|
private |
Definition at line 178 of file esp_spi.cpp.
|
private |
Definition at line 287 of file esp_spi.cpp.
|
private |
Definition at line 571 of file esp_spi.cpp.
|
overridevirtual |
设置 SPI 配置参数。Sets SPI configuration parameters.
Implements LibXR::SPI.
Definition at line 452 of file esp_spi.cpp.
|
staticprivate |
Definition at line 355 of file esp_spi.cpp.
|
private |
Definition at line 600 of file esp_spi.cpp.
|
private |
Definition at line 530 of file esp_spi.cpp.
|
overridevirtual |
进行一次SPI传输(使用当前缓冲区数据,零拷贝,支持双缓冲)。 Performs a SPI transfer (zero-copy, supports double buffering).
| size | 需要传输的数据大小。The size of the data to be transferred. |
| op | 读写操作类型。Type of read/write operation. |
| in_isr | 是否在中断中进行操作。Whether the operation is performed in an ISR. |
Implements LibXR::SPI.
Definition at line 889 of file esp_spi.cpp.
|
private |
Definition at line 503 of file esp_spi.cpp.
|
private |
Definition at line 129 of file esp_spi.hpp.
|
private |
Definition at line 128 of file esp_spi.hpp.
|
private |
Definition at line 127 of file esp_spi.hpp.
|
private |
Definition at line 112 of file esp_spi.hpp.
|
private |
Definition at line 120 of file esp_spi.hpp.
|
private |
Definition at line 121 of file esp_spi.hpp.
|
private |
Definition at line 118 of file esp_spi.hpp.
|
private |
Definition at line 119 of file esp_spi.hpp.
|
private |
Definition at line 125 of file esp_spi.hpp.
|
private |
Definition at line 114 of file esp_spi.hpp.
|
private |
Definition at line 124 of file esp_spi.hpp.
|
private |
Definition at line 126 of file esp_spi.hpp.
|
private |
Definition at line 115 of file esp_spi.hpp.
|
private |
Definition at line 116 of file esp_spi.hpp.
|
private |
Definition at line 117 of file esp_spi.hpp.
|
private |
Definition at line 106 of file esp_spi.hpp.
|
private |
Definition at line 107 of file esp_spi.hpp.
|
private |
Definition at line 113 of file esp_spi.hpp.
|
private |
Definition at line 122 of file esp_spi.hpp.
|
private |
Definition at line 123 of file esp_spi.hpp.
|
staticconstexprprivate |
Definition at line 57 of file esp_spi.hpp.
|
staticconstexprprivate |
Definition at line 56 of file esp_spi.hpp.
|
private |
Definition at line 130 of file esp_spi.hpp.
|
private |
Definition at line 109 of file esp_spi.hpp.
|
private |
Definition at line 110 of file esp_spi.hpp.
|
private |
Definition at line 131 of file esp_spi.hpp.
|
private |
Definition at line 132 of file esp_spi.hpp.
|
private |
Definition at line 108 of file esp_spi.hpp.
|
private |
Definition at line 111 of file esp_spi.hpp.