]> git.gir.st - tmk_keyboard.git/blob - protocol/lufa/LUFA-git/Demos/DualRole/ClassDriver/MouseHostDevice/MouseHostDevice.c
Squashed 'tmk_core/' changes from 8da1898..e5f9940
[tmk_keyboard.git] / protocol / lufa / LUFA-git / Demos / DualRole / ClassDriver / MouseHostDevice / MouseHostDevice.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 MouseHostDevice demo. This file contains the main tasks of
34 * the demo and is responsible for the overall control flow of the demo.
35 */
36
37 #include "MouseHostDevice.h"
38
39 /** Main program entry point. This routine configures the hardware required by the application, then
40 * enters a loop to run the application tasks in sequence.
41 */
42 int main(void)
43 {
44 SetupHardware();
45
46 puts_P(PSTR(ESC_FG_CYAN "Mouse Host/Device Demo running.\r\n" ESC_FG_WHITE));
47
48 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
49 GlobalInterruptEnable();
50
51 for (;;)
52 {
53 /* Determine which USB mode we are currently in */
54 if (USB_CurrentMode == USB_MODE_Host)
55 {
56 MouseHost_Task();
57 HID_Host_USBTask(&Mouse_HID_Host_Interface);
58 }
59 else
60 {
61 HID_Device_USBTask(&Mouse_HID_Device_Interface);
62 }
63
64 USB_USBTask();
65 }
66 }
67
68 /** Configures the board hardware and chip peripherals for the demo's functionality. */
69 void SetupHardware(void)
70 {
71 #if (ARCH == ARCH_AVR8)
72 /* Disable watchdog if enabled by bootloader/fuses */
73 MCUSR &= ~(1 << WDRF);
74 wdt_disable();
75
76 /* Disable clock division */
77 clock_prescale_set(clock_div_1);
78 #endif
79
80 /* Hardware Initialization */
81 Serial_Init(9600, false);
82 LEDs_Init();
83 Joystick_Init();
84 Buttons_Init();
85 USB_Init(USB_MODE_UID);
86
87 /* Create a stdio stream for the serial port for stdin and stdout */
88 Serial_CreateStream(NULL);
89 }
90
91 /** Event handler for the library USB mode change event. */
92 void EVENT_USB_UIDChange(void)
93 {
94 printf_P(PSTR(ESC_FG_YELLOW "UID Change to %S mode\r\n" ESC_FG_WHITE),
95 (USB_CurrentMode == USB_MODE_Device) ? PSTR("Device") : PSTR("Host"));
96
97 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
98 }
99
Imprint / Impressum