Keyboard firmwares for Atmel AVR and Cortex-M
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.

USBDeviceMode.c 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. *
  28. * USB Device Mode management functions and variables. This file contains the LUFA code required to
  29. * manage the USB Mass Storage device mode.
  30. */
  31. #include "USBDeviceMode.h"
  32. /** Message buffer for RNDIS messages processed by the RNDIS device class driver. */
  33. static uint8_t RNDIS_Message_Buffer[192];
  34. /** LUFA RNDIS Class driver interface configuration and state information. This structure is
  35. * passed to all RNDIS Class driver functions, so that multiple instances of the same class
  36. * within a device can be differentiated from one another.
  37. */
  38. USB_ClassInfo_RNDIS_Device_t Ethernet_RNDIS_Interface_Device =
  39. {
  40. .Config =
  41. {
  42. .ControlInterfaceNumber = INTERFACE_ID_CDC_CCI,
  43. .DataINEndpoint =
  44. {
  45. .Address = CDC_TX_EPADDR,
  46. .Size = CDC_TXRX_EPSIZE,
  47. .Banks = 1,
  48. },
  49. .DataOUTEndpoint =
  50. {
  51. .Address = CDC_RX_EPADDR,
  52. .Size = CDC_TXRX_EPSIZE,
  53. .Banks = 1,
  54. },
  55. .NotificationEndpoint =
  56. {
  57. .Address = CDC_NOTIFICATION_EPADDR,
  58. .Size = CDC_NOTIFICATION_EPSIZE,
  59. .Banks = 1,
  60. },
  61. .AdapterVendorDescription = "LUFA RNDIS Adapter",
  62. .AdapterMACAddress = {{0x02, 0x00, 0x02, 0x00, 0x02, 0x00}},
  63. .MessageBuffer = RNDIS_Message_Buffer,
  64. .MessageBufferLength = sizeof(RNDIS_Message_Buffer),
  65. },
  66. };
  67. /** LUFA Mass Storage Class driver interface configuration and state information. This structure is
  68. * passed to all Mass Storage Class driver functions, so that multiple instances of the same class
  69. * within a device can be differentiated from one another.
  70. */
  71. USB_ClassInfo_MS_Device_t Disk_MS_Interface =
  72. {
  73. .Config =
  74. {
  75. .InterfaceNumber = INTERFACE_ID_MassStorage,
  76. .DataINEndpoint =
  77. {
  78. .Address = MASS_STORAGE_IN_EPADDR,
  79. .Size = MASS_STORAGE_IO_EPSIZE,
  80. .Banks = 1,
  81. },
  82. .DataOUTEndpoint =
  83. {
  84. .Address = MASS_STORAGE_OUT_EPADDR,
  85. .Size = MASS_STORAGE_IO_EPSIZE,
  86. .Banks = 1,
  87. },
  88. .TotalLUNs = 1,
  89. },
  90. };
  91. /** USB device mode management task. This function manages the Mass Storage Device class driver when the device is
  92. * initialized in USB device mode.
  93. */
  94. void USBDeviceMode_USBTask(void)
  95. {
  96. if (USB_CurrentMode != USB_MODE_Device)
  97. return;
  98. uIPManagement_ManageNetwork();
  99. RNDIS_Device_USBTask(&Ethernet_RNDIS_Interface_Device);
  100. MS_Device_USBTask(&Disk_MS_Interface);
  101. }
  102. /** Event handler for the library USB Connection event. */
  103. void EVENT_USB_Device_Connect(void)
  104. {
  105. LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
  106. uIPManagement_Init();
  107. }
  108. /** Event handler for the library USB Disconnection event. */
  109. void EVENT_USB_Device_Disconnect(void)
  110. {
  111. LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
  112. }
  113. /** Event handler for the library USB Configuration Changed event. */
  114. void EVENT_USB_Device_ConfigurationChanged(void)
  115. {
  116. bool ConfigSuccess = true;
  117. ConfigSuccess &= RNDIS_Device_ConfigureEndpoints(&Ethernet_RNDIS_Interface_Device);
  118. ConfigSuccess &= MS_Device_ConfigureEndpoints(&Disk_MS_Interface);
  119. LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
  120. }
  121. /** Event handler for the library USB Control Request reception event. */
  122. void EVENT_USB_Device_ControlRequest(void)
  123. {
  124. RNDIS_Device_ProcessControlRequest(&Ethernet_RNDIS_Interface_Device);
  125. MS_Device_ProcessControlRequest(&Disk_MS_Interface);
  126. }
  127. /** Mass Storage class driver callback function the reception of SCSI commands from the host, which must be processed.
  128. *
  129. * \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface configuration structure being referenced
  130. */
  131. bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
  132. {
  133. bool CommandSuccess;
  134. LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
  135. CommandSuccess = SCSI_DecodeSCSICommand(MSInterfaceInfo);
  136. LEDs_SetAllLEDs(LEDMASK_USB_READY);
  137. return CommandSuccess;
  138. }