1 /* 2 * Copyright (c) 2015, Freescale Semiconductor, Inc. 3 * Copyright 2016 NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef _USB_DEVICE_PHDC_H_ 10 #define _USB_DEVICE_PHDC_H_ 11 12 /*! 13 * @addtogroup usb_device_phdc_drv 14 * @{ 15 */ 16 17 /******************************************************************************* 18 * Definitions 19 ******************************************************************************/ 20 21 /*! @brief The class code of the PHDC class */ 22 #define USB_DEVICE_CONFIG_PHDC_CLASS_CODE (0x0FU) 23 /*! @brief The PHDC class set Meta-data message preamble feature request */ 24 #define USB_DEVICE_PHDC_REQUEST_SET_FEATURE (0x03U) 25 /*! @brief The PHDC class clear Meta-data message preamble feature request */ 26 #define USB_DEVICE_PHDC_REQUEST_CLEAR_FEATURE (0x01U) 27 /*! @brief The PHDC class get data status request */ 28 #define USB_DEVICE_PHDC_REQUEST_GET_STATUS (0x00U) 29 /*! @brief Available common EVENT types in PHDC class callback */ 30 typedef enum 31 { 32 kUSB_DevicePhdcEventInterruptInSendComplete = 0x01, /*!< Send data completed or cancelled etc*/ 33 kUSB_DevicePhdcEventBulkInSendComplete, /*!< Send data completed or cancelled etc*/ 34 kUSB_DevicePhdcEventDataReceived, /*!< Data received or cancelled etc*/ 35 kUSB_DevicePhdcEventSetFeature, /*!< Set feature request */ 36 kUSB_DevicePhdcEventClearFeature, /*!< Clear feature request */ 37 kUSB_DevicePhdcEventGetStatus, /*!< Get status request */ 38 } usb_device_phdc_event_t; 39 40 /*! @brief Definition of pipe structure. */ 41 typedef struct _usb_device_phdc_pipe 42 { 43 uint8_t *pipeDataBuffer; /*!< pipe data buffer backup when stall */ 44 uint32_t pipeDataLen; /*!< pipe data length backup when stall */ 45 uint8_t pipeStall; /*!< pipe is stall */ 46 uint8_t ep; /*!< The endpoint number of the pipe. */ 47 uint8_t isBusy; /*!< 1: The pipe is transferring packet, 0: The pipe is idle. */ 48 } usb_device_phdc_pipe_t; 49 50 /*! @brief The PHDC device class status structure */ 51 typedef struct _usb_device_phdc_struct 52 { 53 usb_device_handle handle; /*!< The device handle */ 54 usb_device_class_config_struct_t *configStruct; /*!< The configuration of the class. */ 55 usb_device_interface_struct_t *interfaceHandle; /*!< Current interface handle */ 56 usb_device_phdc_pipe_t bulkIn; /*!< The bulk in pipe for sending data */ 57 usb_device_phdc_pipe_t bulkOut; /*!< The bulk out pipe for receiving data */ 58 usb_device_phdc_pipe_t interruptIn; /*!< The interrupt in pipe for sending data */ 59 uint8_t configuration; /*!< Current configuration */ 60 uint8_t interfaceNumber; /*!< The interface number of the class */ 61 uint8_t alternate; /*!< Current alternate setting of the interface */ 62 } usb_device_phdc_struct_t; 63 64 /******************************************************************************* 65 * API 66 ******************************************************************************/ 67 #if defined(__cplusplus) 68 extern "C" { 69 #endif 70 71 /*! 72 * @brief Initializes the PHDC class. 73 * 74 * This function is used to initialize the PHDC class. 75 * 76 * @param controllerId The controller ID of the USB IP. See the enumeration usb_controller_index_t. 77 * @param config The class configuration information. 78 * @param handle An output parameter used to return pointer of the PHDC class handle to the caller. 79 * 80 * @retval kStatus_USB_Success The PHDC class is initialized successfully. 81 * @retval kStatus_USB_Busy No PHDC device handle available for allocation. 82 * @retval kStatus_USB_InvalidHandle The PHDC device handle allocation failure. 83 * @retval kStatus_USB_InvalidParameter The USB device handle allocation failure. 84 */ 85 extern usb_status_t USB_DevicePhdcInit(uint8_t controllerId, 86 usb_device_class_config_struct_t *config, 87 class_handle_t *handle); 88 89 /*! 90 * @brief Deinitializes the device PHDC class. 91 * 92 * The function deinitializes the device PHDC class. 93 * 94 * @param handle The PHDC class handle received from usb_device_class_config_struct_t::classHandle. 95 * 96 * @retval kStatus_USB_InvalidHandle The device handle is not found. 97 * @retval kStatus_USB_Success The PHDC class is de-initialized successful. 98 */ 99 extern usb_status_t USB_DevicePhdcDeinit(class_handle_t handle); 100 101 /*! 102 * @brief Handles the event passed to the PHDC class. 103 * 104 * This function handles the event passed to the PHDC class. 105 * 106 * @param[in] handle The PHDC class handle received from the usb_device_class_config_struct_t::classHandle. 107 * @param[in] event The event codes. See the enumeration usb_device_class_event_t. 108 * @param[in,out] param The parameter type is determined by the event code. 109 * 110 * @retval kStatus_USB_Success Free device handle successfully. 111 * @retval kStatus_USB_InvalidParameter The device handle is not found. 112 * @retval kStatus_USB_InvalidRequest The request is invalid and the control pipe is stalled by the caller. 113 */ 114 extern usb_status_t USB_DevicePhdcEvent(void *handle, uint32_t event, void *param); 115 116 /*! 117 * @name USB device PHDC class APIs 118 * @{ 119 */ 120 121 /*! 122 * @brief Sends data through a specified endpoint. 123 * 124 * The function is used to send data through a specified endpoint. 125 * The function calls #USB_DeviceSendRequest internally. 126 * 127 * @param[in] handle The PHDC class handle received from the usb_device_class_config_struct_t::classHandle. 128 * @param[in] ep Endpoint index. 129 * @param[in] buffer The memory address to hold the data to be sent. 130 * @param[in] length The data length to be sent. 131 * 132 * @retval kStatus_USB_InvalidHandle The device handle is not found. 133 * @retval kStatus_USB_Busy The previous transfer is pending. 134 * @retval kStatus_USB_Success The sending is successful. 135 * 136 * @note The function can only be called in the same context. 137 */ 138 extern usb_status_t USB_DevicePhdcSend(class_handle_t handle, uint8_t ep, uint8_t *buffer, uint32_t length); 139 140 /*! 141 * @brief Receives data through a specified endpoint. 142 * 143 * The function is used to receive data through a specified endpoint. 144 * The function calls the #USB_DeviceRecvRequest internally. 145 * 146 * @param[in] handle The PHDC class handle received from usb_device_class_config_struct_t::classHandle. 147 * @param[in] ep Endpoint index. 148 * @param[in] buffer The memory address to save the received data. 149 * @param[in] length The data length want to be received. 150 * 151 * @retval kStatus_USB_InvalidHandle The device handle is not found. 152 * @retval kStatus_USB_Busy The previous transfer is pending. 153 * @retval kStatus_USB_Success The receiving is successful. 154 * 155 * @note The function can only be called in the same context. 156 */ 157 extern usb_status_t USB_DevicePhdcRecv(class_handle_t handle, uint8_t ep, uint8_t *buffer, uint32_t length); 158 159 #if defined(__cplusplus) 160 } 161 #endif 162 /*! @}*/ 163 164 /*! @}*/ 165 166 #endif /* _USB_DEVICE_PHDC_H_ */ 167