dc45780c24fa1991a033591e587e10669de966d9
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Host / Printer.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 /** \file
32 * \brief Host mode driver for the library USB Printer Class driver.
33 *
34 * \note This file should not be included directly. It is automatically included as needed by the class driver
35 * dispatch header located in LUFA/Drivers/USB/Class/Printer.h.
36 */
37
38 /** \ingroup Group_USBClassPrinter
39 * @defgroup Group_USBClassPrinterHost Printer Class Host Mode Driver
40 *
41 * \section Sec_Dependencies Module Source Dependencies
42 * The following files must be built with any user project that uses this module:
43 * - LUFA/Drivers/USB/Class/Host/Printer.c
44 *
45 * \section Module Description
46 * Host Mode USB Class driver framework interface, for the Printer USB Class driver.
47 *
48 * @{
49 */
50
51 #ifndef __PRINTER_CLASS_HOST_H__
52 #define __PRINTER_CLASS_HOST_H__
53
54 /* Includes: */
55 #include "../../USB.h"
56 #include "../Common/Printer.h"
57
58 /* Enable C linkage for C++ Compilers: */
59 #if defined(__cplusplus)
60 extern "C" {
61 #endif
62
63 /* Preprocessor Checks: */
64 #if !defined(__INCLUDE_FROM_PRINTER_DRIVER)
65 #error Do not include this file directly. Include LUFA/Drivers/Class/Printer.h instead.
66 #endif
67
68 /* Public Interface - May be used in end-application: */
69 /* Type Defines: */
70 /** Class state structure. An instance of this structure should be made within the user application,
71 * and passed to each of the Printer class driver functions as the PRNTInterfaceInfo parameter. This
72 * stores each Printer interface's configuration and state information.
73 */
74 typedef struct
75 {
76 const struct
77 {
78 uint8_t DataINPipeNumber; /**< Pipe number of the Printer interface's IN data pipe */
79 bool DataINPipeDoubleBank; /** Indicates if the Printer interface's IN data pipe should use double banking */
80
81 uint8_t DataOUTPipeNumber; /**< Pipe number of the Printer interface's OUT data pipe */
82 bool DataOUTPipeDoubleBank; /** Indicates if the Printer interface's OUT data pipe should use double banking */
83 } Config; /**< Config data for the USB class interface within the device. All elements in this section
84 * <b>must</b> be set or the interface will fail to enumerate and operate correctly.
85 */
86 struct
87 {
88 bool IsActive; /**< Indicates if the current interface instance is connected to an attached device, valid
89 * after \ref PRNT_Host_ConfigurePipes() is called and the Host state machine is in the
90 * Configured state
91 */
92 uint8_t InterfaceNumber; /**< Interface index of the Printer interface within the attached device */
93 uint8_t AlternateSetting; /**< Alternate setting within the Printer Interface in the attached device */
94
95 uint16_t DataINPipeSize; /**< Size in bytes of the Printer interface's IN data pipe */
96 uint16_t DataOUTPipeSize; /**< Size in bytes of the Printer interface's OUT data pipe */
97 } State; /**< State data for the USB class interface within the device. All elements in this section
98 * <b>may</b> be set to initial values, but may also be ignored to default to sane values when
99 * the interface is enumerated.
100 */
101 } USB_ClassInfo_PRNT_Host_t;
102
103 /* Enums: */
104 enum PRNTHost_EnumerationFailure_ErrorCodes_t
105 {
106 PRNT_ENUMERROR_NoError = 0, /**< Configuration Descriptor was processed successfully */
107 PRNT_ENUMERROR_InvalidConfigDescriptor = 1, /**< The device returned an invalid Configuration Descriptor */
108 PRNT_ENUMERROR_NoPrinterInterfaceFound = 2, /**< A compatible Printer interface was not found in the device's Configuration Descriptor */
109 PRNT_ENUMERROR_EndpointsNotFound = 3, /**< Compatible Printer endpoints were not found in the device's interfaces */
110 };
111
112 /* Function Prototypes: */
113 /** Host interface configuration routine, to configure a given Printer host interface instance using the
114 * Configuration Descriptor read from an attached USB device. This function automatically updates the given Printer
115 * instance's state values and configures the pipes required to communicate with the interface if it is found within
116 * the device. This should be called once after the stack has enumerated the attached device, while the host state
117 * machine is in the Addressed state.
118 *
119 * \param[in,out] PRNTInterfaceInfo Pointer to a structure containing a Printer Class host configuration and state
120 * \param[in] ConfigDescriptorSize Length of the attached device's Configuration Descriptor
121 * \param[in] DeviceConfigDescriptor Pointer to a buffer containing the attached device's Configuration Descriptor
122 *
123 * \return A value from the \ref PRNTHost_EnumerationFailure_ErrorCodes_t enum
124 */
125 uint8_t PRNT_Host_ConfigurePipes(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo, uint16_t ConfigDescriptorSize,
126 void* DeviceConfigDescriptor) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3);
127
128 /** Configures the printer to enable Bidirectional mode, if it is not already in this mode. This should be called
129 * once the connected device's configuration has been set, to ensure the printer is ready to accept commands.
130 *
131 * \param[in,out] PRNTInterfaceInfo Pointer to a structure containing a Printer Class host configuration and state
132 *
133 * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum
134 */
135 uint8_t PRNT_Host_SetBidirectionalMode(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
136
137 /** Retrieves the status of the virtual Printer port's inbound status lines. The result can then be masked against the
138 * PRNT_PORTSTATUS_* macros to determine the printer port's status.
139 *
140 * \param[in,out] PRNTInterfaceInfo Pointer to a structure containing a Printer Class host configuration and state
141 * \param[out] PortStatus Location where the retrieved port status should be stored
142 *
143 * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum
144 */
145 uint8_t PRNT_Host_GetPortStatus(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo, uint8_t* const PortStatus)
146 ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
147
148 /** Soft-resets the attached printer, readying it for new commands.
149 *
150 * \param[in,out] PRNTInterfaceInfo Pointer to a structure containing a Printer Class host configuration and state
151 *
152 * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum
153 */
154 uint8_t PRNT_Host_SoftReset(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
155
156 /** Sends the given raw data stream to the attached printer's input endpoint. This should contain commands that the
157 * printer is able to understand - for example, PCL data. Not all printers accept all printer languages; see
158 * \ref PRNT_Host_GetDeviceID() for details on determining acceptable languages for an attached printer.
159 *
160 * \note This function must only be called when the Host state machine is in the HOST_STATE_Configured state or the
161 * call will fail.
162 *
163 * \param[in,out] PRNTInterfaceInfo Pointer to a structure containing a Printer Class host configuration and state
164 * \param[in] PrinterCommands Pointer to a buffer containing the raw command stream to send to the printer
165 * \param[in] CommandSize Size in bytes of the command stream to be sent
166 *
167 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum
168 */
169 uint8_t PRNT_Host_SendData(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo, void* PrinterCommands,
170 uint16_t CommandSize) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
171
172 /** Retrieves the attached printer device's ID string, formatted according to IEEE 1284. This string is sent as a
173 * Unicode string from the device and is automatically converted to an ASCII encoded C string by this function, thus
174 * the maximum reportable string length is two less than the size given (to accommodate the Unicode string length
175 * bytes which are removed).
176 *
177 * This string, when supported, contains the model, manufacturer and acceptable printer languages for the attached device.
178 *
179 * \param[in,out] PRNTInterfaceInfo Pointer to a structure containing a Printer Class host configuration and state
180 * \param[out] DeviceIDString Pointer to a buffer where the Device ID string should be stored, in ASCII format
181 * \param[in] BufferSize Size in bytes of the buffer allocated for the Device ID string
182 *
183 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum
184 */
185 uint8_t PRNT_Host_GetDeviceID(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo, char* DeviceIDString,
186 uint16_t BufferSize) ATTR_NON_NULL_PTR_ARG(1);
187
188 /* Inline Functions: */
189 /** General management task for a given Printer host class interface, required for the correct operation of
190 * the interface. This should be called frequently in the main program loop, before the master USB management task
191 * \ref USB_USBTask().
192 *
193 * \param[in,out] PRNTInterfaceInfo Pointer to a structure containing a Printer Class host configuration and state
194 */
195 static inline void PRNT_Host_USBTask(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo);
196 static inline void PRNT_Host_USBTask(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo)
197 {
198 (void)PRNTInterfaceInfo;
199 }
200
201 /* Private Interface - For use in library only: */
202 #if !defined(__DOXYGEN__)
203 /* Macros: */
204 #define PRINTER_CLASS 0x07
205 #define PRINTER_SUBCLASS 0x01
206 #define PRINTER_PROTOCOL 0x02
207
208 #define REQ_GetDeviceID 0
209 #define REQ_GetPortStatus 1
210 #define REQ_SoftReset 2
211
212 #define PRNT_FOUND_DATAPIPE_IN (1 << 0)
213 #define PRNT_FOUND_DATAPIPE_OUT (1 << 1)
214
215 /* Function Prototypes: */
216 #if defined(__INCLUDE_FROM_PRINTER_CLASS_HOST_C)
217 static uint8_t DComp_NextPRNTInterface(void* const CurrentDescriptor);
218 static uint8_t DComp_NextPRNTInterfaceEndpoint(void* const CurrentDescriptor);
219 #endif
220 #endif
221
222 /* Disable C linkage for C++ Compilers: */
223 #if defined(__cplusplus)
224 }
225 #endif
226
227 #endif
228
229 /** @} */