summaryrefslogtreecommitdiff
path: root/common/usbx_device_classes/inc/ux_device_class_printer.h
blob: 80d79dcc7a0053d8292b3b8aa11d561922b5fa42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/**************************************************************************/
/*                                                                        */
/*       Copyright (c) Microsoft Corporation. All rights reserved.        */
/*                                                                        */
/*       This software is licensed under the Microsoft Software License   */
/*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
/*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
/*       and in the root directory of this software.                      */
/*                                                                        */
/**************************************************************************/

/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/** USBX Component                                                        */
/**                                                                       */
/**   Device Printer Class                                                */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

/**************************************************************************/
/*                                                                        */
/*  COMPONENT DEFINITION                                   RELEASE        */
/*                                                                        */
/*    ux_device_class_printer.h                           PORTABLE C      */
/*                                                           6.2.1        */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Chaoqiong Xiao, Microsoft Corporation                               */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This file defines the equivalences for the USBX Device Class        */
/*    Printer component.                                                  */
/*                                                                        */
/*  RELEASE HISTORY                                                       */
/*                                                                        */
/*    DATE              NAME                      DESCRIPTION             */
/*                                                                        */
/*  01-31-2022     Chaoqiong Xiao           Initial Version 6.1.10        */
/*  04-25-2022     Chaoqiong Xiao           Modified comment(s),          */
/*                                            fixed standalone compile,   */
/*                                            resulting in version 6.1.11 */
/*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
/*                                            resulting in version 6.1.12 */
/*  10-31-2022     Yajun xia                Modified comment(s),          */
/*                                            added standalone support,   */
/*                                            resulting in version 6.2.0  */
/*  03-08-2023     Yajun xia                Modified comment(s),          */
/*                                            added error checks support, */
/*                                            resulting in version 6.2.1  */
/*                                                                        */
/**************************************************************************/

#ifndef UX_DEVICE_CLASS_PRINTER_H
#define UX_DEVICE_CLASS_PRINTER_H

/* Determine if a C++ compiler is being used.  If so, ensure that standard
   C is used to process the API information.  */

#ifdef   __cplusplus

