1 /** 2 * @file usbd.h 3 * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited 4 */ 5 6 #ifndef HAL_USBD_H 7 #define HAL_USBD_H 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 /** @addtogroup hal_usbd USBD 14 * usbd hal API. 15 * 16 * @{ 17 */ 18 19 #include <stdint.h> 20 21 #include "usb_device.h" 22 23 /* Endpoint transfer status, for endpoints > 0 */ 24 typedef enum { 25 EP_COMPLETED, /**< Transfer completed */ 26 EP_PENDING, /**< Transfer in progress */ 27 EP_INVALID, /**< Invalid parameter */ 28 EP_STALLED, /**< Endpoint stalled */ 29 } ep_status; 30 31 /* Initialization */ 32 /******************************************************************************************/ 33 34 /** 35 * @brief Initialize usb device driver 36 * 37 * @param[in] pdev point to usb device handler 38 * 39 * @return the operation status, USBD_OK is OK, USBD_BUSY is BUSY, others is error 40 */ 41 usbd_stat_t usbd_hal_init(void *pdev); 42 43 /** 44 * @brief Deinitialize usb device driver 45 * 46 * @param[in] pdev point to usb device handler 47 * 48 * @return the operation status, USBD_OK is OK, USBD_BUSY is BUSY, others is error 49 */ 50 usbd_stat_t usbd_hal_deinit(void *pdev); 51 52 /** 53 * @brief start usb device driver 54 * 55 * @param[in] pdev point to usb device handler 56 * 57 * @return the operation status, USBD_OK is OK, USBD_BUSY is BUSY, others is error 58 */ 59 usbd_stat_t usbd_hal_start(void *pdev); 60 61 /** 62 * @brief stop usb device driver 63 * 64 * @param[in] pdev point to usb device handler 65 * 66 * @return the operation status, USBD_OK is OK, USBD_BUSY is BUSY, others is error 67 */ 68 usbd_stat_t usbd_hal_stop(void *pdev); 69 70 /** 71 * @brief enable usb device interrupt 72 */ 73 void usbd_hal_connect(void); 74 75 /** 76 * @brief disable usb device interrupt 77 */ 78 void usbd_hal_disconnect(void); 79 80 /** 81 * @brief configure usb device info 82 */ 83 void usbd_hal_configure_device(void); 84 85 /** 86 * @brief unconfigure usb device info 87 */ 88 void usbd_hal_unconfigure_device(void); 89 90 /** 91 * @brief set usb device address 92 * 93 * @param[in] pdev point to usb device handler 94 * @param[in] address the usb device address 95 * 96 * @return none 97 */ 98 void usbd_hal_set_address(void *pdev, uint8_t address); 99 100 /* Endpoint 0 */ 101 /******************************************************************************************/ 102 103 /** 104 * @brief Endpoint0 setup(read setup packet) 105 * 106 * @param[in] buffer point to usb device handler 107 * 108 * @return none 109 */ 110 void usbd_hal_ep0_setup(uint8_t *buffer); 111 112 /** 113 * @brief Endpoint0 read packet 114 * 115 * @param[in] pdev point to usb device handler 116 * 117 * @return none 118 */ 119 void usbd_hal_ep0_read(void *pdev); 120 121 /** 122 * @brief Endpoint0 read stage 123 */ 124 void usbd_hal_ep0_read_stage(void); 125 126 /** 127 * @brief Endpoint0 get read result 128 * 129 * @param[in] pdev point to usb device handler 130 * @param[out] buffer point to packet 131 * 132 * @return the length of read packet 133 */ 134 uint32_t usbd_hal_get_ep0_read_result(void *pdev, uint8_t *buffer); 135 136 /** 137 * @brief Endpoint0 write 138 * 139 * @param[in] pdev point to usb device handler 140 * @param[in] buffer point to packet 141 * @param[in] size the length of write packet 142 * 143 * @return none 144 */ 145 void usbd_hal_ep0_write(void *pdev, uint8_t *buffer, uint32_t size); 146 147 /** 148 * @brief Get endpoint0 write result 149 */ 150 void usbd_hal_get_ep0_write_result(void); 151 152 /** 153 * @brief Stall endpoint0 154 * 155 * @param[in] pdev point to usb device handler 156 * 157 * @return none 158 */ 159 void usbd_hal_ep0_stall(void *pdev); 160 161 /* Other endpoints */ 162 /******************************************************************************************/ 163 164 /** 165 * @brief open the endpoint 166 * 167 * @param[in] pdev point to usb device handler 168 * @param[in] endpoint the num of endpoint 169 * @param[in] maxPacket the max size of packet 170 * @param[in] flags options flags for configuring endpoints 171 * 172 * @return true is ok, false is fail 173 */ 174 bool usbd_hal_realise_endpoint(void *pdev, uint8_t endpoint, uint32_t maxPacket, uint32_t flags); 175 176 /** 177 * @brief start read the endpoint data 178 * 179 * @param[in] pdev point to usb device handler 180 * @param[in] endpoint the num of endpoint 181 * @param[in] maximumSize amount of data to be received 182 * 183 * @return endpoint status 184 */ 185 ep_status usbd_hal_endpoint_read(void *pdev, uint8_t endpoint, uint32_t maximumSize); 186 187 /** 188 * @brief read the endpoint data 189 * 190 * @param[in] pdev point to usb device handler 191 * @param[in] endpoint the num of endpoint 192 * @param[out] data point to receive buffer 193 * @param[out] bytesRead amount of data be received 194 * 195 * @return endpoint status 196 */ 197 ep_status usbd_hal_endpoint_read_result(void *pdev, uint8_t endpoint, uint8_t *data, uint32_t *bytesRead); 198 199 /** 200 * @brief start write the endpoint data 201 * 202 * @param[in] pdev point to usb device handler 203 * @param[in] endpoint the num of endpoint 204 * @param[in] data point to write buffer 205 * @param[in] size amount of data to be write 206 * 207 * @return endpoint status 208 */ 209 ep_status usbd_hal_endpoint_write(void *pdev, uint8_t endpoint, uint8_t *data, uint32_t size); 210 211 /** 212 * @brief get writting endpoint data status 213 * 214 * @param[in] pdev point to usb device handler 215 * @param[in] endpoint the num of endpoint 216 * 217 * @return endpoint status 218 */ 219 ep_status usbd_hal_endpoint_write_result(void *pdev, uint8_t endpoint); 220 221 /** 222 * @brief stall the endpoint 223 * 224 * @param[in] pdev point to usb device handler 225 * @param[in] endpoint the num of endpoint 226 * 227 * @return none 228 */ 229 void usbd_hal_stall_endpoint(void *pdev, uint8_t endpoint); 230 231 /** 232 * @brief unstall the endpoint 233 * 234 * @param[in] pdev point to usb device handler 235 * @param[in] endpoint the num of endpoint 236 * 237 * @return none 238 */ 239 void usbd_hal_unstall_endpoint(void *pdev, uint8_t endpoint); 240 241 /** 242 * @brief get the endpoint status of stall 243 * 244 * @param[in] pdev point to usb device handler 245 * @param[in] endpoint the num of endpoint 246 * 247 * @return true is ok, false is false 248 */ 249 bool usbd_hal_get_endpoint_stall_state(void *pdev, uint8_t endpoint); 250 251 /** @} */ 252 253 #ifdef __cplusplus 254 } 255 #endif 256 257 #endif /* HAL_USBD_H */ 258 259