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 
23 #include "usb_charger_detect.h"
24 
25 /*! @brief USB DCD error code */
26 typedef enum _usb_phydcd_status
27 {
28     kStatus_phydcd_Success = 0x00U, /*!< Success */
29     kStatus_phydcd_Error,           /*!< Failed */
30 } usb_phydcd_status_t;
31 /*!
32  * @brief Device dcd callback function typedef.
33  *
34  * This callback function is used to notify the upper layer that the device status has changed.
35  * This callback pointer is passed by calling API dcd Init function.
36  *
37  * @param handle         The device handle. It equals the value returned from #USB_PHYDCD_Init.
38  * @param callbackEvent  The callback event type. See enumeration #usb_device_event_t.
39  * @param eventParam     The event parameter for this callback. The parameter type is determined by the callback event.
40  *
41  * @return A USB error code or kStatus_USB_Success.
42  */
43 typedef usb_phydcd_status_t (*usb_phydcd_callback_t)(void *handle, uint32_t callbackEvent, void *eventParam);
44 typedef void *usb_phydcd_handle;
45 /*! @brief dcd configuration structure */
46 typedef struct _usb_phydcd_config_struct
47 {
48     usb_phydcd_callback_t dcdCallback; /*!< callbacl function for dcd detection*/
49     void *dcdCallbackParam;            /*!< callbacl function parameter for dcd detection */
50 } usb_phydcd_config_struct_t;
51 
52 /*! @brief Available common EVENT types in device callback */
53 typedef enum _usb_phydcd_control
54 {
55     kUSB_DevicePHYDcdRun = 1U, /*!< USB dcd dectect start */
56     kUSB_DevicePHYDcdStop,     /*!< USB dcd module stop */
57     kUSB_DevicePHYDcdEnable,   /*!< Enable USB dcd dectect module */
58     kUSB_DevicePHYDcdDisable,  /*!< Disable USB dcd module moudle */
59 } usb_phydcd_control_t;
60 
61 /*!
62  * @name USB device PHY dcd functions
63  * @{
64  */
65 
66 /*******************************************************************************
67  * API
68  ******************************************************************************/
69 
70 #if defined(__cplusplus)
71 extern "C" {
72 #endif
73 
74 /*!
75  * @brief Initializes the USB dcd instance.
76  *
77  * This function initializes the USB dcd controller module specified by the base.
78  *
79  * @param[in] index      index of the usb analog .
80  * @param[in] config    Pointer of the dcd configuration.
81  * @param[out] dcdHandle   an output parameter, return the pointer of the dcd moudle handle to caller.
82  *
83  * @return A error code or kStatus_phydcd_Success.
84  */
85 usb_phydcd_status_t USB_PHYDCD_Init(uint8_t index, usb_phydcd_config_struct_t *config, usb_phydcd_handle *dcdHandle);
86 
87 /*!
88  * @brief Deinitializes the USB dcd instance.
89  *
90  * This function Deinitializes the USB dcd module specified by the dcd handle.
91  *
92  * @param[in] dcdHandle      The dcd peripheral handle pointer.
93  *
94  * @return A dcd error code or kStatus_phydcd_Success.
95  */
96 
97 usb_phydcd_status_t USB_PHYDCD_Deinit(usb_phydcd_handle dcdHandle);
98 
99 /*!
100  * @brief Control the status of the selected item.
101  *
102  * This function is used to control the status of the selected item..
103  *
104  * @param handle                 The dcd handle. It equals the value returned from USB_DCD_Init.
105  * @param type                   The control type, please refer to the enumeration usb_dcd_event_t.
106  * @param param                  The param type is determined by the selected item. Or the param is NULL pointer.
107  *
108  * @retval kStatus_phydcd_Success              control the status successfully.
109  * @retval kStatus_phydcd_Error                control the status failed .
110  *
111  */
112 usb_phydcd_status_t USB_PHYDCD_Control(usb_phydcd_handle handle, usb_phydcd_control_t type, void *param);
113 /*!
114  * @brief update the status of the dcd detection based on time tick.
115  *
116  * This function is used to update dcd detction on time tick.
117  *
118  * @param handle                 The dcd handle. It equals the value returned from USB_DCD_Init.
119  *
120  * @retval kStatus_phydcd_Success              control the status successfully.
121  * @retval kStatus_phydcd_Error                control the status failed .
122  *
123  */
124 usb_phydcd_status_t USB_PHYDCD_TimerIsrFunction(usb_phydcd_handle handle);
125 /*! @} */
126 
127 #if defined(__cplusplus)
128 }
129 #endif
130 
131 /*! @} */
132 
133 #endif /* __USB_DEVICE_HSDCD_H__ */
134