Fix up broken Studio pseudo-board configuration module, add missing USB driver files.
[pub/USBasp.git] / Demos / Device / ClassDriver / RNDISEthernet / RNDISEthernet.c
index 76c4906..ef643a8 100644 (file)
@@ -1,24 +1,24 @@
 /*
              LUFA Library
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2010.
-              
+     Copyright (C) Dean Camera, 2013.
+
   dean [at] fourwalledcubicle [dot] com
   dean [at] fourwalledcubicle [dot] com
-      www.fourwalledcubicle.com
+           www.lufa-lib.org
 */
 
 /*
 */
 
 /*
-  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2013  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
 
-  Permission to use, copy, modify, distribute, and sell this 
+  Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
   software and its documentation for any purpose is hereby granted
-  without fee, provided that the above copyright notice appear in 
+  without fee, provided that the above copyright notice appear in
   all copies and that both that the copyright notice and this
   all copies and that both that the copyright notice and this
-  permission notice and warranty disclaimer appear in supporting 
-  documentation, and that the name of the author not be used in 
-  advertising or publicity pertaining to distribution of the 
+  permission notice and warranty disclaimer appear in supporting
+  documentation, and that the name of the author not be used in
+  advertising or publicity pertaining to distribution of the
   software without specific, written prior permission.
 
   software without specific, written prior permission.
 
-  The author disclaim all warranties with regard to this
+  The author disclaims all warranties with regard to this
   software, including all implied warranties of merchantability
   and fitness.  In no event shall the author be liable for any
   special, indirect or consequential damages or any damages
   software, including all implied warranties of merchantability
   and fitness.  In no event shall the author be liable for any
   special, indirect or consequential damages or any damages
@@ -45,24 +45,35 @@ USB_ClassInfo_RNDIS_Device_t Ethernet_RNDIS_Interface =
                .Config =
                        {
                                .ControlInterfaceNumber         = 0,
                .Config =
                        {
                                .ControlInterfaceNumber         = 0,
-
-                               .DataINEndpointNumber           = CDC_TX_EPNUM,
-                               .DataINEndpointSize             = CDC_TXRX_EPSIZE,
-                               .DataINEndpointDoubleBank       = false,
-
-                               .DataOUTEndpointNumber          = CDC_RX_EPNUM,
-                               .DataOUTEndpointSize            = CDC_TXRX_EPSIZE,
-                               .DataOUTEndpointDoubleBank      = false,
-
-                               .NotificationEndpointNumber     = CDC_NOTIFICATION_EPNUM,
-                               .NotificationEndpointSize       = CDC_NOTIFICATION_EPSIZE,
-                               .NotificationEndpointDoubleBank = false,
-                               
+                               .DataINEndpoint                 =
+                                       {
+                                               .Address                = CDC_TX_EPADDR,
+                                               .Size                   = CDC_TXRX_EPSIZE,
+                                               .Banks                  = 1,
+                                       },
+                               .DataOUTEndpoint                =
+                                       {
+                                               .Address                = CDC_RX_EPADDR,
+                                               .Size                   = CDC_TXRX_EPSIZE,
+                                               .Banks                  = 1,
+                                       },
+                               .NotificationEndpoint           =
+                                       {
+                                               .Address                = CDC_NOTIFICATION_EPADDR,
+                                               .Size                   = CDC_NOTIFICATION_EPSIZE,
+                                               .Banks                  = 1,
+                                       },
                                .AdapterVendorDescription       = "LUFA RNDIS Demo Adapter",
                                .AdapterMACAddress              = {ADAPTER_MAC_ADDRESS},
                        },
        };
 
                                .AdapterVendorDescription       = "LUFA RNDIS Demo Adapter",
                                .AdapterMACAddress              = {ADAPTER_MAC_ADDRESS},
                        },
        };
 
+/** Global to store the incoming frame from the host before it is processed by the device. */
+static Ethernet_Frame_Info_t FrameIN;
+
+/** Global to store the outgoing frame created in the device before it is sent to the host. */
+static Ethernet_Frame_Info_t FrameOUT;
+
 /** Main program entry point. This routine contains the overall program flow, including initial
  *  setup of all components and the main program loop.
  */
 /** Main program entry point. This routine contains the overall program flow, including initial
  *  setup of all components and the main program loop.
  */
