libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
stm32_usbx.hpp
1#pragma once
2
3#include "main.h"
4
5#if defined(HAL_PCD_MODULE_ENABLED) && defined(LIBXR_SYSTEM_ThreadX)
6
7#include "app_usbx_device.h"
8#include "libxr_def.hpp"
9#include "libxr_rw.hpp"
10#include "mutex.hpp"
11#include "semaphore.hpp"
12#include "tx_api.h"
13#include "uart.hpp"
14#include "ux_api.h"
15#include "ux_device_class_cdc_acm.h"
16#include "ux_device_stack.h"
17
18namespace LibXR
19{
20
21class STM32VirtualUART : public UART
22{
23 public:
24 STM32VirtualUART(PCD_HandleTypeDef *hpcd, ULONG tx_stack_size, UINT tx_priority,
25 ULONG rx_stack_size, UINT rx_priority, uint32_t tx_queue_size = 5,
26 size_t buffer_size = 512);
27
28 ~STM32VirtualUART();
29
30 ErrorCode SetConfig(UART::Configuration config) override;
31
32 static ErrorCode ReadFun(ReadPort &port);
33 static ErrorCode WriteFun(WritePort &port);
34
35 static STM32VirtualUART *instance_;
36
37 UX_SLAVE_CLASS_CDC_ACM *cdc_acm_ = nullptr;
38
39 private:
40 void RxLoop();
41 void TxLoop();
42
43 static void RxThreadEntry(ULONG arg);
44 static void TxThreadEntry(ULONG arg);
45
46 TX_THREAD tx_thread_;
47 TX_THREAD rx_thread_;
48 void *tx_stack_mem_ = nullptr;
49 void *rx_stack_mem_ = nullptr;
50 ULONG tx_stack_size_;
51 ULONG rx_stack_size_;
52 UINT tx_priority_;
53 UINT rx_priority_;
54 size_t buffer_size_;
55
56 uint8_t *rx_buff_;
57 uint8_t *tx_buff_;
58
59 Semaphore write_sem_;
60 Mutex read_mutex_;
61
62 ReadPort _read_port;
63 WritePort _write_port;
64};
65
66} // namespace LibXR
67
68#endif
ErrorCode SetConfig(UART::Configuration config)
设置 UART 配置 / Sets the UART configuration
LibXR 命名空间
Definition ch32_gpio.hpp:9
ErrorCode(* ReadFun)(ReadPort &port)
Function pointer type for read operations.
Definition libxr_rw.hpp:247
ErrorCode(* WriteFun)(WritePort &port)
Function pointer type for write operations.
Definition libxr_rw.hpp:243