3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 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.
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
31 /** \ingroup Group_USBClassPrinter
32 * @defgroup Group_USBClassPrinterHost Printer Class Host Mode Driver
34 * \section Sec_Dependencies Module Source Dependencies
35 * The following files must be built with any user project that uses this module:
36 * - LUFA/Drivers/USB/Class/Host/Printer.c
38 * \section Module Description
39 * Host Mode USB Class driver framework interface, for the Printer USB Class driver.
44 #ifndef __PRINTER_CLASS_HOST_H__
45 #define __PRINTER_CLASS_HOST_H__
48 #include "../../USB.h"
49 #include "../Common/Printer.h"
51 /* Enable C linkage for C++ Compilers: */
52 #if defined(__cplusplus)
56 /* Public Interface - May be used in end-application: */
60 /** Class state structure. An instance of this structure should be made within the user application,
61 * and passed to each of the Printer class driver functions as the PRNTInterfaceInfo parameter. This
62 * stores each Printer interface's configuration and state information.
68 uint8_t DataINPipeNumber
; /**< Pipe number of the Printer interface's IN data pipe */
69 uint8_t DataOUTPipeNumber
; /**< Pipe number of the Printer interface's OUT data pipe */
70 } Config
; /**< Config data for the USB class interface within the device. All elements in this section
71 * <b>must</b> be set or the interface will fail to enumerate and operate correctly.
75 bool IsActive
; /**< Indicates if the current interface instance is connected to an attached device, valid
76 * after \ref PRNT_Host_ConfigurePipes() is called and the Host state machine is in the
79 uint8_t InterfaceNumber
; /**< Interface index of the Printer interface within the attached device */
80 uint8_t AlternateSetting
; /**< Alternate setting within the Printer Interface in the attached device */
82 uint16_t DataINPipeSize
; /**< Size in bytes of the Printer interface's IN data pipe */
83 uint16_t DataOUTPipeSize
; /**< Size in bytes of the Printer interface's OUT data pipe */
84 } State
; /**< State data for the USB class interface within the device. All elements in this section
85 * <b>may</b> be set to initial values, but may also be ignored to default to sane values when
86 * the interface is enumerated.
88 } USB_ClassInfo_PRNT_Host_t
;
91 enum PRNTHost_EnumerationFailure_ErrorCodes_t
93 PRNT_ENUMERROR_NoError
= 0, /**< Configuration Descriptor was processed successfully */
94 PRNT_ENUMERROR_InvalidConfigDescriptor
= 1, /**< The device returned an invalid Configuration Descriptor */
95 PRNT_ENUMERROR_NoPrinterInterfaceFound
= 2, /**< A compatible Printer interface was not found in the device's Configuration Descriptor */
96 PRNT_ENUMERROR_EndpointsNotFound
= 3, /**< Compatible Printer endpoints were not found in the device's interfaces */
99 /* Function Prototypes: */
100 /** General management task for a given Printer host class interface, required for the correct operation of
101 * the interface. This should be called frequently in the main program loop, before the master USB management task
102 * \ref USB_USBTask().
104 * \param[in,out] PRNTInterfaceInfo Pointer to a structure containing a Printer Class host configuration and state
106 void PRNT_Host_USBTask(USB_ClassInfo_PRNT_Host_t
* const PRNTInterfaceInfo
) ATTR_NON_NULL_PTR_ARG(1);
109 /** Host interface configuration routine, to configure a given Printer host interface instance using the
110 * Configuration Descriptor read from an attached USB device. This function automatically updates the given Printer
111 * instance's state values and configures the pipes required to communicate with the interface if it is found within
112 * the device. This should be called once after the stack has enumerated the attached device, while the host state
113 * machine is in the Addressed state.
115 * \param[in,out] PRNTInterfaceInfo Pointer to a structure containing a Printer Class host configuration and state
116 * \param[in] ConfigDescriptorSize Length of the attached device's Configuration Descriptor
117 * \param[in] DeviceConfigDescriptor Pointer to a buffer containing the attached device's Configuration Descriptor
119 * \return A value from the \ref PRNTHost_EnumerationFailure_ErrorCodes_t enum
121 uint8_t PRNT_Host_ConfigurePipes(USB_ClassInfo_PRNT_Host_t
* const PRNTInterfaceInfo
, uint16_t ConfigDescriptorSize
,
122 uint8_t* DeviceConfigDescriptor
) ATTR_NON_NULL_PTR_ARG(1, 3);
124 /** Configures the printer to enable Bidirectional mode, if it is not already in this mode. This should be called
125 * once the connected device's configuration has been set, to ensure the printer is ready to accept commands.
127 * \param[in,out] PRNTInterfaceInfo Pointer to a structure containing a Printer Class host configuration and state
129 * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum
131 uint8_t PRNT_Host_SetBidirectionalMode(USB_ClassInfo_PRNT_Host_t
* const PRNTInterfaceInfo
) ATTR_NON_NULL_PTR_ARG(1);
133 /** Retrieves the status of the virtual Printer port's inbound status lines. The result can then be masked against the
134 * PRNT_PORTSTATUS_* macros to determine the printer port's status.
136 * \param[in,out] PRNTInterfaceInfo Pointer to a structure containing a Printer Class host configuration and state
137 * \param[out] PortStatus Location where the retrieved port status should be stored
139 * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum
141 uint8_t PRNT_Host_GetPortStatus(USB_ClassInfo_PRNT_Host_t
* const PRNTInterfaceInfo
, uint8_t* const PortStatus
)
142 ATTR_NON_NULL_PTR_ARG(1, 2);
144 /** Soft-resets the attached printer, readying it for new commands.
146 * \param[in,out] PRNTInterfaceInfo Pointer to a structure containing a Printer Class host configuration and state
148 * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum
150 uint8_t PRNT_Host_SoftReset(USB_ClassInfo_PRNT_Host_t
* const PRNTInterfaceInfo
) ATTR_NON_NULL_PTR_ARG(1);
152 /** Sends the given raw data stream to the attached printer's input endpoint. This should contain commands that the
153 * printer is able to understand - for example, PCL data. Not all printers accept all printer languages; see
154 * \ref PRNT_Host_GetDeviceID() for details on determining acceptable languages for an attached printer.
156 * \param[in,out] PRNTInterfaceInfo Pointer to a structure containing a Printer Class host configuration and state
157 * \param[in] PrinterCommands Pointer to a buffer containing the raw command stream to send to the printer
158 * \param[in] CommandSize Size in bytes of the command stream to be sent
160 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum
162 uint8_t PRNT_Host_SendData(USB_ClassInfo_PRNT_Host_t
* const PRNTInterfaceInfo
, void* PrinterCommands
,
163 uint16_t CommandSize
) ATTR_NON_NULL_PTR_ARG(1, 2);
165 /** Retrieves the attached printer device's ID string, formatted according to IEEE 1284. This string is sent as a
166 * Unicode string from the device and is automatically converted to an ASCII encoded C string by this function, thus
167 * the maximum reportable string length is two less than the size given (to accomodate the Unicode string length
168 * bytes which are removed).
170 * This string, when supported, contains the model, manufacturer and acceptable printer languages for the attached device.
172 * \param[in,out] PRNTInterfaceInfo Pointer to a structure containing a Printer Class host configuration and state
173 * \param[out] DeviceIDString Pointer to a buffer where the Device ID string should be stored, in ASCII format
174 * \param[in] BufferSize Size in bytes of the buffer allocated for the Device ID string
176 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum
178 uint8_t PRNT_Host_GetDeviceID(USB_ClassInfo_PRNT_Host_t
* const PRNTInterfaceInfo
, char* DeviceIDString
,
179 uint16_t BufferSize
) ATTR_NON_NULL_PTR_ARG(1);
181 /* Private Interface - For use in library only: */
182 #if !defined(__DOXYGEN__)
184 #define PRINTER_CLASS 0x07
185 #define PRINTER_SUBCLASS 0x01
186 #define PRINTER_PROTOCOL 0x02
188 #define REQ_GetDeviceID 0
189 #define REQ_GetPortStatus 1
190 #define REQ_SoftReset 2
192 #define PRNT_FOUND_DATAPIPE_IN (1 << 0)
193 #define PRNT_FOUND_DATAPIPE_OUT (1 << 1)
195 /* Function Prototypes: */
196 #if defined(INCLUDE_FROM_PRINTER_CLASS_HOST_C)
197 static uint8_t DComp_NextPRNTInterface(void* const CurrentDescriptor
);
198 static uint8_t DComp_NextPRNTInterfaceEndpoint(void* const CurrentDescriptor
);
202 /* Disable C linkage for C++ Compilers: */
203 #if defined(__cplusplus)