Fix makefiles -- the auto-addition of -D switches to each LUFA compile time option...
[pub/USBasp.git] / Demos / Device / ClassDriver / RNDISEthernet / RNDISEthernet.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 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 disclaim 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 RNDISEthernet demo. This file contains the main tasks of
34 * the demo and is responsible for the initial application hardware configuration.
35 */
36
37 #include "RNDISEthernet.h"
38
39 /** LUFA RNDIS Class driver interface configuration and state information. This structure is
40 * passed to all RNDIS Class driver functions, so that multiple instances of the same class
41 * within a device can be differentiated from one another.
42 */
43 USB_ClassInfo_RNDIS_Device_t Ethernet_RNDIS_Interface =
44 {
45 .Config =
46 {
47 .ControlInterfaceNumber = 0,
48
49 .DataINEndpointNumber = CDC_TX_EPNUM,
50 .DataINEndpointSize = CDC_TXRX_EPSIZE,
51
52 .DataOUTEndpointNumber = CDC_RX_EPNUM,
53 .DataOUTEndpointSize = CDC_TXRX_EPSIZE,
54
55 .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,
56 .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
57
58 .AdapterVendorDescription = "LUFA RNDIS Demo Adapter",
59 .AdapterMACAddress = {ADAPTER_MAC_ADDRESS},
60 },
61
62 .State =
63 {
64 // Leave all state values to their defaults
65 }
66 };
67
68 /** Main program entry point. This routine contains the overall program flow, including initial
69 * setup of all components and the main program loop.
70 */
71 int main(void)
72 {
73 SetupHardware();
74
75 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
76
77 TCP_Init();
78 Webserver_Init();
79
80 printf_P(PSTR("\r\n\r\n****** RNDIS Demo running. ******\r\n"));
81
82 for (;;)
83 {
84 if (Ethernet_RNDIS_Interface.State.FrameIN.FrameInBuffer)
85 {
86 LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
87 Ethernet_ProcessPacket(&Ethernet_RNDIS_Interface.State.FrameIN, &Ethernet_RNDIS_Interface.State.FrameOUT);
88 LEDs_SetAllLEDs(LEDMASK_USB_READY);
89 }
90
91 TCP_TCPTask(&Ethernet_RNDIS_Interface);
92
93 RNDIS_Device_USBTask(&Ethernet_RNDIS_Interface);
94 USB_USBTask();
95 }
96 }
97
98 /** Configures the board hardware and chip peripherals for the demo's functionality. */
99 void SetupHardware(void)
100 {
101 /* Disable watchdog if enabled by bootloader/fuses */
102 MCUSR &= ~(1 << WDRF);
103 wdt_disable();
104
105 /* Disable clock division */
106 clock_prescale_set(clock_div_1);
107
108 /* Hardware Initialization */
109 LEDs_Init();
110 SerialStream_Init(9600, false);
111 USB_Init();
112 }
113
114 /** Event handler for the library USB Connection event. */
115 void EVENT_USB_Connect(void)
116 {
117 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
118 }
119
120 /** Event handler for the library USB Disconnection event. */
121 void EVENT_USB_Disconnect(void)
122 {
123 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
124 }
125
126 /** Event handler for the library USB Configuration Changed event. */
127 void EVENT_USB_ConfigurationChanged(void)
128 {
129 LEDs_SetAllLEDs(LEDMASK_USB_READY);
130
131 if (!(RNDIS_Device_ConfigureEndpoints(&Ethernet_RNDIS_Interface)))
132 LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
133 }
134
135 /** Event handler for the library USB Unhandled Control Packet event. */
136 void EVENT_USB_UnhandledControlPacket(void)
137 {
138 RNDIS_Device_ProcessControlPacket(&Ethernet_RNDIS_Interface);
139 }