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);
            }
        }
Esempio n. 2
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;
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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 ");
        }