1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2017 NXP
4  * All rights reserved.
5  *
6  *
7  * SPDX-License-Identifier: BSD-3-Clause
8  */
9 
10 #ifndef __USB_DEVICE_DFU_H__
11 #define __USB_DEVICE_DFU_H__
12 
13 /*!
14  * @addtogroup usb_device_dfu_drv
15  * @{
16  */
17 
18 /*******************************************************************************
19  * Definitions
20  ******************************************************************************/
21 
22 /*! @brief The class code of the DFU class */
23 #define USB_DEVICE_CONFIG_DFU_CLASS_CODE (0xFEU)
24 
25 /*! @brief DFU class request */
26 #define USB_DEVICE_DFU_DETACH (0x00U)
27 #define USB_DEVICE_DFU_DNLOAD (0x01U)
28 #define USB_DEVICE_DFU_UPLOAD (0x02U)
29 #define USB_DEVICE_DFU_GETSTATUS (0x03U)
30 #define USB_DEVICE_DFU_CLRSTATUS (0x04U)
31 #define USB_DEVICE_DFU_GETSTATE (0x05U)
32 #define USB_DEVICE_DFU_ABORT (0x06U)
33 
34 /*! @brief Available common EVENT types in dfu class callback */
35 typedef enum _usb_device_dfu_event
36 {
37     kUSB_DeviceDfuEventDetach = 0x01U, /*!< Detach request */
38     kUSB_DeviceDfuEventDownLoad,       /*!< Download request */
39     kUSB_DeviceDfuEventUpLoad,         /*!< Upload request */
40     kUSB_DeviceDfuEventGetStatus,      /*!< Get status request */
41     kUSB_DeviceDfuEventClearStatus,    /*!< Clear status request */
42     kUSB_DeviceDfuEventGetState,       /*!< Get state request */
43     kUSB_DeviceDfuEventAbort,          /*!< Abort request */
44 } usb_device_dfu_event_t;
45 
46 /*! @brief The DFU device class status structure */
47 typedef struct _usb_device_dfu_struct
48 {
49     usb_device_handle handle;                       /*!< The device handle */
50     usb_device_class_config_struct_t *configStruct; /*!< The configuration of the class. */
51 } usb_device_dfu_struct_t;
52 
53 /*******************************************************************************
54  * API
55  ******************************************************************************/
56 
57 #if defined(__cplusplus)
58 extern "C" {
59 #endif
60 
61 /*!
62  * @brief Initialize the dfu class.
63  *
64  * This function is used to initialize the dfu class. This function only can be called by #USB_DeviceClassInit.
65  *
66  * @param[in] controllerId   The controller id of the USB IP. Please refer to the enumeration #usb_controller_index_t.
67  * @param[in] config         The class configuration information.
68  * @param[out] handle        It is out parameter, is used to return pointer of the dfu class handle to the caller.
69  *
70  * @return A USB error code or kStatus_USB_Success.
71  */
72 extern usb_status_t USB_DeviceDfuInit(uint8_t controllerId,
73                                       usb_device_class_config_struct_t *config,
74                                       class_handle_t *handle);
75 
76 /*!
77  * @brief De-initialize the device dfu class.
78  *
79  * The function de-initializes the device dfu class. This function only can be called by #USB_DeviceClassDeinit.
80  *
81  * @param[in] handle The dfu class handle got from usb_device_class_config_struct_t::classHandle.
82  *
83  * @return A USB error code or kStatus_USB_Success.
84  */
85 extern usb_status_t USB_DeviceDfuDeinit(class_handle_t handle);
86 
87 /*!
88  * @brief Handle the event passed to the dfu class.
89  *
90  * This function handles the event passed to the dfu class. This function can only be called by #USB_DeviceClassEvent.
91  *
92  * @param[in] handle          The dfu class handle, got from the usb_device_class_config_struct_t::classHandle.
93  * @param[in] event           The event codes. Please refer to the enumeration usb_device_class_event_t.
94  * @param[in,out] param       The param type is determined by the event code.
95  *
96  * @return A USB error code or kStatus_USB_Success.
97  * @retval kStatus_USB_Success              Free device handle successfully.
98  * @retval kStatus_USB_InvalidParameter     The device handle not be found.
99  * @retval kStatus_USB_InvalidRequest       The request is invalid, and the control pipe will be stalled by the caller.
100  */
101 extern usb_status_t USB_DeviceDfuEvent(void *handle, uint32_t event, void *param);
102 
103 #if defined(__cplusplus)
104 }
105 #endif
106 
107 /*! @}*/
108 
109 #endif /* __USB_DEVICE_DFU_H__ */
110