예제 #1
0
            internal HardwareInstance(Hardware.SPI.SPI_module module)
            {
                Sharing = SpiSharing.Shared;
                Users = 0;

                Module = module;
            }
예제 #2
0
        public NativeSpi(Socket socket, SpiConfiguration configuration, SpiSharing sharing, Hardware.Cpu.Pin chipSelectPin, Hardware.Cpu.Pin busyPin, Module module, Hardware.SPI.SPI_module spiModule)
        {
            _hardwareInstance = GetAndUseInstance(socket, sharing, module, spiModule);
            _chipSelectPin = chipSelectPin;
            _busyPin = busyPin;
            _configuration = ToNativeConfiguration(configuration, chipSelectPin, busyPin, spiModule);

            if (_hardwareInstance.Interface == null && _configuration != null)
                _hardwareInstance.Interface = new Hardware.SPI(_configuration);
        }
예제 #3
0
        public NativeDigitalInput(Socket socket, Socket.Pin pin, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, Module module, Hardware.Cpu.Pin cpuPin)
        {
            if (cpuPin == Hardware.Cpu.Pin.GPIO_NONE)
            {
                // this is a mainboard error but should not happen since we check for this, but it doesnt hurt to double-check
                throw Socket.InvalidSocketException.FunctionalityException(socket, "DigitalInput");
            }

            _port = new Hardware.InputPort(cpuPin, glitchFilterMode == GlitchFilterMode.On, (Hardware.Port.ResistorMode)resistorMode);
        }
예제 #4
0
        public NativeAnalogOutput(Socket socket, Socket.Pin pin, Module module, Hardware.Cpu.AnalogOutputChannel channel)
        {
            if (channel == Hardware.Cpu.AnalogOutputChannel.ANALOG_OUTPUT_NONE)
            {
                Socket.InvalidSocketException.ThrowIfOutOfRange(pin, Socket.Pin.Five, Socket.Pin.Five, "AnalogOutput", module);

                // this is a mainboard error but should not happen since we check for this, but it doesnt hurt to double-check
                throw Socket.InvalidSocketException.FunctionalityException(socket, "AnalogOutput");
            }

            _channel = channel;
            _socket = socket;
        }
예제 #5
0
        public NativeAnalogInput(Socket socket, Socket.Pin pin, Module module, Hardware.Cpu.AnalogChannel channel)
        {
            if (channel == Hardware.Cpu.AnalogChannel.ANALOG_NONE)
            {
                Socket.InvalidSocketException.ThrowIfOutOfRange(pin, Socket.Pin.Three, Socket.Pin.Five, "AnalogInput", module);

                // this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case...
                throw Socket.InvalidSocketException.FunctionalityException(socket, "AnalogInput");
            }

            _channel = channel;
            _socket = socket;            
        }
예제 #6
0
        public NativePwmOutput(Socket socket, Socket.Pin pin, bool invert, Module module, Hardware.Cpu.PWMChannel channel)
        {
            if (channel == Hardware.Cpu.PWMChannel.PWM_NONE)
            {
                Socket.InvalidSocketException.ThrowIfOutOfRange(pin, Socket.Pin.Seven, Socket.Pin.Nine, "PWM", module);

                // this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case...
                throw Socket.InvalidSocketException.FunctionalityException(socket, "PWM");
            }

            _channel = channel;
            _socket = socket;
            _invert = invert;
        }
예제 #7
0
        private static SocketInterfaces.SpiConfiguration ToInterfaceConfiguration(Hardware.SPI.Configuration config)
        {
            if (config == null)
                return null;

            return new SocketInterfaces.SpiConfiguration(
                config.ChipSelect_ActiveState,
                config.ChipSelect_SetupTime,
                config.ChipSelect_HoldTime,
                config.Clock_IdleState,
                config.Clock_Edge,
                config.Clock_RateKHz,
                config.BusyPin_ActiveState);
        }
