Keyboard firmwares for Atmel AVR and Cortex-M
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

PipeStream_UC3.h 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2014.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2014 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 Pipe data stream transmission and reception management for the AVR32 UC3 microcontrollers.
  28. * \copydetails Group_PipeStreamRW_UC3
  29. *
  30. * \note This file should not be included directly. It is automatically included as needed by the USB driver
  31. * dispatch header located in LUFA/Drivers/USB/USB.h.
  32. */
  33. /** \ingroup Group_PipeStreamRW
  34. * \defgroup Group_PipeStreamRW_UC3 Read/Write of Multi-Byte Streams (UC3)
  35. * \brief Pipe data stream transmission and reception management for the Atmel AVR32 UC3 architecture.
  36. *
  37. * Functions, macros, variables, enums and types related to data reading and writing of data streams from
  38. * and to pipes.
  39. *
  40. * @{
  41. */
  42. #ifndef __PIPE_STREAM_UC3_H__
  43. #define __PIPE_STREAM_UC3_H__
  44. /* Includes: */
  45. #include "../../../../Common/Common.h"
  46. #include "../USBMode.h"
  47. #include "../USBTask.h"
  48. /* Enable C linkage for C++ Compilers: */
  49. #if defined(__cplusplus)
  50. extern "C" {
  51. #endif
  52. /* Preprocessor Checks: */
  53. #if !defined(__INCLUDE_FROM_USB_DRIVER)
  54. #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
  55. #endif
  56. /* Public Interface - May be used in end-application: */
  57. /* Function Prototypes: */
  58. /** \name Stream functions for null data */
  59. //@{
  60. /** Reads and discards the given number of bytes from the pipe, discarding fully read packets from the host
  61. * as needed. The last packet is not automatically discarded once the remaining bytes has been read; the
  62. * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearIN() macro.
  63. *
  64. * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or
  65. * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer
  66. * will instead be performed as a series of chunks. Each time the pipe bank becomes empty while there is still data
  67. * to process (and after the current packet has been acknowledged) the BytesProcessed location will be updated with
  68. * the total number of bytes processed in the stream, and the function will exit with an error code of
  69. * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to
  70. * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed
  71. * value reaches the total transfer length.
  72. *
  73. * <b>Single Stream Transfer Example:</b>
  74. * \code
  75. * uint8_t ErrorCode;
  76. *
  77. * if ((ErrorCode = Pipe_Discard_Stream(512, NULL)) != PIPE_RWSTREAM_NoError)
  78. * {
  79. * // Stream failed to complete - check ErrorCode here
  80. * }
  81. * \endcode
  82. *
  83. * <b>Partial Stream Transfers Example:</b>
  84. * \code
  85. * uint8_t ErrorCode;
  86. * uint16_t BytesProcessed;
  87. *
  88. * BytesProcessed = 0;
  89. * while ((ErrorCode = Pipe_Discard_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
  90. * {
  91. * // Stream not yet complete - do other actions here, abort if required
  92. * }
  93. *
  94. * if (ErrorCode != PIPE_RWSTREAM_NoError)
  95. * {
  96. * // Stream failed to complete - check ErrorCode here
  97. * }
  98. * \endcode
  99. *
  100. * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
  101. * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
  102. *
  103. * \param[in] Length Number of bytes to discard via the currently selected pipe.
  104. * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
  105. * updated, \c NULL if the entire stream should be processed at once.
  106. *
  107. * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
  108. */
  109. uint8_t Pipe_Discard_Stream(uint16_t Length,
  110. uint16_t* const BytesProcessed);
  111. /** Writes a given number of zeroed bytes to the pipe, sending full pipe packets from the host to the device
  112. * as needed. The last packet is not automatically sent once the remaining bytes has been written; the
  113. * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearOUT() macro.
  114. *
  115. * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or
  116. * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer
  117. * will instead be performed as a series of chunks. Each time the pipe bank becomes full while there is still data
  118. * to process (and after the current packet transmission has been initiated) the BytesProcessed location will be
  119. * updated with the total number of bytes processed in the stream, and the function will exit with an error code of
  120. * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to
  121. * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed
  122. * value reaches the total transfer length.
  123. *
  124. * <b>Single Stream Transfer Example:</b>
  125. * \code
  126. * uint8_t ErrorCode;
  127. *
  128. * if ((ErrorCode = Pipe_Null_Stream(512, NULL)) != PIPE_RWSTREAM_NoError)
  129. * {
  130. * // Stream failed to complete - check ErrorCode here
  131. * }
  132. * \endcode
  133. *
  134. * <b>Partial Stream Transfers Example:</b>
  135. * \code
  136. * uint8_t ErrorCode;
  137. * uint16_t BytesProcessed;
  138. *
  139. * BytesProcessed = 0;
  140. * while ((ErrorCode = Pipe_Null_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
  141. * {
  142. * // Stream not yet complete - do other actions here, abort if required
  143. * }
  144. *
  145. * if (ErrorCode != PIPE_RWSTREAM_NoError)
  146. * {
  147. * // Stream failed to complete - check ErrorCode here
  148. * }
  149. * \endcode
  150. *
  151. * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
  152. * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
  153. *
  154. * \param[in] Length Number of zero bytes to write via the currently selected pipe.
  155. * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
  156. * updated, \c NULL if the entire stream should be processed at once.
  157. *
  158. * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
  159. */
  160. uint8_t Pipe_Null_Stream(uint16_t Length,
  161. uint16_t* const BytesProcessed);
  162. //@}
  163. /** \name Stream functions for RAM source/destination data */
  164. //@{
  165. /** Writes the given number of bytes to the pipe from the given buffer in little endian,
  166. * sending full packets to the device as needed. The last packet filled is not automatically sent;
  167. * the user is responsible for manually sending the last written packet to the host via the
  168. * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
  169. * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
  170. *
  171. * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
  172. * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
  173. * storage location, the transfer will instead be performed as a series of chunks. Each time
  174. * the pipe bank becomes full while there is still data to process (and after the current
  175. * packet transmission has been initiated) the BytesProcessed location will be updated with the
  176. * total number of bytes processed in the stream, and the function will exit with an error code of
  177. * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
  178. * in the user code - to continue the transfer, call the function again with identical parameters
  179. * and it will resume until the BytesProcessed value reaches the total transfer length.
  180. *
  181. * <b>Single Stream Transfer Example:</b>
  182. * \code
  183. * uint8_t DataStream[512];
  184. * uint8_t ErrorCode;
  185. *
  186. * if ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream),
  187. * NULL)) != PIPE_RWSTREAM_NoError)
  188. * {
  189. * // Stream failed to complete - check ErrorCode here
  190. * }
  191. * \endcode
  192. *
  193. * <b>Partial Stream Transfers Example:</b>
  194. * \code
  195. * uint8_t DataStream[512];
  196. * uint8_t ErrorCode;
  197. * uint16_t BytesProcessed;
  198. *
  199. * BytesProcessed = 0;
  200. * while ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream),
  201. * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
  202. * {
  203. * // Stream not yet complete - do other actions here, abort if required
  204. * }
  205. *
  206. * if (ErrorCode != PIPE_RWSTREAM_NoError)
  207. * {
  208. * // Stream failed to complete - check ErrorCode here
  209. * }
  210. * \endcode
  211. *
  212. * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
  213. * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
  214. *
  215. * \param[in] Buffer Pointer to the source data buffer to read from.
  216. * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
  217. * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
  218. * updated, \c NULL if the entire stream should be written at once.
  219. *
  220. * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
  221. */
  222. uint8_t Pipe_Write_Stream_LE(const void* const Buffer,
  223. uint16_t Length,
  224. uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
  225. /** Writes the given number of bytes to the pipe from the given buffer in big endian,
  226. * sending full packets to the device as needed. The last packet filled is not automatically sent;
  227. * the user is responsible for manually sending the last written packet to the host via the
  228. * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
  229. * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
  230. *
  231. * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
  232. * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
  233. *
  234. * \param[in] Buffer Pointer to the source data buffer to read from.
  235. * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
  236. * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
  237. * updated, \c NULL if the entire stream should be written at once.
  238. *
  239. * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
  240. */
  241. uint8_t Pipe_Write_Stream_BE(const void* const Buffer,
  242. uint16_t Length,
  243. uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
  244. /** Reads the given number of bytes from the pipe into the given buffer in little endian,
  245. * sending full packets to the device as needed. The last packet filled is not automatically sent;
  246. * the user is responsible for manually sending the last written packet to the host via the
  247. * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
  248. * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
  249. *
  250. * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
  251. * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
  252. * storage location, the transfer will instead be performed as a series of chunks. Each time
  253. * the pipe bank becomes empty while there is still data to process (and after the current
  254. * packet has been acknowledged) the BytesProcessed location will be updated with the total number
  255. * of bytes processed in the stream, and the function will exit with an error code of
  256. * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
  257. * in the user code - to continue the transfer, call the function again with identical parameters
  258. * and it will resume until the BytesProcessed value reaches the total transfer length.
  259. *
  260. * <b>Single Stream Transfer Example:</b>
  261. * \code
  262. * uint8_t DataStream[512];
  263. * uint8_t ErrorCode;
  264. *
  265. * if ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream),
  266. * NULL)) != PIPE_RWSTREAM_NoError)
  267. * {
  268. * // Stream failed to complete - check ErrorCode here
  269. * }
  270. * \endcode
  271. *
  272. * <b>Partial Stream Transfers Example:</b>
  273. * \code
  274. * uint8_t DataStream[512];
  275. * uint8_t ErrorCode;
  276. * uint16_t BytesProcessed;
  277. *
  278. * BytesProcessed = 0;
  279. * while ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream),
  280. * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
  281. * {
  282. * // Stream not yet complete - do other actions here, abort if required
  283. * }
  284. *
  285. * if (ErrorCode != PIPE_RWSTREAM_NoError)
  286. * {
  287. * // Stream failed to complete - check ErrorCode here
  288. * }
  289. * \endcode
  290. *
  291. * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
  292. * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
  293. *
  294. * \param[out] Buffer Pointer to the source data buffer to write to.
  295. * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
  296. * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
  297. * updated, \c NULL if the entire stream should be read at once.
  298. *
  299. * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
  300. */
  301. uint8_t Pipe_Read_Stream_LE(void* const Buffer,
  302. uint16_t Length,
  303. uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
  304. /** Reads the given number of bytes from the pipe into the given buffer in big endian,
  305. * sending full packets to the device as needed. The last packet filled is not automatically sent;
  306. * the user is responsible for manually sending the last written packet to the host via the
  307. * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
  308. * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
  309. *
  310. * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
  311. * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
  312. *
  313. * \param[out] Buffer Pointer to the source data buffer to write to.
  314. * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
  315. * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
  316. * updated, \c NULL if the entire stream should be read at once.
  317. *
  318. * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
  319. */
  320. uint8_t Pipe_Read_Stream_BE(void* const Buffer,
  321. uint16_t Length,
  322. uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
  323. //@}
  324. /* Disable C linkage for C++ Compilers: */
  325. #if defined(__cplusplus)
  326. }
  327. #endif
  328. #endif
  329. /** @} */