Ejemplo n.º 1
0
        /// <summary> Configures the internal resistor for the given pin. </summary>
        /// <param name="Pin"> THe pin to configure. </param>
        /// <param name="ResMode"> The resistor to apply. </param>
        internal static void SetResistor(int Pin, ResistorState ResMode)
        {
            if (!Initialized)
            {
                throw new InvalidOperationException("Cannot perform GPIO operations until the system is initialized. Call RasperryPi.Initialize().");
            }
            int ResistorVal = 0;

            if (ResMode == ResistorState.PULL_UP)
            {
                ResistorVal = 2;
            }
            else if (ResMode == ResistorState.PULL_DOWN)
            {
                ResistorVal = 1;
            }
            External.SetResistor(Pin, ResistorVal);
        }
Ejemplo n.º 2
0
        /// <summary> Creates a 8-bit pin mode from the specified parameters. </summary>
        internal static byte GetPinMode(bool FastSlew, bool EnableReceiver, ResistorState Resistor, byte ModeID)
        {
            // Bit | Function           | Modes
            // ====|====================|=====================
            // 0   | Reserved           | 0
            // 0   | Slew Rate          | 0=Fast, 1=Slow
            // 0   | Receiver Enable    | 0=Disable, 1=Enable
            // 0   | Resistor Selection | 0=Pulldown, 1=Pullup
            // ----|--------------------|---------------------
            // 0   | Resistor Enable    | 0=Enable, 1=Disable
            // 000 | Mux Select         | Value, 0 through 7
            // -----------------------------------------------
            // Source: AM3359 Technical Reference Manual: http://www.ti.com/product/AM3359/technicaldocuments
            // Version P, Page 1512, Section 9.3.1.50, Table 9-60
            // Find by searching "conf_<module>" in other versions.
            byte Output = 0b0000_0000;

            if (!FastSlew)
            {
                Output |= 0b0100_0000;
            }
            if (EnableReceiver)
            {
                Output |= 0b0010_0000;
            }
            if (Resistor == ResistorState.PULL_UP)
            {
                Output |= 0b0001_0000;
            }
            else if (Resistor == ResistorState.NONE)
            {
                Output |= 0b0000_1000;
            }
            if (ModeID >= 0b000 && ModeID <= 0b111)
            {
                Output |= ModeID;
            }
            return(Output);
        }
Ejemplo n.º 3
0
 /// <summary> Resistor state cannot be changed during runtime on BBB, it must be set in the device tree overlay. This will throw an exception. </summary>
 public void SetResistor(ResistorState Resistor)
 {
     throw new NotImplementedException("Resistor state cannot be changed on BBB without re-applying device tree overlay.");
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Sets the input to either have a ~50KΩ pullup resistor, pulldown resistor, or no resistor.
 /// </summary>
 public void SetResistor(ResistorState Resistor)
 {
     RaspberryPi.SetResistor(this.PinNumber, Resistor);
 }
Ejemplo n.º 5
0
 public void SetResistor(ResistorState Resistor)
 {
     throw new InvalidOperationException("PCA9535E does not have configurable input resistors.");
 }
Ejemplo n.º 6
0
 public void SetResistor(ResistorState Resistor) => this.Input.SetResistor(Resistor);