public MFTestResults CompositeDeviceTest() { MFTestResults testResult = MFTestResults.Pass; // Gain access to all USB controllers UsbController[] controllers = UsbController.GetControllers(); // Set up all buttons to be monitored buttons.up = new InputPort((Cpu.Pin) 43, true, Port.ResistorMode.Disabled); buttons.down = new InputPort((Cpu.Pin) 42, true, Port.ResistorMode.Disabled); buttons.left = new InputPort((Cpu.Pin) 48, true, Port.ResistorMode.Disabled); buttons.right = new InputPort((Cpu.Pin) 44, true, Port.ResistorMode.Disabled); buttons.b1 = new InputPort((Cpu.Pin) 40, true, Port.ResistorMode.Disabled); buttons.b2 = new InputPort((Cpu.Pin) 45, true, Port.ResistorMode.Disabled); buttons.b3 = new InputPort((Cpu.Pin) 46, true, Port.ResistorMode.Disabled); buttons.done = new InputPort((Cpu.Pin) 47, true, Port.ResistorMode.Disabled); // Use the first available USB controller if it exists if (controllers.Length < 1) { Debug.Print("No USB controllers exist for this device - we're done!"); return(MFTestResults.Skip); } UsbController UsbPort = controllers[0]; // Configure the USB port and open streams to both interfaces if (!ConfigureMouseAndPinger(UsbPort)) // If USB configure fails, we're done { testResult = MFTestResults.Fail; } UsbStream pinger = UsbPort.CreateUsbStream(1, 2); // Pinger writes to endpoint 1 and reads from endpoint 2 UsbStream mouse = UsbPort.CreateUsbStream(3, UsbStream.NullEndpoint); // Mouse is write only to endpoint 3 MouseAndPingerLoop(mouse, pinger); // Behave like both a mouse and "TinyBooter // Done being a mouse and a pinger. Start being just a pinger pinger.Close(); mouse.Close(); UsbPort.Stop(); Thread.Sleep(500); // Keep USB port disconnected for half a second to be sure host has seen if (!ConfigurePinger(UsbPort)) { testResult = MFTestResults.Fail; } pinger = UsbPort.CreateUsbStream(1, 2); // Pinger writes to endpoint 1 and reads from endpoint 2 PingerLoop(pinger); // Done being just a pinger. Start being a mouse and pinger again pinger.Close(); UsbPort.Stop(); Thread.Sleep(500); // Keep USB port disconnected for half a second to be sure host has seen return(testResult); }
/// <summary> /// Execution entry point. /// </summary> public static void Main() { // Gain access to all USB controllers. UsbController[] controllers = UsbController.GetControllers(); HardwareProvider hwProvider = new HardwareProvider(); // Set up all buttons to be monitored. buttons.Up = new InputPort(hwProvider.GetButtonPins(Button.VK_UP), true, Port.ResistorMode.Disabled); buttons.Down = new InputPort(hwProvider.GetButtonPins(Button.VK_DOWN), true, Port.ResistorMode.Disabled); buttons.Left = new InputPort(hwProvider.GetButtonPins(Button.VK_LEFT), true, Port.ResistorMode.Disabled); buttons.Right = new InputPort(hwProvider.GetButtonPins(Button.VK_RIGHT), true, Port.ResistorMode.Disabled); buttons.LeftMouseButton = new InputPort(hwProvider.GetButtonPins(Button.VK_BACK), true, Port.ResistorMode.Disabled); buttons.RightMouseButton = new InputPort(hwProvider.GetButtonPins(Button.VK_HOME), true, Port.ResistorMode.Disabled); buttons.Toggle = new InputPort(hwProvider.GetButtonPins(Button.VK_SELECT), true, Port.ResistorMode.Disabled); buttons.Done = new InputPort(hwProvider.GetButtonPins(Button.VK_MENU), true, Port.ResistorMode.Disabled); // Use the first available USB controller, if it exists. if (controllers.Length < 1) { Debug.Print("No USB controllers exist for this device - we're done."); return; } UsbController UsbPort = controllers[0]; UsbStream mouseStream = null; if (UsbPort.Status == UsbController.PortState.Running) { Debug.Print( "USB controller 0 is up and running - are you debugging with USB?"); Debug.Print( "Make sure your platform supports overriding the debug transport."); Thread.Sleep(500); } try { ConfigureUsbPort(UsbPort, true); mouseStream = UsbPort.CreateUsbStream(3, UsbStream.NullEndpoint); } catch (Exception e) { Debug.Print( "Mouse stream could not be created due to exception " + e.Message); Debug.Print( "Perhaps your native configuration does not contain endpoint 3?"); return; } // Be a mouse until the Done button is pressed. MouseLoop(UsbPort, mouseStream); mouseStream.Close(); }