예제 #8
0
        private static Microsoft.SPOT.Hardware.SPI.Configuration ToNativeConfiguration(SpiConfiguration config, Hardware.Cpu.Pin chipSelectPin, Hardware.Cpu.Pin busyPin, Hardware.SPI.SPI_module spiModule)
        {
            if (config == null)
                return new Microsoft.SPOT.Hardware.SPI.Configuration(chipSelectPin, false, 0, 0, false, false, 0, spiModule, busyPin, false);

            return new Microsoft.SPOT.Hardware.SPI.Configuration(
                chipSelectPin,
                config.IsChipSelectActiveHigh,
                config.ChipSelectSetupTime,
                config.ChipSelectHoldTime,
                config.IsClockIdleHigh,
                config.IsClockSamplingEdgeRising,
                config.ClockRateKHz,
                spiModule,
                busyPin,
                config.IsBusyActiveHigh);
        }
예제 #9
0
        public static void Main()
        {
            var songs = new[]
                            {
                                "The Simpsons:d=4,o=5,b=160:c.6,e6,f#6,8a6,g.6,e6,c6,8a,8f#,8f#,8f#,2g,8p,8p,8f#,8f#,8f#,8g,a#.,8c6,8c6,8c6,c6"
                                ,
                                "Indiana:d=4,o=5,b=250:e,8p,8f,8g,8p,1c6,8p.,d,8p,8e,1f,p.,g,8p,8a,8b,8p,1f6,p,a,8p,8b,2c6,2d6,2e6,e,8p,8f,8g,8p,1c6,p,d6,8p,8e6,1f.6,g,8p,8g,e.6,8p,d6,8p,8g,e.6,8p,d6,8p,8g,f.6,8p,e6,8p,8d6,2c6"
                                ,
                                "TakeOnMe:d=4,o=4,b=160:8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5,8f#5,8e5,8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5"
                                ,
                                "Entertainer:d=4,o=5,b=140:8d,8d#,8e,c6,8e,c6,8e,2c.6,8c6,8d6,8d#6,8e6,8c6,8d6,e6,8b,d6,2c6,p,8d,8d#,8e,c6,8e,c6,8e,2c.6,8p,8a,8g,8f#,8a,8c6,e6,8d6,8c6,8a,2d6"
                                ,
                                "Muppets:d=4,o=5,b=250:c6,c6,a,b,8a,b,g,p,c6,c6,a,8b,8a,8p,g.,p,e,e,g,f,8e,f,8c6,8c,8d,e,8e,8e,8p,8e,g,2p,c6,c6,a,b,8a,b,g,p,c6,c6,a,8b,a,g.,p,e,e,g,f,8e,f,8c6,8c,8d,e,8e,d,8d,c"
                                ,
                                "Xfiles:d=4,o=5,b=125:e,b,a,b,d6,2b.,1p,e,b,a,b,e6,2b.,1p,g6,f#6,e6,d6,e6,2b.,1p,g6,f#6,e6,d6,f#6,2b.,1p,e,b,a,b,d6,2b.,1p,e,b,a,b,e6,2b.,1p,e6,2b."
                                ,
                                "Looney:d=4,o=5,b=140:32p,c6,8f6,8e6,8d6,8c6,a.,8c6,8f6,8e6,8d6,8d#6,e.6,8e6,8e6,8c6,8d6,8c6,8e6,8c6,8d6,8a,8c6,8g,8a#,8a,8f"
                                ,
                                "20thCenFox:d=16,o=5,b=140:b,8p,b,b,2b,p,c6,32p,b,32p,c6,32p,b,32p,c6,32p,b,8p,b,b,b,32p,b,32p,b,32p,b,32p,b,32p,b,32p,b,32p,g#,32p,a,32p,b,8p,b,b,2b,4p,8e,8g#,8b,1c#6,8f#,8a,8c#6,1e6,8a,8c#6,8e6,1e6,8b,8g#,8a,2b"
                                ,
                                "Bond:d=4,o=5,b=80:32p,16c#6,32d#6,32d#6,16d#6,8d#6,16c#6,16c#6,16c#6,16c#6,32e6,32e6,16e6,8e6,16d#6,16d#6,16d#6,16c#6,32d#6,32d#6,16d#6,8d#6,16c#6,16c#6,16c#6,16c#6,32e6,32e6,16e6,8e6,16d#6,16d6,16c#6,16c#7,c.7,16g#6,16f#6,g#.6"
                                ,
                                "MASH:d=8,o=5,b=140:4a,4g,f#,g,p,f#,p,g,p,f#,p,2e.,p,f#,e,4f#,e,f#,p,e,p,4d.,p,f#,4e,d,e,p,d,p,e,p,d,p,2c#.,p,d,c#,4d,c#,d,p,e,p,4f#,p,a,p,4b,a,b,p,a,p,b,p,2a.,4p,a,b,a,4b,a,b,p,2a.,a,4f#,a,b,p,d6,p,4e.6,d6,b,p,a,p,2b"
                                ,
                                "StarWars:d=4,o=5,b=45:32p,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#.6,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#6"
                                ,
                                "GoodBad:d=4,o=5,b=56:32p,32a#,32d#6,32a#,32d#6,8a#.,16f#.,16g#.,d#,32a#,32d#6,32a#,32d#6,8a#.,16f#.,16g#.,c#6,32a#,32d#6,32a#,32d#6,8a#.,16f#.,32f.,32d#.,c#,32a#,32d#6,32a#,32d#6,8a#.,16g#.,d#"
                                ,
                                "TopGun:d=4,o=4,b=31:32p,16c#,16g#,16g#,32f#,32f,32f#,32f,16d#,16d#,32c#,32d#,16f,32d#,32f,16f#,32f,32c#,16f,d#,16c#,16g#,16g#,32f#,32f,32f#,32f,16d#,16d#,32c#,32d#,16f,32d#,32f,16f#,32f,32c#,g#"
                                ,
                                "A-Team:d=8,o=5,b=125:4d#6,a#,2d#6,16p,g#,4a#,4d#.,p,16g,16a#,d#6,a#,f6,2d#6,16p,c#.6,16c6,16a#,g#.,2a#"
                                ,
                                "Flinstones:d=4,o=5,b=40:32p,16f6,16a#,16a#6,32g6,16f6,16a#.,16f6,32d#6,32d6,32d6,32d#6,32f6,16a#,16c6,d6,16f6,16a#.,16a#6,32g6,16f6,16a#.,32f6,32f6,32d#6,32d6,32d6,32d#6,32f6,16a#,16c6,a#,16a6,16d.6,16a#6,32a6,32a6,32g6,32f#6,32a6,8g6,16g6,16c.6,32a6,32a6,32g6,32g6,32f6,32e6,32g6,8f6,16f6,16a#.,16a#6,32g6,16f6,16a#.,16f6,32d#6,32d6,32d6,32d#6,32f6,16a#,16c.6,32d6,32d#6,32f6,16a#,16c.6,32d6,32d#6,32f6,16a#6,16c7,8a#.6"
                                ,
                                "Jeopardy:d=4,o=6,b=125:c,f,c,f5,c,f,2c,c,f,c,f,a.,8g,8f,8e,8d,8c#,c,f,c,f5,c,f,2c,f.,8d,c,a#5,a5,g5,f5,p,d#,g#,d#,g#5,d#,g#,2d#,d#,g#,d#,g#,c.7,8a#,8g#,8g,8f,8e,d#,g#,d#,g#5,d#,g#,2d#,g#.,8f,d#,c#,c,p,a#5,p,g#.5,d#,g#"
                                ,
                                "Gadget:d=16,o=5,b=50:32d#,32f,32f#,32g#,a#,f#,a,f,g#,f#,32d#,32f,32f#,32g#,a#,d#6,4d6,32d#,32f,32f#,32g#,a#,f#,a,f,g#,f#,8d#"
                                ,
                                "Smurfs:d=32,o=5,b=200:4c#6,16p,4f#6,p,16c#6,p,8d#6,p,8b,p,4g#,16p,4c#6,p,16a#,p,8f#,p,8a#,p,4g#,4p,g#,p,a#,p,b,p,c6,p,4c#6,16p,4f#6,p,16c#6,p,8d#6,p,8b,p,4g#,16p,4c#6,p,16a#,p,8b,p,8f,p,4f#"
                                ,
                                "MahnaMahna:d=16,o=6,b=125:c#,c.,b5,8a#.5,8f.,4g#,a#,g.,4d#,8p,c#,c.,b5,8a#.5,8f.,g#.,8a#.,4g,8p,c#,c.,b5,8a#.5,8f.,4g#,f,g.,8d#.,f,g.,8d#.,f,8g,8d#.,f,8g,d#,8c,a#5,8d#.,8d#.,4d#,8d#."
                                ,
                                "LeisureSuit:d=16,o=6,b=56:f.5,f#.5,g.5,g#5,32a#5,f5,g#.5,a#.5,32f5,g#5,32a#5,g#5,8c#.,a#5,32c#,a5,a#.5,c#.,32a5,a#5,32c#,d#,8e,c#.,f.,f.,f.,f.,f,32e,d#,8d,a#.5,e,32f,e,32f,c#,d#.,c#"
                                ,
                                "MissionImp:d=16,o=6,b=95:32d,32d#,32d,32d#,32d,32d#,32d,32d#,32d,32d,32d#,32e,32f,32f#,32g,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,a#,g,2d,32p,a#,g,2c#,32p,a#,g,2c,a#5,8c,2p,32p,a#5,g5,2f#,32p,a#5,g5,2f,32p,a#5,g5,2e,d#,8d"
                                ,
                                "axelf2:d=4,o=5,b=125:e,8g.,8e,16e,8a,8e,8d,e,8b.,8e,16e,8c6,8b,8g,8e,8b,8e6,16e,8d,16d,8b4,8f#,e,2p,e,8g.,8e,16e,8a,8e,8d,e,8b.,8e,16e,8c6,8b,8g,8e,8b,8e6,16e,8d,16d,8b4,8f#,e"
                                ,
                                "StWars:d=4,o=5,b=160:8f,8f,8f,2a#.,2f.6,8d#6,8d6,8c6,2a#.6,f.6,8d#6,8d6,8c6,2a#.6,f.6,8d#6,8d6,8d#6,2c6,p,8f,8f,8f,2a#.,2f.6,8d#6,8d6,8c6,2a#.6,f.6,8d#6,8d6,8c6,2a#.6,f.6,8d#6,8d6,8d#6,2c6"
                                ,
                                "PacMan:d=4,o=5,b=90:32b,32p,32b6,32p,32f#6,32p,32d#6,32p,32b6,32f#6,16p,16d#6,16p,32c6,32p,32c7,32p,32g6,32p,32e6,32p,32c7,32g6,16p,16e6,16p,32b,32p,32b6,32p,32f#6,32p,32d#6,32p,32b6,32f#6,16p,16d#6,16p,32d#6,32e6,32f6,32p,32f6,32f#6,32g6,32p,32g6,32g#6,32a6,32p,32b.6"
                            };

            var pwm = new PWM(Cpu.PWMChannel.PWM_4, 50, 0, false);
            var player = new RttlPlayer(new PwmSpeaker(pwm));

            foreach (string song in songs)
                player.Play(song);

            pwm.Stop();
        }
