libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
ch32_usb_endpoint.hpp
1#pragma once
2
3#include "ch32_usb.hpp"
4#include "libxr_def.hpp"
5#include "libxr_type.hpp"
6#include "usb/core/ep.hpp"
7
8namespace LibXR
9{
10
11#if defined(USBFSD)
12
16class CH32EndpointOtgFs : public USB::Endpoint
17{
18 public:
19 CH32EndpointOtgFs(EPNumber ep_num, Direction dir, LibXR::RawData buffer,
20 bool single_direction);
21
22 void Configure(const Config& cfg) override;
23 void Close() override;
24 ErrorCode Transfer(size_t size) override;
25
26 void TransferComplete(size_t size);
27 ErrorCode Stall() override;
28 ErrorCode ClearStall() override;
29
30 void SwitchBuffer() override;
31
32 bool tog_ = false;
33 bool is_isochronous_ = false;
34 bool single_direction_ = false;
35
36 size_t last_transfer_size_ = 0;
37 RawData dma_buffer_;
38
39 static constexpr uint8_t EP_OTG_FS_MAX_SIZE = 8;
40 static inline CH32EndpointOtgFs* map_otg_fs_[EP_OTG_FS_MAX_SIZE][2] = {};
41};
42
43#endif // defined(USBFSD)
44
45#if defined(RCC_APB1Periph_USB)
46
50class CH32EndpointDevFs : public USB::Endpoint
51{
52 public:
53 CH32EndpointDevFs(EPNumber ep_num, Direction dir, LibXR::RawData buffer,
54 bool is_isochronous);
55
56 void Configure(const Config& cfg) override;
57 void Close() override;
58 ErrorCode Transfer(size_t size) override;
59
60 void TransferComplete(size_t size);
61
62 void CopyRxDataToBuffer(size_t size);
63
64 ErrorCode Stall() override;
65 ErrorCode ClearStall() override;
66
67 void SwitchBuffer() override;
68
69 static void ResetPMAAllocator();
70 static void SetEpTxStatus(uint8_t ep, uint16_t status);
71 static void SetEpRxStatus(uint8_t ep, uint16_t status);
72 static void ClearEpCtrTx(uint8_t ep);
73 static void ClearEpCtrRx(uint8_t ep);
74 static uint16_t GetRxCount(uint8_t ep);
75
76 bool is_isochronous_ = false;
77
78 size_t last_transfer_size_ = 0;
79
80 uint16_t pma_addr_ = 0;
81
82 static constexpr uint8_t EP_DEV_FS_MAX_SIZE = 8;
83 static inline CH32EndpointDevFs* map_dev_fs_[EP_DEV_FS_MAX_SIZE][2] = {};
84};
85
86#endif // defined(RCC_APB1Periph_USB)
87
88#if defined(USBHSD)
89
93class CH32EndpointOtgHs : public USB::Endpoint
94{
95 public:
96 CH32EndpointOtgHs(EPNumber ep_num, Direction dir, LibXR::RawData buffer,
97 bool double_buffer);
98
99 void Configure(const Config& cfg) override;
100 void Close() override;
101 ErrorCode Transfer(size_t size) override;
102
103 void TransferComplete(size_t size);
104 ErrorCode Stall() override;
105 ErrorCode ClearStall() override;
106
107 void SwitchBuffer() override;
108
109 uint8_t dev_id_;
110 bool tog0_ = false;
111 bool tog1_ = false;
112 bool hw_double_buffer_ = false;
113
114 size_t last_transfer_size_ = 0;
115 RawData dma_buffer_;
116
117 static constexpr uint8_t EP_OTG_HS_MAX_SIZE = 16;
118 static inline CH32EndpointOtgHs* map_otg_hs_[EP_OTG_HS_MAX_SIZE][2] = {};
119};
120
121#endif // defined(USBHSD)
122
123} // namespace LibXR
原始数据封装类。 A class for encapsulating raw data.
LibXR 命名空间
Definition ch32_can.hpp:14
ErrorCode
定义错误码枚举