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 RawData dma_buff_rx_, dma_buff_tx_;
67
68 SPI_HandleTypeDef *spi_handle_;
69
70 stm32_spi_id_t id_ = STM32_SPI_ID_ERROR;
71
72 uint32_t dma_enable_min_size_ = 3;
73
74 OperationRW rw_op_;
75
76 RawData read_buff_;
77
78 bool mem_read_ = false;
79
80 static STM32SPI *map[STM32_SPI_NUMBER]; // NOLINT
81};
82
83} // namespace LibXR
84
85#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:13
ErrorCode ReadAndWrite(RawData read_data, ConstRawData write_data, OperationRW &op) override
进行 SPI 读写操作。Performs SPI read and write operations.
Definition stm32_spi.cpp:85
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.
ErrorCode SetConfig(SPI::Configuration config) override
设置 SPI 配置参数。Sets SPI configuration parameters.
LibXR 命名空间
Definition ch32_gpio.hpp:9
存储 SPI 配置参数的结构体。Structure for storing SPI configuration parameters.
Definition spi.hpp:46