// Note: A constructor summary is auto-generated by the doc builder. /// <summary> /// </summary> /// <remarks>This automatically checks that the socket supports Type P, and reserves the pin. /// An exception will be thrown if there is a problem with these checks.</remarks> /// <param name="socket">The socket that supports pulse width modulation (PWM) output.</param> /// <param name="pin">The pin on the socket that supports PWM.</param> /// <param name="invert">Whether to invert the output voltage.</param> /// <param name="module">The module using this PWM output interface, which can be null if unspecified.</param> public PWMOutput(Socket socket, Socket.Pin pin, bool invert, Module module) { socket.EnsureTypeIsSupported('P', module); socket.ReservePin(pin, module); Cpu.PWMChannel channel = Cpu.PWMChannel.PWM_NONE; switch (pin) { case Socket.Pin.Seven: channel = socket.PWM7; break; case Socket.Pin.Eight: channel = socket.PWM8; break; case Socket.Pin.Nine: channel = socket.PWM9; break; } if (channel == Cpu.PWMChannel.PWM_NONE && socket.PwmOutputIndirector != null) { Interface = socket.PwmOutputIndirector(socket, pin, invert, module); } else { Interface = new NativePwmOutput(socket, pin, invert, module, channel); } }
/// <summary> /// Creates an instance of <see cref="AnalogInput" /> for the given socket and pin number. /// </summary> /// <remarks>This automatically checks that the socket supports Type A, and reserves the pin used. /// An exception will be thrown if there is a problem with these checks.</remarks> /// <param name="socket">The socket.</param> /// <param name="pin">The analog input pin to use.</param> /// <param name="module">The module using the socket, which can be null if unspecified.</param> /// <returns>An instance of <see cref="AnalogInput" /> for the given socket and pin number.</returns> public static AnalogInput Create(Socket socket, Socket.Pin pin, Module module) { socket.EnsureTypeIsSupported('A', module); socket.ReservePin(pin, module); Cpu.AnalogChannel channel = Cpu.AnalogChannel.ANALOG_NONE; switch (pin) { case Socket.Pin.Three: channel = socket.AnalogInput3; break; case Socket.Pin.Four: channel = socket.AnalogInput4; break; case Socket.Pin.Five: channel = socket.AnalogInput5; break; } // native implementation is preferred to an indirected one if (channel == Cpu.AnalogChannel.ANALOG_NONE && socket.AnalogInputIndirector != null) { return(socket.AnalogInputIndirector(socket, pin, module)); } else { return(new NativeAnalogInput(socket, pin, module, channel)); } }
public static Gadgeteer.SocketInterfaces.AnalogInput Create(Socket socket, Socket.Pin pin, Module module) { socket.EnsureTypeIsSupported('A', module); socket.ReservePin(pin, module); Cpu.AnalogChannel channel = Cpu.AnalogChannel.ANALOG_NONE; switch (pin) { case Socket.Pin.Three: channel = socket.AnalogInput3; break; case Socket.Pin.Four: channel = socket.AnalogInput4; break; case Socket.Pin.Five: channel = socket.AnalogInput5; break; } if ((channel == Cpu.AnalogChannel.ANALOG_NONE) && (socket.AnalogInputIndirector != null)) { return(socket.AnalogInputIndirector(socket, pin, module)); } return(new NativeAnalogInput(socket, pin, module, channel)); }
/// <summary> /// Tells GadgeteerCore that a pin is being used on this socket. A <see cref="PinConflictException"/> will be thrown if the pin is already reserved. /// This is called by Gadgteeer.Interface classes automatically. Gadgeteer.Modules which do not use a Gadgeteer.Interface helper class in using a pin should call this directly. /// Note that Gadgeteer allows mainboard pins to be reused across multiple sockets, so the reservation check also checks if the pin is used on a different socket where the pin is shared. /// </summary> /// <param name="pin">The socket pin being used</param> /// <param name="module">The module using the socket pin (can be null, but if it is not null a more useful error message will be generated).</param> /// <returns></returns> public Cpu.Pin ReservePin(Socket.Pin pin, Module module) { Cpu.Pin cpuPin = CpuPins[(int)pin]; if (cpuPin == UnspecifiedPin) { throw new PinMissingException(this, pin); } if (cpuPin == UnnumberedPin) { // bypass checks, return no pin return(Cpu.Pin.GPIO_NONE); } // Check to see if pin is already reserved foreach (PinReservation reservation in _reservedPins) { if (cpuPin == reservation.CpuPin) { throw new PinConflictException(this, pin, module, reservation); } } // see if this is a display socket and reboot if we need to disable the LCD controller if (!(module is Module.DisplayModule) && (SupportsType('R') || SupportsType('G') || SupportsType('B'))) { Module.DisplayModule.LCDControllerPinReuse(); } _reservedPins.Add(new PinReservation(this, pin, cpuPin, module)); return(cpuPin); }
public PinReservation(Socket socket, Socket.Pin pin, Cpu.Pin cpuPin, Module module) { ReservingSocket = socket; ReservingModule = module; ReservingPin = pin; CpuPin = cpuPin; }
/// <summary> /// Tells GadgeteerCore that a pin is being used on this socket. /// This is called by Gadgteeer.Interface classes automatically. Gadgeteer.Modules which do not use a Gadgeteer.Interface helper class in using a pin should call this directly. /// </summary> /// <param name="pin">The socket pin being used</param> /// <param name="module">The module using the socket pin (can be null, but if it is not null a more useful error message will be generated).</param> /// <returns></returns> public Cpu.Pin ReservePin(Socket.Pin pin, Module module) { if (pin == Pin.None) { return(UnspecifiedPin); } Cpu.Pin cpuPin = CpuPins[(int)pin]; if (cpuPin == UnspecifiedPin) { throw new PinMissingException(this, pin); } if (cpuPin == UnnumberedPin) { // bypass checks, return no pin return(Cpu.Pin.GPIO_NONE); } // see if this is a display socket and reboot if we need to disable the LCD controller if (!(module is Module.DisplayModule) && (SupportsType('R') || SupportsType('G') || SupportsType('B'))) { Program.Mainboard.EnsureRgbSocketPinsAvailable(); } return(cpuPin); }
/// <summary> /// Creates an instance of <see cref="PwmOutput" /> for the given socket and pin number. /// </summary> /// <remarks>This automatically checks that the socket supports Type P, and reserves the pin. /// An exception will be thrown if there is a problem with these checks.</remarks> /// <param name="socket">The socket that supports pulse width modulation (PWM) output.</param> /// <param name="pin">The pin on the socket that supports PWM.</param> /// <param name="invert">Whether to invert the output voltage.</param> /// <param name="module">The module using this PWM output interface, which can be null if unspecified.</param> /// <returns>An instance of <see cref="PwmOutput" /> for the given socket and pin number.</returns> public static PwmOutput Create(Socket socket, Socket.Pin pin, bool invert, Module module) { socket.EnsureTypeIsSupported('P', module); socket.ReservePin(pin, module); Cpu.PWMChannel channel = Cpu.PWMChannel.PWM_NONE; switch (pin) { case Socket.Pin.Seven: channel = socket.PWM7; break; case Socket.Pin.Eight: channel = socket.PWM8; break; case Socket.Pin.Nine: channel = socket.PWM9; break; } // native implementation is preferred to an indirected one if (channel == Cpu.PWMChannel.PWM_NONE && socket.PwmOutputIndirector != null) { return(socket.PwmOutputIndirector(socket, pin, invert, module)); } else { return(new NativePwmOutput(socket, pin, invert, module, channel)); } }
public static PwmOutput Create(Socket socket, Socket.Pin pin, bool invert, Module module) { socket.EnsureTypeIsSupported('P', module); socket.ReservePin(pin, module); Cpu.PWMChannel channel = Cpu.PWMChannel.PWM_NONE; switch (pin) { case Socket.Pin.Seven: channel = socket.PWM7; break; case Socket.Pin.Eight: channel = socket.PWM8; break; case Socket.Pin.Nine: channel = socket.PWM9; break; } if ((channel == Cpu.PWMChannel.PWM_NONE) && (socket.PwmOutputIndirector != null)) { return(socket.PwmOutputIndirector(socket, pin, invert, module)); } return(new NativePwmOutput(socket, pin, invert, module, channel)); }
/// <summary> /// Creates an instance of <see cref="I2CBus" /> for the given socket and pins. /// </summary> /// <remarks>This automatically checks that the socket supports Type I, and reserves the SDA and SCL pins. /// An exception will be thrown if there is a problem with these checks.</remarks> /// <param name="address">The address for the I2C device.</param> /// <param name="clockRateKhz">The clock rate, in kHz, used when communicating with the I2C device.</param> /// <param name="sdaPin">The SDA pin used by the I2C device.</param> /// <param name="sclPin">The SCL pin used by the I2C device.</param> /// <param name="socket">The socket for this I2C device interface.</param> /// <param name="module">The module using this I2C interface, which can be null if unspecified.</param> /// <returns>An instance of <see cref="I2CBus" /> for the given socket.</returns> public static I2CBus Create(Socket socket, ushort address, int clockRateKhz, Socket.Pin sdaPin, Socket.Pin sclPin, Module module) { // There is only one I�C module in .NET Micro Framework, so the NativeI2CBus would just go and use it // regardless of the requested pins, so we need to do the checks here instead. Cpu.Pin reservedSclPin = socket.ReservePin(sclPin, module); Cpu.Pin reservedSdaPin = socket.ReservePin(sdaPin, module); Cpu.Pin nativeSclPin, nativeSdaPin; HardwareProvider.HwProvider.GetI2CPins(out nativeSclPin, out nativeSdaPin); // native implementation is preferred to an indirected one if (reservedSdaPin == nativeSdaPin && reservedSclPin == nativeSclPin) { return(new NativeI2CBus(socket, address, clockRateKhz, module)); } else if (socket.I2CBusIndirector != null) { return(socket.I2CBusIndirector(socket, sdaPin, sclPin, address, clockRateKhz, module)); } else { return(new SoftwareI2CBus(socket, sdaPin, sclPin, address, clockRateKhz, module)); } }
public NativeDigitalOutput(Socket socket, Socket.Pin pin, bool initialState, Module module, Cpu.Pin cpuPin) { if (cpuPin == Cpu.Pin.GPIO_NONE) { throw Socket.InvalidSocketException.FunctionalityException(socket, "DigitalOutput"); } this._port = new OutputPort(cpuPin, initialState); }
public NativeDigitalInput(Socket socket, Socket.Pin pin, GlitchFilterMode glitchFilterMode, Gadgeteer.SocketInterfaces.ResistorMode resistorMode, Module module, Cpu.Pin cpuPin) { if (cpuPin == Cpu.Pin.GPIO_NONE) { throw Socket.InvalidSocketException.FunctionalityException(socket, "DigitalInput"); } this._port = new InputPort(cpuPin, glitchFilterMode == GlitchFilterMode.On, (Port.ResistorMode)resistorMode); }
public static DigitalIO Create(Socket socket, Socket.Pin pin, bool initialState, GlitchFilterMode glitchFilterMode, Gadgeteer.SocketInterfaces.ResistorMode resistorMode, Module module) { Cpu.Pin cpuPin = socket.ReservePin(pin, module); if ((cpuPin == Cpu.Pin.GPIO_NONE) && (socket.DigitalIOIndirector != null)) { return(socket.DigitalIOIndirector(socket, pin, initialState, glitchFilterMode, resistorMode, module)); } return(new NativeDigitalIO(socket, pin, initialState, glitchFilterMode, resistorMode, module, cpuPin)); }
public static DigitalOutput Create(Socket socket, Socket.Pin pin, bool initialState, Module module) { Cpu.Pin cpuPin = socket.ReservePin(pin, module); if ((cpuPin == Cpu.Pin.GPIO_NONE) && (socket.DigitalOutputIndirector != null)) { return(socket.DigitalOutputIndirector(socket, pin, initialState, module)); } return(new NativeDigitalOutput(socket, pin, initialState, module, cpuPin)); }
public static InterruptInput Create(Socket socket, Socket.Pin pin, GlitchFilterMode glitchFilterMode, Gadgeteer.SocketInterfaces.ResistorMode resistorMode, Gadgeteer.SocketInterfaces.InterruptMode interruptMode, Module module) { Cpu.Pin cpuPin = socket.ReservePin(pin, module); if ((cpuPin == Cpu.Pin.GPIO_NONE) && (socket.InterruptIndirector != null)) { return(socket.InterruptIndirector(socket, pin, glitchFilterMode, resistorMode, interruptMode, module)); } return(new NativeInterruptInput(socket, pin, glitchFilterMode, resistorMode, interruptMode, module, cpuPin)); }
public NativeDigitalOutput(Socket socket, Socket.Pin pin, bool initialState, 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, "DigitalOutput"); } _port = new Hardware.OutputPort(cpuPin, initialState); }
public NativeDigitalIO(Socket socket, Socket.Pin pin, bool initialState, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, Module module, Cpu.Pin cpuPin) { if (cpuPin == 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, "DigitalIO"); } _port = new TristatePort(cpuPin, initialState, glitchFilterMode == GlitchFilterMode.On, (Port.ResistorMode)resistorMode); }
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); }
public NativeAnalogInput(Socket socket, Socket.Pin pin, Module module, Cpu.AnalogChannel channel) { if (channel == Cpu.AnalogChannel.ANALOG_NONE) { Socket.InvalidSocketException.ThrowIfOutOfRange(pin, Socket.Pin.Three, Socket.Pin.Five, "AnalogInput", module); throw Socket.InvalidSocketException.FunctionalityException(socket, "AnalogInput"); } this._channel = channel; this._socket = socket; }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <param name="socket">The socket for the digital input interface.</param> /// <param name="pin">The pin used by the digital input interface.</param> /// <param name="glitchFilterMode"> /// A value from the <see cref="GlitchFilterMode"/> enumeration that specifies /// whether to enable the glitch filter on this digital input interface. /// </param> /// <param name="resistorMode"> /// A value from the <see cref="ResistorMode"/> enumeration that establishes a default state for the digital input interface. N.B. .NET Gadgeteer mainboards are only required to support ResistorMode.PullUp on interruptable GPIOs and are never required to support ResistorMode.PullDown; consider putting the resistor on the module itself. /// </param> /// <param name="module">The module using this interface, which can be null if unspecified.</param> public DigitalInput(Socket socket, Socket.Pin pin, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, Module module) { this.port = new InputPort(socket.ReservePin(pin, module), glitchFilterMode == GlitchFilterMode.On, (Port.ResistorMode)resistorMode); if (this.port == null) { // this is a mainboard error but should not happen since we check for this, but it doesnt hurt to double-check throw new Socket.InvalidSocketException("Socket " + socket + " has an error with its Digital Input functionality. Please try a different socket."); } }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <param name="socket">The socket for the digital output interface.</param> /// <param name="pin">The pin used by the digital output interface.</param> /// <param name="initialState">The initial state to place on the digital output interface port.</param> /// <param name="module">The module using this interface (which can be null if unspecified).</param> public DigitalOutput(Socket socket, Socket.Pin pin, bool initialState, Module module) { this.port = new OutputPort(socket.ReservePin(pin, module), initialState); if (this.port == null) { // this is a mainboard error but should not happen since we check for this, but it doesnt hurt to double-check throw new Socket.InvalidSocketException("Socket " + socket + " has an error with its Digital Output functionality. Please try a different socket."); } }
public NativePwmOutput(Socket socket, Socket.Pin pin, bool invert, Module module, Cpu.PWMChannel channel) { if (channel == Cpu.PWMChannel.PWM_NONE) { Socket.InvalidSocketException.ThrowIfOutOfRange(pin, Socket.Pin.Seven, Socket.Pin.Nine, "PWM", module); throw Socket.InvalidSocketException.FunctionalityException(socket, "PWM"); } this._channel = channel; this._socket = socket; this._invert = invert; }
public static Gadgeteer.SocketInterfaces.AnalogOutput Create(Socket socket, Socket.Pin pin, Module module) { socket.EnsureTypeIsSupported('O', module); socket.ReservePin(pin, module); Cpu.AnalogOutputChannel channel = socket.AnalogOutput5; if ((channel == Cpu.AnalogOutputChannel.ANALOG_OUTPUT_NONE) && (socket.AnalogOutputIndirector != null)) { return(socket.AnalogOutputIndirector(socket, pin, module)); } return(new NativeAnalogOutput(socket, pin, module, channel)); }
public NativeAnalogInput(Socket socket, Socket.Pin pin, Module module, Cpu.AnalogChannel channel) { if (channel == 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; }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <param name="socket">The socket for the interrupt input interface.</param> /// <param name="pin">The pin used by the interrupt input interface.</param> /// <param name="glitchFilterMode"> /// A value from the <see cref="GlitchFilterMode"/> enumeration that specifies /// whether to enable the glitch filter on this interrupt input interface. /// </param> /// <param name="resistorMode"> /// A value from the <see cref="ResistorMode"/> enumeration that establishes a default state for the interrupt input interface. N.B. .NET Gadgeteer mainboards are only required to support ResistorMode.PullUp on interruptable GPIOs and are never required to support ResistorMode.PullDown; consider putting the resistor on the module itself. /// </param> /// <param name="interruptMode"> /// A value from the <see cref="InterruptMode"/> enumeration that establishes the requisite conditions /// for the interface port to generate an interrupt. /// </param> /// <param name="module">The module using this interrupt input interface, which can be null if unspecified.</param> public InterruptInput(Socket socket, Socket.Pin pin, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, InterruptMode interruptMode, Module module) { this.port = new InterruptPort(socket.ReservePin(pin, module), glitchFilterMode == GlitchFilterMode.On, (Port.ResistorMode)resistorMode, (Port.InterruptMode)interruptMode); if (this.port == null) { // this is a mainboard error but should not happen since we check for this, but it doesnt hurt to double-check throw new Socket.InvalidSocketException("Socket " + socket + " has an error with its Interrupt Input functionality. Please try a different socket."); } this.SynchronousUnsafeEventInvocation = false; this.port.OnInterrupt += new NativeEventHandler(this._port_OnInterrupt); }
public static void ThrowIfOutOfRange(Socket.Pin pin, Socket.Pin from, Socket.Pin to, string iface, Module module) { if ((pin < from) || (pin > to)) { object[] objArray1 = new object[] { "Cannot use ", iface, " interface on pin ", pin, " - pin must be in range ", from, " to ", to, "." }; string message = string.Concat(objArray1); if (module != null) { message = "Module " + module + ": "; } throw new Socket.InvalidSocketException(message); } }
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; }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <remarks>This automatically checks that the socket supports Type O, and reserves the pin. /// An exception will be thrown if there is a problem with these checks.</remarks> /// <param name="socket">The analog output capable socket.</param> /// <param name="pin">The pin to assign to the analog output.</param> /// <param name="module">The module using this analog output interface, which can be null if unspecified.</param> public AnalogOutput(Socket socket, Socket.Pin pin, Module module) { this.socket = socket; socket.EnsureTypeIsSupported('O', module); port = socket.AnalogOutput; if (port == null) { // this is a mainboard error but should not happen since we check for this, but it doesnt hurt to double-check throw new Socket.InvalidSocketException("Socket " + socket + " has an error with its Analog Output functionality. Please try a different socket."); } socket.ReservePin(pin, module); }
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; }
/// <summary> /// Creates an instance of <see cref="DigitalOutput" /> for the given socket and pin number. /// </summary> /// <param name="socket">The socket for the digital output interface.</param> /// <param name="pin">The pin used by the digital output interface.</param> /// <param name="initialState">The initial state to place on the digital output interface port.</param> /// <param name="module">The module using this interface (which can be null if unspecified).</param> /// <returns>An instance of <see cref="DigitalOutput" /> for the given socket and pin number.</returns> public static DigitalOutput Create(Socket socket, Socket.Pin pin, bool initialState, Module module) { Cpu.Pin reservedPin = socket.ReservePin(pin, module); // native implementation is preferred to an indirected one if (reservedPin == Cpu.Pin.GPIO_NONE && socket.DigitalOutputIndirector != null) { return(socket.DigitalOutputIndirector(socket, pin, initialState, module)); } else { return(new NativeDigitalOutput(socket, pin, initialState, module, reservedPin)); } }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <param name="socket">The socket for the interrupt input interface.</param> /// <param name="pin">The pin used by the interrupt input interface.</param> /// <param name="glitchFilterMode"> /// A value from the <see cref="GlitchFilterMode"/> enumeration that specifies /// whether to enable the glitch filter on this interrupt input interface. /// </param> /// <param name="resistorMode"> /// A value from the <see cref="ResistorMode"/> enumeration that establishes a default state for the interrupt input interface. N.B. .NET Gadgeteer mainboards are only required to support ResistorMode.PullUp on interruptable GPIOs and are never required to support ResistorMode.PullDown; consider putting the resistor on the module itself. /// </param> /// <param name="interruptMode"> /// A value from the <see cref="InterruptMode"/> enumeration that establishes the requisite conditions /// for the interface port to generate an interrupt. /// </param> /// <param name="module">The module using this interrupt input interface, which can be null if unspecified.</param> public InterruptInput(Socket socket, Socket.Pin pin, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, InterruptMode interruptMode, Module module) { Cpu.Pin reservedPin = socket.ReservePin(pin, module); // native implementation is preferred to an indirected one if (reservedPin == Cpu.Pin.GPIO_NONE && socket.InterruptIndirector != null) { Interface = socket.InterruptIndirector(socket, pin, glitchFilterMode, resistorMode, interruptMode, module); } else { Interface = new NativeInterruptInput(socket, pin, glitchFilterMode, resistorMode, interruptMode, module, reservedPin); } }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary> /// </summary> /// <remarks>This automatically checks that the socket supports Type P, and reserves the pin. /// An exception will be thrown if there is a problem with these checks.</remarks> /// <param name="socket">The socket that supports pulse width modulation (PWM) output.</param> /// <param name="pin">The pin on the socket that supports PWM.</param> /// <param name="module">The module using this PWM output interface, which can be null if unspecified.</param> public PWMOutput(Socket socket, Socket.Pin pin, Module module) { this.pin = pin; socket.EnsureTypeIsSupported('P',module); switch(pin) { case Socket.Pin.Seven: pwm = socket.PWM7; break; case Socket.Pin.Eight: pwm = socket.PWM8; break; case Socket.Pin.Nine: pwm = socket.PWM9; break; default: if (module != null) { throw new Socket.InvalidSocketException("Module " + module + " cannot use PWM interface on pin " + pin + " - pin must be in range 7 to 9."); } else { throw new Socket.InvalidSocketException("Cannot use PWM interface on pin " + pin + " - pin must be in range 7 to 9."); } } if (pwm == null) { // this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case... throw new Socket.InvalidSocketException("Socket " + socket + " has an error with its PWM functionality. Please try a different socket."); } socket.ReservePin(pin, module); this.pwm.Active = false; }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <remarks>This automatically checks that the socket supports Type X or Y as appropriate, and reserves the SDA and SCL pins. /// An exception will be thrown if there is a problem with these checks.</remarks> /// <param name="socket">The socket for this software I2C device interface.</param> /// <param name="address">The address of the I2C device.</param> /// <param name="clockRateKHz">The maximum clock speed supported by the I2C device.</param> /// <param name="sdaPin">The socket pin used for I2C data.</param> /// <param name="sclPin">The socket pin used for I2C clock.</param> /// <param name="module">The module using this I2C interface, which can be null if unspecified.</param> public SoftwareI2CBus(Socket socket, Socket.Pin sdaPin, Socket.Pin sclPin, ushort address, int clockRateKHz, Module module) { this.address = (byte)address; this.clockRateKHz = clockRateKHz; // see if we've already reserved the pins and got instances of the ports, otherwise do that. string sdaPinString = socket.ToString() + "___" + sdaPin; if (!ReservedSdaPinPorts.Contains(sdaPinString)) { sdaPort = DigitalIOFactory.Create(socket, sdaPin, false, GlitchFilterMode.Off, ForceManagedPullUps ? ResistorMode.PullUp : ResistorMode.Disabled, module); ReservedSdaPinPorts.Add(sdaPinString, sdaPort); } else { sdaPort = (DigitalIO)ReservedSdaPinPorts[sdaPinString]; } string sclPinString = socket.ToString() + "___" + sclPin; if (!ReservedSclPinPorts.Contains(sclPinString)) { sclPort = DigitalIOFactory.Create(socket, sclPin, false, GlitchFilterMode.Off, ForceManagedPullUps ? ResistorMode.PullUp : ResistorMode.Disabled, module); ReservedSclPinPorts.Add(sclPinString, sclPort); } else { sclPort = (DigitalIO)ReservedSclPinPorts[sclPinString]; } this.socket = socket; this.sdaPin = sdaPin; this.sclPin = sclPin; lock (SoftwareI2CTimeoutList) { timeoutCount = -1; // Prevent the TimeoutHandler thread from watching this port for now SoftwareI2CTimeoutList.Add(this); if (timeoutThread == null) { threadExit = false; timeoutThread = new Thread(TimeoutHandler); timeoutThread.Start(); } } }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <remarks>This automatically checks that the socket supports Type X or Y as appropriate, and reserves the SDA and SCL pins. /// An exception will be thrown if there is a problem with these checks.</remarks> /// <param name="socket">The socket for this software I2C device interface.</param> /// <param name="sdaPin">The socket pin used for I2C data.</param> /// <param name="sclPin">The socket pin used for I2C clock.</param> /// <param name="module">The module using this I2C interface, which can be null if unspecified.</param> public SoftwareI2C(Socket socket, Socket.Pin sdaPin, Socket.Pin sclPin, Module module) { // first check the socket is compatible if (sclPin > Socket.Pin.Five || sdaPin > Socket.Pin.Five) { socket.EnsureTypeIsSupported('Y', module); } else { socket.EnsureTypeIsSupported(new char[] { 'X', 'Y' }, module); } if (ForceManagedSoftwareI2CImplementation || socket.NativeI2CWriteRead == null) usingManaged = true; // then see if we've already reserved the pins and got instances of the ports, otherwise do that. string sdaPinString = socket.ToString() + "___" + sdaPin; if (!ReservedSdaPinPorts.Contains(sdaPinString)) { Cpu.Pin sdaCpuPin = socket.ReservePin(sdaPin, module); if (usingManaged) { sdaPort = new TristatePort(sdaCpuPin, false, false, ForceManagedPullUps ? Port.ResistorMode.PullUp : Port.ResistorMode.Disabled); } ReservedSdaPinPorts.Add(sdaPinString, sdaPort); } else { sdaPort = (TristatePort)ReservedSdaPinPorts[sdaPinString]; } string sclPinString = socket.ToString() + "___" + sclPin; if (!ReservedSclPinPorts.Contains(sclPinString)) { Cpu.Pin sclCpuPin = socket.ReservePin(sclPin, module); if (usingManaged) { sclPort = new TristatePort(sclCpuPin, false, false, ForceManagedPullUps ? Port.ResistorMode.PullUp : Port.ResistorMode.Disabled); } ReservedSclPinPorts.Add(sclPinString, sclPort); } else { sclPort = (TristatePort)ReservedSclPinPorts[sclPinString]; } this.socket = socket; this.sdaPin = sdaPin; this.sclPin = sclPin; if (usingManaged) { lock (SoftwareI2CTimeoutList) { timeoutCount = -1; // Prevent the TimeoutHandler thread from watching this port for now SoftwareI2CTimeoutList.Add(this); if (timeoutThread == null) { threadExit = false; timeoutThread = new Thread(new ThreadStart(TimeoutHandler)); timeoutThread.Start(); } } } }