Exemplo n.º 1
0
        private void Dispose(bool fDisposing)
        {
            if (!m_disposed)
            {
                try
                {
                    HardwareProvider hwProvider = HardwareProvider.HwProvider;

                    if (hwProvider != null)
                    {
                        Cpu.Pin scl;
                        Cpu.Pin sda;

                        hwProvider.GetI2CPins(out scl, out sda);

                        if (scl != Cpu.Pin.GPIO_NONE)
                        {
                            Port.ReservePin(scl, false);
                        }

                        if (sda != Cpu.Pin.GPIO_NONE)
                        {
                            Port.ReservePin(sda, false);
                        }
                    }
                }
                finally
                {
                    m_disposed = true;
                }
            }
        }
Exemplo n.º 2
0
        //--//

        public I2CDevice(Configuration config)
        {
            this.Config = config;

            HardwareProvider hwProvider = HardwareProvider.HwProvider;

            if (hwProvider != null)
            {
                Cpu.Pin scl;
                Cpu.Pin sda;

                hwProvider.GetI2CPins(out scl, out sda);

                if (scl != Cpu.Pin.GPIO_NONE)
                {
                    Port.ReservePin(scl, true);
                }

                if (sda != Cpu.Pin.GPIO_NONE)
                {
                    Port.ReservePin(sda, true);
                }
            }

            Initialize();

            m_disposed = false;
        }
Exemplo n.º 3
0
        public static void Main()
        {
            HardwareProvider.Register(new MyHardwareProvider());

            SerialPort serialPortA = new SerialPort("COM1");

            serialPortA.Open();                                               //reserves Pin 0,1,2 and 3 for COM1
            OutputPort outputPort = new OutputPort(Cpu.Pin.GPIO_Pin1, false); // will fail

            Port.ReservePin(Cpu.Pin.GPIO_Pin1, true);
        }
        // This class maps GPIOs to Buttons processable by Microsoft.SPOT.Presentation
        public GPIOButtonInputProvider(PresentationSource source)
        {
            // Set the input source.
            this.source = source;
            // Register our object as an input source with the input manager and get back an
            // InputProviderSite object which forwards the input report to the input manager,
            // which then places the input in the staging area.
            site = InputManager.CurrentInputManager.RegisterInputProvider(this);
            // Create a delegate that refers to the InputProviderSite object's ReportInput method
            callback   = new ReportInputCallback(site.ReportInput);
            Dispatcher = Dispatcher.CurrentDispatcher;

            // Create a hardware provider
            HardwareProvider hwProvider = new HardwareProvider();

            // Create the pins we will need for the buttons
            // Default their values for the emulator
            Cpu.Pin pinLeft   = Cpu.Pin.GPIO_Pin0;
            Cpu.Pin pinRight  = Cpu.Pin.GPIO_Pin1;
            Cpu.Pin pinUp     = Cpu.Pin.GPIO_Pin2;
            Cpu.Pin pinSelect = Cpu.Pin.GPIO_Pin3;
            Cpu.Pin pinDown   = Cpu.Pin.GPIO_Pin4;

            // Use the hardware provider to get the pins
            // If the left pin is not set then assume none of them are
            // and set the left pin back to the default emulator value
            if ((pinLeft = hwProvider.GetButtonPins(Button.VK_LEFT)) == Cpu.Pin.GPIO_NONE)
            {
                pinLeft = Cpu.Pin.GPIO_Pin0;
            }
            else
            {
                pinRight  = hwProvider.GetButtonPins(Button.VK_RIGHT);
                pinUp     = hwProvider.GetButtonPins(Button.VK_UP);
                pinSelect = hwProvider.GetButtonPins(Button.VK_SELECT);
                pinDown   = hwProvider.GetButtonPins(Button.VK_DOWN);
            }

            // Allocate button pads and assign the (emulated) hardware pins as input
            // from specific buttons.
            ButtonPad[] buttons = new ButtonPad[]
            {
                // Associate the buttons to the pins as discovered or set above
                new ButtonPad(this, Button.VK_LEFT, pinLeft),
                new ButtonPad(this, Button.VK_RIGHT, pinRight),
                new ButtonPad(this, Button.VK_UP, pinUp),
                new ButtonPad(this, Button.VK_SELECT, pinSelect),
                new ButtonPad(this, Button.VK_DOWN, pinDown),
            };

            this.buttons = buttons;
        }