/* Yes, C++ compiler is present.  Use standard C.  */
extern   "C" {

#endif

/* Internal option: enable the basic USBX error checking. This define is typically used
   while debugging application.  */
#if defined(UX_ENABLE_ERROR_CHECKING) && !defined(UX_DEVICE_CLASS_PRINTER_ENABLE_ERROR_CHECKING)
#define UX_DEVICE_CLASS_PRINTER_ENABLE_ERROR_CHECKING
#endif

/* Defined, _write is pending ZLP automatically (complete transfer) after buffer is sent.  */

/* #define UX_DEVICE_CLASS_PRINTER_WRITE_AUTO_ZLP  */


/* Define Printer Class USB Class constants.  */
#define UX_DEVICE_CLASS_PRINTER_CLASS                                    7

#define UX_DEVICE_CLASS_PRINTER_SUBCLASS                                 1

#define UX_DEVICE_CLASS_PRINTER_PROTOCOL_UNIDIRECTIONAL                  1
#define UX_DEVICE_CLASS_PRINTER_PROTOCOL_BIDIRECTIONAL                   2
#define UX_DEVICE_CLASS_PRINTER_PROTOCOL_1284_4_COMPATIBLE_BIDIR         3


/* Device Printer Requests */
#define UX_DEVICE_CLASS_PRINTER_GET_DEVICE_ID                            0x00
#define UX_DEVICE_CLASS_PRINTER_GET_PORT_STATUS                          0x01
#define UX_DEVICE_CLASS_PRINTER_SOFT_RESET                               0x02


/* Printer Port Status.  */
#define UX_DEVICE_CLASS_PRINTER_PAPER_EMPTY                             (1u << 5)
#define UX_DEVICE_CLASS_PRINTER_SELECT                                  (1u << 4)
#define UX_DEVICE_CLASS_PRINTER_NOT_ERROR                               (1u << 3)


/* Printer IOCTL code.  */
#define UX_DEVICE_CLASS_PRINTER_IOCTL_PORT_STATUS_SET                   1
#define UX_DEVICE_CLASS_PRINTER_IOCTL_READ_TIMEOUT_SET                  2
#define UX_DEVICE_CLASS_PRINTER_IOCTL_WRITE_TIMEOUT_SET                 3

#if defined(UX_DEVICE_STANDALONE)

/* Printer read state machine states.  */
#define UX_DEVICE_CLASS_PRINTER_READ_START                              (UX_STATE_STEP + 1)
#define UX_DEVICE_CLASS_PRINTER_READ_WAIT                               (UX_STATE_STEP + 2)

/* Printer write state machine states.  */
#define UX_DEVICE_CLASS_PRINTER_WRITE_START                             (UX_STATE_STEP + 1)
#define UX_DEVICE_CLASS_PRINTER_WRITE_WAIT                              (UX_STATE_STEP + 2)
#endif

/* Define Device Printer Class Calling Parameter structure */

typedef struct UX_DEVICE_CLASS_PRINTER_PARAMETER_STRUCT
{
    UCHAR                   *ux_device_class_printer_device_id; /* IEEE 1284 string, first 2 big endian length.  */
    VOID                    (*ux_device_class_printer_instance_activate)(VOID *);
    VOID                    (*ux_device_class_printer_instance_deactivate)(VOID *);
    VOID                    (*ux_device_class_printer_soft_reset)(VOID *);
} UX_DEVICE_CLASS_PRINTER_PARAMETER;


/* Define Printer Class structure.  */

typedef struct UX_DEVICE_CLASS_PRINTER_STRUCT
{
    UX_SLAVE_INTERFACE      *ux_device_class_printer_interface;
    UX_SLAVE_ENDPOINT       *ux_device_class_printer_endpoint_out;
    UX_SLAVE_ENDPOINT       *ux_device_class_printer_endpoint_in;
    ULONG                   ux_device_class_printer_port_status;
    UX_DEVICE_CLASS_PRINTER_PARAMETER
                            ux_device_class_printer_parameter;
#if !defined(UX_DEVICE_STANDALONE)
    UX_MUTEX                ux_device_class_printer_endpoint_out_mutex;
    UX_MUTEX                ux_device_class_printer_endpoint_in_mutex;
#else
    UCHAR                  *ux_device_class_printer_read_buffer;
    ULONG                   ux_device_class_printer_read_requested_length;
    ULONG                   ux_device_class_printer_read_transfer_length;
    ULONG                   ux_device_class_printer_read_actual_length;
    UINT                    ux_device_class_printer_read_status;
    UINT                    ux_device_class_printer_read_state;

    UCHAR                  *ux_device_class_printer_write_buffer;
    ULONG                   ux_device_class_printer_write_transfer_length;
    ULONG                   ux_device_class_printer_write_host_length;
    ULONG                   ux_device_class_printer_write_requested_length;
    ULONG                   ux_device_class_printer_write_actual_length;
    UINT                    ux_device_class_printer_write_status;
    UINT                    ux_device_class_printer_write_state;
#endif
} UX_DEVICE_CLASS_PRINTER;


/* Define Device Printer Class prototypes.  */

UINT  _ux_device_class_printer_activate(UX_SLAVE_CLASS_COMMAND *command);
UINT  _ux_device_class_printer_control_request(UX_SLAVE_CLASS_COMMAND *command);
UINT  _ux_device_class_printer_deactivate(UX_SLAVE_CLASS_COMMAND *command);
UINT  _ux_device_class_printer_entry(UX_SLAVE_CLASS_COMMAND *command);
UINT  _ux_device_class_printer_initialize(UX_SLAVE_CLASS_COMMAND *command);
UINT  _ux_device_class_printer_uninitialize(UX_SLAVE_CLASS_COMMAND *command);

VOID  _ux_device_class_printer_soft_reset(UX_DEVICE_CLASS_PRINTER *printer);

UINT  _ux_device_class_printer_write(UX_DEVICE_CLASS_PRINTER *printer, UCHAR *buffer,
                                ULONG requested_length, ULONG *actual_length);
UINT  _ux_device_class_printer_read(UX_DEVICE_CLASS_PRINTER *printer, UCHAR *buffer,
                                ULONG requested_length, ULONG *actual_length);

UINT  _ux_device_class_printer_ioctl(UX_DEVICE_CLASS_PRINTER *printer, ULONG ioctl_function,
                                    VOID *parameter);
#if defined(UX_DEVICE_STANDALONE)
UINT  _ux_device_class_printer_write_run(UX_DEVICE_CLASS_PRINTER *printer, UCHAR *buffer,
                                ULONG requested_length, ULONG *actual_length);
UINT  _ux_device_class_printer_read_run(UX_DEVICE_CLASS_PRINTER *printer, UCHAR *buffer,
                                ULONG requested_length, ULONG *actual_length);
#endif

UINT  _uxe_device_class_printer_initialize(UX_SLAVE_CLASS_COMMAND *command);
UINT  _uxe_device_class_printer_read(UX_DEVICE_CLASS_PRINTER *printer, UCHAR *buffer,
                                ULONG requested_length, ULONG *actual_length);
UINT  _uxe_device_class_printer_write(UX_DEVICE_CLASS_PRINTER *printer, UCHAR *buffer,
                                ULONG requested_length, ULONG *actual_length);
UINT  _uxe_device_class_printer_ioctl(UX_DEVICE_CLASS_PRINTER *printer, ULONG ioctl_function,
                                    VOID *parameter);

/* Define Device Printer Class API prototypes.  */
#if defined(UX_DEVICE_CLASS_PRINTER_ENABLE_ERROR_CHECKING)

#define ux_device_class_printer_entry               _ux_device_class_printer_entry
#define ux_device_class_printer_read                _uxe_device_class_printer_read
#define ux_device_class_printer_write               _uxe_device_class_printer_write
#define ux_device_class_printer_ioctl               _uxe_device_class_printer_ioctl

#else

#define ux_device_class_printer_entry               _ux_device_class_printer_entry
#define ux_device_class_printer_read                _ux_device_class_printer_read
#define ux_device_class_printer_write               _ux_device_class_printer_write
#define ux_device_class_printer_ioctl               _ux_device_class_printer_ioctl

#endif

#if defined(UX_DEVICE_STANDALONE)
#define ux_device_class_printer_read_run            _ux_device_class_printer_read_run
#define ux_device_class_printer_write_run           _ux_device_class_printer_write_run
#endif

/* Determine if a C++ compiler is being used.  If so, complete the standard
   C conditional started above.  */
#ifdef __cplusplus
}
#endif

#endif /* UX_DEVICE_CLASS_PRINTER_H */