libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::SPI Class Referenceabstract

串行外设接口(SPI)抽象类。Abstract class for Serial Peripheral Interface (SPI). More...

#include <spi.hpp>

Inheritance diagram for LibXR::SPI:

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...
 
using OperationRW = WriteOperation
 定义读写操作类型的别名。Defines an alias for the read/write operation type.
 

Public Member Functions

 SPI ()
 默认构造函数。Default 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 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.
 

Detailed Description

串行外设接口(SPI)抽象类。Abstract class for Serial Peripheral Interface (SPI).

Definition at line 12 of file spi.hpp.

Member Typedef Documentation

◆ OperationRW

定义读写操作类型的别名。Defines an alias for the read/write operation type.

Definition at line 39 of file spi.hpp.

Member Enumeration Documentation

◆ ClockPhase

定义 SPI 时钟相位。Defines the SPI clock phase.

Enumerator
EDGE_1 

在第一个时钟边沿采样数据。Data sampled on the first clock edge.

EDGE_2 

在第二个时钟边沿采样数据。Data sampled on the second clock edge.

Definition at line 29 of file spi.hpp.

30 {
31 EDGE_1 = 0,
32 EDGE_2 = 1
33 };
@ EDGE_2
在第二个时钟边沿采样数据。Data sampled on the second clock edge.
@ EDGE_1
在第一个时钟边沿采样数据。Data sampled on the first clock edge.

◆ ClockPolarity

定义 SPI 时钟极性。Defines the SPI clock polarity.

Enumerator
LOW 

时钟空闲时为低电平。Clock idle low.

HIGH 

时钟空闲时为高电平。Clock idle high.

Definition at line 19 of file spi.hpp.

20 {
21 LOW = 0,
22 HIGH = 1
23 };
@ LOW
时钟空闲时为低电平。Clock idle low.
@ HIGH
时钟空闲时为高电平。Clock idle high.

Constructor & Destructor Documentation

◆ SPI()

LibXR::SPI::SPI ( )
inline

默认构造函数。Default constructor.

Definition at line 66 of file spi.hpp.

66{}

Member Function Documentation

◆ MemRead()

virtual ErrorCode LibXR::SPI::MemRead ( uint16_t  reg,
RawData  read_data,
OperationRW op 
)
pure virtual

SPI 设备的寄存器读取数据。 Reads data from a specific register of the SPI device.

Parameters
reg寄存器地址。Register address.
read_data读取的数据缓冲区。Buffer to store read data.
op操作类型(同步/异步)。Operation mode (sync/async).
Returns
操作结果的错误码。Error code indicating success or failure.

Implemented in LibXR::STM32SPI.

◆ MemWrite()

virtual ErrorCode LibXR::SPI::MemWrite ( uint16_t  reg,
ConstRawData  write_data,
OperationRW op 
)
pure virtual

SPI 设备的寄存器写入数据。 Writes data to a specific register of the SPI device.

Parameters
reg寄存器地址。Register address.
write_data写入的数据缓冲区。Buffer containing data to write.
op操作类型(同步/异步)。Operation mode (sync/async).
Returns
操作结果的错误码。Error code indicating success or failure.

Implemented in LibXR::STM32SPI.

◆ Read()

virtual ErrorCode LibXR::SPI::Read ( RawData  read_data,
OperationRW op 
)
inlinevirtual

进行 SPI 读取操作。Performs SPI read operation.

Parameters
read_data存储读取数据的缓冲区。Buffer to store the read data.
op读写操作类型。Type of read/write operation.
Returns
操作结果的错误码。Error code indicating the result of the operation.

Definition at line 84 of file spi.hpp.

85 {
86 return ReadAndWrite(read_data, ConstRawData(nullptr, 0), op);
87 }
virtual ErrorCode ReadAndWrite(RawData read_data, ConstRawData write_data, OperationRW &op)=0
进行 SPI 读写操作。Performs SPI read and write operations.

◆ ReadAndWrite()

virtual ErrorCode LibXR::SPI::ReadAndWrite ( RawData  read_data,
ConstRawData  write_data,
OperationRW op 
)
pure virtual

进行 SPI 读写操作。Performs SPI read and write operations.

Parameters
read_data存储读取数据的缓冲区。Buffer to store the read data.
write_data需要写入的数据缓冲区。Buffer containing the data to be written.
op读写操作类型。Type of read/write operation.
Returns
操作结果的错误码。Error code indicating the result of the operation.

Implemented in LibXR::STM32SPI.

◆ SetConfig()

virtual ErrorCode LibXR::SPI::SetConfig ( Configuration  config)
pure virtual

设置 SPI 配置参数。Sets SPI configuration parameters.

Parameters
config需要应用的 SPI 配置。The SPI configuration to apply.
Returns
操作结果的错误码。Error code indicating the result of the operation.

Implemented in LibXR::STM32SPI.

◆ Write()

virtual ErrorCode LibXR::SPI::Write ( ConstRawData  write_data,
OperationRW op 
)
inlinevirtual

进行 SPI 写入操作。Performs SPI write operation.

Parameters
write_data需要写入的数据缓冲区。Buffer containing the data to be written.
op读写操作类型。Type of read/write operation.
Returns
操作结果的错误码。Error code indicating the result of the operation.

Definition at line 95 of file spi.hpp.

96 {
97 return ReadAndWrite(RawData(nullptr, 0), write_data, op);
98 }

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