]> git.gir.st - tmk_keyboard.git/blob - protocol/lufa/LUFA-git/LUFA/CodeTemplates/DeviceTemplate/DeviceApplication.c
Squashed 'tmk_core/' changes from caca2c0..dc0e46e
[tmk_keyboard.git] / protocol / lufa / LUFA-git / LUFA / CodeTemplates / DeviceTemplate / DeviceApplication.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2014.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
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
28 this software.
29 */
30
31 /** \file
32 *
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.
36 */
37
38 #include "DeviceApplication.h"
39
40 /** Main program entry point. This routine contains the overall program flow, including initial
41 * setup of all components and the main program loop.
42 */
43 int main(void)
44 {
45 SetupHardware();
46
47 GlobalInterruptEnable();
48
49 for (;;)
50 {
51 USB_USBTask();
52 }
53 }
54
55 /** Configures the board hardware and chip peripherals for the demo's functionality. */
56 void SetupHardware(void)
57 {
58 #if (ARCH == ARCH_AVR8)
59 /* Disable watchdog if enabled by bootloader/fuses */
60 MCUSR &= ~(1 << WDRF);
61 wdt_disable();
62
63 /* Disable clock division */
64 clock_prescale_set(clock_div_1);
65
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);
72
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);
76
77 PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
78
79 /* Hardware Initialization */
80 USB_Init(USB_OPT_RC32MCLKSRC | USB_OPT_BUSEVENT_PRIHIGH);
81 #endif
82 }
83
84 /** Event handler for the library USB Connection event. */
85 void EVENT_USB_Device_Connect(void)
86 {
87
88 }
89
90 /** Event handler for the library USB Disconnection event. */
91 void EVENT_USB_Device_Disconnect(void)
92 {
93
94 }
95
96 /** Event handler for the library USB Configuration Changed event. */
97 void EVENT_USB_Device_ConfigurationChanged(void)
98 {
99
100 }
101
102 /** Event handler for the library USB Control Request reception event. */
103 void EVENT_USB_Device_ControlRequest(void)
104 {
105
106 }
Imprint / Impressum