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.

DeviceApplication.c 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 device application. This file contains the
  29. * main tasks of the application and is responsible for the initial
  30. * application hardware configuration.
  31. */
  32. #include "DeviceApplication.h"
  33. /** Main program entry point. This routine contains the overall program flow, including initial
  34. * setup of all components and the main program loop.
  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. #if (ARCH == ARCH_AVR8)
  49. /* Disable watchdog if enabled by bootloader/fuses */
  50. MCUSR &= ~(1 << WDRF);
  51. wdt_disable();
  52. /* Disable clock division */
  53. clock_prescale_set(clock_div_1);
  54. /* Hardware Initialization */
  55. USB_Init(USB_MODE_Device, USB_DEVICE_OPT_FULLSPEED | USB_OPT_AUTO_PLL);
  56. #elif (ARCH == ARCH_XMEGA)
  57. /* Start the PLL to multiply the 2MHz RC oscillator to 32MHz and switch the CPU core to run from it */
  58. XMEGACLK_StartPLL(CLOCK_SRC_INT_RC2MHZ, 2000000, F_CPU);
  59. XMEGACLK_SetCPUClockSource(CLOCK_SRC_PLL);
  60. /* Start the 32MHz internal RC oscillator and start the DFLL to increase it to 48MHz using the USB SOF as a reference */
  61. XMEGACLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ);
  62. XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB);
  63. PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
  64. /* Hardware Initialization */
  65. USB_Init(USB_OPT_RC32MCLKSRC | USB_OPT_BUSEVENT_PRIHIGH);
  66. #endif
  67. }
  68. /** Event handler for the library USB Connection event. */
  69. void EVENT_USB_Device_Connect(void)
  70. {
  71. }
  72. /** Event handler for the library USB Disconnection event. */
  73. void EVENT_USB_Device_Disconnect(void)
  74. {
  75. }
  76. /** Event handler for the library USB Configuration Changed event. */
  77. void EVENT_USB_Device_ConfigurationChanged(void)
  78. {
  79. }
  80. /** Event handler for the library USB Control Request reception event. */
  81. void EVENT_USB_Device_ControlRequest(void)
  82. {
  83. }