예제 #10
0
        private static HardwareInstance GetAndUseInstance(Socket socket, SpiSharing sharing, Module module, Hardware.SPI.SPI_module spiModule)
        {
            if (spiModule == Socket.SocketInterfaces.SPIMissing)
            {
                // this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case...
                throw Socket.InvalidSocketException.FunctionalityException(socket, "SPI");
            }

            HardwareInstance foundInstance = null;

            for (int i = 0; i < Instances.Count; i++)
            {
                HardwareInstance instance = (HardwareInstance)Instances[i];

                if (instance.Module == spiModule)
                    foundInstance = instance;
            }

            if (foundInstance == null)
                Instances.Add(foundInstance = new HardwareInstance(spiModule));

            if (foundInstance.Users == 0)
            {
                socket.ReservePin(Socket.Pin.Seven, module);
                socket.ReservePin(Socket.Pin.Eight, module);
                socket.ReservePin(Socket.Pin.Nine, module);
            }
            else
            {
                if (foundInstance.Sharing != SocketInterfaces.SpiSharing.Shared)
                    throw new Exception("SPI bus " + spiModule + " is already reserved, cannot instantiate it again.");

                if (foundInstance.Sharing == SocketInterfaces.SpiSharing.Exclusive)
                    throw new Exception("SPI bus " + spiModule + " is already shared among " + foundInstance.Users + " users, cannot instantiate it for exclusive use.");
            }

            lock (foundInstance)
            {
                foundInstance.Users++;
                foundInstance.Sharing = sharing;
            }

            return foundInstance;
        }