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 #define UX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "ux_api.h"
28 #include "ux_device_class_printer.h"
29 #include "ux_device_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_device_class_printer_entry                      PORTABLE C      */
37 /*                                                           6.2.1        */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function is the entry point of the printer class. It           */
45 /*    will be called by the device stack enumeration module when the      */
46 /*    host has sent a SET_CONFIGURATION command and the printer interface */
47 /*    needs to be mounted.                                                */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    command                               Pointer to class command      */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    Completion Status                                                   */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _ux_device_class_printer_initialize   Initialize printer class      */
60 /*    _ux_device_class_printer_uninitialize Uninitialize printer class    */
61 /*    _ux_device_class_printer_activate     Activate printer class        */
62 /*    _ux_device_class_printer_deactivate   Deactivate printer class      */
63 /*    _ux_device_class_printer_control_request                            */
64 /*                                          Request control               */
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    Device Stack                                                        */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  01-31-2022     Chaoqiong Xiao           Initial Version 6.1.10        */
75 /*  03-08-2023     Yajun Xia                Modified comment(s),          */
76 /*                                            added error checks support, */
77 /*                                            resulting in version 6.2.1  */
78 /*                                                                        */
79 /**************************************************************************/
_ux_device_class_printer_entry(UX_SLAVE_CLASS_COMMAND * command)80 UINT  _ux_device_class_printer_entry(UX_SLAVE_CLASS_COMMAND *command)
81 {
82 
83 UINT        status;
84 
85 
86     /* The command request will tell us we need to do here, either a enumeration
87        query, an activation or a deactivation.  */
88     switch (command -> ux_slave_class_command_request)
89     {
90 
91     case UX_SLAVE_CLASS_COMMAND_INITIALIZE:
92 
93         /* Call the init function of the Printer class.  */
94 #if defined(UX_DEVICE_CLASS_PRINTER_ENABLE_ERROR_CHECKING)
95         status =  _uxe_device_class_printer_initialize(command);
96 #else
97         status =  _ux_device_class_printer_initialize(command);
98 #endif
99 
100         /* Return the completion status.  */
101         return(status);
102 
103     case UX_SLAVE_CLASS_COMMAND_UNINITIALIZE:
104 
105         /* Call the init function of the Printer class.  */
106         status =  _ux_device_class_printer_uninitialize(command);
107 
108         /* Return the completion status.  */
109         return(status);
110 
111     case UX_SLAVE_CLASS_COMMAND_QUERY:
112 
113         /* Check the CLASS definition in the interface descriptor. */
114         if (command -> ux_slave_class_command_class == UX_DEVICE_CLASS_PRINTER_CLASS &&
115             command -> ux_slave_class_command_subclass == UX_DEVICE_CLASS_PRINTER_SUBCLASS)
116             return(UX_SUCCESS);
117         else
118             return(UX_NO_CLASS_MATCH);
119 
120     case UX_SLAVE_CLASS_COMMAND_ACTIVATE:
121 
122         /* The activate command is used when the host has sent a SET_CONFIGURATION command
123            and this interface has to be mounted. Both Bulk endpoints have to be mounted
124            and the printer thread needs to be activated.  */
125         status =  _ux_device_class_printer_activate(command);
126 
127         /* Return the completion status.  */
128         return(status);
129 
130     case UX_SLAVE_CLASS_COMMAND_DEACTIVATE:
131 
132         /* The deactivate command is used when the device has been extracted.
133            The device endpoints have to be dismounted and the printer thread canceled.  */
134         status =  _ux_device_class_printer_deactivate(command);
135 
136         /* Return the completion status.  */
137         return(status);
138 
139     case UX_SLAVE_CLASS_COMMAND_REQUEST:
140 
141         /* The request command is used when the host sends a command on the control endpoint.  */
142         status = _ux_device_class_printer_control_request(command);
143 
144         /* Return the completion status.  */
145         return(status);
146 
147     default:
148 
149         /* If trace is enabled, insert this event into the trace buffer.  */
150         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
151 
152         /* Return an error.  */
153         return(UX_FUNCTION_NOT_SUPPORTED);
154     }
155 }
156