1 /*************************************************************************** 2 * Copyright (c) 2024 Microsoft Corporation 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the MIT License which is available at 6 * https://opensource.org/licenses/MIT. 7 * 8 * SPDX-License-Identifier: MIT 9 **************************************************************************/ 10 11 12 /**************************************************************************/ 13 /**************************************************************************/ 14 /** */ 15 /** USBX Component */ 16 /** */ 17 /** Printer Class */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 23 /**************************************************************************/ 24 /* */ 25 /* COMPONENT DEFINITION RELEASE */ 26 /* */ 27 /* ux_host_class_printer.h PORTABLE C */ 28 /* 6.3.0 */ 29 /* AUTHOR */ 30 /* */ 31 /* Chaoqiong Xiao, Microsoft Corporation */ 32 /* */ 33 /* DESCRIPTION */ 34 /* */ 35 /* This file contains all the header and extern functions used by the */ 36 /* USBX printer class. */ 37 /* */ 38 /* RELEASE HISTORY */ 39 /* */ 40 /* DATE NAME DESCRIPTION */ 41 /* */ 42 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ 43 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ 44 /* used UX prefix to refer to */ 45 /* TX symbols instead of using */ 46 /* them directly, */ 47 /* resulting in version 6.1 */ 48 /* 08-02-2021 Wen Wang Modified comment(s), */ 49 /* added extern "C" keyword */ 50 /* for compatibility with C++, */ 51 /* resulting in version 6.1.8 */ 52 /* 10-15-2021 Chaoqiong Xiao Modified comment(s), */ 53 /* added entry public define, */ 54 /* resulting in version 6.1.9 */ 55 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */ 56 /* added standalone support, */ 57 /* added a new protocol const, */ 58 /* resulting in version 6.1.10 */ 59 /* 10-31-2023 Yajun xia Modified comment(s), */ 60 /* added error checks support, */ 61 /* resulting in version 6.3.0 */ 62 /* */ 63 /**************************************************************************/ 64 65 #ifndef UX_HOST_CLASS_PRINTER_H 66 #define UX_HOST_CLASS_PRINTER_H 67 68 /* Determine if a C++ compiler is being used. If so, ensure that standard 69 C is used to process the API information. */ 70 71 #ifdef __cplusplus 72 73 /* Yes, C++ compiler is present. Use standard C. */ 74 extern "C" { 75 76 #endif 77 78 /* Internal option: enable the basic USBX error checking. This define is typically used 79 while debugging application. */ 80 #if defined(UX_ENABLE_ERROR_CHECKING) && !defined(UX_HOST_CLASS_PRINTER_ENABLE_ERROR_CHECKING) 81 #define UX_HOST_CLASS_PRINTER_ENABLE_ERROR_CHECKING 82 #endif 83 84 /* Define Printer Class constants. */ 85 86 #define UX_HOST_CLASS_PRINTER_CLASS_TRANSFER_TIMEOUT 300000 87 #define UX_HOST_CLASS_PRINTER_CLASS 7 88 #define UX_HOST_CLASS_PRINTER_SUBCLASS 1 89 #define UX_HOST_CLASS_PRINTER_PROTOCOL_BI_DIRECTIONAL 2 90 #define UX_HOST_CLASS_PRINTER_PROTOCOL_IEEE_1284_4_BI_DIR 3 91 #define UX_HOST_CLASS_PRINTER_GET_STATUS 1 92 #define UX_HOST_CLASS_PRINTER_SOFT_RESET 2 93 #define UX_HOST_CLASS_PRINTER_STATUS_LENGTH 4 94 #define UX_HOST_CLASS_PRINTER_DESCRIPTOR_LENGTH 1024 95 #define UX_HOST_CLASS_PRINTER_GET_DEVICE_ID 0 96 #define UX_HOST_CLASS_PRINTER_NAME_LENGTH 64 97 98 99 /* Define Printer Class 1284 descriptor tag constants. */ 100 101 #define UX_HOST_CLASS_PRINTER_TAG_DESCRIPTION "DESCRIPTION:" 102 #define UX_HOST_CLASS_PRINTER_TAG_DES "DES:" 103 104 105 /* Define Printer Class string constants. */ 106 107 #define UX_HOST_CLASS_PRINTER_GENERIC_NAME "USB PRINTER" 108 109 110 /* Define Printer flag constants. */ 111 112 #define UX_HOST_CLASS_PRINTER_FLAG_LOCK 0x1u 113 114 115 /* Define Printer Class structure. */ 116 117 typedef struct UX_HOST_CLASS_PRINTER_STRUCT 118 { 119 120 struct UX_HOST_CLASS_PRINTER_STRUCT 121 *ux_host_class_printer_next_instance; 122 UX_HOST_CLASS *ux_host_class_printer_class; 123 UX_DEVICE *ux_host_class_printer_device; 124 UX_INTERFACE *ux_host_class_printer_interface; 125 UX_ENDPOINT *ux_host_class_printer_bulk_out_endpoint; 126 UX_ENDPOINT *ux_host_class_printer_bulk_in_endpoint; 127 UINT ux_host_class_printer_state; 128 UCHAR ux_host_class_printer_name[UX_HOST_CLASS_PRINTER_NAME_LENGTH]; 129 #if !defined(UX_HOST_STANDALONE) 130 UX_SEMAPHORE ux_host_class_printer_semaphore; 131 #else 132 UCHAR *ux_host_class_printer_allocated; 133 ULONG ux_host_class_printer_flags; 134 UINT ux_host_class_printer_status; 135 UCHAR ux_host_class_printer_enum_state; 136 UCHAR ux_host_class_printer_read_state; 137 UCHAR ux_host_class_printer_write_state; 138 UCHAR ux_host_class_printer_next_state; 139 #endif 140 } UX_HOST_CLASS_PRINTER; 141 142 143 #if !defined(UX_HOST_STANDALONE) 144 #define _ux_host_class_printer_unlock(printer) _ux_host_semaphore_put(&(printer) -> ux_host_class_printer_semaphore) 145 #else 146 #define _ux_host_class_printer_unlock(printer) do { (printer)->ux_host_class_printer_flags &= ~UX_HOST_CLASS_PRINTER_FLAG_LOCK; } while(0) 147 #endif 148 149 150 /* Define Printer Class function prototypes. */ 151 152 UINT _ux_host_class_printer_activate(UX_HOST_CLASS_COMMAND *command); 153 UINT _ux_host_class_printer_configure(UX_HOST_CLASS_PRINTER *printer); 154 UINT _ux_host_class_printer_deactivate(UX_HOST_CLASS_COMMAND *command); 155 UINT _ux_host_class_printer_endpoints_get(UX_HOST_CLASS_PRINTER *printer); 156 UINT _ux_host_class_printer_entry(UX_HOST_CLASS_COMMAND *command); 157 UINT _ux_host_class_printer_name_get(UX_HOST_CLASS_PRINTER *printer); 158 UINT _ux_host_class_printer_device_id_get(UX_HOST_CLASS_PRINTER *printer, UCHAR *descriptor_buffer, ULONG length); 159 UINT _ux_host_class_printer_read (UX_HOST_CLASS_PRINTER *printer, UCHAR *data_pointer, 160 ULONG requested_length, ULONG *actual_length); 161 UINT _ux_host_class_printer_soft_reset(UX_HOST_CLASS_PRINTER *printer); 162 UINT _ux_host_class_printer_status_get(UX_HOST_CLASS_PRINTER *printer, ULONG *printer_status); 163 UINT _ux_host_class_printer_write(UX_HOST_CLASS_PRINTER *printer, UCHAR * data_pointer, 164 ULONG requested_length, ULONG *actual_length); 165 166 // UINT _uxe_host_class_printer_activate(UX_HOST_CLASS_COMMAND *command); 167 UINT _uxe_host_class_printer_name_get(UX_HOST_CLASS_PRINTER *printer); 168 UINT _uxe_host_class_printer_device_id_get(UX_HOST_CLASS_PRINTER *printer, UCHAR *descriptor_buffer, ULONG length); 169 UINT _uxe_host_class_printer_read (UX_HOST_CLASS_PRINTER *printer, UCHAR *data_pointer, 170 ULONG requested_length, ULONG *actual_length); 171 UINT _uxe_host_class_printer_soft_reset(UX_HOST_CLASS_PRINTER *printer); 172 UINT _uxe_host_class_printer_status_get(UX_HOST_CLASS_PRINTER *printer, ULONG *printer_status); 173 UINT _uxe_host_class_printer_write(UX_HOST_CLASS_PRINTER *printer, UCHAR * data_pointer, 174 ULONG requested_length, ULONG *actual_length); 175 176 /* Define Printer Class API prototypes. */ 177 #if defined(UX_HOST_CLASS_PRINTER_ENABLE_ERROR_CHECKING) 178 179 #define ux_host_class_printer_entry _ux_host_class_printer_entry 180 #define ux_host_class_printer_activate _ux_host_class_printer_activate 181 #define ux_host_class_printer_name_get _uxe_host_class_printer_name_get 182 #define ux_host_class_printer_device_id_get _uxe_host_class_printer_device_id_get 183 #define ux_host_class_printer_read _uxe_host_class_printer_read 184 #define ux_host_class_printer_soft_reset _uxe_host_class_printer_soft_reset 185 #define ux_host_class_printer_status_get _uxe_host_class_printer_status_get 186 #define ux_host_class_printer_write _uxe_host_class_printer_write 187 188 #else 189 190 #define ux_host_class_printer_entry _ux_host_class_printer_entry 191 #define ux_host_class_printer_activate _ux_host_class_printer_activate 192 #define ux_host_class_printer_name_get _ux_host_class_printer_name_get 193 #define ux_host_class_printer_device_id_get _ux_host_class_printer_device_id_get 194 #define ux_host_class_printer_read _ux_host_class_printer_read 195 #define ux_host_class_printer_soft_reset _ux_host_class_printer_soft_reset 196 #define ux_host_class_printer_status_get _ux_host_class_printer_status_get 197 #define ux_host_class_printer_write _ux_host_class_printer_write 198 199 #endif /* UX_HOST_CLASS_PRINTER_ENABLE_ERROR_CHECKING */ 200 201 /* Determine if a C++ compiler is being used. If so, complete the standard 202 C conditional started above. */ 203 #ifdef __cplusplus 204 } 205 #endif 206 207 #endif 208