My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

udc.h 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. /**
  2. * \file
  3. *
  4. * \brief Interface of the USB Device Controller (UDC)
  5. *
  6. * Copyright (c) 2009-2015 Atmel Corporation. All rights reserved.
  7. *
  8. * \asf_license_start
  9. *
  10. * \page License
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. *
  18. * 2. Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. *
  22. * 3. The name of Atmel may not be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * 4. This software may only be redistributed and used in connection with an
  26. * Atmel microcontroller product.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  29. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  30. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  31. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  32. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  36. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * \asf_license_stop
  41. *
  42. */
  43. /*
  44. * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
  45. */
  46. #ifndef _UDC_H_
  47. #define _UDC_H_
  48. #include "conf_usb.h"
  49. #include "usb_protocol.h"
  50. #include "udc_desc.h"
  51. #include "udd.h"
  52. #if USB_DEVICE_VENDOR_ID == 0
  53. # error USB_DEVICE_VENDOR_ID cannot be equal to 0
  54. #endif
  55. #if USB_DEVICE_PRODUCT_ID == 0
  56. # error USB_DEVICE_PRODUCT_ID cannot be equal to 0
  57. #endif
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. /**
  62. * \ingroup usb_device_group
  63. * \defgroup udc_group USB Device Controller (UDC)
  64. *
  65. * The UDC provides a high-level abstraction of the usb device.
  66. * You can use these functions to control the main device state
  67. * (start/attach/wakeup).
  68. *
  69. * \section USB_DEVICE_CONF USB Device Custom configuration
  70. * The following USB Device configuration must be included in the conf_usb.h
  71. * file of the application.
  72. *
  73. * USB_DEVICE_VENDOR_ID (Word)<br>
  74. * Vendor ID provided by USB org (ATMEL 0x03EB).
  75. *
  76. * USB_DEVICE_PRODUCT_ID (Word)<br>
  77. * Product ID (Referenced in usb_atmel.h).
  78. *
  79. * USB_DEVICE_MAJOR_VERSION (Byte)<br>
  80. * Major version of the device
  81. *
  82. * USB_DEVICE_MINOR_VERSION (Byte)<br>
  83. * Minor version of the device
  84. *
  85. * USB_DEVICE_MANUFACTURE_NAME (string)<br>
  86. * ASCII name for the manufacture
  87. *
  88. * USB_DEVICE_PRODUCT_NAME (string)<br>
  89. * ASCII name for the product
  90. *
  91. * USB_DEVICE_SERIAL_NAME (string)<br>
  92. * ASCII name to enable and set a serial number
  93. *
  94. * USB_DEVICE_POWER (Numeric)<br>
  95. * (unit mA) Maximum device power
  96. *
  97. * USB_DEVICE_ATTR (Byte)<br>
  98. * USB attributes available:
  99. * - USB_CONFIG_ATTR_SELF_POWERED
  100. * - USB_CONFIG_ATTR_REMOTE_WAKEUP
  101. * Note: if remote wake enabled then defines remotewakeup callbacks,
  102. * see Table 5-2. External API from UDC - Callback
  103. *
  104. * USB_DEVICE_LOW_SPEED (Only defined)<br>
  105. * Force the USB Device to run in low speed
  106. *
  107. * USB_DEVICE_HS_SUPPORT (Only defined)<br>
  108. * Authorize the USB Device to run in high speed
  109. *
  110. * USB_DEVICE_MAX_EP (Byte)<br>
  111. * Define the maximum endpoint number used by the USB Device.<br>
  112. * This one is already defined in UDI default configuration.
  113. * Ex:
  114. * - When endpoint control 0x00, endpoint 0x01 and
  115. * endpoint 0x82 is used then USB_DEVICE_MAX_EP=2
  116. * - When only endpoint control 0x00 is used then USB_DEVICE_MAX_EP=0
  117. * - When endpoint 0x01 and endpoint 0x81 is used then USB_DEVICE_MAX_EP=1<br>
  118. * (configuration not possible on USBB interface)
  119. * @{
  120. */
  121. /**
  122. * \brief Authorizes the VBUS event
  123. *
  124. * \return true, if the VBUS monitoring is possible.
  125. *
  126. * \section udc_vbus_monitoring VBus monitoring used cases
  127. *
  128. * The VBus monitoring is used only for USB SELF Power application.
  129. *
  130. * - By default the USB device is automatically attached when Vbus is high
  131. * or when USB is start for devices without internal Vbus monitoring.
  132. * conf_usb.h file does not contains define USB_DEVICE_ATTACH_AUTO_DISABLE.
  133. * \code //#define USB_DEVICE_ATTACH_AUTO_DISABLE \endcode
  134. *
  135. * - Add custom VBUS monitoring. conf_usb.h file contains define
  136. * USB_DEVICE_ATTACH_AUTO_DISABLE:
  137. * \code #define USB_DEVICE_ATTACH_AUTO_DISABLE \endcode
  138. * User C file contains:
  139. * \code
  140. // Authorize VBUS monitoring
  141. if (!udc_include_vbus_monitoring()) {
  142. // Implement custom VBUS monitoring via GPIO or other
  143. }
  144. Event_VBUS_present() // VBUS interrupt or GPIO interrupt or other
  145. {
  146. // Attach USB Device
  147. udc_attach();
  148. }
  149. \endcode
  150. *
  151. * - Case of battery charging. conf_usb.h file contains define
  152. * USB_DEVICE_ATTACH_AUTO_DISABLE:
  153. * \code #define USB_DEVICE_ATTACH_AUTO_DISABLE \endcode
  154. * User C file contains:
  155. * \code
  156. Event VBUS present() // VBUS interrupt or GPIO interrupt or ..
  157. {
  158. // Authorize battery charging, but wait key press to start USB.
  159. }
  160. Event Key press()
  161. {
  162. // Stop batteries charging
  163. // Start USB
  164. udc_attach();
  165. }
  166. \endcode
  167. */
  168. static inline bool udc_include_vbus_monitoring(void)
  169. {
  170. return udd_include_vbus_monitoring();
  171. }
  172. /*! \brief Start the USB Device stack
  173. */
  174. void udc_start(void);
  175. /*! \brief Stop the USB Device stack
  176. */
  177. void udc_stop(void);
  178. /**
  179. * \brief Attach device to the bus when possible
  180. *
  181. * \warning If a VBus control is included in driver,
  182. * then it will attach device when an acceptable Vbus
  183. * level from the host is detected.
  184. */
  185. static inline void udc_attach(void)
  186. {
  187. udd_attach();
  188. }
  189. /**
  190. * \brief Detaches the device from the bus
  191. *
  192. * The driver must remove pull-up on USB line D- or D+.
  193. */
  194. static inline void udc_detach(void)
  195. {
  196. udd_detach();
  197. }
  198. /*! \brief The USB driver sends a resume signal called \e "Upstream Resume"
  199. * This is authorized only when the remote wakeup feature is enabled by host.
  200. */
  201. static inline void udc_remotewakeup(void)
  202. {
  203. udd_send_remotewakeup();
  204. }
  205. /**
  206. * \brief Returns a pointer on the current interface descriptor
  207. *
  208. * \return pointer on the current interface descriptor.
  209. */
  210. usb_iface_desc_t UDC_DESC_STORAGE *udc_get_interface_desc(void);
  211. //@}
  212. /**
  213. * \ingroup usb_group
  214. * \defgroup usb_device_group USB Stack Device
  215. *
  216. * This module includes USB Stack Device implementation.
  217. * The stack is divided in three parts:
  218. * - USB Device Controller (UDC) provides USB chapter 9 compliance
  219. * - USB Device Interface (UDI) provides USB Class compliance
  220. * - USB Device Driver (UDD) provides USB Driver for each Atmel MCU
  221. * Many USB Device applications can be implemented on Atmel MCU.
  222. * Atmel provides many application notes for different applications:
  223. * - AVR4900, provides general information about Device Stack
  224. * - AVR4901, explains how to create a new class
  225. * - AVR4902, explains how to create a composite device
  226. * - AVR49xx, all device classes provided in ASF have an application note
  227. *
  228. * A basic USB knowledge is required to understand the USB Device
  229. * Class application notes (HID,MS,CDC,PHDC,...).
  230. * Then, to create an USB device with
  231. * only one class provided by ASF, refer directly to the application note
  232. * corresponding to this USB class. The USB Device application note for
  233. * New Class and Composite is dedicated to advanced USB users.
  234. *
  235. * @{
  236. */
  237. //! @}
  238. #ifdef __cplusplus
  239. }
  240. #endif
  241. /**
  242. * \ingroup udc_group
  243. * \defgroup udc_basic_use_case_setup_prereq USB Device Controller (UDC) - Prerequisites
  244. * Common prerequisites for all USB devices.
  245. *
  246. * This module is based on USB device stack full interrupt driven, and supporting
  247. * \ref sleepmgr_group sleepmgr. For AVR and SAM3/4 devices the \ref clk_group clock services
  248. * is supported. For SAMD devices the \ref asfdoc_sam0_system_clock_group clock driver is supported.
  249. *
  250. * The following procedure must be executed to setup the project correctly:
  251. * - Specify the clock configuration:
  252. * - XMEGA USB devices need 48MHz clock input.\n
  253. * XMEGA USB devices need CPU frequency higher than 12MHz.\n
  254. * You can use either an internal RC48MHz auto calibrated by Start of Frames
  255. * or an external OSC.
  256. * - UC3 and SAM3/4 devices without USB high speed support need 48MHz clock input.\n
  257. * You must use a PLL and an external OSC.
  258. * - UC3 and SAM3/4 devices with USB high speed support need 12MHz clock input.\n
  259. * You must use an external OSC.
  260. * - UC3 devices with USBC hardware need CPU frequency higher than 25MHz.
  261. * - SAMD devices without USB high speed support need 48MHz clock input.\n
  262. * You should use DFLL with USBCRM.
  263. * - In conf_board.h, the define CONF_BOARD_USB_PORT must be added to enable USB lines.
  264. * (Not mandatory for all boards)
  265. * - Enable interrupts
  266. * - Initialize the clock service
  267. *
  268. * The usage of \ref sleepmgr_group sleepmgr service is optional, but recommended to reduce power
  269. * consumption:
  270. * - Initialize the sleep manager service
  271. * - Activate sleep mode when the application is in IDLE state
  272. *
  273. * \subpage udc_conf_clock.
  274. *
  275. * for AVR and SAM3/4 devices, add to the initialization code:
  276. * \code
  277. sysclk_init();
  278. irq_initialize_vectors();
  279. cpu_irq_enable();
  280. board_init();
  281. sleepmgr_init(); // Optional
  282. \endcode
  283. *
  284. * For SAMD devices, add to the initialization code:
  285. * \code
  286. system_init();
  287. irq_initialize_vectors();
  288. cpu_irq_enable();
  289. sleepmgr_init(); // Optional
  290. \endcode
  291. * Add to the main IDLE loop:
  292. * \code
  293. sleepmgr_enter_sleep(); // Optional
  294. \endcode
  295. *
  296. */
  297. /**
  298. * \ingroup udc_group
  299. * \defgroup udc_basic_use_case_setup_code USB Device Controller (UDC) - Example code
  300. * Common example code for all USB devices.
  301. *
  302. * Content of conf_usb.h:
  303. * \code
  304. #define USB_DEVICE_VENDOR_ID 0x03EB
  305. #define USB_DEVICE_PRODUCT_ID 0xXXXX
  306. #define USB_DEVICE_MAJOR_VERSION 1
  307. #define USB_DEVICE_MINOR_VERSION 0
  308. #define USB_DEVICE_POWER 100
  309. #define USB_DEVICE_ATTR USB_CONFIG_ATTR_BUS_POWERED
  310. \endcode
  311. *
  312. * Add to application C-file:
  313. * \code
  314. void usb_init(void)
  315. {
  316. udc_start();
  317. }
  318. \endcode
  319. */
  320. /**
  321. * \ingroup udc_group
  322. * \defgroup udc_basic_use_case_setup_flow USB Device Controller (UDC) - Workflow
  323. * Common workflow for all USB devices.
  324. *
  325. * -# Ensure that conf_usb.h is available and contains the following configuration
  326. * which is the main USB device configuration:
  327. * - \code // Vendor ID provided by USB org (ATMEL 0x03EB)
  328. #define USB_DEVICE_VENDOR_ID 0x03EB // Type Word
  329. // Product ID (Atmel PID referenced in usb_atmel.h)
  330. #define USB_DEVICE_PRODUCT_ID 0xXXXX // Type Word
  331. // Major version of the device
  332. #define USB_DEVICE_MAJOR_VERSION 1 // Type Byte
  333. // Minor version of the device
  334. #define USB_DEVICE_MINOR_VERSION 0 // Type Byte
  335. // Maximum device power (mA)
  336. #define USB_DEVICE_POWER 100 // Type 9-bits
  337. // USB attributes to enable features
  338. #define USB_DEVICE_ATTR USB_CONFIG_ATTR_BUS_POWERED // Flags \endcode
  339. * -# Call the USB device stack start function to enable stack and start USB:
  340. * - \code udc_start(); \endcode
  341. * \note In case of USB dual roles (Device and Host) managed through USB OTG connector
  342. * (USB ID pin), the call of udc_start() must be removed and replaced by uhc_start().
  343. * SeRefer to "AVR4950 section 6.1 Dual roles" for further information about dual roles.
  344. */
  345. /**
  346. * \page udc_conf_clock conf_clock.h examples with USB support
  347. *
  348. * Content of XMEGA conf_clock.h:
  349. * \code
  350. // Configuration based on internal RC:
  351. // USB clock need of 48Mhz
  352. #define CONFIG_USBCLK_SOURCE USBCLK_SRC_RCOSC
  353. #define CONFIG_OSC_RC32_CAL 48000000UL
  354. #define CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC OSC_ID_USBSOF
  355. // CPU clock need of clock > 12MHz to run with USB (Here 24MHz)
  356. #define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_RC32MHZ
  357. #define CONFIG_SYSCLK_PSADIV SYSCLK_PSADIV_2
  358. #define CONFIG_SYSCLK_PSBCDIV SYSCLK_PSBCDIV_1_1
  359. \endcode
  360. *
  361. * Content of conf_clock.h for AT32UC3A0, AT32UC3A1, AT32UC3B devices (USBB):
  362. * \code
  363. // Configuration based on 12MHz external OSC:
  364. #define CONFIG_PLL1_SOURCE PLL_SRC_OSC0
  365. #define CONFIG_PLL1_MUL 8
  366. #define CONFIG_PLL1_DIV 2
  367. #define CONFIG_USBCLK_SOURCE USBCLK_SRC_PLL1
  368. #define CONFIG_USBCLK_DIV 1 // Fusb = Fsys/(2 ^ USB_div)
  369. \endcode
  370. *
  371. * Content of conf_clock.h for AT32UC3A3, AT32UC3A4 devices (USBB with high speed support):
  372. * \code
  373. // Configuration based on 12MHz external OSC:
  374. #define CONFIG_USBCLK_SOURCE USBCLK_SRC_OSC0
  375. #define CONFIG_USBCLK_DIV 1 // Fusb = Fsys/(2 ^ USB_div)
  376. \endcode
  377. *
  378. * Content of conf_clock.h for AT32UC3C, ATUCXXD, ATUCXXL3U, ATUCXXL4U devices (USBC):
  379. * \code
  380. // Configuration based on 12MHz external OSC:
  381. #define CONFIG_PLL1_SOURCE PLL_SRC_OSC0
  382. #define CONFIG_PLL1_MUL 8
  383. #define CONFIG_PLL1_DIV 2
  384. #define CONFIG_USBCLK_SOURCE USBCLK_SRC_PLL1
  385. #define CONFIG_USBCLK_DIV 1 // Fusb = Fsys/(2 ^ USB_div)
  386. // CPU clock need of clock > 25MHz to run with USBC
  387. #define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_PLL1
  388. \endcode
  389. *
  390. * Content of conf_clock.h for SAM3S, SAM3SD, SAM4S devices (UPD: USB Peripheral Device):
  391. * \code
  392. // PLL1 (B) Options (Fpll = (Fclk * PLL_mul) / PLL_div)
  393. #define CONFIG_PLL1_SOURCE PLL_SRC_MAINCK_XTAL
  394. #define CONFIG_PLL1_MUL 16
  395. #define CONFIG_PLL1_DIV 2
  396. // USB Clock Source Options (Fusb = FpllX / USB_div)
  397. #define CONFIG_USBCLK_SOURCE USBCLK_SRC_PLL1
  398. #define CONFIG_USBCLK_DIV 2
  399. \endcode
  400. *
  401. * Content of conf_clock.h for SAM3U device (UPDHS: USB Peripheral Device High Speed):
  402. * \code
  403. // USB Clock Source fixed at UPLL.
  404. \endcode
  405. *
  406. * Content of conf_clock.h for SAM3X, SAM3A devices (UOTGHS: USB OTG High Speed):
  407. * \code
  408. // USB Clock Source fixed at UPLL.
  409. #define CONFIG_USBCLK_SOURCE USBCLK_SRC_UPLL
  410. #define CONFIG_USBCLK_DIV 1
  411. \endcode
  412. *
  413. * Content of conf_clocks.h for SAMD devices (USB):
  414. * \code
  415. // System clock bus configuration
  416. # define CONF_CLOCK_FLASH_WAIT_STATES 2
  417. // USB Clock Source fixed at DFLL.
  418. // SYSTEM_CLOCK_SOURCE_DFLL configuration - Digital Frequency Locked Loop
  419. # define CONF_CLOCK_DFLL_ENABLE true
  420. # define CONF_CLOCK_DFLL_LOOP_MODE SYSTEM_CLOCK_DFLL_LOOP_MODE_USB_RECOVERY
  421. # define CONF_CLOCK_DFLL_ON_DEMAND true
  422. // Set this to true to configure the GCLK when running clocks_init.
  423. // If set to false, none of the GCLK generators will be configured in clocks_init().
  424. # define CONF_CLOCK_CONFIGURE_GCLK true
  425. // Configure GCLK generator 0 (Main Clock)
  426. # define CONF_CLOCK_GCLK_0_ENABLE true
  427. # define CONF_CLOCK_GCLK_0_RUN_IN_STANDBY true
  428. # define CONF_CLOCK_GCLK_0_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_DFLL
  429. # define CONF_CLOCK_GCLK_0_PRESCALER 1
  430. # define CONF_CLOCK_GCLK_0_OUTPUT_ENABLE false
  431. \endcode
  432. */
  433. /**
  434. * \page udc_use_case_1 Change USB speed
  435. *
  436. * In this use case, the USB device is used with different USB speeds.
  437. *
  438. * \section udc_use_case_1_setup Setup steps
  439. *
  440. * Prior to implement this use case, be sure to have already
  441. * apply the UDI module "basic use case".
  442. *
  443. * \section udc_use_case_1_usage Usage steps
  444. *
  445. * \subsection udc_use_case_1_usage_code Example code
  446. * Content of conf_usb.h:
  447. * \code
  448. #if // Low speed
  449. #define USB_DEVICE_LOW_SPEED
  450. // #define USB_DEVICE_HS_SUPPORT
  451. #elif // Full speed
  452. // #define USB_DEVICE_LOW_SPEED
  453. // #define USB_DEVICE_HS_SUPPORT
  454. #elif // High speed
  455. // #define USB_DEVICE_LOW_SPEED
  456. #define USB_DEVICE_HS_SUPPORT
  457. #endif
  458. \endcode
  459. *
  460. * \subsection udc_use_case_1_usage_flow Workflow
  461. * -# Ensure that conf_usb.h is available and contains the following parameters
  462. * required for a USB device low speed (1.5Mbit/s):
  463. * - \code #define USB_DEVICE_LOW_SPEED
  464. //#define USB_DEVICE_HS_SUPPORT \endcode
  465. * -# Ensure that conf_usb.h contains the following parameters
  466. * required for a USB device full speed (12Mbit/s):
  467. * - \code //#define USB_DEVICE_LOW_SPEED
  468. //#define USB_DEVICE_HS_SUPPORT \endcode
  469. * -# Ensure that conf_usb.h contains the following parameters
  470. * required for a USB device high speed (480Mbit/s):
  471. * - \code //#define USB_DEVICE_LOW_SPEED
  472. #define USB_DEVICE_HS_SUPPORT \endcode
  473. */
  474. /**
  475. * \page udc_use_case_2 Use USB strings
  476. *
  477. * In this use case, the usual USB strings is added in the USB device.
  478. *
  479. * \section udc_use_case_2_setup Setup steps
  480. * Prior to implement this use case, be sure to have already
  481. * apply the UDI module "basic use case".
  482. *
  483. * \section udc_use_case_2_usage Usage steps
  484. *
  485. * \subsection udc_use_case_2_usage_code Example code
  486. * Content of conf_usb.h:
  487. * \code
  488. #define USB_DEVICE_MANUFACTURE_NAME "Manufacture name"
  489. #define USB_DEVICE_PRODUCT_NAME "Product name"
  490. #define USB_DEVICE_SERIAL_NAME "12...EF"
  491. \endcode
  492. *
  493. * \subsection udc_use_case_2_usage_flow Workflow
  494. * -# Ensure that conf_usb.h is available and contains the following parameters
  495. * required to enable different USB strings:
  496. * - \code // Static ASCII name for the manufacture
  497. #define USB_DEVICE_MANUFACTURE_NAME "Manufacture name" \endcode
  498. * - \code // Static ASCII name for the product
  499. #define USB_DEVICE_PRODUCT_NAME "Product name" \endcode
  500. * - \code // Static ASCII name to enable and set a serial number
  501. #define USB_DEVICE_SERIAL_NAME "12...EF" \endcode
  502. */
  503. /**
  504. * \page udc_use_case_3 Use USB remote wakeup feature
  505. *
  506. * In this use case, the USB remote wakeup feature is enabled.
  507. *
  508. * \section udc_use_case_3_setup Setup steps
  509. * Prior to implement this use case, be sure to have already
  510. * apply the UDI module "basic use case".
  511. *
  512. * \section udc_use_case_3_usage Usage steps
  513. *
  514. * \subsection udc_use_case_3_usage_code Example code
  515. * Content of conf_usb.h:
  516. * \code
  517. #define USB_DEVICE_ATTR \
  518. (USB_CONFIG_ATTR_REMOTE_WAKEUP | USB_CONFIG_ATTR_..._POWERED)
  519. #define UDC_REMOTEWAKEUP_ENABLE() my_callback_remotewakeup_enable()
  520. extern void my_callback_remotewakeup_enable(void);
  521. #define UDC_REMOTEWAKEUP_DISABLE() my_callback_remotewakeup_disable()
  522. extern void my_callback_remotewakeup_disable(void);
  523. \endcode
  524. *
  525. * Add to application C-file:
  526. * \code
  527. void my_callback_remotewakeup_enable(void)
  528. {
  529. // Enable application wakeup events (e.g. enable GPIO interrupt)
  530. }
  531. void my_callback_remotewakeup_disable(void)
  532. {
  533. // Disable application wakeup events (e.g. disable GPIO interrupt)
  534. }
  535. void my_interrupt_event(void)
  536. {
  537. udc_remotewakeup();
  538. }
  539. \endcode
  540. *
  541. * \subsection udc_use_case_3_usage_flow Workflow
  542. * -# Ensure that conf_usb.h is available and contains the following parameters
  543. * required to enable remote wakeup feature:
  544. * - \code // Authorizes the remote wakeup feature
  545. #define USB_DEVICE_ATTR (USB_CONFIG_ATTR_REMOTE_WAKEUP | USB_CONFIG_ATTR_..._POWERED) \endcode
  546. * - \code // Define callback called when the host enables the remotewakeup feature
  547. #define UDC_REMOTEWAKEUP_ENABLE() my_callback_remotewakeup_enable()
  548. extern void my_callback_remotewakeup_enable(void); \endcode
  549. * - \code // Define callback called when the host disables the remotewakeup feature
  550. #define UDC_REMOTEWAKEUP_DISABLE() my_callback_remotewakeup_disable()
  551. extern void my_callback_remotewakeup_disable(void); \endcode
  552. * -# Send a remote wakeup (USB upstream):
  553. * - \code udc_remotewakeup(); \endcode
  554. */
  555. /**
  556. * \page udc_use_case_5 Bus power application recommendations
  557. *
  558. * In this use case, the USB device BUS power feature is enabled.
  559. * This feature requires a correct power consumption management.
  560. *
  561. * \section udc_use_case_5_setup Setup steps
  562. * Prior to implement this use case, be sure to have already
  563. * apply the UDI module "basic use case".
  564. *
  565. * \section udc_use_case_5_usage Usage steps
  566. *
  567. * \subsection udc_use_case_5_usage_code Example code
  568. * Content of conf_usb.h:
  569. * \code
  570. #define USB_DEVICE_ATTR (USB_CONFIG_ATTR_BUS_POWERED)
  571. #define UDC_SUSPEND_EVENT() user_callback_suspend_action()
  572. extern void user_callback_suspend_action(void)
  573. #define UDC_RESUME_EVENT() user_callback_resume_action()
  574. extern void user_callback_resume_action(void)
  575. \endcode
  576. *
  577. * Add to application C-file:
  578. * \code
  579. void user_callback_suspend_action(void)
  580. {
  581. // Disable hardware component to reduce power consumption
  582. }
  583. void user_callback_resume_action(void)
  584. {
  585. // Re-enable hardware component
  586. }
  587. \endcode
  588. *
  589. * \subsection udc_use_case_5_usage_flow Workflow
  590. * -# Ensure that conf_usb.h is available and contains the following parameters:
  591. * - \code // Authorizes the BUS power feature
  592. #define USB_DEVICE_ATTR (USB_CONFIG_ATTR_BUS_POWERED) \endcode
  593. * - \code // Define callback called when the host suspend the USB line
  594. #define UDC_SUSPEND_EVENT() user_callback_suspend_action()
  595. extern void user_callback_suspend_action(void); \endcode
  596. * - \code // Define callback called when the host or device resume the USB line
  597. #define UDC_RESUME_EVENT() user_callback_resume_action()
  598. extern void user_callback_resume_action(void); \endcode
  599. * -# Reduce power consumption in suspend mode (max. 2.5mA on Vbus):
  600. * - \code void user_callback_suspend_action(void)
  601. {
  602. turn_off_components();
  603. } \endcode
  604. */
  605. /**
  606. * \page udc_use_case_6 USB dynamic serial number
  607. *
  608. * In this use case, the USB serial strings is dynamic.
  609. * For a static serial string refer to \ref udc_use_case_2.
  610. *
  611. * \section udc_use_case_6_setup Setup steps
  612. * Prior to implement this use case, be sure to have already
  613. * apply the UDI module "basic use case".
  614. *
  615. * \section udc_use_case_6_usage Usage steps
  616. *
  617. * \subsection udc_use_case_6_usage_code Example code
  618. * Content of conf_usb.h:
  619. * \code
  620. #define USB_DEVICE_SERIAL_NAME
  621. #define USB_DEVICE_GET_SERIAL_NAME_POINTER serial_number
  622. #define USB_DEVICE_GET_SERIAL_NAME_LENGTH 12
  623. extern uint8_t serial_number[];
  624. \endcode
  625. *
  626. * Add to application C-file:
  627. * \code
  628. uint8_t serial_number[USB_DEVICE_GET_SERIAL_NAME_LENGTH];
  629. void init_build_usb_serial_number(void)
  630. {
  631. serial_number[0] = 'A';
  632. serial_number[1] = 'B';
  633. ...
  634. serial_number[USB_DEVICE_GET_SERIAL_NAME_LENGTH-1] = 'C';
  635. } \endcode
  636. *
  637. * \subsection udc_use_case_6_usage_flow Workflow
  638. * -# Ensure that conf_usb.h is available and contains the following parameters
  639. * required to enable a USB serial number strings dynamically:
  640. * - \code #define USB_DEVICE_SERIAL_NAME // Define this empty
  641. #define USB_DEVICE_GET_SERIAL_NAME_POINTER serial_number // Give serial array pointer
  642. #define USB_DEVICE_GET_SERIAL_NAME_LENGTH 12 // Give size of serial array
  643. extern uint8_t serial_number[]; // Declare external serial array \endcode
  644. * -# Before start USB stack, initialize the serial array
  645. * - \code
  646. uint8_t serial_number[USB_DEVICE_GET_SERIAL_NAME_LENGTH];
  647. void init_build_usb_serial_number(void)
  648. {
  649. serial_number[0] = 'A';
  650. serial_number[1] = 'B';
  651. ...
  652. serial_number[USB_DEVICE_GET_SERIAL_NAME_LENGTH-1] = 'C';
  653. } \endcode
  654. */
  655. #endif // _UDC_H_