libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
dfu_def.hpp
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
6#include "crc.hpp"
7#include "dev_core.hpp"
8#include "flash.hpp"
9#include "timebase.hpp"
10#include "webusb.hpp"
11
12namespace LibXR::USB
13{
17enum class DFURequest : uint8_t
18{
19 DETACH = 0x00,
20 DNLOAD = 0x01,
21 UPLOAD = 0x02,
22 GETSTATUS = 0x03,
23 CLRSTATUS = 0x04,
24 GETSTATE = 0x05,
25 ABORT = 0x06,
26};
27
31enum class DFUState : uint8_t
32{
33 APP_IDLE = 0x00,
34 APP_DETACH = 0x01,
35 DFU_IDLE = 0x02,
36 DFU_DNLOAD_SYNC = 0x03,
37 DFU_DNBUSY = 0x04,
38 DFU_DNLOAD_IDLE = 0x05,
39 DFU_MANIFEST_SYNC = 0x06,
40 DFU_MANIFEST = 0x07,
41 DFU_MANIFEST_WAIT_RESET = 0x08,
42 DFU_UPLOAD_IDLE = 0x09,
43 DFU_ERROR = 0x0A,
44};
45
49enum class DFUStatusCode : uint8_t
50{
51 OK = 0x00,
52 ERR_TARGET = 0x01,
53 ERR_FILE = 0x02,
54 ERR_WRITE = 0x03,
55 ERR_ERASE = 0x04,
56 ERR_CHECK_ERASED = 0x05,
57 ERR_PROG = 0x06,
58 ERR_VERIFY = 0x07,
59 ERR_ADDRESS = 0x08,
60 ERR_NOTDONE = 0x09,
61 ERR_FIRMWARE = 0x0A,
62 ERR_VENDOR = 0x0B,
63 ERR_USBR = 0x0C,
64 ERR_POR = 0x0D,
65 ERR_UNKNOWN = 0x0E,
66 ERR_STALLEDPKT = 0x0F,
67};
68
73{
74 bool can_download = true;
75 bool can_upload = true;
76 bool manifestation_tolerant = true;
77 bool will_detach = false;
78 uint16_t detach_timeout_ms = 1000u;
79 uint16_t transfer_size = 1024u;
80};
81
86{
87 protected:
88 // DFU 单接口类共享的公共状态:
89 // - 一个接口字符串
90 // - 可选 WebUSB BOS capability
91 // - 一组当前 interface/alt setting 状态
92 // Shared single-interface DFU class state:
93 // - one interface string
94 // - optional WebUSB BOS capability
95 // - one active interface/alt-setting pair
97 const char* interface_string, const char* webusb_landing_page_url = nullptr,
98 uint8_t webusb_vendor_code = LibXR::USB::WebUsb::WEBUSB_VENDOR_CODE_DEFAULT)
99 : interface_string_(interface_string),
100 webusb_cap_(webusb_landing_page_url, webusb_vendor_code)
101 {
102 }
103
104 const char* GetInterfaceString(size_t local_interface_index) const override
105 {
106 return (local_interface_index == 0u) ? interface_string_ : nullptr;
107 }
108
109 size_t GetBosCapabilityCount() override { return webusb_cap_.Enabled() ? 1u : 0u; }
110
111 BosCapability* GetBosCapability(size_t index) override
112 {
113 return (index == 0u && webusb_cap_.Enabled()) ? &webusb_cap_ : nullptr;
114 }
115
116 uint8_t interface_num_ = 0u;
117 uint8_t current_alt_setting_ = 0u;
118 bool inited_ = false;
119
120 private:
121 const char* interface_string_ = nullptr;
122
123 protected:
125};
126
127} // namespace LibXR::USB
BOS 能力接口 / BOS capability interface.
Definition bos.hpp:57
USB 设备类接口基类 / USB device class interface base.
DFU 单接口类公共基类 / Common base for single-interface DFU classes.
Definition dfu_def.hpp:86
const char * GetInterfaceString(size_t local_interface_index) const override
返回本类暴露的第 N 个接口字符串 Return the string for the Nth local interface exposed by this class.
Definition dfu_def.hpp:104
size_t GetBosCapabilityCount() override
返回本类提供的 BOS capability 数量 Return the number of BOS capabilities exposed by this class.
Definition dfu_def.hpp:109
BosCapability * GetBosCapability(size_t index) override
返回指定 BOS capability Return the BOS capability at the given index.
Definition dfu_def.hpp:111
WebUSB BOS 能力包装器 / WebUSB BOS capability wrapper.
Definition webusb.hpp:60
bool Enabled() const
当前是否启用 WebUSB / Whether WebUSB is currently enabled
Definition webusb.hpp:84
@ OK
操作成功 | Operation successful
DFU 功能能力集合 / DFU functional capability set.
Definition dfu_def.hpp:73