/ samd51 / usb_start.c
usb_start.c
 1  /*
 2   * Code generated from Atmel Start.
 3   *
 4   * This file will be overwritten when reconfiguring your Atmel Start project.
 5   * Please copy examples or other code you want to keep to a separate file or main.c
 6   * to avoid loosing it when reconfiguring.
 7   */
 8  #include "atmel_start.h"
 9  #include "usb_start.h"
10  
11  /* Max LUN number */
12  #define CONF_USB_MSC_MAX_LUN 0
13  
14  #if CONF_USBD_HS_SP
15  static uint8_t multi_desc_bytes[] = {
16      /* Device descriptors and Configuration descriptors list. */
17      COMPOSITE_HS_DESCES_LS_FS};
18  static uint8_t multi_desc_bytes_hs[] = {
19      /* Device descriptors and Configuration descriptors list. */
20      COMPOSITE_HS_DESCES_HS};
21  #else
22  static uint8_t multi_desc_bytes[] = {
23      /* Device descriptors and Configuration descriptors list. */
24      COMPOSITE_DESCES_LS_FS};
25  #endif
26  
27  static struct usbd_descriptors multi_desc[] = {{multi_desc_bytes, multi_desc_bytes + sizeof(multi_desc_bytes)}
28  #if CONF_USBD_HS_SP
29                                                 ,
30                                                 {multi_desc_bytes_hs, multi_desc_bytes_hs + sizeof(multi_desc_bytes_hs)}
31  #endif
32  };
33  
34  /** Ctrl endpoint buffer */
35  static uint8_t ctrl_buffer[64];
36  
37  void composite_device_init(void)
38  {
39  	/* usb stack init */
40  	usbdc_init(ctrl_buffer);
41  
42  /* usbdc_register_funcion inside */
43  #if CONF_USB_COMPOSITE_CDC_ACM_EN
44  	cdcdf_acm_init();
45  #endif
46  #if CONF_USB_COMPOSITE_HID_MOUSE_EN
47  	hiddf_mouse_init();
48  #endif
49  #if CONF_USB_COMPOSITE_HID_KEYBOARD_EN
50  	hiddf_keyboard_init();
51  #endif
52  #if CONF_USB_COMPOSITE_MSC_EN
53  	mscdf_init(CONF_USB_MSC_MAX_LUN);
54  #endif
55  }
56  
57  void composite_device_start(void)
58  {
59  	usbdc_start(multi_desc);
60  	usbdc_attach();
61  }
62  
63  void composite_device_example(void)
64  {
65  
66  	/* Initialize */
67  	/* It's done with system init ... */
68  
69  	/* Before start do function related initializations */
70  	/* Add your code here ... */
71  
72  	/* Start device */
73  	composite_device_start();
74  
75  	/* Main loop */
76  	while (1) {
77  		if (cdcdf_acm_is_enabled()) {
78  			/* CDC ACM process*/
79  		}
80  		if (hiddf_mouse_is_enabled()) {
81  			/* HID Mouse process */
82  		}
83  		if (hiddf_keyboard_is_enabled()) {
84  			/* HID Keyboard process */
85  		};
86  		if (mscdf_is_enabled()) {
87  			/* MSC process */
88  		}
89  	}
90  }
91  
92  void usb_init(void)
93  {
94  
95  	composite_device_init();
96  }