|
libxr
1.0
Want to be the best embedded framework
|
串行外设接口(SPI)抽象类。Abstract class for Serial Peripheral Interface (SPI). More...
#include <spi.hpp>
Data Structures | |
| struct | Configuration |
| 存储 SPI 配置参数的结构体。Structure for storing SPI configuration parameters. More... | |
| struct | ReadWriteInfo |
| 存储 SPI 读写操作信息的结构体。Structure for storing SPI read/write operation information. More... | |
Public Types | |
| 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. | |
Public Member Functions | |
| SPI (RawData rx_buffer, RawData tx_buffer) | |
| 构造函数。Constructor. | |
| virtual ErrorCode | ReadAndWrite (RawData read_data, ConstRawData write_data, OperationRW &op)=0 |
| 进行 SPI 读写操作。Performs SPI read and write operations. | |
| virtual ErrorCode | Read (RawData read_data, OperationRW &op) |
| 进行 SPI 读取操作。Performs SPI read operation. | |
| virtual ErrorCode | Write (ConstRawData write_data, OperationRW &op) |
| 进行 SPI 写入操作。Performs SPI write operation. | |
| virtual ErrorCode | SetConfig (Configuration config)=0 |
| 设置 SPI 配置参数。Sets SPI configuration parameters. | |
| virtual uint32_t | GetMaxBusSpeed () const =0 |
| 获取 SPI 设备的最大时钟速度。Gets the maximum clock speed of the SPI device. | |
| virtual Prescaler | GetMaxPrescaler () const =0 |
| 获取 SPI 设备的最大分频系数。Gets the maximum prescaler of the SPI device. | |
| 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. | |
| virtual ErrorCode | Transfer (size_t size, OperationRW &op)=0 |
| 进行一次SPI传输(使用当前缓冲区数据,零拷贝,支持双缓冲)。 Performs a SPI transfer (zero-copy, supports double buffering). | |
| virtual ErrorCode | MemWrite (uint16_t reg, ConstRawData write_data, OperationRW &op)=0 |
| 向 SPI 设备的寄存器写入数据。 Writes data to a specific register of the SPI device. | |
| virtual ErrorCode | MemRead (uint16_t reg, RawData read_data, OperationRW &op)=0 |
| 从 SPI 设备的寄存器读取数据。 Reads data from a specific register of the SPI device. | |
| Configuration & | GetConfig () |
| 获取 SPI 配置参数。Gets the SPI configuration parameters. | |
| bool | IsDoubleBuffer () const |
| 检查是否使用双缓冲区。Checks if double buffering is enabled. | |
Static Public Member Functions | |
| static constexpr uint32_t | PrescalerToDiv (Prescaler prescaler) |
| 将分频系数转换为除数。Converts a prescaler to a divisor. | |
Private Attributes | |
| Configuration | config_ |
| RawData | rx_buffer_ |
| RawData | tx_buffer_ |
| DoubleBuffer | double_buffer_rx_ |
| DoubleBuffer | double_buffer_tx_ |
串行外设接口(SPI)抽象类。Abstract class for Serial Peripheral Interface (SPI).
|
strong |
|
strong |
|
strong |
Definition at line 36 of file spi.hpp.
构造函数。Constructor.
| rx_buffer | 存储接收数据的缓冲区。Buffer to store received data. |
| tx_buffer | 存储发送数据的缓冲区。Buffer to store data to be sent. |
Definition at line 110 of file spi.hpp.
|
inline |
计算 SPI 分频系数。Calculates the SPI prescaler.
| target_max_bus_speed | 目标最大总线速度(单位:Hz)。 Target maximum bus speed (in Hz). |
| target_min_bus_speed | 目标最小总线速度(单位:Hz)。 Target minimum bus speed (in Hz). |
| increase | 是否从最小分频系数开始。Whether to start from the minimum prescaler. |
Definition at line 195 of file spi.hpp.
|
inline |
获取缓冲区的有效数据长度。Gets the length of valid data in the buffer.
Definition at line 351 of file spi.hpp.
|
inline |
|
inline |
|
pure virtual |
获取 SPI 设备的最大时钟速度。Gets the maximum clock speed of the SPI device.
Implemented in LibXR::CH32SPI, and LibXR::STM32SPI.
|
pure virtual |
获取 SPI 设备的最大分频系数。Gets the maximum prescaler of the SPI device.
Implemented in LibXR::CH32SPI, and LibXR::STM32SPI.
|
inline |
获取接收数据的缓冲区。Gets the buffer for storing received data.
Definition at line 303 of file spi.hpp.
|
inline |
|
inline |
检查是否使用双缓冲区。Checks if double buffering is enabled.
Definition at line 396 of file spi.hpp.
|
pure virtual |
从 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). |
Implemented in LibXR::CH32SPI, and LibXR::STM32SPI.
|
pure virtual |
向 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). |
Implemented in LibXR::CH32SPI, and LibXR::STM32SPI.
|
inlinestaticconstexpr |
|
inlinevirtual |
进行 SPI 读取操作。Performs SPI read operation.
| read_data | 存储读取数据的缓冲区。Buffer to store the read data. |
| op | 读写操作类型。Type of read/write operation. |
Definition at line 134 of file spi.hpp.
|
pure virtual |
进行 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. |
Implemented in LibXR::CH32SPI, and LibXR::STM32SPI.
|
inline |
设置缓冲区的有效数据长度。Sets the length of valid data in the buffer.
Definition at line 346 of file spi.hpp.
|
pure virtual |
设置 SPI 配置参数。Sets SPI configuration parameters.
Implemented in LibXR::CH32SPI, and LibXR::STM32SPI.
|
inline |
切换缓冲区。Switches the buffer.
Definition at line 334 of file spi.hpp.
|
pure virtual |
进行一次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. |
Implemented in LibXR::CH32SPI, and LibXR::STM32SPI.
|
inlinevirtual |
|
private |
|
private |
|
private |