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 is_isochronous);
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
35 size_t last_transfer_size_ = 0;
36 RawData dma_buffer_;
37
38 static constexpr uint8_t EP_OTG_FS_MAX_SIZE = 8;
39 static inline CH32EndpointOtgFs* map_otg_fs_[EP_OTG_FS_MAX_SIZE][2] = {};
40};
41
42#endif // defined(USBFSD)
43
44#if defined(RCC_APB1Periph_USB)
45
49class CH32EndpointDevFs : public USB::Endpoint
50{
51 public:
52 CH32EndpointDevFs(EPNumber ep_num, Direction dir, LibXR::RawData buffer,
53 bool is_isochronous);
54
55 void Configure(const Config& cfg) override;
56 void Close() override;
57 ErrorCode Transfer(size_t size) override;
58
59 void TransferComplete(size_t size);
60
61 void CopyRxDataToBuffer(size_t size);
62
63 ErrorCode Stall() override;
64 ErrorCode ClearStall() override;
65
66 void SwitchBuffer() override;
67
68 static void ResetPMAAllocator();
69 static void SetEpTxStatus(uint8_t ep, uint16_t status);
70 static void SetEpRxStatus(uint8_t ep, uint16_t status);
71 static void ClearEpCtrTx(uint8_t ep);
72 static void ClearEpCtrRx(uint8_t ep);
73 static uint16_t GetRxCount(uint8_t ep);
74
75 bool is_isochronous_ = false;
76
77 size_t last_transfer_size_ = 0;
78
79 uint16_t pma_addr_ = 0;
80
81 static constexpr uint8_t EP_DEV_FS_MAX_SIZE = 8;
82 static inline CH32EndpointDevFs* map_dev_fs_[EP_DEV_FS_MAX_SIZE][2] = {};
83};
84
85#endif // defined(RCC_APB1Periph_USB)
86
87#if defined(USBHSD)
88
92class CH32EndpointOtgHs : public USB::Endpoint
93{
94 public:
95 CH32EndpointOtgHs(EPNumber ep_num, Direction dir, LibXR::RawData buffer,
96 bool double_buffer);
97
98 void Configure(const Config& cfg) override;
99 void Close() override;
100 ErrorCode Transfer(size_t size) override;
101
102 void TransferComplete(size_t size);
103 ErrorCode Stall() override;
104 ErrorCode ClearStall() override;
105
106 void SwitchBuffer() override;
107
108 uint8_t dev_id_;
109 bool tog0_ = false;
110 bool tog1_ = false;
111 bool hw_double_buffer_ = false;
112
113 size_t last_transfer_size_ = 0;
114 RawData dma_buffer_;
115
116 static constexpr uint8_t EP_OTG_HS_MAX_SIZE = 16;
117 static inline CH32EndpointOtgHs* map_otg_hs_[EP_OTG_HS_MAX_SIZE][2] = {};
118};
119
120#endif // defined(USBHSD)
121
122} // namespace LibXR
原始数据封装类。 A class for encapsulating raw data.
LibXR 命名空间
Definition ch32_can.hpp:14