Exemplo n.º 5
0
        public static void Print()
        {
            HardwareProvider provider = HardwareProvider.HwProvider;

            int cnt = provider.GetPWMChannelsCount();

            for (int i = 0; i < cnt; i++)
            {
                var     channel = (Cpu.PWMChannel)i;
                Cpu.Pin pin     = provider.GetPwmPinForChannel(channel);
                Debug.Print("PWMChannel" + channel + ": pin=" + Stm32F4Discovery.GetPinName(pin));
            }
        }
Exemplo n.º 6
0
        public static void Print()
        {
            HardwareProvider provider = HardwareProvider.HwProvider;
            var cnt = provider.GetAnalogChannelsCount();

            for (int i = 0; i < cnt; i++)
            {
                var     channel    = (Cpu.AnalogChannel)i;
                Cpu.Pin pin        = provider.GetAnalogPinForChannel(channel);
                int[]   precisions = provider.GetAvailablePrecisionInBitsForChannel(channel);

                Debug.Print("AnalogChannel" + channel +
                            ": pin=" + Stm32F4Discovery.GetPinName(pin) +
                            " precisions=" + precisions.Join(", "));
            }
        }
Exemplo n.º 7
0
        public static void Print()
        {
            HardwareProvider provider = HardwareProvider.HwProvider;
            var cnt = provider.GetSpiPortsCount();

            for (int i = 0; i < cnt; i++)
            {
                var     module = (SPI.SPI_module)i;
                Cpu.Pin msk, miso, mosi;
                provider.GetSpiPins(module, out msk, out miso, out mosi);
                Debug.Print("SPI_module" + (i + 1) +
                            ": (msk, miso, mosi)=(" +
                            Stm32F4Discovery.GetPinName(msk) + ", " +
                            Stm32F4Discovery.GetPinName(miso) + ", " +
                            Stm32F4Discovery.GetPinName(mosi) + ")");
            }
        }
