3      Copyright (C) Dean Camera, 2014. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2014  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  12   Permission to use, copy, modify, distribute, and sell this 
  13   software and its documentation for any purpose is hereby granted 
  14   without fee, provided that the above copyright notice appear in 
  15   all copies and that both that the copyright notice and this 
  16   permission notice and warranty disclaimer appear in supporting 
  17   documentation, and that the name of the author not be used in 
  18   advertising or publicity pertaining to distribution of the 
  19   software without specific, written prior permission. 
  21   The author disclaims all warranties with regard to this 
  22   software, including all implied warranties of merchantability 
  23   and fitness.  In no event shall the author be liable for any 
  24   special, indirect or consequential damages or any damages 
  25   whatsoever resulting from loss of use, data or profits, whether 
  26   in an action of contract, negligence or other tortious action, 
  27   arising out of or in connection with the use or performance of 
  33  *  Main source file for the USB device application. This file contains the 
  34  *  main tasks of the application and is responsible for the initial 
  35  *  application hardware configuration. 
  38 #include "DeviceApplication.h" 
  40 /** Main program entry point. This routine contains the overall program flow, including initial 
  41  *  setup of all components and the main program loop. 
  47         GlobalInterruptEnable(); 
  55 /** Configures the board hardware and chip peripherals for the demo's functionality. */ 
  56 void SetupHardware(void) 
  58         #if (ARCH == ARCH_AVR8) 
  59                 /* Disable watchdog if enabled by bootloader/fuses */ 
  60                 MCUSR 
&= ~(1 << WDRF
); 
  63                 /* Disable clock division */ 
  64                 clock_prescale_set(clock_div_1
); 
  66                 /* Hardware Initialization */ 
  67                 USB_Init(USB_MODE_Device
, USB_DEVICE_OPT_FULLSPEED 
| USB_OPT_AUTO_PLL
); 
  68         #elif (ARCH == ARCH_XMEGA) 
  69                 /* Start the PLL to multiply the 2MHz RC oscillator to 32MHz and switch the CPU core to run from it */ 
  70                 XMEGACLK_StartPLL(CLOCK_SRC_INT_RC2MHZ
, 2000000, F_CPU
); 
  71                 XMEGACLK_SetCPUClockSource(CLOCK_SRC_PLL
); 
  73                 /* Start the 32MHz internal RC oscillator and start the DFLL to increase it to 48MHz using the USB SOF as a reference */ 
  74                 XMEGACLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ
); 
  75                 XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ
, DFLL_REF_INT_USBSOF
, F_USB
); 
  77                 PMIC
.CTRL 
= PMIC_LOLVLEN_bm 
| PMIC_MEDLVLEN_bm 
| PMIC_HILVLEN_bm
; 
  79                 /* Hardware Initialization */ 
  80                 USB_Init(USB_OPT_RC32MCLKSRC 
| USB_OPT_BUSEVENT_PRIHIGH
); 
  84 /** Event handler for the library USB Connection event. */ 
  85 void EVENT_USB_Device_Connect(void) 
  90 /** Event handler for the library USB Disconnection event. */ 
  91 void EVENT_USB_Device_Disconnect(void) 
  96 /** Event handler for the library USB Configuration Changed event. */ 
  97 void EVENT_USB_Device_ConfigurationChanged(void) 
 102 /** Event handler for the library USB Control Request reception event. */ 
 103 void EVENT_USB_Device_ControlRequest(void)