app_usbd_class_base.h 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  1. /**
  2. * Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef APP_USBD_CLASS_BASE_H__
  41. #define APP_USBD_CLASS_BASE_H__
  42. #include <stdint.h>
  43. #include <stddef.h>
  44. #include "app_usbd_types.h"
  45. #include "nrf_drv_usbd.h"
  46. #include "nrf_assert.h"
  47. #include "app_util.h"
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. /**
  52. * @defgroup app_usbd_class_base USBD Class Base module
  53. * @ingroup app_usbd
  54. *
  55. * @brief @tagAPI52840 The base for any class instance is defined in this module.
  56. *
  57. * @details Any class instance must start from base class instance structure.
  58. * This makes them compatible with USBD library independently of the
  59. * implementation details.
  60. * @{
  61. */
  62. /**
  63. * @brief Endpoint configuration.
  64. */
  65. typedef struct
  66. {
  67. nrf_drv_usbd_ep_t address; //!< Endpoint address
  68. } app_usbd_class_ep_conf_t;
  69. /**
  70. * @brief Interface configuration.
  71. */
  72. typedef struct
  73. {
  74. uint8_t number; //!< Interface number
  75. uint8_t ep_cnt; //!< Endpoint number
  76. uint8_t ep_offset; //!< Offset of the first endpoint
  77. /**< Offset in bytes of the first endpoint.
  78. * The offset is calculated from the address of this interface structure
  79. */
  80. } app_usbd_class_iface_conf_t;
  81. /**
  82. * @brief Instance variable data.
  83. */
  84. typedef struct
  85. {
  86. app_usbd_class_inst_t const * p_next; //!< Pointer to the next instance
  87. app_usbd_class_inst_t const * p_sof_next; //!< Pointer to the next SOF event requiring instance
  88. app_usbd_sof_interrupt_handler_t sof_handler; //!< Instance specific SOF interrupt handler
  89. } app_usbd_class_data_t;
  90. /**
  91. * @brief Class descriptor context.
  92. */
  93. typedef struct
  94. {
  95. uint32_t line; //!< Number of line to resume writing descriptors from
  96. uint8_t data_buffer; //!< Data from last call of feeder
  97. } app_usbd_class_descriptor_ctx_t;
  98. /**
  99. * @brief Class descriptor state.
  100. */
  101. typedef struct
  102. {
  103. uint8_t * p_buffer; //!< Pointer to buffer
  104. uint32_t current_size; //!< Current size of descriptor
  105. uint32_t maximum_size; //!< Maximum size of descriptor
  106. app_usbd_class_descriptor_ctx_t * p_context; //!< Pointer to context
  107. } app_usbd_class_descriptor_state_t;
  108. /**
  109. * @brief Class interface function set.
  110. * */
  111. typedef struct {
  112. /**
  113. * @brief Instance callback function.
  114. *
  115. * The function used by every class instance.
  116. * @param[in,out] p_inst Instance of the class.
  117. * @param[in] p_event Event to process.
  118. *
  119. * @return Standard error code.
  120. *
  121. * @note If given event is not supported by class, return @ref NRF_ERROR_NOT_SUPPORTED
  122. */
  123. ret_code_t (* event_handler)(app_usbd_class_inst_t const * const p_inst,
  124. app_usbd_complex_evt_t const * const p_event);
  125. /**
  126. * @brief Instance feed descriptors.
  127. *
  128. * Feeds whole descriptor of the instance.
  129. * @param[in] p_ctx Class descriptor context.
  130. * @param[in,out] p_inst Instance of the class.
  131. * @param[out] p_buff Buffer for descriptor.
  132. * @param[in] max_size Requested size of the descriptor.
  133. *
  134. * @return True if not finished feeding the descriptor, false if done.
  135. */
  136. bool (* feed_descriptors)(app_usbd_class_descriptor_ctx_t * p_ctx,
  137. app_usbd_class_inst_t const * p_inst,
  138. uint8_t * p_buff,
  139. size_t max_size);
  140. /**
  141. * @brief Select interface
  142. *
  143. * Function called when class interface has to be selected.
  144. *
  145. * This function would be called for every interface when:
  146. * - SET_INTERFACE command is processed by the default handler
  147. * - SET_CONFIG(1) command is processed by the default handler
  148. *
  149. * @note Remember to disable all the endpoints that are not used
  150. * in the selected configuration.
  151. * @note If this function pointer is NULL default procedure would
  152. * just enable all the interface endpoints and selecting
  153. * alternate configurations other than 0 would generate error.
  154. * @note Calling the function with alternate setting 0 has to always succeed.
  155. *
  156. * @param[in,out] p_inst Instance of the class
  157. * @param[in] iface_idx Index of the interface inside class structure
  158. * @param[in] alternate Alternate setting that should be selected
  159. *
  160. * @return Function has to return @ref NRF_SUCCESS when it has successfully proceed
  161. * interface selection.
  162. * If it returns @ref NRF_ERROR_NOT_SUPPORTED, default function would be used
  163. * to proceed the request - just like there would be NULL pointer in this field.
  164. * Any other kind of error would make library to STALL the request.
  165. */
  166. ret_code_t (* iface_select)(app_usbd_class_inst_t const * const p_inst,
  167. uint8_t iface_idx,
  168. uint8_t alternate);
  169. /**
  170. * @brief Deselect interface.
  171. *
  172. * Function called when the class interface has to be deselected.
  173. *
  174. * This function would be called for every interface when:
  175. * - Library start internal event is processed by the default handler
  176. * - RESET event is processed by the default handler
  177. * - SET_ADDRESS is processed by the default handler
  178. * - SET_CONFIG(0) is processed by the default handler
  179. *
  180. * @note Just after this function is called all the interface
  181. * endpoints would be disabled.
  182. * This function does not has to take care about it.
  183. * @note If this function pointer is NULL default procedure would
  184. * just disable all the interface endpoints.
  185. *
  186. * @param[in,out] p_inst Instance of the class.
  187. * @param[in] iface_idx Index of the interface inside class structure.
  188. */
  189. void (* iface_deselect)(app_usbd_class_inst_t const * const p_inst, uint8_t iface_idx);
  190. /**
  191. * @brief Get current interface.
  192. *
  193. * Function called when class interface has to return its alternate settings
  194. * in reaction on GET_INTERFACE command.
  195. * It should be defined in a pair with @ref app_usbd_class_methods_t::iface_select.
  196. *
  197. * @param[in] p_inst Instance of the class.
  198. * @param[in] iface_idx Index of the interface inside class structure.
  199. *
  200. * @return Current alternate setting of the selected interface.
  201. *
  202. * @note For the classes that support this function, when an interface that has not alternate
  203. * configurations has been selected this function has to return 0 - default alternate setting.
  204. *
  205. * @note If this function pointer it NULL default procedure would return alternate interface
  206. * value 0.
  207. */
  208. uint8_t (* iface_selection_get)(app_usbd_class_inst_t const * const p_inst, uint8_t iface_idx);
  209. } app_usbd_class_methods_t;
  210. /**
  211. * @brief The instance structure itself.
  212. *
  213. * The structure of base class instance.
  214. */
  215. struct app_usbd_class_inst_s
  216. {
  217. app_usbd_class_data_t * p_data; //!< Pointer to non-constant data
  218. app_usbd_class_methods_t const * p_class_methods; //!< Class interface methods
  219. struct
  220. {
  221. uint8_t cnt; //!< Number of defined interfaces
  222. uint8_t config[]; //!< Interface configuration data followed by endpoint data
  223. } iface; //!< Interface structure
  224. };
  225. /**
  226. * @brief Get total number of interfaces.
  227. *
  228. *
  229. */
  230. static inline uint8_t app_usbd_class_iface_count_get(app_usbd_class_inst_t const * const p_inst)
  231. {
  232. return p_inst->iface.cnt;
  233. }
  234. /**
  235. * @brief Interface accessing function.
  236. *
  237. * Get interface pointer.
  238. * Interfaces create continuous array in the memory so it is possible to get
  239. * interface with index 0 and then just iterate to the next one.
  240. *
  241. * @param p_inst Pointer to the class instance
  242. * @param iface_idx Index of the instance to get.
  243. * This is not the interface identifier.
  244. * Technically it is the index of the interface in the class description array.
  245. * @return Pointer to the interface configuration parameters or NULL if given index is out of interface scope for given class.
  246. */
  247. static inline app_usbd_class_iface_conf_t const * app_usbd_class_iface_get(
  248. app_usbd_class_inst_t const * const p_inst,
  249. uint8_t iface_idx)
  250. {
  251. ASSERT(NULL != p_inst);
  252. if (iface_idx >= (app_usbd_class_iface_count_get(p_inst)))
  253. {
  254. return NULL;
  255. }
  256. app_usbd_class_iface_conf_t const * p_interface =
  257. (app_usbd_class_iface_conf_t const * )(p_inst->iface.config);
  258. return &(p_interface[iface_idx]);
  259. }
  260. /**
  261. * @brief Get interface number.
  262. *
  263. * @param p_iface Pointer to interface structure.
  264. *
  265. * @return Interface number from interface configuration structure.
  266. */
  267. static inline uint8_t app_usbd_class_iface_number_get(
  268. app_usbd_class_iface_conf_t const * const p_iface)
  269. {
  270. return p_iface->number;
  271. }
  272. /**
  273. * @brief Get number of endpoints in interface.
  274. *
  275. * @param p_iface Pointer to interface structure.
  276. *
  277. * @return Number of endpoints used by given interface.
  278. */
  279. static inline uint8_t app_usbd_class_iface_ep_count_get(
  280. app_usbd_class_iface_conf_t const * const p_iface)
  281. {
  282. return p_iface->ep_cnt;
  283. }
  284. /**
  285. * @brief Interface Endpoint accessing function.
  286. *
  287. * @param p_iface Interface configuration pointer.
  288. * @param ep_idx Endpoint index.
  289. *
  290. * @return Endpoint information structure pointer or NULL if given index is outside of endpoints for selected interface.
  291. *
  292. * @sa app_usbd_class_iface_get
  293. */
  294. static inline app_usbd_class_ep_conf_t const * app_usbd_class_iface_ep_get(
  295. app_usbd_class_iface_conf_t const * const p_iface,
  296. uint8_t ep_idx)
  297. {
  298. ASSERT(NULL != p_iface);
  299. if (ep_idx >= p_iface->ep_cnt)
  300. {
  301. return NULL;
  302. }
  303. app_usbd_class_ep_conf_t const * p_ep =
  304. (app_usbd_class_ep_conf_t const * )(((uint8_t const *)p_iface) + p_iface->ep_offset);
  305. return &(p_ep[ep_idx]);
  306. }
  307. /**
  308. * @brief Translate endpoint address to class index.
  309. *
  310. * @param p_iface Interface configuration pointer.
  311. * @param ep_address Endpoint address.
  312. *
  313. * @return Endpoint index or number of endpoints if not found.
  314. *
  315. */
  316. static inline uint8_t app_usbd_class_iface_ep_idx_get(
  317. app_usbd_class_iface_conf_t const * const p_iface,
  318. nrf_drv_usbd_ep_t ep_address)
  319. {
  320. ASSERT(NULL != p_iface);
  321. app_usbd_class_ep_conf_t const * p_ep =
  322. (app_usbd_class_ep_conf_t const * )(((uint8_t const *)p_iface) + p_iface->ep_offset);
  323. uint8_t i;
  324. for (i = 0; i < p_iface->ep_cnt; ++i)
  325. {
  326. if (ep_address == p_ep[i].address)
  327. {
  328. break;
  329. }
  330. }
  331. return i;
  332. }
  333. /**
  334. * @brief Get the selected endpoint address.
  335. *
  336. * @param p_ep Endpoint configuration structure.
  337. *
  338. * @return Endpoint address
  339. */
  340. static inline nrf_drv_usbd_ep_t app_usbd_class_ep_address_get(app_usbd_class_ep_conf_t const * p_ep)
  341. {
  342. return (nrf_drv_usbd_ep_t)p_ep->address;
  343. }
  344. /**
  345. * @brief Get the pointer to the writable instance data.
  346. *
  347. * @param p_inst Instance pointer.
  348. * @return Pointer to writable instance data.
  349. */
  350. static inline app_usbd_class_data_t * app_usbd_class_data_access(
  351. app_usbd_class_inst_t const * const p_inst)
  352. {
  353. return p_inst->p_data;
  354. }
  355. /**
  356. * @name Internal macros for argument mapping
  357. *
  358. * Functions to be used as a mapping macro for @ref MACRO_MAP, @ref MACRO_MAP_FOR or @ref MACRO_MAP_FOR_PARAM
  359. * @{
  360. */
  361. /**
  362. * @brief Count the number of endpoints in given configuration.
  363. *
  364. * Config should be given as a interface configuration in a brackets:
  365. * @code
  366. * (interface_nr, ep1, ep2, ep3)
  367. * @endcode
  368. * Number of endpoints may vary from 0 to a few (technically up to 16, but it seems not to make sense to use more than 4).
  369. * Interface number is always present.
  370. *
  371. * @param iface_config Single interface configuration (in brackets).
  372. *
  373. * @return Number of endpoints in interface. This is computed value - can be used by compiler but not by preprocessor.
  374. */
  375. #define APP_USBD_CLASS_CONF_IFACE_EP_COUNT_(iface_config) \
  376. (NUM_VA_ARGS(BRACKET_EXTRACT(iface_config)) - 1)
  377. /**
  378. * @brief Adds the number of endpoints in given config to the current value.
  379. *
  380. * This is basically @ref APP_USBD_CLASS_CONF_IFACE_EP_COUNT_ with plus sign added.
  381. *
  382. * @param iface_config See parameters documentation in @ref APP_USBD_CLASS_CONF_IFACE_EP_COUNT_
  383. *
  384. * @return Plus sign followed by number of endpoints in interface.
  385. *
  386. * @sa APP_USBD_CLASS_CONF_IFACE_EP_COUNT_
  387. */
  388. #define APP_USBD_CLASS_CONF_IFACE_EP_PLUS_COUNT_(iface_config) \
  389. + APP_USBD_CLASS_CONF_IFACE_EP_COUNT_(iface_config)
  390. /**
  391. * @brief Create variable for endpoint.
  392. */
  393. /**
  394. * @brief Extract endpoints given interface configuration.
  395. *
  396. * This macro gets single endpoint configuration and extracts all the endpoints.
  397. * It also adds comma on the end of extracted endpoints.
  398. * This way when this macro is called few times it generates nice list of all endpoints
  399. * that may be used to array initialization.
  400. *
  401. * @param iface_config Single interface configuration in brackets.
  402. * The format should be similar like described in @ref APP_USBD_CLASS_CONF_IFACE_EP_COUNT_.
  403. */
  404. #define APP_USBD_CLASS_IFACE_EP_EXTRACT_(iface_config) \
  405. CONCAT_2(APP_USBD_CLASS_IFACE_EP_EXTRACT_, \
  406. NUM_VA_ARGS_IS_MORE_THAN_1(BRACKET_EXTRACT(iface_config))) \
  407. (BRACKET_EXTRACT(iface_config))
  408. /**
  409. * @brief Auxiliary macro for @ref APP_USBD_CLASS_IFACE_EP_EXTRACT_
  410. *
  411. * This macro is called when interface has no endpoints.
  412. */
  413. #define APP_USBD_CLASS_IFACE_EP_EXTRACT_0(iface_nr)
  414. /**
  415. * @brief Auxiliary macro for @ref APP_USBD_CLASS_IFACE_EP_EXTRACT_
  416. *
  417. * This macro is called when interface has at least one endpoint.
  418. */
  419. #define APP_USBD_CLASS_IFACE_EP_EXTRACT_1(...) \
  420. APP_USBD_CLASS_IFACE_EP_EXTRACT_1_(__VA_ARGS__)
  421. #define APP_USBD_CLASS_IFACE_EP_EXTRACT_1_(iface_nr, ...) \
  422. MACRO_MAP_REC(APP_USBD_CLASS_IFACE_EP_EXTRACT_1__, __VA_ARGS__)
  423. #define APP_USBD_CLASS_IFACE_EP_EXTRACT_1__(ep) \
  424. {(nrf_drv_usbd_ep_t) (ep)},
  425. /**
  426. * @brief Generate configuration for single interface.
  427. *
  428. * This macro extract configuration for single interface.
  429. * The configuration is inside curly brackets and comma is added on the end.
  430. * This mean it can be directly used to init array of interface configurations.
  431. *
  432. * @param iface_config Single interface configuration.
  433. * @param N Currently processed configuration.
  434. * @param iface_configs All interfaces configuration in brackets.
  435. */
  436. #define APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_(iface_config, N, iface_configs) \
  437. CONCAT_2(APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_, \
  438. NUM_VA_ARGS_IS_MORE_THAN_1(BRACKET_EXTRACT(iface_config))) \
  439. (N, iface_configs, BRACKET_EXTRACT(iface_config))
  440. /**
  441. * @brief Macro used when there was an error extracting number of configs.
  442. *
  443. * Throws a syntax error.
  444. */
  445. #define APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_x(iface_config, N, iface_configs) \
  446. [N] = !!!iface_config!!!
  447. /**
  448. * @brief Auxiliary macro for @ref APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_
  449. *
  450. * This macro is called when interface has no endpoints.
  451. */
  452. #define APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_0(N, iface_configs, iface_nr) \
  453. APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_0_(N, iface_configs, iface_nr)
  454. #define APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_0_(N, iface_configs, iface_nr) \
  455. { .number = iface_nr, .ep_cnt = 0, .ep_offset = 0 },
  456. /**
  457. * @brief Auxiliary macro for @ref APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_
  458. *
  459. * This macro is called when interface has at last one endpoint.
  460. */
  461. #define APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_1(N, iface_configs, ...) \
  462. APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_1_(N, iface_configs, __VA_ARGS__)
  463. #define APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_1_(N, iface_configs, iface_nr, ...) \
  464. { .number = iface_nr, .ep_cnt = NUM_VA_ARGS(__VA_ARGS__), \
  465. .ep_offset = APP_USBD_CLASS_CONF_TOTAL_EP_COUNT_N(N, iface_configs) * \
  466. sizeof(app_usbd_class_ep_conf_t) \
  467. + ((NUM_VA_ARGS(BRACKET_EXTRACT(iface_configs)) - N) * \
  468. sizeof(app_usbd_class_iface_conf_t)) \
  469. },
  470. /** @} */
  471. /**
  472. * @name Macros that uses mapping macros internally
  473. *
  474. * Auxiliary macros that uses mapping macros to make some calculations or realize other functionality.
  475. * Mapped here for easier unit testing and to hide complex mapping functions calling.
  476. * @{
  477. */
  478. /**
  479. * @brief Count total number of endpoints.
  480. *
  481. * @param iface_configs List of interface configurations like explained
  482. * in documentation for @ref APP_USBD_CLASS_INSTANCE_TYPEDEF
  483. *
  484. * @return The equation to calculate the number of endpoints by compiler.
  485. */
  486. #define APP_USBD_CLASS_CONF_TOTAL_EP_COUNT(iface_configs) \
  487. (0 MACRO_MAP(APP_USBD_CLASS_CONF_IFACE_EP_PLUS_COUNT_, BRACKET_EXTRACT(iface_configs)))
  488. /**
  489. * @brief Count total number of endpoint up-to interface index.
  490. *
  491. * The version of @ref APP_USBD_CLASS_CONF_TOTAL_EP_COUNT macro which takes the
  492. * number of interfaces to analyze.
  493. *
  494. * @param N Number of interfaces to analyze.
  495. * @param iface_configs List of interface configurations like explained
  496. * in documentation for @ref APP_USBD_CLASS_INSTANCE_TYPEDEF
  497. *
  498. * @return The equation to calculate the number of endpoints by compiler.
  499. */
  500. #define APP_USBD_CLASS_CONF_TOTAL_EP_COUNT_N(N, iface_configs) \
  501. (0 MACRO_MAP_N(N, APP_USBD_CLASS_CONF_IFACE_EP_PLUS_COUNT_, BRACKET_EXTRACT(iface_configs)))
  502. /**
  503. * @brief Extract configurations for interfaces.
  504. *
  505. * This macro extracts the configurations for every interface.
  506. * Basically uses the @ref APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_ macro on every
  507. * configuration found.
  508. *
  509. * This should generate interface configuration initialization data
  510. * in comma separated initializers in curly braces.
  511. *
  512. * @param iface_configs List of interface configurations like explained
  513. * in documentation for @ref APP_USBD_CLASS_INSTANCE_TYPEDEF
  514. *
  515. * @return Comma separated initialization data for all interfaces.
  516. */
  517. /*lint -emacro( (40), APP_USBD_CLASS_IFACES_CONFIG_EXTRACT) */
  518. #define APP_USBD_CLASS_IFACES_CONFIG_EXTRACT(iface_configs) \
  519. MACRO_MAP_FOR_PARAM(iface_configs, \
  520. APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_, \
  521. BRACKET_EXTRACT(iface_configs))
  522. /**
  523. * @brief Extract all endpoints.
  524. *
  525. * Macro that extracts all endpoints from every interface.
  526. *
  527. * @param iface_configs List of interface configurations like explained
  528. * in documentation for @ref APP_USBD_CLASS_INSTANCE_TYPEDEF
  529. *
  530. * @return Comma separated list of endpoints.
  531. */
  532. /*lint -emacro( (40), APP_USBD_CLASS_IFACES_EP_EXTRACT) */
  533. #define APP_USBD_CLASS_IFACES_EP_EXTRACT(iface_configs) \
  534. MACRO_MAP(APP_USBD_CLASS_IFACE_EP_EXTRACT_, BRACKET_EXTRACT(iface_configs))
  535. /** @} */
  536. /**
  537. * @brief USBD instance of class mnemonic.
  538. *
  539. * Macro that generates mnemonic for the name of the structure that describes instance for selected class.
  540. *
  541. * @param type_name The name of the instance without _t postfix.
  542. *
  543. * @return The name with the right postfix to create the name for the type for the class.
  544. */
  545. #define APP_USBD_CLASS_INSTANCE_TYPE(type_name) CONCAT_2(type_name, _t)
  546. /**
  547. * @brief USBD data for instance class mnemonic.
  548. *
  549. * The mnemonic of the variable type that holds writable part of the class instance.
  550. *
  551. * @param type_name The name of the instance without _t postfix.
  552. *
  553. * @return The name with the right postfix to create the name for the data type for the class.
  554. */
  555. #define APP_USBD_CLASS_DATA_TYPE(type_name) CONCAT_2(type_name, _data_t)
  556. /**
  557. * @brief Declare class specific member of class instance.
  558. *
  559. * @param type Type of the attached class configuration.
  560. *
  561. * @sa APP_USBD_CLASS_INSTANCE_TYPEDEF
  562. */
  563. #define APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC(type) type class_part;
  564. /**
  565. * @brief Used if there is no class specific configuration.
  566. *
  567. * This constant can be used if there is no specific configuration inside created instance.
  568. *
  569. * @sa APP_USBD_CLASS_INSTANCE_TYPEDEF
  570. */
  571. #define APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC_NONE
  572. /**
  573. * @brief Declare class specific member of class data.
  574. *
  575. * @param type Type of the attached class data.
  576. *
  577. * @sa APP_USBD_CLASS_DATA_TYPEDEF
  578. */
  579. #define APP_USBD_CLASS_DATA_SPECIFIC_DEC(type) APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC(type)
  580. /**
  581. * @brief Used if there is no class specific data.
  582. *
  583. * This constant can be used if there is no specific writable data inside created instance.
  584. *
  585. * @sa APP_USBD_CLASS_DATA_TYPEDEF
  586. */
  587. #define APP_USBD_CLASS_DATA_SPECIFIC_DEC_NONE APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC_NONE
  588. /**
  589. * @brief Instance structure declaration.
  590. *
  591. * The macro that declares a variable type that would be used to store given class instance.
  592. * Class instance stores all the data from @ref app_usbd_class_inst_t and overlaid data for specified class.
  593. *
  594. * The structure of interface configuration data:
  595. * @code
  596. * (
  597. * (iface1_nr, (ep1, ep2, ep3)),
  598. (iface2_nr),
  599. (iface3_nr, (ep4))
  600. * )
  601. * @endcode
  602. *
  603. * @param type_name The name of the instance without _t postfix.
  604. * @param interfaces_configs List of interface configurations like explained above.
  605. * @param class_config_dec Result of the macro
  606. * @ref APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC or
  607. * @ref APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC_NONE
  608. *
  609. * @return The definition of the structure type that holds all the required data.
  610. *
  611. * @note It should not be used directly in the final application. See @ref APP_USBD_CLASS_DATA_TYPEDEF instead.
  612. *
  613. * @note APP_USBD_CLASS_DATA_TYPEDEF has to be called first for the compilation to success.
  614. *
  615. * @sa APP_USBD_CLASS_TYPEDEF
  616. */
  617. #define APP_USBD_CLASS_INSTANCE_TYPEDEF(type_name, interfaces_configs, class_config_dec) \
  618. typedef union CONCAT_2(type_name, _u) \
  619. { \
  620. app_usbd_class_inst_t base; \
  621. struct \
  622. { \
  623. APP_USBD_CLASS_DATA_TYPE(type_name) * p_data; \
  624. app_usbd_class_methods_t const * p_class_methods; \
  625. struct \
  626. { \
  627. uint8_t cnt; \
  628. app_usbd_class_iface_conf_t \
  629. config[NUM_VA_ARGS(BRACKET_EXTRACT(interfaces_configs))]; \
  630. app_usbd_class_ep_conf_t \
  631. ep[APP_USBD_CLASS_CONF_TOTAL_EP_COUNT(interfaces_configs)]; \
  632. } iface; \
  633. class_config_dec \
  634. } specific; \
  635. } APP_USBD_CLASS_INSTANCE_TYPE(type_name)
  636. /**
  637. * @brief Same as @ref APP_USBD_CLASS_INSTANCE_TYPEDEF but for class with EP0 only.
  638. */
  639. #define APP_USBD_CLASS_INSTANCE_NO_EP_TYPEDEF(type_name, interfaces_configs, class_config_dec) \
  640. typedef union CONCAT_2(type_name, _u) \
  641. { \
  642. app_usbd_class_inst_t base; \
  643. struct \
  644. { \
  645. APP_USBD_CLASS_DATA_TYPE(type_name) * p_data; \
  646. app_usbd_class_methods_t const * p_class_methods; \
  647. struct \
  648. { \
  649. uint8_t cnt; \
  650. app_usbd_class_iface_conf_t \
  651. config[NUM_VA_ARGS(BRACKET_EXTRACT(interfaces_configs))]; \
  652. } iface; \
  653. class_config_dec \
  654. } specific; \
  655. } APP_USBD_CLASS_INSTANCE_TYPE(type_name)
  656. /**
  657. * @brief Writable data structure declaration.
  658. *
  659. * The macro that declares a variable type that would be used to store given class writable data.
  660. * Writable data contains base part of the type @ref app_usbd_class_data_t followed by
  661. * class specific data.
  662. *
  663. * @param type_name The name of the type without _t postfix.
  664. * @param class_data_dec Result of the macro
  665. * @ref APP_USBD_CLASS_DATA_SPECIFIC_DEC or
  666. * @ref APP_USBD_CLASS_DATA_SPECIFIC_DEC_NONE
  667. *
  668. * @return The definition of the structure type that holds all the required writable data.
  669. *
  670. * @note It should not be used directly in the final application. See @ref APP_USBD_CLASS_DATA_TYPEDEF instead.
  671. *
  672. * @sa APP_USBD_CLASS_TYPEDEF
  673. */
  674. #define APP_USBD_CLASS_DATA_TYPEDEF(type_name, class_data_dec) \
  675. typedef struct \
  676. { \
  677. app_usbd_class_data_t base; \
  678. class_data_dec \
  679. }APP_USBD_CLASS_DATA_TYPE(type_name)
  680. /**
  681. * @brief Declare all data types required by the class instance.
  682. *
  683. * Macro that declares data type first and then instance type.
  684. *
  685. * @param type_name The name of the type without _t postfix.
  686. * @param interface_configs List of interface configurations like in @ref APP_USBD_CLASS_INSTANCE_TYPEDEF.
  687. * @param class_config_dec Result of the macro
  688. * @ref APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC or
  689. * @ref APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC_NONE
  690. * @param class_data_dec Result of the macro
  691. * @ref APP_USBD_CLASS_DATA_SPECIFIC_DEC or
  692. * @ref APP_USBD_CLASS_DATA_SPECIFIC_DEC_NONE
  693. *
  694. * @return Declaration of the data type for the instance and instance itself.
  695. *
  696. * @sa APP_USBD_CLASS_DATA_TYPEDEF
  697. * @sa APP_USBD_CLASS_INSTANCE_TYPEDEF
  698. */
  699. #define APP_USBD_CLASS_TYPEDEF(type_name, interface_configs, class_config_dec, class_data_dec) \
  700. APP_USBD_CLASS_DATA_TYPEDEF(type_name, class_data_dec); \
  701. APP_USBD_CLASS_INSTANCE_TYPEDEF(type_name, interface_configs, class_config_dec)
  702. /**
  703. * @brief Same as @ref APP_USBD_CLASS_TYPEDEF but for class with EP0 only.
  704. */
  705. #define APP_USBD_CLASS_NO_EP_TYPEDEF(type_name, \
  706. interface_configs, \
  707. class_config_dec, \
  708. class_data_dec) \
  709. APP_USBD_CLASS_DATA_TYPEDEF(type_name, class_data_dec); \
  710. APP_USBD_CLASS_INSTANCE_NO_EP_TYPEDEF(type_name, interface_configs, class_config_dec)
  711. /**
  712. * @brief Forward declaration of type defined by @ref APP_USBD_CLASS_TYPEDEF
  713. *
  714. * @param type_name The name of the type without _t postfix.
  715. * */
  716. #define APP_USBD_CLASS_FORWARD(type_name) union CONCAT_2(type_name, _u)
  717. /**
  718. * @brief Generate the initialization data for.
  719. *
  720. * Macro that generates the initialization data for instance.
  721. *
  722. * @param p_ram_data Pointer to writable instance data structure.
  723. * @param class_methods Class methods.
  724. * @param interfaces_configs Exactly the same interface config data that in @ref APP_USBD_CLASS_INSTANCE_TYPEDEF
  725. * @param class_config_part Configuration part. The data should be inside brackets.
  726. * Any data here would be removed from brackets and then put as an initialization
  727. * data for class_part member of instance structure.
  728. *
  729. * @note It should not be used directly in the final application. See @ref APP_USBD_CLASS_INST_DEF instead.
  730. */
  731. #define APP_USBD_CLASS_INSTANCE_INITVAL(p_ram_data, \
  732. class_methods, \
  733. interfaces_configs, \
  734. class_config_part) \
  735. { \
  736. .specific = { \
  737. .p_data = p_ram_data, \
  738. .p_class_methods = class_methods, \
  739. .iface = { \
  740. .cnt = NUM_VA_ARGS(BRACKET_EXTRACT(interfaces_configs)), \
  741. .config = { APP_USBD_CLASS_IFACES_CONFIG_EXTRACT(interfaces_configs) }, \
  742. .ep = { APP_USBD_CLASS_IFACES_EP_EXTRACT(interfaces_configs) } \
  743. }, \
  744. BRACKET_EXTRACT(class_config_part) \
  745. } \
  746. }
  747. /**
  748. * @brief Same as @ref APP_USBD_CLASS_INSTANCE_INITVAL but for class with EP0 only.
  749. */
  750. #define APP_USBD_CLASS_INSTANCE_NO_EP_INITVAL(p_ram_data, \
  751. class_methods, \
  752. interfaces_configs, \
  753. class_config_part) \
  754. { \
  755. .specific = { \
  756. .p_data = p_ram_data, \
  757. .p_class_methods = class_methods, \
  758. .iface = { \
  759. .cnt = NUM_VA_ARGS(BRACKET_EXTRACT(interfaces_configs)), \
  760. .config = { APP_USBD_CLASS_IFACES_CONFIG_EXTRACT(interfaces_configs) } \
  761. }, \
  762. BRACKET_EXTRACT(class_config_part) \
  763. } \
  764. }
  765. /**
  766. * @brief Define the base class instance.
  767. *
  768. * Macro that defines whole instance variable and fill it with initialization data.
  769. *
  770. * The tricky part is @c class_config_part.
  771. * The configuration data here has to be placed inside brackets.
  772. * Then any type of values can be used depending on the type used in @ref APP_USBD_CLASS_TYPEDEF.
  773. * If instance does not has any specyfic data, use just empty bracket here.
  774. * @code
  775. * APP_USBD_CLASS_TYPEDEF(
  776. * some_base_class,
  777. * CLASS_BASE_CONFIGURATION,
  778. * APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC_NONE,
  779. * APP_USBD_CLASS_DATA_SPECIFIC_DEC_NONE
  780. * );
  781. * APP_USBD_CLASS_INST_DEF(
  782. * some_base_class_inst,
  783. * some_base_class,
  784. * base_class_event_handler,
  785. * CLASS_BASE_CONFIGURATION,
  786. * () // Empty configuration
  787. * );
  788. * @endcode
  789. *
  790. * If the type of instance configuration is simple type, just provide initialization value:
  791. * @code
  792. * APP_USBD_CLASS_TYPEDEF(
  793. * some_base_class,
  794. * CLASS_BASE_CONFIGURATION,
  795. * APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC_NONE,
  796. * APP_USBD_CLASS_DATA_SPECIFIC_DEC(uint8_t)
  797. * );
  798. * APP_USBD_CLASS_INST_DEF(
  799. * some_base_class_inst,
  800. * some_base_class,
  801. * base_class_event_handler,
  802. * CLASS_BASE_CONFIGURATION,
  803. * (12) // Example values
  804. * );
  805. * @endcode
  806. *
  807. * If the type of instance configuration is structure, provide initialization value for the whole structure:
  808. * @code
  809. * typedef structure
  810. * {
  811. * uint32_t p1;
  812. * uint8_t p2;
  813. * }my_config_t;
  814. *
  815. * APP_USBD_CLASS_TYPEDEF(
  816. * some_base_class,
  817. * CLASS_BASE_CONFIGURATION,
  818. * APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC_NONE,
  819. * APP_USBD_CLASS_DATA_SPECIFIC_DEC(my_config_t)
  820. * );
  821. * APP_USBD_CLASS_INST_DEF(
  822. * some_base_class_inst,
  823. * some_base_class,
  824. * base_class_event_handler,
  825. * CLASS_BASE_CONFIGURATION,
  826. * ({12, 3}) // Example values
  827. * );
  828. * @endcode
  829. *
  830. * @param instance_name The name of created instance variable.
  831. * It would be constant variable and its type would be app_usbd_class_inst_t.
  832. * @param type_name The name of the variable type. It has to be the same type that was passed to
  833. * @ref APP_USBD_CLASS_TYPEDEF
  834. * @param class_methods Class unified interface.
  835. * @param interfaces_configs The same configuration data that the one passed to @ref APP_USBD_CLASS_TYPEDEF
  836. * @param class_config_part Configuration data to the type that was declared by class_data_dec when calling
  837. * @ref APP_USBD_CLASS_TYPEDEF.
  838. * Configuration data has to be provided in brackets.
  839. * It would be extracted from brackets and placed in initialization part of configuration structure.
  840. * See detailed description of this macro for more informations.
  841. */
  842. #define APP_USBD_CLASS_INST_DEF(instance_name, \
  843. type_name, \
  844. class_methods, \
  845. interfaces_configs, \
  846. class_config_part) \
  847. static APP_USBD_CLASS_DATA_TYPE(type_name) CONCAT_2(instance_name, _data); \
  848. static const APP_USBD_CLASS_INSTANCE_TYPE(type_name) instance_name = \
  849. APP_USBD_CLASS_INSTANCE_INITVAL( \
  850. &CONCAT_2(instance_name, _data), \
  851. class_methods, \
  852. interfaces_configs, \
  853. class_config_part)
  854. /**
  855. * @brief Define the base class instance in global scope.
  856. *
  857. * This is the same macro like @ref APP_USBD_CLASS_INST_DEF but it creates the instance
  858. * without static keyword.
  859. *
  860. * @param instance_name See documentation for @ref APP_USBD_CLASS_INST_DEF
  861. * @param type_name See documentation for @ref APP_USBD_CLASS_INST_DEF
  862. * @param class_methods See documentation for @ref APP_USBD_CLASS_INST_DEF
  863. * @param interfaces_configs See documentation for @ref APP_USBD_CLASS_INST_DEF
  864. * @param class_config_part See documentation for @ref APP_USBD_CLASS_INST_DEF
  865. */
  866. #define APP_USBD_CLASS_INST_GLOBAL_DEF(instance_name, \
  867. type_name, \
  868. class_methods, \
  869. interfaces_configs, \
  870. class_config_part) \
  871. static APP_USBD_CLASS_DATA_TYPE(type_name) CONCAT_2(instance_name, _data); \
  872. const APP_USBD_CLASS_INSTANCE_TYPE(type_name) instance_name = \
  873. APP_USBD_CLASS_INSTANCE_INITVAL( \
  874. &CONCAT_2(instance_name, _data), \
  875. class_methods, \
  876. interfaces_configs, \
  877. class_config_part)
  878. /**
  879. * @brief Same as @ref APP_USBD_CLASS_INST_GLOBAL_DEF but for class with EP0 only.
  880. */
  881. #define APP_USBD_CLASS_INST_NO_EP_GLOBAL_DEF(instance_name, \
  882. type_name, \
  883. class_methods, \
  884. interfaces_configs, \
  885. class_config_part) \
  886. static APP_USBD_CLASS_DATA_TYPE(type_name) CONCAT_2(instance_name, _data); \
  887. const APP_USBD_CLASS_INSTANCE_TYPE(type_name) instance_name = \
  888. APP_USBD_CLASS_INSTANCE_NO_EP_INITVAL( \
  889. &CONCAT_2(instance_name, _data), \
  890. class_methods, \
  891. interfaces_configs, \
  892. class_config_part)
  893. /**
  894. * @brief Access class specific configuration.
  895. *
  896. * Macro that returns class specific configuration.
  897. *
  898. * @param[in] p_inst Instance pointer.
  899. *
  900. * @return A pointer for class specific part of the instance.
  901. *
  902. * @note If macro is used on the instance that has no class specific configuration
  903. * an error would be generated during compilation.
  904. */
  905. #define APP_USBD_CLASS_GET_SPECIFIC_CONFIG(p_inst) (&((p_inst)->specific.class_part))
  906. /**
  907. * @brief Access class specific data.
  908. *
  909. * @param[in] p_inst Instance pointer.
  910. *
  911. * @return A pointer for class specific part of writable data.
  912. *
  913. * @note If macro is used on the instance that has no class specific data
  914. * an error would be generated during compilation.
  915. */
  916. #define APP_USBD_CLASS_GET_SPECIFIC_DATA(p_inst) (&(((p_inst)->specific.p_data)->class_part))
  917. /**
  918. * @brief Macro to get base instance from class specific instance.
  919. *
  920. * This macro may be used on class specific instance to get base instance that
  921. * can be processed by base instance access functions.
  922. * Class specific instance can be just casted to class base instance,
  923. * but then we would totally lost type safety.
  924. *
  925. * A little more safe is to use pointer to base member of class instance.
  926. * This would generate an error when used on any variable that has no base member
  927. * and would generate also error if this base member is wrong type.
  928. */
  929. #define APP_USBD_CLASS_BASE_INSTANCE(p_inst) (&((p_inst)->base))
  930. /*lint -emacro(142 438 616 646, APP_USBD_CLASS_DESCRIPTOR_INIT, APP_USBD_CLASS_DESCRIPTOR_BEGIN, APP_USBD_CLASS_DESCRIPTOR_YIELD, APP_USBD_CLASS_DESCRIPTOR_END, APP_USBD_CLASS_DESCRIPTOR_WRITE)*/
  931. /**
  932. * @brief Initialize class descriptor.
  933. *
  934. * @param[in] p_ctx Class descriptor context.
  935. */
  936. #define APP_USBD_CLASS_DESCRIPTOR_INIT(p_ctx) \
  937. (p_ctx)->line = 0;
  938. /**
  939. * @brief Begin class descriptor.
  940. *
  941. * @param[in] p_ctx Class descriptor context.
  942. * @param[in] p_buff Buffer to write into.
  943. * @param[in] max_size Size of the buffer.
  944. */
  945. #define APP_USBD_CLASS_DESCRIPTOR_BEGIN(p_ctx, p_buff, max_size) \
  946. ASSERT((p_ctx) != NULL); \
  947. app_usbd_class_descriptor_state_t this_descriptor_feed; \
  948. this_descriptor_feed.p_buffer = (p_buff); \
  949. this_descriptor_feed.current_size = 0; \
  950. this_descriptor_feed.maximum_size = (max_size); \
  951. this_descriptor_feed.p_context = (p_ctx); \
  952. switch ((this_descriptor_feed.p_context)->line) \
  953. { \
  954. case 0: \
  955. ;
  956. /**
  957. * @brief Yield class descriptor
  958. *
  959. */
  960. #define APP_USBD_CLASS_DESCRIPTOR_YIELD() \
  961. do \
  962. { \
  963. (this_descriptor_feed.p_context)->line = __LINE__; \
  964. return true; \
  965. case __LINE__: \
  966. ; \
  967. } while (0)
  968. /*lint -emacro(438 527, APP_USBD_CLASS_DESCRIPTOR_END)*/
  969. /**
  970. * @brief End class descriptor.
  971. *
  972. * This function has to be called at the end of class descriptor feeder function.
  973. * No other operations in feeder function can be done after calling it.
  974. */
  975. #define APP_USBD_CLASS_DESCRIPTOR_END() \
  976. APP_USBD_CLASS_DESCRIPTOR_YIELD(); \
  977. } \
  978. (this_descriptor_feed.p_context)->line = 0; \
  979. return false;
  980. /**
  981. * @brief Write descriptor using protothreads.
  982. *
  983. * This function writes one byte to the buffer with offset. If buffer is full
  984. * it yields.
  985. *
  986. * It is used by the class descriptor feeders internally.
  987. *
  988. * @ref APP_USBD_CLASS_DESCRIPTOR_BEGIN has to be called before using this function.
  989. * @ref APP_USBD_CLASS_DESCRIPTOR_END has to be called after last use of this function.
  990. *
  991. * @param data Byte to be written to buffer.
  992. */
  993. #define APP_USBD_CLASS_DESCRIPTOR_WRITE(data) \
  994. do \
  995. { \
  996. (this_descriptor_feed.p_context)->data_buffer = (data); \
  997. if (this_descriptor_feed.current_size >= this_descriptor_feed.maximum_size) \
  998. { \
  999. APP_USBD_CLASS_DESCRIPTOR_YIELD(); \
  1000. } \
  1001. if(this_descriptor_feed.p_buffer != NULL) \
  1002. { \
  1003. *(this_descriptor_feed.p_buffer + this_descriptor_feed.current_size) = \
  1004. (this_descriptor_feed.p_context)->data_buffer; \
  1005. } \
  1006. this_descriptor_feed.current_size++; \
  1007. } while(0);
  1008. /** @} */
  1009. #ifdef __cplusplus
  1010. }
  1011. #endif
  1012. #endif /* APP_USBD_CLASS_BASE_H__ */