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.

HostApplication.c 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. * Main source file for the USB host application. This file contains the
  29. * main tasks of the application and is responsible for the initial
  30. * application hardware configuration.
  31. */
  32. #include "HostApplication.h"
  33. /** Main program entry point. This routine configures the hardware required by the application, then
  34. * enters a loop to run the application tasks in sequence.
  35. */
  36. int main(void)
  37. {
  38. SetupHardware();
  39. GlobalInterruptEnable();
  40. for (;;)
  41. {
  42. USB_USBTask();
  43. }
  44. }
  45. /** Configures the board hardware and chip peripherals for the demo's functionality. */
  46. void SetupHardware(void)
  47. {
  48. /* Disable watchdog if enabled by bootloader/fuses */
  49. MCUSR &= ~(1 << WDRF);
  50. wdt_disable();
  51. /* Disable clock division */
  52. clock_prescale_set(clock_div_1);
  53. /* Hardware Initialization */
  54. USB_Init(USB_MODE_Host, USB_DEVICE_OPT_FULLSPEED | USB_OPT_AUTO_PLL);
  55. }
  56. /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and
  57. * starts the library USB task to begin the enumeration and USB management process.
  58. */
  59. void EVENT_USB_Host_DeviceAttached(void)
  60. {
  61. }
  62. /** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and
  63. * stops the library USB task management process.
  64. */
  65. void EVENT_USB_Host_DeviceUnattached(void)
  66. {
  67. }
  68. /** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully
  69. * enumerated by the host and is now ready to be used by the application.
  70. */
  71. void EVENT_USB_Host_DeviceEnumerationComplete(void)
  72. {
  73. uint16_t ConfigDescriptorSize;
  74. uint8_t ConfigDescriptorData[512];
  75. if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,
  76. sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)
  77. {
  78. return;
  79. }
  80. if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful)
  81. {
  82. return;
  83. }
  84. }
  85. /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */
  86. void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
  87. {
  88. USB_Disable();
  89. for(;;);
  90. }
  91. /** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while
  92. * enumerating an attached USB device.
  93. */
  94. void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,
  95. const uint8_t SubErrorCode)
  96. {
  97. }
  98. /* Required callback for retrieving descriptors from a LUFA device - unless the USB_HOST_ONLY configuration
  99. * option is set, this is still required even in an application that uses host mode only.
  100. */
  101. uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
  102. const uint8_t wIndex,
  103. const void** const DescriptorAddress
  104. #if defined(HAS_MULTIPLE_DESCRIPTOR_ADDRESS_SPACES)
  105. , uint8_t* const DescriptorMemorySpace
  106. #endif
  107. )
  108. {
  109. return 0;
  110. }