5#ifdef HAL_SPI_MODULE_ENABLED
11#include "libxr_def.hpp"
12#include "libxr_rw.hpp"
45stm32_spi_id_t STM32_SPI_GetID(SPI_TypeDef *addr);
58 id_(STM32_SPI_GetID(spi_handle_->Instance)),
61 ASSERT(id_ != STM32_SPI_ID_ERROR);
74 return ErrorCode::BUSY;
84 read_buff_ = read_data;
90 if (op.
type == OperationRW::OperationType::BLOCK)
92 return op.
data.sem_info.sem->
Wait(op.
data.sem_info.timeout);
111 if (op.
type == OperationRW::OperationType::BLOCK)
113 return op.
data.sem_info.sem->
Wait(op.
data.sem_info.timeout);
122 switch (
config.clock_polarity)
132 switch (
config.clock_phase)
151 return ErrorCode::BUSY;
159 if (
need_read + 1 > dma_enable_min_size_)
165 read_buff_ = read_data;
174 if (op.
type == OperationRW::OperationType::BLOCK)
176 return op.
data.sem_info.sem->
Wait(op.
data.sem_info.timeout);
178 return ErrorCode::OK;
196 if (op.
type == OperationRW::OperationType::BLOCK)
198 return op.
data.sem_info.sem->
Wait(op.
data.sem_info.timeout);
211 return ErrorCode::BUSY;
224 read_buff_ = {
nullptr, 0};
231 if (op.
type == OperationRW::OperationType::BLOCK)
233 return op.
data.sem_info.sem->
Wait(op.
data.sem_info.timeout);
235 return ErrorCode::OK;
250 if (op.
type == OperationRW::OperationType::BLOCK)
252 return op.
data.sem_info.sem->
Wait(op.
data.sem_info.timeout);
259 RawData dma_buff_rx_, dma_buff_tx_;
263 stm32_spi_id_t id_ = STM32_SPI_ID_ERROR;
271 bool mem_read_ =
false;
273 static STM32SPI *map[STM32_SPI_NUMBER];
常量原始数据封装类。 A class for encapsulating constant raw data.
size_t size_
数据大小(字节)。 The size of the data (in bytes).
const void * addr_
数据存储地址(常量)。 The storage address of the data (constant).
void UpdateStatus(bool in_isr, Args &&...args)
Updates operation status based on type.
void MarkAsRunning()
标记操作为运行状态。 Marks the operation as running.
union LibXR::Operation::@4 data
原始数据封装类。 A class for encapsulating raw data.
size_t size_
数据大小(字节)。 The size of the data (in bytes).
void * addr_
数据存储地址。 The storage address of the data.
串行外设接口(SPI)抽象类。Abstract class for Serial Peripheral Interface (SPI).
@ EDGE_2
在第二个时钟边沿采样数据。Data sampled on the second clock edge.
@ EDGE_1
在第一个时钟边沿采样数据。Data sampled on the first clock edge.
SPI()
默认构造函数。Default constructor.
WriteOperation OperationRW
定义读写操作类型的别名。Defines an alias for the read/write operation type.
@ LOW
时钟空闲时为低电平。Clock idle low.
@ HIGH
时钟空闲时为高电平。Clock idle high.
ErrorCode MemRead(uint16_t reg, RawData read_data, OperationRW &op) override
从 SPI 设备的寄存器读取数据。 Reads data from a specific register of the SPI device.
ErrorCode ReadAndWrite(RawData read_data, ConstRawData write_data, OperationRW &op) override
进行 SPI 读写操作。Performs SPI read and write operations.
ErrorCode SetConfig(SPI::Configuration config) override
设置 SPI 配置参数。Sets SPI configuration parameters.
ErrorCode MemWrite(uint16_t reg, ConstRawData write_data, OperationRW &op) override
向 SPI 设备的寄存器写入数据。 Writes data to a specific register of the SPI device.
ErrorCode Wait(uint32_t timeout=UINT32_MAX)
等待(减少)信号量 Waits (decrements) the semaphore
LibXR Color Control Library / LibXR终端颜色控制库
constexpr auto max(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最大值
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值
存储 SPI 配置参数的结构体。Structure for storing SPI configuration parameters.