StillImageClassHost.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2017.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  9. Permission to use, copy, modify, distribute, and sell this
  10. software and its documentation for any purpose is hereby granted
  11. without fee, provided that the above copyright notice appear in
  12. all copies and that both that the copyright notice and this
  13. permission notice and warranty disclaimer appear in supporting
  14. documentation, and that the name of the author not be used in
  15. advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.
  17. The author disclaims all warranties with regard to this
  18. software, including all implied warranties of merchantability
  19. and fitness. In no event shall the author be liable for any
  20. special, indirect or consequential damages or any damages
  21. whatsoever resulting from loss of use, data or profits, whether
  22. in an action of contract, negligence or other tortious action,
  23. arising out of or in connection with the use or performance of
  24. this software.
  25. */
  26. /** \file
  27. * \brief Host mode driver for the library USB Still Image Class driver.
  28. *
  29. * Host mode driver for the library USB Still Image Class driver.
  30. *
  31. * \note This file should not be included directly. It is automatically included as needed by the USB module driver
  32. * dispatch header located in LUFA/Drivers/USB.h.
  33. */
  34. /** \ingroup Group_USBClassSI
  35. * \defgroup Group_USBClassStillImageHost Still Image Class Host Mode Driver
  36. *
  37. * \section Sec_USBClassStillImageHost_Dependencies Module Source Dependencies
  38. * The following files must be built with any user project that uses this module:
  39. * - LUFA/Drivers/USB/Class/Host/StillImageClassHost.c <i>(Makefile source module name: LUFA_SRC_USBCLASS)</i>
  40. *
  41. * \section Sec_USBClassStillImageHost_ModDescription Module Description
  42. * Host Mode USB Class driver framework interface, for the Still Image USB Class driver.
  43. *
  44. * @{
  45. */
  46. #ifndef __SI_CLASS_HOST_H__
  47. #define __SI_CLASS_HOST_H__
  48. /* Includes: */
  49. #include "../../USB.h"
  50. #include "../Common/StillImageClassCommon.h"
  51. /* Enable C linkage for C++ Compilers: */
  52. #if defined(__cplusplus)
  53. extern "C" {
  54. #endif
  55. /* Preprocessor Checks: */
  56. #if !defined(__INCLUDE_FROM_SI_DRIVER)
  57. #error Do not include this file directly. Include LUFA/Drivers/USB.h instead.
  58. #endif
  59. /* Public Interface - May be used in end-application: */
  60. /* Macros: */
  61. /** Error code for some Still Image Host functions, indicating a logical (and not hardware) error. */
  62. #define SI_ERROR_LOGICAL_CMD_FAILED 0x80
  63. /* Type Defines: */
  64. /** \brief Still Image Class Host Mode Configuration and State Structure.
  65. *
  66. * Class state structure. An instance of this structure should be made within the user application,
  67. * and passed to each of the Still Image class driver functions as the \c SIInterfaceInfo parameter. This
  68. * stores each Still Image interface's configuration and state information.
  69. */
  70. typedef struct
  71. {
  72. struct
  73. {
  74. USB_Pipe_Table_t DataINPipe; /**< Data IN Pipe configuration table. */
  75. USB_Pipe_Table_t DataOUTPipe; /**< Data OUT Pipe configuration table. */
  76. USB_Pipe_Table_t EventsPipe; /**< Event notification IN Pipe configuration table. */
  77. } Config; /**< Config data for the USB class interface within the device. All elements in this section
  78. * <b>must</b> be set or the interface will fail to enumerate and operate correctly.
  79. */
  80. struct
  81. {
  82. bool IsActive; /**< Indicates if the current interface instance is connected to an attached device, valid
  83. * after \ref SI_Host_ConfigurePipes() is called and the Host state machine is in the
  84. * Configured state.
  85. */
  86. uint8_t InterfaceNumber; /**< Interface index of the Still Image interface within the attached device. */
  87. bool IsSessionOpen; /**< Indicates if a PIMA session is currently open with the attached device. */
  88. uint32_t TransactionID; /**< Transaction ID for the next transaction to send to the device. */
  89. } State; /**< State data for the USB class interface within the device. All elements in this section
  90. * <b>may</b> be set to initial values, but may also be ignored to default to sane values when
  91. * the interface is enumerated.
  92. */
  93. } USB_ClassInfo_SI_Host_t;
  94. /* Enums: */
  95. /** Enum for the possible error codes returned by the \ref SI_Host_ConfigurePipes() function. */
  96. enum SI_Host_EnumerationFailure_ErrorCodes_t
  97. {
  98. SI_ENUMERROR_NoError = 0, /**< Configuration Descriptor was processed successfully. */
  99. SI_ENUMERROR_InvalidConfigDescriptor = 1, /**< The device returned an invalid Configuration Descriptor. */
  100. SI_ENUMERROR_NoCompatibleInterfaceFound = 2, /**< A compatible Still Image interface was not found in the device's
  101. * Configuration Descriptor.
  102. */
  103. SI_ENUMERROR_PipeConfigurationFailed = 3, /**< One or more pipes for the specified interface could not be configured correctly. */
  104. };
  105. /* Function Prototypes: */
  106. /** Host interface configuration routine, to configure a given Still Image host interface instance using the
  107. * Configuration Descriptor read from an attached USB device. This function automatically updates the given Still
  108. * Image Host instance's state values and configures the pipes required to communicate with the interface if it is
  109. * found within the device. This should be called once after the stack has enumerated the attached device, while
  110. * the host state machine is in the Addressed state.
  111. *
  112. * \param[in,out] SIInterfaceInfo Pointer to a structure containing a Still Image Class host configuration and state.
  113. * \param[in] ConfigDescriptorSize Length of the attached device's Configuration Descriptor.
  114. * \param[in] ConfigDescriptorData Pointer to a buffer containing the attached device's Configuration Descriptor.
  115. *
  116. * \return A value from the \ref SI_Host_EnumerationFailure_ErrorCodes_t enum.
  117. */
  118. uint8_t SI_Host_ConfigurePipes(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo,
  119. uint16_t ConfigDescriptorSize,
  120. void* ConfigDescriptorData) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3);
  121. /** Opens a new PIMA session with the attached device. This should be used before any session-orientated PIMA commands
  122. * are issued to the device. Only one session can be open at the one time.
  123. *
  124. * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
  125. * call will fail.
  126. *
  127. * \param[in,out] SIInterfaceInfo Pointer to a structure containing a Still Image Class host configuration and state.
  128. *
  129. * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum, or \ref SI_ERROR_LOGICAL_CMD_FAILED if the device
  130. * returned a logical command failure.
  131. */
  132. uint8_t SI_Host_OpenSession(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
  133. /** Closes an already opened PIMA session with the attached device. This should be used after all session-orientated
  134. * PIMA commands have been issued to the device.
  135. *
  136. * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
  137. * call will fail.
  138. *
  139. * \param[in,out] SIInterfaceInfo Pointer to a structure containing a Still Image Class host configuration and state.
  140. *
  141. * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum, or \ref SI_ERROR_LOGICAL_CMD_FAILED if the device
  142. * returned a logical command failure.
  143. */
  144. uint8_t SI_Host_CloseSession(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
  145. /** Sends a raw PIMA block header to the device, filling out the transaction ID automatically. This can be used to send
  146. * arbitrary PIMA blocks to the device with or without parameters.
  147. *
  148. * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
  149. * call will fail.
  150. *
  151. * \param[in,out] SIInterfaceInfo Pointer to a structure containing a Still Image Class host configuration and state.
  152. * \param[in] PIMAHeader Pointer to a PIMA container structure that is to be sent.
  153. *
  154. * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
  155. */
  156. uint8_t SI_Host_SendBlockHeader(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo,
  157. PIMA_Container_t* const PIMAHeader) ATTR_NON_NULL_PTR_ARG(1)
  158. ATTR_NON_NULL_PTR_ARG(2);
  159. /** Receives a raw PIMA block header from the device. This can be used to receive arbitrary PIMA blocks from the device with
  160. * or without parameters.
  161. *
  162. * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
  163. * call will fail.
  164. *
  165. * \param[in,out] SIInterfaceInfo Pointer to a structure containing a Still Image Class host configuration and state.
  166. * \param[out] PIMAHeader Pointer to a PIMA container structure where the received block is to be stored.
  167. *
  168. * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
  169. */
  170. uint8_t SI_Host_ReceiveBlockHeader(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo,
  171. PIMA_Container_t* const PIMAHeader) ATTR_NON_NULL_PTR_ARG(1)
  172. ATTR_NON_NULL_PTR_ARG(2);
  173. /** Sends a given PIMA command to the attached device, filling out the PIMA command header's Transaction ID automatically.
  174. *
  175. * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
  176. * call will fail.
  177. *
  178. * \param[in,out] SIInterfaceInfo Pointer to a structure containing a Still Image Class host configuration and state.
  179. * \param[in] Operation PIMA operation code to issue to the device.
  180. * \param[in] TotalParams Total number of 32-bit parameters to send to the device in the issued command block.
  181. * \param[in] Params Pointer to an array of 32-bit values containing the parameters to send in the command block.
  182. *
  183. * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum, or \ref SI_ERROR_LOGICAL_CMD_FAILED if the device
  184. * returned a logical command failure.
  185. */
  186. uint8_t SI_Host_SendCommand(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo,
  187. const uint16_t Operation,
  188. const uint8_t TotalParams,
  189. uint32_t* const Params) ATTR_NON_NULL_PTR_ARG(1);
  190. /** Receives and checks a response block from the attached Still Image device, once a command has been issued and all data
  191. * associated with the command has been transferred.
  192. *
  193. * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
  194. * call will fail.
  195. *
  196. * \param[in,out] SIInterfaceInfo Pointer to a structure containing a Still Image Class host configuration and state.
  197. *
  198. * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum, or \ref SI_ERROR_LOGICAL_CMD_FAILED if the device
  199. * returned a logical command failure.
  200. */
  201. uint8_t SI_Host_ReceiveResponse(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
  202. /** Indicates if the device has issued a PIMA event block to the host via the asynchronous events pipe.
  203. *
  204. * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
  205. * call will fail.
  206. *
  207. * \param[in,out] SIInterfaceInfo Pointer to a structure containing a Still Image Class host configuration and state.
  208. *
  209. * \return Boolean \c true if an event is waiting to be read, \c false otherwise.
  210. */
  211. bool SI_Host_IsEventReceived(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
  212. /** Receives an asynchronous event block from the device via the asynchronous events pipe.
  213. *
  214. * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
  215. * call will fail.
  216. *
  217. * \param[in,out] SIInterfaceInfo Pointer to a structure containing a Still Image Class host configuration and state.
  218. * \param[out] PIMAHeader Pointer to a PIMA container structure where the event should be stored.
  219. *
  220. * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum, or \ref SI_ERROR_LOGICAL_CMD_FAILED if the device
  221. * returned a logical command failure.
  222. */
  223. uint8_t SI_Host_ReceiveEventHeader(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo,
  224. PIMA_Container_t* const PIMAHeader) ATTR_NON_NULL_PTR_ARG(1)
  225. ATTR_NON_NULL_PTR_ARG(2);
  226. /** Sends arbitrary data to the attached device, for use in the data phase of PIMA commands which require data
  227. * transfer beyond the regular PIMA command block parameters.
  228. *
  229. * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
  230. * call will fail.
  231. *
  232. * \param[in,out] SIInterfaceInfo Pointer to a structure containing a Still Image Class host configuration and state.
  233. * \param[in] Buffer Pointer to a buffer where the data to send has been stored.
  234. * \param[in] Bytes Length in bytes of the data in the buffer to send to the attached device.
  235. *
  236. * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
  237. */
  238. uint8_t SI_Host_SendData(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo,
  239. const void* Buffer,
  240. const uint16_t Bytes) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
  241. /** Receives arbitrary data from the attached device, for use in the data phase of PIMA commands which require data
  242. * transfer beyond the regular PIMA command block parameters.
  243. *
  244. * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
  245. * call will fail.
  246. *
  247. * \param[in,out] SIInterfaceInfo Pointer to a structure containing a Still Image Class host configuration and state.
  248. * \param[out] Buffer Pointer to a buffer where the received data is to be stored.
  249. * \param[in] Bytes Length in bytes of the data to read.
  250. *
  251. * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
  252. */
  253. uint8_t SI_Host_ReadData(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo,
  254. void* Buffer,
  255. const uint16_t Bytes) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
  256. /* Inline Functions: */
  257. /** General management task for a given Still Image host class interface, required for the correct operation of the
  258. * interface. This should be called frequently in the main program loop, before the master USB management task
  259. * \ref USB_USBTask().
  260. *
  261. * \param[in,out] SIInterfaceInfo Pointer to a structure containing a Still Image Class host configuration and state.
  262. */
  263. static inline void SI_Host_USBTask(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
  264. static inline void SI_Host_USBTask(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo)
  265. {
  266. (void)SIInterfaceInfo;
  267. }
  268. /* Private Interface - For use in library only: */
  269. #if !defined(__DOXYGEN__)
  270. /* Macros: */
  271. #define SI_COMMAND_DATA_TIMEOUT_MS 10000
  272. /* Function Prototypes: */
  273. #if defined(__INCLUDE_FROM_STILLIMAGE_HOST_C)
  274. static uint8_t DCOMP_SI_Host_NextSIInterface(void* const CurrentDescriptor)
  275. ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
  276. static uint8_t DCOMP_SI_Host_NextSIInterfaceEndpoint(void* const CurrentDescriptor)
  277. ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
  278. #endif
  279. #endif
  280. /* Disable C linkage for C++ Compilers: */
  281. #if defined(__cplusplus)
  282. }
  283. #endif
  284. #endif
  285. /** @} */