Exemplo n.º 8
0
        public GPIOButtonInputProvider(GPIOButtonInputHandler buttonInputHandler)
        {
            if (buttonInputHandler == null)
            {
                throw new ArgumentNullException("buttonInputHandler");
            }
            m_buttonInputHandler = buttonInputHandler;
            m_dispatcher         = Dispatcher.CurrentDispatcher;

            // Create a hardware provider.
            HardwareProvider hwProvider = new HardwareProvider();

            // Create the pins that are needed for the buttons.
            // Default their values for the emulator.
            Cpu.Pin pinLeft   = Cpu.Pin.GPIO_Pin0;
            Cpu.Pin pinRight  = Cpu.Pin.GPIO_Pin1;
            Cpu.Pin pinUp     = Cpu.Pin.GPIO_Pin2;
            Cpu.Pin pinSelect = Cpu.Pin.GPIO_Pin3;
            Cpu.Pin pinDown   = Cpu.Pin.GPIO_Pin4;

            // Use the hardware provider to get the pins.  If the left pin is
            // not set, assume none of the pins are set, and set the left pin
            // back to the default emulator value.
            if ((pinLeft = hwProvider.GetButtonPins(Button.VK_LEFT)) == Cpu.Pin.GPIO_NONE)
            {
                pinLeft = Cpu.Pin.GPIO_Pin0;
            }
            else
            {
                pinRight  = hwProvider.GetButtonPins(Button.VK_RIGHT);
                pinUp     = hwProvider.GetButtonPins(Button.VK_UP);
                pinSelect = hwProvider.GetButtonPins(Button.VK_SELECT);
                pinDown   = hwProvider.GetButtonPins(Button.VK_DOWN);
            }

            // Allocate button pads and assign the (emulated) hardware pins as input from specific buttons.
            m_buttons = new ButtonPad[]
            {
                // Associate the buttons to the pins as discovered or set above.
                new ButtonPad(this, Button.VK_LEFT, pinLeft),
                new ButtonPad(this, Button.VK_RIGHT, pinRight),
                new ButtonPad(this, Button.VK_UP, pinUp),
                new ButtonPad(this, Button.VK_SELECT, pinSelect),
                new ButtonPad(this, Button.VK_DOWN, pinDown),
            };
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates an instance.
        /// </summary>
        public FeatherBoard()
        {
            try
            {
                // Initialize hardware
                HardwareProvider.Initialize();

                // Initialize components
                Network = WifiDevice.Initialize();
                Led     = new LedDevice(SC20100.GpioPin.PE11);
            }
            catch
            {
                // Close devices in case partially initialized
                Network?.Dispose();

                // Continue error
                throw;
            }
        }
Exemplo n.º 10
0
        public static void Print()
        {
            HardwareProvider provider = HardwareProvider.HwProvider;
            var cnt = provider.GetSerialPortsCount();

            for (int i = 0; i < cnt; i++)
            {
                string  comPort = Serial.COM1.Substring(0, 3) + (i + 1);
                Cpu.Pin rxPin, txPin, ctsPin, rtsPin;
                provider.GetSerialPins(comPort, out rxPin, out txPin, out ctsPin, out rtsPin);
                uint max, min;
                provider.GetBaudRateBoundary(i, out max, out min);

                Debug.Print(comPort + ": (rx, tx, cts, rts)=(" +
                            Stm32F4Discovery.GetPinName(rxPin) + ", " +
                            Stm32F4Discovery.GetPinName(txPin) + ", " +
                            Stm32F4Discovery.GetPinName(ctsPin) + ", " +
                            Stm32F4Discovery.GetPinName(rtsPin) + ")" +
                            " baud=" + min + "..." + max);
            }
        }
Exemplo n.º 11
0
        private static void GetPorts()
        {
            HardwareProvider hwProvider = HardwareProvider.HwProvider;

            if (hwProvider != null)
            {
                Cpu.Pin scl; //24 - B8
                Cpu.Pin sda; //25 - B9

                hwProvider.GetI2CPins(out scl, out sda);

                if (scl != Cpu.Pin.GPIO_NONE)
                {
                    Port.ReservePin(scl, true);
                }

                if (sda != Cpu.Pin.GPIO_NONE)
                {
                    Port.ReservePin(sda, true);
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates an instance.
        /// </summary>
        public DuinoBoard()
        {
            try
            {
                // Initialize hardware
                HardwareProvider.Initialize();

                // Initialize components
                Network = WifiDevice.Initialize();
                Storage = CardDevice.Connect(SC20100.StorageController.SdCard);
                Led     = new LedDevice(SC20100.GpioPin.PE11);
            }
            catch
            {
                // Close devices in case partially initialized
                Network?.Dispose();
                Storage?.Dispose();

                // Continue error
                throw;
            }
        }
 static STM32F429I_Discovery()
 {
     HardwareProvider.Register(new Stm32F4DiscoveryHardwareProvider());
 }
Exemplo n.º 14
0
 public void InitializeHWProvider()
 {
     myHardwareProvider = new HardwareProvider();
 }
Exemplo n.º 15
0
        private void HandlePinReservations(bool fReserve)
        {
            int exceptLevel = 0;

            Cpu.Pin rxPin  = Cpu.Pin.GPIO_NONE;
            Cpu.Pin txPin  = Cpu.Pin.GPIO_NONE;
            Cpu.Pin CTSPin = Cpu.Pin.GPIO_NONE;
            Cpu.Pin RTSPin = Cpu.Pin.GPIO_NONE;

            try
            {
                HardwareProvider hwProvider = HardwareProvider.HwProvider;
                if (hwProvider != null)
                {
                    hwProvider.GetSerialPins(m_portName, out rxPin, out txPin, out CTSPin, out RTSPin);

                    if (rxPin != Cpu.Pin.GPIO_NONE)
                    {
                        Port.ReservePin(rxPin, fReserve);
                        exceptLevel = 1;
                    }

                    if (txPin != Cpu.Pin.GPIO_NONE)
                    {
                        Port.ReservePin(txPin, fReserve);
                        exceptLevel = 2;
                    }

                    if (m_config.Handshake == Handshake.RequestToSend)
                    {
                        if (CTSPin != Cpu.Pin.GPIO_NONE)
                        {
                            Port.ReservePin(CTSPin, fReserve);
                            exceptLevel = 3;
                        }

                        if (RTSPin != Cpu.Pin.GPIO_NONE)
                        {
                            Port.ReservePin(RTSPin, fReserve);
                            exceptLevel = 4;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (fReserve)
                {
                    // unreserve the pin in the case of an exception
                    switch (exceptLevel)
                    {
                    case 4:
                        Port.ReservePin(RTSPin, false);
                        // fall through
                        goto case 3;

                    case 3:
                        Port.ReservePin(CTSPin, false);
                        // fall through
                        goto case 2;

                    case 2:
                        Port.ReservePin(txPin, false);
                        // fall through
                        goto case 1;

                    case 1:
                        Port.ReservePin(rxPin, false);
                        break;
                    }
                }

                throw e;
            }
        }
Exemplo n.º 16
0
        public static void Main(string[] args)
        {
            HardwareProvider hwProvider = HardwareProvider.HwProvider;

            Debug.Print("Test GPIO Hardware provider functions ");

            while (true)
            {
                // GPIO
                int            GpioCnt = hwProvider.GetPinsCount();
                Cpu.PinUsage[] PinMap;
                int            size;
                hwProvider.GetPinsMap(out PinMap, out size);
                Debug.Print("------------------------------");

                Debug.Print("-------Pin Map ----------");
                for (int i = 0; i < GpioCnt; i++)
                {
                    Debug.Print("Pin Map - usage" + i + " : " + PinMap[i]);
                }
                Debug.Print("Pin count size " + size);

                Debug.Print("------------------------------");
                Debug.Print("---Pin Usage -------");

                Cpu.PinUsage OnePinUsage;
                for (int i = 0; i < GpioCnt; i++)
                {
                    OnePinUsage = hwProvider.GetPinsUsage((Cpu.Pin)i);
                    if (OnePinUsage != PinMap[i])
                    {
                        Debug.Print("ERRORR       **** ");
                    }
                    Debug.Print("cnt " + i + "usage" + OnePinUsage);
                }
                Debug.Print("------------------------------");

                Cpu.PinValidResistorMode OnePinResistorMode = hwProvider.GetSupportedResistorModes((Cpu.Pin) 0);
                Debug.Print("Reistor Mode " + OnePinResistorMode);

                Debug.Print("------------------------------");

                Cpu.PinValidInterruptMode OnePinIntMode = hwProvider.GetSupportedInterruptModes((Cpu.Pin) 0);
                Debug.Print("Interrupt Mode " + OnePinIntMode);
                Debug.Print("------------------------------");



                // serial
                Cpu.Pin rxPin;
                Cpu.Pin txPin;
                Cpu.Pin ctsPin;
                Cpu.Pin rtsPin;

                hwProvider.GetSerialPins("COM1", out rxPin, out txPin, out ctsPin, out rtsPin);
                Debug.Print("Serial Port : ");
                Debug.Print("Rx- " + rxPin);
                Debug.Print("Tx- " + txPin);
                Debug.Print("cts- " + ctsPin);
                Debug.Print("Rts- " + rtsPin);

                int SerialNo = hwProvider.GetSerialPortsCount();
                Debug.Print("Total Serial Port : " + SerialNo);

                System.IO.Ports.BaudRate[] StandardBR;
                hwProvider.GetSupportBaudRates(0, out StandardBR, out size);
                Debug.Print("#Standard Baudrate size" + size);
                for (int i = 0; i < size; i++)
                {
                    Debug.Print("Baudrate " + StandardBR[i]);
                }
                Debug.Print("------------------------------");



                bool SupportNonStandardBR = hwProvider.SupportsNonStandardBaudRate(0);
                Debug.Print("Support NonStandard Baudrate " + SupportNonStandardBR);

                uint br = 115200;
                Debug.Print(" support " + br);

                bool result;
                result = hwProvider.IsSupportedBaudRate(0, ref br);
                Debug.Print(" result " + result + "(" + br + ")");

                uint maxbr, minbr;
                hwProvider.GetBaudRateBoundary(0, out maxbr, out minbr);
                Debug.Print("Com 0 max br" + maxbr + " minBr: " + minbr);

                br     = maxbr + 1000;
                result = hwProvider.IsSupportedBaudRate(0, ref br);
                Debug.Print(" over max+100 result " + result + "(" + br + ")");

                // SPI
                Cpu.Pin msk;
                Cpu.Pin miso;
                Cpu.Pin mosi;

                hwProvider.GetSpiPins(SPI.SPI_module.SPI1, out msk, out miso, out mosi);
                Debug.Print("SPI Port : ");
                Debug.Print("msk- " + msk);
                Debug.Print("miso- " + miso);
                Debug.Print("mosi- " + mosi);


                int SpiNo = hwProvider.GetSpiPortsCount();
                Debug.Print("Total Spi Port : " + SpiNo);

                // I2C
                Cpu.Pin scl;
                Cpu.Pin sda;

                hwProvider.GetI2CPins(out scl, out sda);
                Debug.Print("I2C Port : ");
                Debug.Print("scl- " + scl);
                Debug.Print("sda- " + sda);


                // LCD
                int width, height, orientation, bpp;
                hwProvider.GetLCDMetrics(out width, out height, out bpp, out orientation);
                Debug.Print("width : " + height);
                Debug.Print("Length : " + height);
                Debug.Print("Bit Per Pixel : " + bpp);
                Debug.Print("orientatoin " + orientation);


                //get button -
                Debug.Print("Button Menu pin no " + hwProvider.GetButtonPins(Button.VK_MENU));
                Debug.Print("Button Select pin no " + hwProvider.GetButtonPins(Button.VK_SELECT));
                Debug.Print("Button Back pin no " + hwProvider.GetButtonPins(Button.VK_BACK));
                Debug.Print("Button Up pin no " + hwProvider.GetButtonPins(Button.VK_UP));
                Debug.Print("Button down pin no " + hwProvider.GetButtonPins(Button.VK_DOWN));
                Debug.Print("Button Left pin no " + hwProvider.GetButtonPins(Button.VK_LEFT));

                Debug.Print("Button right pin no " + hwProvider.GetButtonPins(Button.VK_RIGHT));
                Debug.Print("Button home pin no " + hwProvider.GetButtonPins(Button.VK_HOME));
                Debug.Print("Button appdef pin no " + hwProvider.GetButtonPins(Button.AppDefined1));
                Debug.Print("Button VK convert pin no " + hwProvider.GetButtonPins(Button.VK_CONVERT));



                Thread.Sleep(1000);
            }
        }
Exemplo n.º 17
0
        public static void Main()
        {
            Debug.Print("\n\n");
            Debug.Print("Hello world - i'm trying to find what are hidden to this firmware ");
            Debug.Print("\n\n");

            HardwareProvider provider = HardwareProvider.HwProvider;

            var cnt = provider.GetAnalogChannelsCount();

            for (int i = 0; i < cnt; i++)
            {
                var     channel    = (Cpu.AnalogChannel)i;
                Cpu.Pin pin        = provider.GetAnalogPinForChannel(channel);
                int[]   precisions = provider.GetAvailablePrecisionInBitsForChannel(channel);

                Debug.Print("AnalogChannel" + channel + ": pin=" + pin.ToString() + "(" + STM32F411RE.Hardware.Pin.GetPinName(pin) + "): precisions=" + precisions[0].ToString() + " bit");
            }
            Debug.Print("\n\n");

            cnt = 0;
            cnt = provider.GetAnalogOutputChannelsCount();
            for (int i = 0; i < cnt; i++)
            {
                var     channel    = (Cpu.AnalogOutputChannel)i;
                Cpu.Pin pin        = provider.GetAnalogOutputPinForChannel(channel);
                int[]   precisions = provider.GetAvailableAnalogOutputPrecisionInBitsForChannel(channel);

                Debug.Print("AnalogOutputChannel" + ": pin=" + pin.ToString() + "(" + STM32F411RE.Hardware.Pin.GetPinName(pin) + "): precisions=" + precisions[0].ToString() + " bit");
            }
            Debug.Print("\n\n");

            /* find pwm */
            cnt = 0;
            cnt = provider.GetPWMChannelsCount();
            for (int i = 0; i < cnt; i++)
            {
                var     channel = (Cpu.PWMChannel)i;
                Cpu.Pin pin     = provider.GetPwmPinForChannel(channel);
                Debug.Print("PWMChannel" + channel + ": pin=" + pin.ToString() + "(" + STM32F411RE.Hardware.Pin.GetPinName(pin) + ")");
            }
            Debug.Print("\n\n");

            /*find uart */
            cnt = 0;
            cnt = provider.GetSerialPortsCount();
            for (int i = 0; i < cnt; i++)
            {
                string  comPort = Serial.COM1.Substring(0, 3) + (i + 1);
                Cpu.Pin rxPin, txPin, ctsPin, rtsPin;
                provider.GetSerialPins(comPort, out rxPin, out txPin, out ctsPin, out rtsPin);
                uint max, min;
                provider.GetBaudRateBoundary(i, out max, out min);

                Debug.Print(comPort + ": (rx, tx, cts, rts)=(" +
                            STM32F411RE.Hardware.Pin.GetPinName(rxPin) + ", " +
                            STM32F411RE.Hardware.Pin.GetPinName(txPin) + ", " +
                            STM32F411RE.Hardware.Pin.GetPinName(ctsPin) + ", " +
                            STM32F411RE.Hardware.Pin.GetPinName(rtsPin) + ")" +
                            " baud=" + min + "..." + max);
            }
            Debug.Print("\n\n");
            /* find i2c */
            Cpu.Pin i2cscl, i2csda;
            provider.GetI2CPins(out i2cscl, out i2csda);
            Debug.Print("I2C module:(scl value=" + i2cscl.ToString() + "(" + STM32F411RE.Hardware.Pin.GetPinName(i2cscl) + "),sda=" + i2csda.ToString() + "(" + STM32F411RE.Hardware.Pin.GetPinName(i2csda) + "));");
            Debug.Print("\n\n");

            /* find SPI */
            var spicnt = provider.GetSpiPortsCount();

            for (int i = 0; i < spicnt; i++)
            {
                var module = (SPI.SPI_module)i;

                Cpu.Pin msk, miso, mosi;
                provider.GetSpiPins(module, out msk, out miso, out mosi);
                Debug.Print("SPI_module" + (i + 1) + ": (msk=" + msk.ToString() + "(" + STM32F411RE.Hardware.Pin.GetPinName(msk) + "), miso=" + miso.ToString() + "(" + STM32F411RE.Hardware.Pin.GetPinName(miso) + "), mosi=" + mosi.ToString() + "(" + STM32F411RE.Hardware.Pin.GetPinName(mosi) + "));");
            }
            Debug.Print("\n\n");

            UsbController[] controllers = UsbController.GetControllers();
            for (int i = 0; i < controllers.Length; i++)
            {
                Debug.Print("USB" + i + ": " + Convert(controllers[i].Status));
                Thread.Sleep(500);
            }

            Debug.Print("\n\n");
            Debug.Print("Finished check of hardware ");
        }
 static STM32F411RE()
 {
     HardwareProvider.Register(new STM32F411REHardwareProvider());
 }
Exemplo n.º 19
0
 public static void Main()
 {
     HardwareProvider.Register(new RaspberryPiHWProvider());
     new SPIExample().Run();
 }
        /// <summary>
        /// Maps GPIOs to Buttons that can be processed by
        /// Microsoft.SPOT.Presentation.
        /// </summary>
        /// <param name="source"></param>
        public GPIOButtonInputProvider(PresentationSource source)
        {
            // Set the input source.
            this.source = source;

            // Register our object as an input source with the input manager and
            // get back an InputProviderSite object which forwards the input
            // report to the input manager, which then places the input in the
            // staging area.
            site = InputManager.CurrentInputManager.RegisterInputProvider(this);

            // Create a delegate that refers to the InputProviderSite object's
            // ReportInput method.
            callback = new DispatcherOperationCallback(delegate(object report)
            {
#if MF_FRAMEWORK_VERSION_V3_0
                return(site.ReportInput((InputReport)report));
#else
                InputReportArgs args = (InputReportArgs)report;
                return(site.ReportInput(args.Device, args.Report));
#endif
            });
            Dispatcher = Dispatcher.CurrentDispatcher;

            // Create a hardware provider.
            HardwareProvider hwProvider = new HardwareProvider();

            // Create the pins that are needed for the buttons.  Default their
            // values for the emulator.
            Cpu.Pin pinLeft   = Cpu.Pin.GPIO_Pin0;
            Cpu.Pin pinRight  = Cpu.Pin.GPIO_Pin1;
            Cpu.Pin pinUp     = Cpu.Pin.GPIO_Pin2;
            Cpu.Pin pinSelect = Cpu.Pin.GPIO_Pin3;
            Cpu.Pin pinDown   = Cpu.Pin.GPIO_Pin4;

            // Use the hardware provider to get the pins.  If the left pin is
            // not set, assume none of the pins are set, and set the left pin
            // back to the default emulator value.
            if ((pinLeft = hwProvider.GetButtonPins(Button.VK_LEFT)) ==
                Cpu.Pin.GPIO_NONE)
            {
                pinLeft = Cpu.Pin.GPIO_Pin0;
            }
            else
            {
                pinRight  = hwProvider.GetButtonPins(Button.VK_RIGHT);
                pinUp     = hwProvider.GetButtonPins(Button.VK_UP);
                pinSelect = hwProvider.GetButtonPins(Button.VK_SELECT);
                pinDown   = hwProvider.GetButtonPins(Button.VK_DOWN);
            }

            // Allocate button pads and assign the (emulated) hardware pins as
            // input from specific buttons.
            ButtonPad[] buttons = new ButtonPad[]
            {
                // Associate the buttons to the pins as discovered or set above
                new ButtonPad(this, Button.VK_LEFT, pinLeft),
                new ButtonPad(this, Button.VK_RIGHT, pinRight),
                new ButtonPad(this, Button.VK_UP, pinUp),
                new ButtonPad(this, Button.VK_SELECT, pinSelect),
                new ButtonPad(this, Button.VK_DOWN, pinDown),
            };

            this.buttons = buttons;
        }
Exemplo n.º 21
0
        /// <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();
        }