VSF Documented
vsf_usbd_DFU.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_DFU_H__
19#define __VSF_USBD_DFU_H__
20
21/*============================ INCLUDES ======================================*/
22
24
25#if VSF_USE_USB_DEVICE == ENABLED && VSF_USBD_USE_DFU == ENABLED
26
27#include "../../../common/class/DFU/vsf_usb_DFU.h"
28#include "./vsf_usbd_DFU_desc.h"
29
30#if defined(__VSF_USBD_DFU_CLASS_IMPLEMENT)
31# undef __VSF_USBD_DFU_CLASS_IMPLEMENT
32# define __VSF_CLASS_IMPLEMENT__
33#elif defined(__VSF_USBD_DFU_CLASS_INHERIT__)
34# undef __VSF_USBD_DFU_CLASS_INHERIT__
35# define __VSF_CLASS_INHERIT__
36#endif
37#include "utilities/ooc_class.h"
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/*============================ MACROS ========================================*/
44
45#define USB_DFU_IFS_NUM 1
46
47#define __usbd_dfu_desc_iad(__name, __ifs_start, __i_func, __protocol, __dfu_attr, __detach_timeout, __transfer_size)\
48 USB_DESC_DFU_IAD((__ifs_start), (__i_func), (__protocol), (__dfu_attr), (__detach_timeout), (__transfer_size))
49#define __usbd_dfu_desc(__name, __ifs_start, __i_func, __protocol, __dfu_attr, __detach_timeout, __transfer_size)\
50 USB_DESC_DFU((__ifs_start), (__i_func), (__protocol), (__dfu_attr), (__detach_timeout), (__transfer_size))
51
52#define USB_DFU_PARAM(__PROTOCOL, __DFU_ATTR, __TRANSFER_SIZE, __TRANSFER_BUFFER)\
53 .protocol = (__PROTOCOL), \
54 .attribute = (__DFU_ATTR), \
55 .transfer_size = (__TRANSFER_SIZE), \
56 .transfer_buffer = (__TRANSFER_BUFFER),
57
58#define __usbd_dfu_func1(__name, __func_id, __protocol, __dfu_attr, __transfer_size, __transfer_buffer)\
59 vk_usbd_dfu_t __##__name##_DFU##__func_id = { \
60 USB_DFU_PARAM((__protocol), (__dfu_attr), (__transfer_size), (__transfer_buffer))\
61 };
62#define __usbd_dfu_func0(__name, __func_id, __protocol, __dfu_attr, __transfer_size)\
63 static uint8_t __##__name##_DFU##__transfer_buffer[__transfer_size];\
64 __usbd_dfu_func1(__name, __func_id, (__protocol), (__dfu_attr), (__transfer_size), __##__name##_DFU##__transfer_buffer)
65
66#define __usbd_dfu_func(__name, __func_id, __protocol, __dfu_attr, __transfer_size, ...)\
67 __PLOOC_EVAL(__usbd_dfu_func, __VA_ARGS__)(__name, __func_id, (__protocol), (__dfu_attr), (__transfer_size), ##__VA_ARGS__)
68
69#define __usbd_dfu_ifs(__name, __func_id) \
70 USB_IFS(&vk_usbd_dfu, &__##__name##_DFU##__func_id)
71
72#define usbd_dfu_desc(__name, __ifs_start, __i_func, __protocol, __dfu_attr, __detach_timeout, __transfer_size)\
73 __usbd_dfu_desc(__name, (__ifs_start), __i_func, (__protocol), (__dfu_attr), (__detach_timeout), (__transfer_size))
74#define usbd_dfu_desc_iad(__name, __ifs_start, __i_func, __protocol, __dfu_attr, __detach_timeout, __transfer_size)\
75 __usbd_dfu_desc_iad(__name, (__ifs_start), __i_func, (__protocol), (__dfu_attr), (__transfer_size))
76#define usbd_dfu_func(__name, __func_id, __protocol, __dfu_attr, __transfer_size, ...)\
77 __usbd_dfu_func(__name, __func_id, (__protocol), (__dfu_attr), (__transfer_size), ##__VA_ARGS__)
78#define usbd_dfu_ifs(__name, __func_id) \
79 __usbd_dfu_ifs(__name, __func_id)
80
81/*============================ MACROFIED FUNCTIONS ===========================*/
82/*============================ TYPES =========================================*/
83
85 public_member(
86 uint8_t protocol;
88 uint16_t transfer_size;
89 uint8_t *transfer_buffer;
90 )
91 private_member(
93 uint16_t block_idx;
94 uint16_t cur_size;
95 uint32_t addr;
96
97 vk_usbd_dev_t *dev;
98 vk_usbd_ifs_t *ifs;
99 )
100};
101
102/*============================ GLOBAL VARIABLES ==============================*/
103
104extern const vk_usbd_class_op_t vk_usbd_dfu;
105
106/*============================ PROTOTYPES ====================================*/
107
109
110#ifdef __cplusplus
111}
112#endif
113
114#endif // VSF_USE_USB_DEVICE && VSF_USBD_USE_DFU
115#endif // __VSF_USBD_DFU_H__
vsf_err_t
Definition __type.h:42
Definition vsf_usbd_DFU.h:84
#define vsf_class(__name)
Definition ooc_class.h:48
unsigned short uint16_t
Definition stdint.h:7
unsigned uint32_t
Definition stdint.h:9
unsigned char uint8_t
Definition stdint.h:5
Definition sysfs.h:10
Definition vsf_usb_dfu.h:106
uint8_t status
Definition vsf_tgui.h:122
const vk_usbd_class_op_t vk_usbd_dfu
void vk_usbd_dfu_downloaded(vk_usbd_dfu_t *dfu, vsf_err_t result)