@@ -74,18 +85,27 @@ int main(void)
        Webserver_Init();
 
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
        Webserver_Init();
 
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
-       sei();
+       GlobalInterruptEnable();
 
        for (;;)
        {
 
        for (;;)
        {
-               if (Ethernet_RNDIS_Interface.State.FrameIN.FrameInBuffer)
+               if (RNDIS_Device_IsPacketReceived(&Ethernet_RNDIS_Interface))
                {
                        LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
                {
                        LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
-                       Ethernet_ProcessPacket(&Ethernet_RNDIS_Interface.State.FrameIN, &Ethernet_RNDIS_Interface.State.FrameOUT);
+
+                       RNDIS_Device_ReadPacket(&Ethernet_RNDIS_Interface, &FrameIN.FrameData, &FrameIN.FrameLength);
+                       Ethernet_ProcessPacket(&FrameIN, &FrameOUT);
+
+                       if (FrameOUT.FrameLength)
+                       {
+                               RNDIS_Device_SendPacket(&Ethernet_RNDIS_Interface, &FrameOUT.FrameData, FrameOUT.FrameLength);
+                               FrameOUT.FrameLength = 0;
+                       }
+
                        LEDs_SetAllLEDs(LEDMASK_USB_READY);
                }
 
                        LEDs_SetAllLEDs(LEDMASK_USB_READY);
                }
 
-               TCP_TCPTask(&Ethernet_RNDIS_Interface);
+               TCP_TCPTask(&Ethernet_RNDIS_Interface, &FrameOUT);
 
                RNDIS_Device_USBTask(&Ethernet_RNDIS_Interface);
                USB_USBTask();
 
                RNDIS_Device_USBTask(&Ethernet_RNDIS_Interface);
                USB_USBTask();
@@ -104,8 +124,11 @@ void SetupHardware(void)
 
        /* Hardware Initialization */
        LEDs_Init();
 
        /* Hardware Initialization */
        LEDs_Init();
-       SerialStream_Init(9600, false);
+       Serial_Init(9600, false);
        USB_Init();
        USB_Init();
+
+       /* Create a stdio stream for the serial port for stdin and stdout */
+       Serial_CreateStream(NULL);
 }
 
 /** Event handler for the library USB Connection event. */
 }
 
 /** Event handler for the library USB Connection event. */
@@ -123,14 +146,16 @@ void EVENT_USB_Device_Disconnect(void)
 /** Event handler for the library USB Configuration Changed event. */
 void EVENT_USB_Device_ConfigurationChanged(void)
 {
 /** Event handler for the library USB Configuration Changed event. */
 void EVENT_USB_Device_ConfigurationChanged(void)
 {
-       LEDs_SetAllLEDs(LEDMASK_USB_READY);
+       bool ConfigSuccess = true;
+
+       ConfigSuccess &= RNDIS_Device_ConfigureEndpoints(&Ethernet_RNDIS_Interface);
 
 
-       if (!(RNDIS_Device_ConfigureEndpoints(&Ethernet_RNDIS_Interface)))
-         LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+       LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
 }
 
 }
 
-/** Event handler for the library USB Unhandled Control Request event. */
-void EVENT_USB_Device_UnhandledControlRequest(void)
+/** Event handler for the library USB Control Request reception event. */
+void EVENT_USB_Device_ControlRequest(void)
 {
        RNDIS_Device_ProcessControlRequest(&Ethernet_RNDIS_Interface);
 }
 {
        RNDIS_Device_ProcessControlRequest(&Ethernet_RNDIS_Interface);
 }
+