1 /* 2 * Copyright (c) 2016, Freescale Semiconductor, Inc. 3 * Copyright 2016 NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef __USB_HOST_PRINTER_H__ 10 #define __USB_HOST_PRINTER_H__ 11 12 /******************************************************************************* 13 * Definitions 14 ******************************************************************************/ 15 16 /*! 17 * @addtogroup usb_host_printer_drv 18 * @{ 19 */ 20 21 /*! @brief Printer class code */ 22 #define USB_HOST_PRINTER_CLASS_CODE (7U) 23 /*! @brief Printer sub-class code */ 24 #define USB_HOST_PRINTER_SUBCLASS_CODE (1U) 25 /*! @brief Printer class protocol code (Unidirectional interface) */ 26 #define USB_HOST_PRINTER_PROTOCOL_UNIDIRECTION (1U) 27 /*! @brief Printer class protocol code (Bi-directional interface) */ 28 #define USB_HOST_PRINTER_PROTOCOL_BIDIRECTION (2U) 29 /*! @brief Printer class protocol code (IEEE® 1284.4 compatible bi-directional interface) */ 30 #define USB_HOST_PRINTER_PROTOCOL_IEEE1284 (3U) 31 32 /*! @brief Printer class-specific request (GET_DEVICE_ID) */ 33 #define USB_HOST_PRINTER_GET_DEVICE_ID (0) 34 /*! @brief Printer class-specific request (GET_PORT_STATUS) */ 35 #define USB_HOST_PRINTER_GET_PORT_STATUS (1) 36 /*! @brief Printer class-specific request (SOFT_RESET) */ 37 #define USB_HOST_PRINTER_SOFT_RESET (2) 38 39 /*! @brief Paper empty bit mask for GET_PORT_STATUS */ 40 #define USB_HOST_PRINTER_PORT_STATUS_PAPER_EMPTRY_MASK (0x20U) 41 /*! @brief Select bit mask for GET_PORT_STATUS */ 42 #define USB_HOST_PRINTER_PORT_STATUS_SELECT_MASK (0x10U) 43 /*! @brief Error bit mask for GET_PORT_STATUS */ 44 #define USB_HOST_PRINTER_PORT_STATUS_NOT_ERROR_MASK (0x08U) 45 46 /*! @brief Printer instance structure and printer usb_host_class_handle pointer to this structure */ 47 typedef struct _usb_host_printer_instance 48 { 49 usb_host_handle hostHandle; /*!< This instance's related host handle*/ 50 usb_device_handle deviceHandle; /*!< This instance's related device handle*/ 51 usb_host_interface_handle interfaceHandle; /*!< This instance's related interface handle*/ 52 usb_host_pipe_handle controlPipe; /*!< This instance's related device control pipe*/ 53 usb_host_pipe_handle inPipe; /*!< Printer bulk in pipe*/ 54 usb_host_pipe_handle outPipe; /*!< Printer bulk out pipe*/ 55 transfer_callback_t inCallbackFn; /*!< Printer bulk in transfer callback function pointer*/ 56 void *inCallbackParam; /*!< Printer bulk in transfer callback parameter*/ 57 transfer_callback_t outCallbackFn; /*!< Printer bulk out transfer callback function pointer*/ 58 void *outCallbackParam; /*!< Printer bulk out transfer callback parameter*/ 59 transfer_callback_t controlCallbackFn; /*!< Printer control transfer callback function pointer*/ 60 void *controlCallbackParam; /*!< Printer control transfer callback parameter*/ 61 usb_host_transfer_t *controlTransfer; /*!< Ongoing control transfer*/ 62 #if ((defined USB_HOST_CONFIG_CLASS_AUTO_CLEAR_STALL) && USB_HOST_CONFIG_CLASS_AUTO_CLEAR_STALL) 63 uint8_t *stallDataBuffer; 64 uint32_t stallDataLength; 65 #endif 66 67 uint16_t inPacketSize; /*!< Printer bulk in maximum packet size*/ 68 uint16_t outPacketSize; /*!< Printer bulk out maximum packet size*/ 69 } usb_host_printer_instance_t; 70 71 /******************************************************************************* 72 * API 73 ******************************************************************************/ 74 75 #ifdef __cplusplus 76 extern "C" { 77 #endif 78 79 /*! 80 * @name USB host printer class APIs 81 * @{ 82 */ 83 84 /*! 85 * @brief Initializes the printer instance. 86 * 87 * This function allocate the resource for the printer instance. 88 * 89 * @param[in] deviceHandle The device handle. 90 * @param[out] classHandle Return class handle. 91 * 92 * @retval kStatus_USB_Success The device is initialized successfully. 93 * @retval kStatus_USB_AllocFail Allocate memory fail. 94 */ 95 extern usb_status_t USB_HostPrinterInit(usb_device_handle deviceHandle, usb_host_class_handle *classHandle); 96 97 /*! 98 * @brief Sets the interface. 99 * 100 * This function binds the interface with the printer instance. 101 * 102 * @param[in] classHandle The class handle. 103 * @param[in] interfaceHandle The interface handle. 104 * @param[in] alternateSetting The alternate setting value. 105 * @param[in] callbackFn This callback is called after this function completes. 106 * @param[in] callbackParam The first parameter in the callback function. 107 * 108 * @retval kStatus_USB_Success The device is initialized successfully. 109 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 110 * @retval kStatus_USB_Busy There is no idle transfer. 111 * @retval kStatus_USB_Error Send transfer fail. See the USB_HostSendSetup. 112 * @retval kStatus_USB_Busy Callback return status, there is no idle pipe. 113 * @retval kStatus_USB_TransferStall Callback return status, the transfer is stalled by the device. 114 * @retval kStatus_USB_Error Callback return status, open pipe fail. See the USB_HostOpenPipe. 115 */ 116 extern usb_status_t USB_HostPrinterSetInterface(usb_host_class_handle classHandle, 117 usb_host_interface_handle interfaceHandle, 118 uint8_t alternateSetting, 119 transfer_callback_t callbackFn, 120 void *callbackParam); 121 122 /*! 123 * @brief De-initializes the printer instance. 124 * 125 * This function frees the resources for the printer instance. 126 * 127 * @param[in] deviceHandle The device handle. 128 * @param[in] classHandle The class handle. 129 * 130 * @retval kStatus_USB_Success The device is de-initialized successfully. 131 */ 132 extern usb_status_t USB_HostPrinterDeinit(usb_device_handle deviceHandle, usb_host_class_handle classHandle); 133 134 /*! 135 * @brief Receives data. 136 * 137 * This function implements the printer receiving data. 138 * 139 * @param[in] classHandle The class handle. 140 * @param[out] buffer The buffer pointer. 141 * @param[in] bufferLength The buffer length. 142 * @param[in] callbackFn This callback is called after this function completes. 143 * @param[in] callbackParam The first parameter in the callback function. 144 * 145 * @retval kStatus_USB_Success Receive request successfully. 146 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 147 * @retval kStatus_USB_Busy There is no idle transfer. 148 * @retval kStatus_USB_Error Pipe is not initialized. 149 * Or, send transfer fail. See the USB_HostRecv. 150 */ 151 extern usb_status_t USB_HostPrinterRecv(usb_host_class_handle classHandle, 152 uint8_t *buffer, 153 uint32_t bufferLength, 154 transfer_callback_t callbackFn, 155 void *callbackParam); 156 157 /*! 158 * @brief Sends data. 159 * 160 * This function implements the printer sending data. 161 * 162 * @param[in] classHandle The class handle. 163 * @param[in] buffer The buffer pointer. 164 * @param[in] bufferLength The buffer length. 165 * @param[in] callbackFn This callback is called after this function completes. 166 * @param[in] callbackParam The first parameter in the callback function. 167 * 168 * @retval kStatus_USB_Success Send request successfully. 169 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 170 * @retval kStatus_USB_Busy There is no idle transfer. 171 * @retval kStatus_USB_Error Pipe is not initialized. 172 * Or, send transfer fail. See the USB_HostSend. 173 */ 174 extern usb_status_t USB_HostPrinterSend(usb_host_class_handle classHandle, 175 uint8_t *buffer, 176 uint32_t bufferLength, 177 transfer_callback_t callbackFn, 178 void *callbackParam); 179 180 /*! 181 * @brief Gets the pipe maximum packet size. 182 * 183 * @param[in] classHandle The class handle. 184 * @param[in] pipeType Its value is USB_ENDPOINT_CONTROL, USB_ENDPOINT_ISOCHRONOUS, USB_ENDPOINT_BULK or 185 * USB_ENDPOINT_INTERRUPT. See the usb_spec.h 186 * @param[in] direction Pipe direction. 187 * 188 * @retval 0 The classHandle is NULL. 189 * @retval Maximum Packet size. 190 */ 191 extern uint16_t USB_HostPrinterGetPacketsize(usb_host_class_handle classHandle, uint8_t pipeType, uint8_t direction); 192 193 /*! 194 * @brief Printer get device ID. 195 * 196 * This function implements the printer class-specific request (GET_DEVICE_ID). 197 * 198 * @param[in] classHandle The class handle. 199 * @param[in] interfaceIndex Interface index. 200 * @param[in] alternateSetting Get the alternateSetting's device ID. 201 * @param[out] buffer The buffer pointer. 202 * @param[in] length The buffer length. 203 * @param[in] callbackFn This callback is called after this function completes. 204 * @param[in] callbackParam The first parameter in the callback function. 205 * 206 * @retval kStatus_USB_Success Request successful. 207 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 208 * @retval kStatus_USB_Busy There is no idle transfer. 209 * @retval kStatus_USB_Error Send transfer fail. See the USB_HostSendSetup. 210 */ 211 extern usb_status_t USB_HostPrinterGetDeviceId(usb_host_class_handle classHandle, 212 uint8_t interfaceIndex, 213 uint8_t alternateSetting, 214 uint8_t *buffer, 215 uint32_t length, 216 transfer_callback_t callbackFn, 217 void *callbackParam); 218 219 /*! 220 * @brief Printer get port status. 221 * 222 * This function implements the printer class-specific request (GET_PORT_STATUS). 223 * 224 * @param[in] classHandle The class handle. 225 * @param[in] portStatus Port status buffer. 226 * @param[in] callbackFn This callback is called after this function completes. 227 * @param[in] callbackParam The first parameter in the callback function. 228 * 229 * @retval kStatus_USB_Success Request successful. 230 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 231 * @retval kStatus_USB_Busy There is no idle transfer. 232 * @retval kStatus_USB_Error Send transfer fail. See the USB_HostSendSetup. 233 */ 234 extern usb_status_t USB_HostPrinterGetPortStatus(usb_host_class_handle classHandle, 235 uint8_t *portStatus, 236 transfer_callback_t callbackFn, 237 void *callbackParam); 238 239 /*! 240 * @brief Printer soft reset. 241 * 242 * This function implements the printer class-specific request (SOFT_RESET). 243 * 244 * @param[in] classHandle The class handle. 245 * @param[in] portStatus Port status buffer. 246 * @param[in] callbackFn This callback is called after this function completes. 247 * @param[in] callbackParam The first parameter in the callback function. 248 * 249 * @retval kStatus_USB_Success Request successful. 250 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 251 * @retval kStatus_USB_Busy There is no idle transfer. 252 * @retval kStatus_USB_Error Send transfer fail. See the USB_HostSendSetup. 253 */ 254 extern usb_status_t USB_HostPrinterSoftReset(usb_host_class_handle classHandle, 255 transfer_callback_t callbackFn, 256 void *callbackParam); 257 /*! @}*/ 258 259 #ifdef __cplusplus 260 } 261 #endif 262 263 /*! @}*/ 264 265 #endif /* __USB_HOST_PRINTER_H__ */ 266