VSF Documented
vsf_usbd_webusb.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_USBD_WEBUSB_H__
19#define __VSF_USBD_WEBUSB_H__
20
21/*============================ INCLUDES ======================================*/
22
24
25#if VSF_USE_USB_DEVICE == ENABLED
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/*============================ MACROS ========================================*/
32
33#define USB_BOS_CAP_WEBUSB_LEN USB_DESC_BOS_CAPABILITY_LEN(4)
34
35#define USB_DT_WEBUSB_URL 0x03
36#define USB_REQ_WEBUSB_GET_URL 0x02
37
38#define WEBUSB_URL_PREFIX_HTTP 0x00
39#define WEBUSB_URL_PREFIX_HTTPS 0x01
40#define WEBUSB_URL_PREFIX_NONE 0xFF
41
42/*============================ MACROFIED FUNCTIONS ===========================*/
43
44#define USB_WEBUSB_URL_DESC(__PREFIX, __URL_LEN, ...) \
45 3 + (__URL_LEN), \
46 USB_DT_WEBUSB_URL, \
47 (__PREFIX), \
48 __VA_ARGS__
49
50#define __bos_desc_webusb(__vendor_code, __landing_page) \
51 USB_DESC_BOS_CAPABILITY_HEADER(4, 5, \
52 0x38, 0xB6, 0x08, 0x34, /* uuid: winusb */ \
53 0xA9, 0x09, 0xA0, 0x47, \
54 0x8B, 0xFD, 0xA0, 0x76, \
55 0x88, 0x15, 0xB6, 0x65, \
56 ) \
57 USB_DESC_WORD(0x0100), /* bcdVersion */ \
58 (__vendor_code), /* bVendorCode */ \
59 (__landing_page), /* iLandingPage */
60
61#define bos_desc_webusb(__vendor_code, __landing_page) \
62 __bos_desc_webusb((__vendor_code), (__landing_page))
63
64#define __usbd_webusb_url_desc(__name, __landing_page, __prefix, __url_len, __url)\
65 struct { \
66 uint8_t bLength; \
67 uint8_t bDescriptorType; \
68 uint8_t bScheme; \
69 char url_utf8[(__url_len) + 3]; \
70 } VSF_CAL_PACKED const __##__name##_webusb_url##__landing_page##_desc = {\
71 .bLength = 6 + (__url_len), \
72 .bDescriptorType = USB_DT_WEBUSB_URL, \
73 .bScheme = (__prefix), \
74 .url_utf8 = (__url), \
75 }; \
76
77#define usbd_webusb_url_desc(__name, __landing_page, __prefix, __url_len, __url)\
78 __usbd_webusb_url_desc(__name, __landing_page, (__prefix), (__url_len), (__url))
79
80#define __usbd_webusb_url_desc_buffer(__name, __landing_page) \
81 &__##__name##_webusb_url##__landing_page##_desc
82#define __usbd_webusb_url_desc_len(__name, __landing_page) \
83 sizeof(__##__name##_webusb_url##__landing_page##_desc)
84#define usbd_webusb_url_desc_buffer(__name, __landing_page) \
85 __usbd_webusb_url_desc_buffer(__name, __landing_page)
86#define usbd_webusb_url_desc_len(__name, __landing_page) \
87 __usbd_webusb_url_desc_len(__name, __landing_page)
88
89/*============================ TYPES =========================================*/
90/*============================ GLOBAL VARIABLES ==============================*/
91/*============================ PROTOTYPES ====================================*/
92
93#ifdef __cplusplus
94}
95#endif
96
97#endif // VSF_USE_USB_DEVICE
98#endif // __VSF_USBD_WEBUSB_H__