2 * @brief Host mode driver for the library USB Still Image Class driver
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * Copyright(C) Dean Camera, 2011, 2012
\r
7 * All rights reserved.
\r
10 * Software that is described herein is for illustrative purposes only
\r
11 * which provides customers with programming information regarding the
\r
12 * LPC products. This software is supplied "AS IS" without any warranties of
\r
13 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
14 * all warranties, express or implied, including all implied warranties of
\r
15 * merchantability, fitness for a particular purpose and non-infringement of
\r
16 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
17 * or liability for the use of the software, conveys no license or rights under any
\r
18 * patent, copyright, mask work right, or any other intellectual property rights in
\r
19 * or to any products. NXP Semiconductors reserves the right to make changes
\r
20 * in the software without notification. NXP Semiconductors also makes no
\r
21 * representation or warranty that such application will be suitable for the
\r
22 * specified use without further testing or modification.
\r
25 * Permission to use, copy, modify, and distribute this software and its
\r
26 * documentation is hereby granted, under NXP Semiconductors' and its
\r
27 * licensor's relevant copyrights in the software, without fee, provided that it
\r
28 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
29 * copyright, permission, and disclaimer notice must appear in all copies of
\r
33 /** @ingroup Group_USBClassSI
\r
34 * @defgroup Group_USBClassStillImageHost Still Image Class Host Mode Driver
\r
36 * @section Sec_Dependencies Module Source Dependencies
\r
37 * The following files must be built with any user project that uses this module:
\r
38 * - LPCUSBlib/Drivers/USB/Class/Host/StillImage.c <i>(Makefile source module name: LPCUSBlib_SRC_USBCLASS)</i>
\r
40 * @section Sec_ModDescription Module Description
\r
41 * Host Mode USB Class driver framework interface, for the Still Image USB Class driver.
\r
46 #ifndef __SI_CLASS_HOST_H__
\r
47 #define __SI_CLASS_HOST_H__
\r
50 #include "../../USB.h"
\r
51 #include "../Common/StillImageClassCommon.h"
\r
53 /* Enable C linkage for C++ Compilers: */
\r
54 #if defined(__cplusplus)
\r
58 /* Preprocessor Checks: */
\r
59 #if !defined(__INCLUDE_FROM_SI_DRIVER)
\r
60 #error Do not include this file directly. Include LPCUSBlib/Drivers/USB.h instead.
\r
63 /* Public Interface - May be used in end-application: */
\r
65 /** Error code for some Still Image Host functions, indicating a logical (and not hardware) error. */
\r
66 #define SI_ERROR_LOGICAL_CMD_FAILED 0x80
\r
69 /** @brief Still Image Class Host Mode Configuration and State Structure.
\r
71 * Class state structure. An instance of this structure should be made within the user application,
\r
72 * and passed to each of the Still Image class driver functions as the \c SIInterfaceInfo parameter. This
\r
73 * stores each Still Image interface's configuration and state information.
\r
79 uint8_t DataINPipeNumber; /**< Pipe number of the Still Image interface's IN data pipe. */
\r
80 bool DataINPipeDoubleBank; /**< Indicates if the Still Image interface's IN data pipe should use double banking. */
\r
82 uint8_t DataOUTPipeNumber; /**< Pipe number of the Still Image interface's OUT data pipe. */
\r
83 bool DataOUTPipeDoubleBank; /**< Indicates if the Still Image interface's OUT data pipe should use double banking. */
\r
85 uint8_t EventsPipeNumber; /**< Pipe number of the Still Image interface's IN events endpoint, if used. */
\r
86 bool EventsPipeDoubleBank; /**< Indicates if the Still Image interface's events data pipe should use double banking. */
\r
87 uint8_t PortNumber; /**< Port number that this interface is running.
\r
89 } Config; /**< Config data for the USB class interface within the device. All elements in this section
\r
90 * <b>must</b> be set or the interface will fail to enumerate and operate correctly.
\r
94 bool IsActive; /**< Indicates if the current interface instance is connected to an attached device, valid
\r
95 * after @ref SI_Host_ConfigurePipes() is called and the Host state machine is in the
\r
98 uint8_t InterfaceNumber; /**< Interface index of the Still Image interface within the attached device. */
\r
100 uint16_t DataINPipeSize; /**< Size in bytes of the Still Image interface's IN data pipe. */
\r
101 uint16_t DataOUTPipeSize; /**< Size in bytes of the Still Image interface's OUT data pipe. */
\r
102 uint16_t EventsPipeSize; /**< Size in bytes of the Still Image interface's IN events pipe. */
\r
104 bool IsSessionOpen; /**< Indicates if a PIMA session is currently open with the attached device. */
\r
105 uint32_t TransactionID; /**< Transaction ID for the next transaction to send to the device. */
\r
106 } State; /**< State data for the USB class interface within the device. All elements in this section
\r
107 * <b>may</b> be set to initial values, but may also be ignored to default to sane values when
\r
108 * the interface is enumerated.
\r
110 } USB_ClassInfo_SI_Host_t;
\r
113 /** Enum for the possible error codes returned by the @ref SI_Host_ConfigurePipes() function. */
\r
114 enum SI_Host_EnumerationFailure_ErrorCodes_t
\r
116 SI_ENUMERROR_NoError = 0, /**< Configuration Descriptor was processed successfully. */
\r
117 SI_ENUMERROR_InvalidConfigDescriptor = 1, /**< The device returned an invalid Configuration Descriptor. */
\r
118 SI_ENUMERROR_NoCompatibleInterfaceFound = 2, /**< A compatible Still Image interface was not found in the device's
\r
119 * Configuration Descriptor.
\r
121 SI_ENUMERROR_PipeConfigurationFailed = 3, /**< One or more pipes for the specified interface could not be configured correctly. */
\r
124 /* Function Prototypes: */
\r
125 /** @brief Host interface configuration routine, to configure a given Still Image host interface instance using the
\r
126 * Configuration Descriptor read from an attached USB device. This function automatically updates the given Still
\r
127 * Image Host instance's state values and configures the pipes required to communicate with the interface if it is
\r
128 * found within the device. This should be called once after the stack has enumerated the attached device, while
\r
129 * the host state machine is in the Addressed state.
\r
131 * @param SIInterfaceInfo : Pointer to a structure containing a Still Image Class host configuration and state.
\r
132 * @param ConfigDescriptorSize : Length of the attached device's Configuration Descriptor.
\r
133 * @param ConfigDescriptorData : Pointer to a buffer containing the attached device's Configuration Descriptor.
\r
135 * @return A value from the @ref SI_Host_EnumerationFailure_ErrorCodes_t enum.
\r
137 uint8_t SI_Host_ConfigurePipes(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo,
\r
138 uint16_t ConfigDescriptorSize,
\r
139 void* ConfigDescriptorData) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3);
\r
141 /** @brief Opens a new PIMA session with the attached device. This should be used before any session-orientated PIMA commands
\r
142 * are issued to the device. Only one session can be open at the one time.
\r
144 * @pre This function must only be called when the Host state machine is in the @ref HOST_STATE_Configured state or the
\r
147 * @param SIInterfaceInfo : Pointer to a structure containing a Still Image Class host configuration and state.
\r
149 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum, or @ref SI_ERROR_LOGICAL_CMD_FAILED if the device
\r
150 * returned a logical command failure.
\r
152 uint8_t SI_Host_OpenSession(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
\r
154 /** @brief Closes an already opened PIMA session with the attached device. This should be used after all session-orientated
\r
155 * PIMA commands have been issued to the device.
\r
157 * @pre This function must only be called when the Host state machine is in the @ref HOST_STATE_Configured state or the
\r
160 * @param SIInterfaceInfo : Pointer to a structure containing a Still Image Class host configuration and state.
\r
162 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum, or @ref SI_ERROR_LOGICAL_CMD_FAILED if the device
\r
163 * returned a logical command failure.
\r
165 uint8_t SI_Host_CloseSession(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
\r
167 /** @brief Sends a raw PIMA block header to the device, filling out the transaction ID automatically. This can be used to send
\r
168 * arbitrary PIMA blocks to the device with or without parameters.
\r
170 * @pre This function must only be called when the Host state machine is in the @ref HOST_STATE_Configured state or the
\r
173 * @param SIInterfaceInfo : Pointer to a structure containing a Still Image Class host configuration and state.
\r
174 * @param PIMAHeader : Pointer to a PIMA container structure that is to be sent.
\r
176 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum.
\r
178 uint8_t SI_Host_SendBlockHeader(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo,
\r
179 PIMA_Container_t* const PIMAHeader) ATTR_NON_NULL_PTR_ARG(1)
\r
180 ATTR_NON_NULL_PTR_ARG(2);
\r
182 /** @brief Receives a raw PIMA block header from the device. This can be used to receive arbitrary PIMA blocks from the device with
\r
183 * or without parameters.
\r
185 * @pre This function must only be called when the Host state machine is in the @ref HOST_STATE_Configured state or the
\r
188 * @param SIInterfaceInfo : Pointer to a structure containing a Still Image Class host configuration and state.
\r
189 * @param PIMAHeader : Pointer to a PIMA container structure where the received block is to be stored.
\r
191 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum.
\r
193 uint8_t SI_Host_ReceiveBlockHeader(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo,
\r
194 PIMA_Container_t* const PIMAHeader) ATTR_NON_NULL_PTR_ARG(1)
\r
195 ATTR_NON_NULL_PTR_ARG(2);
\r
197 /** @brief Sends a given PIMA command to the attached device, filling out the PIMA command header's Transaction ID automatically.
\r
199 * @pre This function must only be called when the Host state machine is in the @ref HOST_STATE_Configured state or the
\r
202 * @param SIInterfaceInfo : Pointer to a structure containing a Still Image Class host configuration and state.
\r
203 * @param Operation : PIMA operation code to issue to the device.
\r
204 * @param TotalParams : Total number of 32-bit parameters to send to the device in the issued command block.
\r
205 * @param Params : Pointer to an array of 32-bit values containing the parameters to send in the command block.
\r
207 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum, or @ref SI_ERROR_LOGICAL_CMD_FAILED if the device
\r
208 * returned a logical command failure.
\r
210 uint8_t SI_Host_SendCommand(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo,
\r
211 const uint16_t Operation,
\r
212 const uint8_t TotalParams,
\r
213 uint32_t* const Params) ATTR_NON_NULL_PTR_ARG(1);
\r
215 /** @brief Receives and checks a response block from the attached Still Image device, once a command has been issued and all data
\r
216 * associated with the command has been transferred.
\r
218 * @pre This function must only be called when the Host state machine is in the @ref HOST_STATE_Configured state or the
\r
221 * @param SIInterfaceInfo : Pointer to a structure containing a Still Image Class host configuration and state.
\r
223 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum, or @ref SI_ERROR_LOGICAL_CMD_FAILED if the device
\r
224 * returned a logical command failure.
\r
226 uint8_t SI_Host_ReceiveResponse(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
\r
228 /** @brief Indicates if the device has issued a PIMA event block to the host via the asynchronous events pipe.
\r
230 * @pre This function must only be called when the Host state machine is in the @ref HOST_STATE_Configured state or the
\r
233 * @param SIInterfaceInfo : Pointer to a structure containing a Still Image Class host configuration and state.
\r
235 * @return Boolean \c true if an event is waiting to be read, \c false otherwise.
\r
237 bool SI_Host_IsEventReceived(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
\r
239 /** @brief Receives an asynchronous event block from the device via the asynchronous events pipe.
\r
241 * @pre This function must only be called when the Host state machine is in the @ref HOST_STATE_Configured state or the
\r
244 * @param SIInterfaceInfo : Pointer to a structure containing a Still Image Class host configuration and state.
\r
245 * @param PIMAHeader : Pointer to a PIMA container structure where the event should be stored.
\r
247 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum, or @ref SI_ERROR_LOGICAL_CMD_FAILED if the device
\r
248 * returned a logical command failure.
\r
250 uint8_t SI_Host_ReceiveEventHeader(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo,
\r
251 PIMA_Container_t* const PIMAHeader) ATTR_NON_NULL_PTR_ARG(1)
\r
252 ATTR_NON_NULL_PTR_ARG(2);
\r
254 /** @brief Sends arbitrary data to the attached device, for use in the data phase of PIMA commands which require data
\r
255 * transfer beyond the regular PIMA command block parameters.
\r
257 * @pre This function must only be called when the Host state machine is in the @ref HOST_STATE_Configured state or the
\r
260 * @param SIInterfaceInfo : Pointer to a structure containing a Still Image Class host configuration and state.
\r
261 * @param Buffer : Pointer to a buffer where the data to send has been stored.
\r
262 * @param Bytes : Length in bytes of the data in the buffer to send to the attached device.
\r
264 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum.
\r
266 uint8_t SI_Host_SendData(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo,
\r
268 const uint16_t Bytes) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
\r
270 /** @brief Receives arbitrary data from the attached device, for use in the data phase of PIMA commands which require data
\r
271 * transfer beyond the regular PIMA command block parameters.
\r
273 * @pre This function must only be called when the Host state machine is in the @ref HOST_STATE_Configured state or the
\r
276 * @param SIInterfaceInfo : Pointer to a structure containing a Still Image Class host configuration and state.
\r
277 * @param Buffer : Pointer to a buffer where the received data is to be stored.
\r
278 * @param Bytes : Length in bytes of the data to read.
\r
280 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum.
\r
282 uint8_t SI_Host_ReadData(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo,
\r
284 const uint16_t Bytes) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
\r
286 /* Inline Functions: */
\r
287 /** @brief General management task for a given Still Image host class interface, required for the correct operation of the
\r
288 * interface. This should be called frequently in the main program loop, before the master USB management task
\r
289 * @ref USB_USBTask().
\r
291 * @param SIInterfaceInfo : Pointer to a structure containing a Still Image Class host configuration and state.
\r
294 static inline void SI_Host_USBTask(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
\r
295 static inline void SI_Host_USBTask(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo)
\r
297 (void)SIInterfaceInfo;
\r
300 /* Private Interface - For use in library only: */
\r
301 #if !defined(__DOXYGEN__)
\r
303 #define SI_COMMAND_DATA_TIMEOUT_MS 10000
\r
305 /* Function Prototypes: */
\r
306 #if defined(__INCLUDE_FROM_STILLIMAGE_HOST_C)
\r
307 static uint8_t DCOMP_SI_Host_NextSIInterface(void* const CurrentDescriptor)
\r
308 ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
\r
309 static uint8_t DCOMP_SI_Host_NextSIInterfaceEndpoint(void* const CurrentDescriptor)
\r
310 ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
\r
314 /* Disable C linkage for C++ Compilers: */
\r
315 #if defined(__cplusplus)
\r