1 /*
2  * Copyright 2019 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef __USB_DEVICE_HSDCD_H__
9 #define __USB_DEVICE_HSDCD_H__
10 #include "fsl_common.h"
11 #include "fsl_device_registers.h"
12 
13 /*!
14  * @addtogroup usb_device_hsdcd_driver
15  * @{
16  */
17 
18 /*******************************************************************************
19  * Definitions
20  ******************************************************************************/
21 /******************* Macro definitions ***************/
22 #include "usb_charger_detect.h"
23 /*! @brief USB error code */
24 typedef enum _usb_hsdcd_status
25 {
26     kStatus_hsdcd_Success = 0x00U, /*!< Success */
27     kStatus_hsdcd_Error,           /*!< Failed */
28 } usb_hsdcd_status_t;
29 /*!
30  * @brief Device dcd callback function typedef.
31  *
32  * This callback function is used to notify the upper layer that the device status has changed.
33  * This callback pointer is passed by calling API dcd Init function.
34  *
35  * @param handle          The device handle. It equals the value returned from #USB_DCD_Init.
36  * @param callbackEvent  The callback event type. See enumeration #usb_device_event_t.
37  * @param eventParam     The event parameter for this callback. The parameter type is determined by the callback event.
38  *
39  * @return A USB error code or kStatus_USB_Success.
40  */
41 typedef usb_hsdcd_status_t (*usb_hsdcd_callback_t)(void *handle, uint32_t callbackEvent, void *eventParam);
42 typedef void *usb_hsdcd_handle;
43 /*! @brief dcd configuration structure */
44 typedef struct _usb_hsdcd_config_struct
45 {
46     usb_hsdcd_callback_t dcdCallback; /*!< DCD base address*/
47     void *dcdCallbackParam;           /*!< DCD callback parameter*/
48 } usb_hsdcd_config_struct_t;
49 
50 /*! @brief Available common EVENT types in device callback */
51 typedef enum _usb_hsdcd_control
52 {
53     kUSB_DeviceHSDcdRun = 1U, /*!< USB dcd dectect start */
54     kUSB_DeviceHSDcdStop,     /*!< USB dcd module reset */
55     kUSB_DeviceHSDcdEnable,   /*!< Enable USB dcd dectect module */
56     kUSB_DeviceHSDcdDisable,  /*!< USB dcd module moudle */
57     kUSB_HostHSDcdSetType,    /*!< set host dcd type */
58 } usb_hsdcd_control_t;
59 
60 /*!
61  * @name USB device hs dcd functions
62  * @{
63  */
64 
65 /*******************************************************************************
66  * API
67  ******************************************************************************/
68 
69 #if defined(__cplusplus)
70 extern "C" {
71 #endif
72 
73 /*!
74  * @brief Initializes the USB dcd instance.
75  *
76  * This function initializes the USB dcd controller module specified by the base.
77  *
78  * @param[in] base      Pointer of the dcd register base.
79  * @param[in] config    Pointer of the dcd configuration.
80  * @param[out] dcdHandle   an output parameter, return the pointer of the dcd moudle handle to caller.
81  *
82  * @return A error code or kStatus_hsdcd_Success.
83  */
84 usb_hsdcd_status_t USB_HSDCD_Init(USBHSDCD_Type *base, usb_hsdcd_config_struct_t *config, usb_hsdcd_handle *dcdHandle);
85 
86 /*!
87  * @brief Deinitializes the USB dcd instance.
88  *
89  * This function Deinitializes the USB dcd module specified by the dcd handle.
90  *
91  * @param[in] handle      The dcd peripheral handle pointer.
92  *
93  * @return A dcd error code or kStatus_hsdcd_Success.
94  */
95 
96 usb_hsdcd_status_t USB_HSDCD_Deinit(usb_hsdcd_handle handle);
97 
98 /*!
99  * @brief Control the status of the selected item.
100  *
101  * This function is used to control the status of the selected item..
102  *
103  * @param handle                 The dcd handle. It equals the value returned from USB_DCD_Init.
104  * @param type                   The control type, please refer to the enumeration usb_dcd_event_t.
105  * @param param                  The param type is determined by the selected item. Or the param is NULL pointer.
106  *
107  * @retval kStatus_dcd_Success              control the status successfully.
108  * @retval kStatus_USB_Error                control the status failed .
109  *
110  */
111 usb_hsdcd_status_t USB_HSDCD_Control(usb_hsdcd_handle handle, usb_hsdcd_control_t type, void *param);
112 /*!
113  * @brief Device dcd ISR function.
114  *
115  * The function is the dcd interrupt service routine.
116  *
117  * @param[in] deviceHandle The device handle got from #USB_DeviceHSDCD_Init.
118  */
119 extern void USB_HSDcdIsrFunction(usb_hsdcd_handle handle);
120 /*! @} */
121 
122 #if defined(__cplusplus)
123 }
124 #endif
125 
126 /*! @} */
127 
128 #endif /* __USB_DEVICE_HSDCD_H__ */
129