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 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Device Printer Class                                                */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 /**************************************************************************/
23 /*                                                                        */
24 /*  COMPONENT DEFINITION                                   RELEASE        */
25 /*                                                                        */
26 /*    ux_device_class_printer.h                           PORTABLE C      */
27 /*                                                           6.2.1        */
28 /*  AUTHOR                                                                */
29 /*                                                                        */
30 /*    Chaoqiong Xiao, Microsoft Corporation                               */
31 /*                                                                        */
32 /*  DESCRIPTION                                                           */
33 /*                                                                        */
34 /*    This file defines the equivalences for the USBX Device Class        */
35 /*    Printer component.                                                  */
36 /*                                                                        */
37 /*  RELEASE HISTORY                                                       */
38 /*                                                                        */
39 /*    DATE              NAME                      DESCRIPTION             */
40 /*                                                                        */
41 /*  01-31-2022     Chaoqiong Xiao           Initial Version 6.1.10        */
42 /*  04-25-2022     Chaoqiong Xiao           Modified comment(s),          */
43 /*                                            fixed standalone compile,   */
44 /*                                            resulting in version 6.1.11 */
45 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
46 /*                                            resulting in version 6.1.12 */
47 /*  10-31-2022     Yajun xia                Modified comment(s),          */
48 /*                                            added standalone support,   */
49 /*                                            resulting in version 6.2.0  */
50 /*  03-08-2023     Yajun xia                Modified comment(s),          */
51 /*                                            added error checks support, */
52 /*                                            resulting in version 6.2.1  */
53 /*                                                                        */
54 /**************************************************************************/
55 
56 #ifndef UX_DEVICE_CLASS_PRINTER_H
57 #define UX_DEVICE_CLASS_PRINTER_H
58 
59 /* Determine if a C++ compiler is being used.  If so, ensure that standard
60    C is used to process the API information.  */
61 
62 #ifdef   __cplusplus
63 
64 /* Yes, C++ compiler is present.  Use standard C.  */
65 extern   "C" {
66 
67 #endif
68 
69 /* Internal option: enable the basic USBX error checking. This define is typically used
70    while debugging application.  */
71 #if defined(UX_ENABLE_ERROR_CHECKING) && !defined(UX_DEVICE_CLASS_PRINTER_ENABLE_ERROR_CHECKING)
72 #define UX_DEVICE_CLASS_PRINTER_ENABLE_ERROR_CHECKING
73 #endif
74 
75 /* Defined, _write is pending ZLP automatically (complete transfer) after buffer is sent.  */
76 
77 /* #define UX_DEVICE_CLASS_PRINTER_WRITE_AUTO_ZLP  */
78 
79 
80 /* Define Printer Class USB Class constants.  */
81 #define UX_DEVICE_CLASS_PRINTER_CLASS                                    7
82 
83 #define UX_DEVICE_CLASS_PRINTER_SUBCLASS                                 1
84 
85 #define UX_DEVICE_CLASS_PRINTER_PROTOCOL_UNIDIRECTIONAL                  1
86 #define UX_DEVICE_CLASS_PRINTER_PROTOCOL_BIDIRECTIONAL                   2
87 #define UX_DEVICE_CLASS_PRINTER_PROTOCOL_1284_4_COMPATIBLE_BIDIR         3
88 
89 
90 /* Device Printer Requests */
91 #define UX_DEVICE_CLASS_PRINTER_GET_DEVICE_ID                            0x00
92 #define UX_DEVICE_CLASS_PRINTER_GET_PORT_STATUS                          0x01
93 #define UX_DEVICE_CLASS_PRINTER_SOFT_RESET                               0x02
94 
95 
96 /* Printer Port Status.  */
97 #define UX_DEVICE_CLASS_PRINTER_PAPER_EMPTY                             (1u << 5)
98 #define UX_DEVICE_CLASS_PRINTER_SELECT                                  (1u << 4)
99 #define UX_DEVICE_CLASS_PRINTER_NOT_ERROR                               (1u << 3)
100 
101 
102 /* Printer IOCTL code.  */
103 #define UX_DEVICE_CLASS_PRINTER_IOCTL_PORT_STATUS_SET                   1
104 #define UX_DEVICE_CLASS_PRINTER_IOCTL_READ_TIMEOUT_SET                  2
105 #define UX_DEVICE_CLASS_PRINTER_IOCTL_WRITE_TIMEOUT_SET                 3
106 
107 #if defined(UX_DEVICE_STANDALONE)
108 
109 /* Printer read state machine states.  */
110 #define UX_DEVICE_CLASS_PRINTER_READ_START                              (UX_STATE_STEP + 1)
111 #define UX_DEVICE_CLASS_PRINTER_READ_WAIT                               (UX_STATE_STEP + 2)
112 
113 /* Printer write state machine states.  */
114 #define UX_DEVICE_CLASS_PRINTER_WRITE_START                             (UX_STATE_STEP + 1)
115 #define UX_DEVICE_CLASS_PRINTER_WRITE_WAIT                              (UX_STATE_STEP + 2)
116 #endif
117 
118 /* Define Device Printer Class Calling Parameter structure */
119 
120 typedef struct UX_DEVICE_CLASS_PRINTER_PARAMETER_STRUCT
121 {
122     UCHAR                   *ux_device_class_printer_device_id; /* IEEE 1284 string, first 2 big endian length.  */
123     VOID                    (*ux_device_class_printer_instance_activate)(VOID *);
124     VOID                    (*ux_device_class_printer_instance_deactivate)(VOID *);
125     VOID                    (*ux_device_class_printer_soft_reset)(VOID *);
126 } UX_DEVICE_CLASS_PRINTER_PARAMETER;
127 
128 
129 /* Define Printer Class structure.  */
130 
131 typedef struct UX_DEVICE_CLASS_PRINTER_STRUCT
132 {
133     UX_SLAVE_INTERFACE      *ux_device_class_printer_interface;
134     UX_SLAVE_ENDPOINT       *ux_device_class_printer_endpoint_out;
135     UX_SLAVE_ENDPOINT       *ux_device_class_printer_endpoint_in;
136     ULONG                   ux_device_class_printer_port_status;
137     UX_DEVICE_CLASS_PRINTER_PARAMETER
138                             ux_device_class_printer_parameter;
139 #if !defined(UX_DEVICE_STANDALONE)
140     UX_MUTEX                ux_device_class_printer_endpoint_out_mutex;
141     UX_MUTEX                ux_device_class_printer_endpoint_in_mutex;
142 #else
143     UCHAR                  *ux_device_class_printer_read_buffer;
144     ULONG                   ux_device_class_printer_read_requested_length;
145     ULONG                   ux_device_class_printer_read_transfer_length;
146     ULONG                   ux_device_class_printer_read_actual_length;
147     UINT                    ux_device_class_printer_read_status;
148     UINT                    ux_device_class_printer_read_state;
149 
150     UCHAR                  *ux_device_class_printer_write_buffer;
151     ULONG                   ux_device_class_printer_write_transfer_length;
152     ULONG                   ux_device_class_printer_write_host_length;
153     ULONG                   ux_device_class_printer_write_requested_length;
154     ULONG                   ux_device_class_printer_write_actual_length;
155     UINT                    ux_device_class_printer_write_status;
156     UINT                    ux_device_class_printer_write_state;
157 #endif
158 } UX_DEVICE_CLASS_PRINTER;
159 
160 
161 /* Define Device Printer Class prototypes.  */
162 
163 UINT  _ux_device_class_printer_activate(UX_SLAVE_CLASS_COMMAND *command);
164 UINT  _ux_device_class_printer_control_request(UX_SLAVE_CLASS_COMMAND *command);
165 UINT  _ux_device_class_printer_deactivate(UX_SLAVE_CLASS_COMMAND *command);
166 UINT  _ux_device_class_printer_entry(UX_SLAVE_CLASS_COMMAND *command);
167 UINT  _ux_device_class_printer_initialize(UX_SLAVE_CLASS_COMMAND *command);
168 UINT  _ux_device_class_printer_uninitialize(UX_SLAVE_CLASS_COMMAND *command);
169 
170 VOID  _ux_device_class_printer_soft_reset(UX_DEVICE_CLASS_PRINTER *printer);
171 
172 UINT  _ux_device_class_printer_write(UX_DEVICE_CLASS_PRINTER *printer, UCHAR *buffer,
173                                 ULONG requested_length, ULONG *actual_length);
174 UINT  _ux_device_class_printer_read(UX_DEVICE_CLASS_PRINTER *printer, UCHAR *buffer,
175                                 ULONG requested_length, ULONG *actual_length);
176 
177 UINT  _ux_device_class_printer_ioctl(UX_DEVICE_CLASS_PRINTER *printer, ULONG ioctl_function,
178                                     VOID *parameter);
179 #if defined(UX_DEVICE_STANDALONE)
180 UINT  _ux_device_class_printer_write_run(UX_DEVICE_CLASS_PRINTER *printer, UCHAR *buffer,
181                                 ULONG requested_length, ULONG *actual_length);
182 UINT  _ux_device_class_printer_read_run(UX_DEVICE_CLASS_PRINTER *printer, UCHAR *buffer,
183                                 ULONG requested_length, ULONG *actual_length);
184 #endif
185 
186 UINT  _uxe_device_class_printer_initialize(UX_SLAVE_CLASS_COMMAND *command);
187 UINT  _uxe_device_class_printer_read(UX_DEVICE_CLASS_PRINTER *printer, UCHAR *buffer,
188                                 ULONG requested_length, ULONG *actual_length);
189 UINT  _uxe_device_class_printer_write(UX_DEVICE_CLASS_PRINTER *printer, UCHAR *buffer,
190                                 ULONG requested_length, ULONG *actual_length);
191 UINT  _uxe_device_class_printer_ioctl(UX_DEVICE_CLASS_PRINTER *printer, ULONG ioctl_function,
192                                     VOID *parameter);
193 
194 /* Define Device Printer Class API prototypes.  */
195 #if defined(UX_DEVICE_CLASS_PRINTER_ENABLE_ERROR_CHECKING)
196 
197 #define ux_device_class_printer_entry               _ux_device_class_printer_entry
198 #define ux_device_class_printer_read                _uxe_device_class_printer_read
199 #define ux_device_class_printer_write               _uxe_device_class_printer_write
200 #define ux_device_class_printer_ioctl               _uxe_device_class_printer_ioctl
201 
202 #else
203 
204 #define ux_device_class_printer_entry               _ux_device_class_printer_entry
205 #define ux_device_class_printer_read                _ux_device_class_printer_read
206 #define ux_device_class_printer_write               _ux_device_class_printer_write
207 #define ux_device_class_printer_ioctl               _ux_device_class_printer_ioctl
208 
209 #endif
210 
211 #if defined(UX_DEVICE_STANDALONE)
212 #define ux_device_class_printer_read_run            _ux_device_class_printer_read_run
213 #define ux_device_class_printer_write_run           _ux_device_class_printer_write_run
214 #endif
215 
216 /* Determine if a C++ compiler is being used.  If so, complete the standard
217    C conditional started above.  */
218 #ifdef __cplusplus
219 }
220 #endif
221 
222 #endif /* UX_DEVICE_CLASS_PRINTER_H */
223