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