Move new Class Driver powered demos to a new ClassDriver subdirectory, re-add old...
[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_t Ethernet_RNDIS_Interface =
44 {
45 .ControlInterfaceNumber = 0,
46
47 .DataINEndpointNumber = CDC_TX_EPNUM,
48 .DataINEndpointSize = CDC_TXRX_EPSIZE,
49
50 .DataOUTEndpointNumber = CDC_RX_EPNUM,
51 .DataOUTEndpointSize = CDC_TXRX_EPSIZE,
52
53 .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,
54 .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
55
56 .AdapterVendorDescription = "LUFA RNDIS Demo Adapter",
57 .AdapterMACAddress = {ADAPTER_MAC_ADDRESS},
58 };
59
60 /** Main program entry point. This routine contains the overall program flow, including initial
61 * setup of all components and the main program loop.
62 */
63 int main(void)
64 {
65 SetupHardware();
66
67 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
68
69 TCP_Init();
70 Webserver_Init();
71
72 printf_P(PSTR("\r\n\r\n****** RNDIS Demo running. ******\r\n"));
73
74 for (;;)
75 {
76 if (Ethernet_RNDIS_Interface.FrameIN.FrameInBuffer)
77 {
78 LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
79 Ethernet_ProcessPacket(&Ethernet_RNDIS_Interface.FrameIN, &Ethernet_RNDIS_Interface.FrameOUT);
80 LEDs_SetAllLEDs(LEDMASK_USB_READY);
81 }
82
83 TCP_TCPTask(&Ethernet_RNDIS_Interface);
84
85 USB_RNDIS_USBTask(&Ethernet_RNDIS_Interface);
86 USB_USBTask();
87 }
88 }
89
90 /** Configures the board hardware and chip peripherals for the demo's functionality. */
91 void SetupHardware(void)
92 {
93 /* Disable watchdog if enabled by bootloader/fuses */
94 MCUSR &= ~(1 << WDRF);
95 wdt_disable();
96
97 /* Disable clock division */
98 clock_prescale_set(clock_div_1);
99
100 /* Hardware Initialization */
101 LEDs_Init();
102 SerialStream_Init(9600, false);
103 USB_Init();
104 }
105
106 /** Event handler for the library USB Connection event. */
107 void EVENT_USB_Connect(void)
108 {
109 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
110 }
111
112 /** Event handler for the library USB Disconnection event. */
113 void EVENT_USB_Disconnect(void)
114 {
115 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
116 }
117
118 /** Event handler for the library USB Configuration Changed event. */
119 void EVENT_USB_ConfigurationChanged(void)
120 {
121 LEDs_SetAllLEDs(LEDMASK_USB_READY);
122
123 if (!(USB_RNDIS_ConfigureEndpoints(&Ethernet_RNDIS_Interface)))
124 LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
125 }
126
127 /** Event handler for the library USB Unhandled Control Packet event. */
128 void EVENT_USB_UnhandledControlPacket(void)
129 {
130 USB_RNDIS_ProcessControlPacket(&Ethernet_RNDIS_Interface);
131 }