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.

USBTask.c 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #define __INCLUDE_FROM_USBTASK_C
  27. #define __INCLUDE_FROM_USB_DRIVER
  28. #include "USBTask.h"
  29. volatile bool USB_IsInitialized;
  30. USB_Request_Header_t USB_ControlRequest;
  31. #if defined(USB_CAN_BE_HOST) && !defined(HOST_STATE_AS_GPIOR)
  32. volatile uint8_t USB_HostState;
  33. #endif
  34. #if defined(USB_CAN_BE_DEVICE) && !defined(DEVICE_STATE_AS_GPIOR)
  35. volatile uint8_t USB_DeviceState;
  36. #endif
  37. void USB_USBTask(void)
  38. {
  39. #if defined(USB_CAN_BE_BOTH)
  40. if (USB_CurrentMode == USB_MODE_Device)
  41. USB_DeviceTask();
  42. else if (USB_CurrentMode == USB_MODE_Host)
  43. USB_HostTask();
  44. #elif defined(USB_CAN_BE_HOST)
  45. USB_HostTask();
  46. #elif defined(USB_CAN_BE_DEVICE)
  47. USB_DeviceTask();
  48. #endif
  49. }
  50. #if defined(USB_CAN_BE_DEVICE)
  51. static void USB_DeviceTask(void)
  52. {
  53. if (USB_DeviceState == DEVICE_STATE_Unattached)
  54. return;
  55. uint8_t PrevEndpoint = Endpoint_GetCurrentEndpoint();
  56. Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
  57. if (Endpoint_IsSETUPReceived())
  58. USB_Device_ProcessControlRequest();
  59. Endpoint_SelectEndpoint(PrevEndpoint);
  60. }
  61. #endif
  62. #if defined(USB_CAN_BE_HOST)
  63. static void USB_HostTask(void)
  64. {
  65. uint8_t PrevPipe = Pipe_GetCurrentPipe();
  66. Pipe_SelectPipe(PIPE_CONTROLPIPE);
  67. USB_Host_ProcessNextHostState();
  68. Pipe_SelectPipe(PrevPipe);
  69. }
  70. #endif