libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
stm32_spi.hpp
1#pragma once
2
3#include <cstring>
4
5#include "main.h"
6
7#ifdef HAL_SPI_MODULE_ENABLED
8
9#ifdef SPI
10#undef SPI
11#endif
12
13#include "libxr_def.hpp"
14#include "libxr_rw.hpp"
15#include "spi.hpp"
16
17typedef enum
18{
19#ifdef SPI1
20 STM32_SPI1,
21#endif
22#ifdef SPI2
23 STM32_SPI2,
24#endif
25#ifdef SPI3
26 STM32_SPI3,
27#endif
28#ifdef SPI4
29 STM32_SPI4,
30#endif
31#ifdef SPI5
32 STM32_SPI5,
33#endif
34#ifdef SPI6
35 STM32_SPI6,
36#endif
37#ifdef SPI7
38 STM32_SPI7,
39#endif
40#ifdef SPI8
41 STM32_SPI8,
42#endif
43 STM32_SPI_NUMBER,
44 STM32_SPI_ID_ERROR
45} stm32_spi_id_t;
46
47stm32_spi_id_t STM32_SPI_GetID(SPI_TypeDef *addr); // NOLINT
48
49namespace LibXR
50{
51class STM32SPI : public SPI
52{
53 public:
54 STM32SPI(SPI_HandleTypeDef *spi_handle, RawData dma_buff_rx, RawData dma_buff_tx,
55 uint32_t dma_enable_min_size = 3);
56
57 ErrorCode ReadAndWrite(RawData read_data, ConstRawData write_data,
58 OperationRW &op) override;
59
60 ErrorCode SetConfig(SPI::Configuration config) override;
61
62 ErrorCode MemRead(uint16_t reg, RawData read_data, OperationRW &op) override;
63
64 ErrorCode MemWrite(uint16_t reg, ConstRawData write_data, OperationRW &op) override;
65
66 uint32_t GetMaxBusSpeed() const override;
67
68 Prescaler GetMaxPrescaler() const override;
69
70 ErrorCode Transfer(size_t size, OperationRW &op) override;
71
72 SPI_HandleTypeDef *spi_handle_;
73
74 stm32_spi_id_t id_ = STM32_SPI_ID_ERROR;
75
76 uint32_t dma_enable_min_size_ = 3;
77
78 OperationRW rw_op_;
79
80 RawData read_buff_;
81
82 bool mem_read_ = false;
83
84 static STM32SPI *map[STM32_SPI_NUMBER]; // NOLINT
85};
86
87} // namespace LibXR
88
89#endif
常量原始数据封装类。 A class for encapsulating constant raw data.
原始数据封装类。 A class for encapsulating raw data.
串行外设接口(SPI)抽象类。Abstract class for Serial Peripheral Interface (SPI).
Definition spi.hpp:14
ErrorCode ReadAndWrite(RawData read_data, ConstRawData write_data, OperationRW &op) override
进行 SPI 读写操作。Performs SPI read and write operations.
Definition stm32_spi.cpp:83
ErrorCode MemRead(uint16_t reg, RawData read_data, OperationRW &op) override
从 SPI 设备的寄存器读取数据。 Reads data from a specific register of the SPI device.
ErrorCode MemWrite(uint16_t reg, ConstRawData write_data, OperationRW &op) override
向 SPI 设备的寄存器写入数据。 Writes data to a specific register of the SPI device.
uint32_t GetMaxBusSpeed() const override
获取 SPI 设备的最大时钟速度。Gets the maximum clock speed of the SPI device.
ErrorCode Transfer(size_t size, OperationRW &op) override
进行一次SPI传输(使用当前缓冲区数据,零拷贝,支持双缓冲)。 Performs a SPI transfer (zero-copy, supports double buffering).
ErrorCode SetConfig(SPI::Configuration config) override
设置 SPI 配置参数。Sets SPI configuration parameters.
Prescaler GetMaxPrescaler() const override
获取 SPI 设备的最大分频系数。Gets the maximum prescaler of the SPI device.
LibXR 命名空间
存储 SPI 配置参数的结构体。Structure for storing SPI configuration parameters.
Definition spi.hpp:85