libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
stm32_usb_ep.hpp
1#pragma once
2
3#include "libxr_def.hpp"
4#include "main.h"
5#include "stm32_usb.hpp"
6#include "stm32_usb_dev.hpp"
7#include "usb/core/ep.hpp"
8
9#if defined(HAL_PCD_MODULE_ENABLED)
10
11namespace LibXR
12{
13
15{
16 public:
17#if defined(USB_OTG_HS) || defined(USB_OTG_FS)
18 STM32Endpoint(EPNumber ep_num, stm32_usb_dev_id_t id, PCD_HandleTypeDef* hpcd,
19 Direction dir, size_t fifo_size, LibXR::RawData buffer);
20#endif
21#if defined(USB_BASE)
22 STM32Endpoint(EPNumber ep_num, stm32_usb_dev_id_t id, PCD_HandleTypeDef* hpcd,
23 Direction dir, size_t hw_buffer_offset, size_t hw_buffer_size,
24 bool double_hw_buffer, LibXR::RawData buffer);
25#endif
26
27 void Configure(const Config& cfg) override;
28 void Close() override;
29 ErrorCode Transfer(size_t size) override;
30
31 ErrorCode Stall() override;
32 ErrorCode ClearStall() override;
33
34 size_t MaxTransferSize() const override;
35
36 PCD_HandleTypeDef* hpcd_;
37#if defined(USB_OTG_FS) || defined(USB_OTG_HS)
38 size_t fifo_size_ = 0;
39#endif
40#if defined(USB_BASE)
41 size_t hw_buffer_size_ = 0;
42 bool double_hw_buffer_ = false;
43#endif
44 stm32_usb_dev_id_t id_;
45
46#if defined(USB_OTG_HS)
47#if defined(USB_OTG_HS_MAX_IN_ENDPOINTS)
48 static constexpr uint8_t EP_OTG_HS_MAX_SIZE =
49 LibXR::max(USB_OTG_HS_MAX_IN_ENDPOINTS, USB_OTG_HS_MAX_OUT_ENDPOINTS);
50#else
51 static constexpr uint8_t EP_OTG_HS_MAX_SIZE = 9;
52#endif
53
54 static inline STM32Endpoint* map_hs_[EP_OTG_HS_MAX_SIZE][2] = {};
55#endif
56
57#if defined(USB_OTG_FS)
58#if defined(USB_OTG_FS_MAX_IN_ENDPOINTS)
59 static constexpr uint8_t EP_OTG_FS_MAX_SIZE =
60 LibXR::max(USB_OTG_FS_MAX_IN_ENDPOINTS, USB_OTG_FS_MAX_OUT_ENDPOINTS);
61#elif defined(STM32H7) || defined(STM32N6)
62 static constexpr uint8_t EP_OTG_FS_MAX_SIZE = 9;
63#else
64 static constexpr uint8_t EP_OTG_FS_MAX_SIZE = 6;
65#endif
66 static inline STM32Endpoint* map_fs_[EP_OTG_FS_MAX_SIZE][2] = {};
67#endif
68
69#if defined(USB_BASE)
70 static constexpr uint8_t EP_OTG_FS_MAX_SIZE = 8;
71 static inline STM32Endpoint* map_otg_fs_[EP_OTG_FS_MAX_SIZE][2] = {};
72#endif
73};
74
75} // namespace LibXR
76
77#endif
原始数据封装类。 A class for encapsulating raw data.
ErrorCode Transfer(size_t size) override
传输数据 Transfer data
ErrorCode ClearStall() override
清除端点停止状态 Clear endpoint stop status
void Configure(const Config &cfg) override
二次初始化/配置端点协议参数(由Pool/Manager分配后调用) Configure endpoint protocol parameters (call after pool allocation...
void Close() override
关闭端点(软禁用/资源复位) Close (soft disable)
ErrorCode Stall() override
停止端点传输 Stop endpoint transfer
size_t MaxTransferSize() const override
返回最大可传输字节数 Return the maximum transferable size at this time
USB端点基类 / USB Endpoint base class.
Definition ep.hpp:22
EPNumber
端点号 / Endpoint number
Definition ep.hpp:39
Direction
端点方向 Endpoint direction
Definition ep.hpp:29
LibXR 命名空间
Definition ch32_gpio.hpp:9
constexpr auto max(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最大值
端点配置结构体 Endpoint configuration struct
Definition ep.hpp:140