public override void SetPullUp(int gpioIndex, MadeInTheUSB.GPIO.PinState d) { var mcpGpioIndex = gpioIndex - this.GpioStartIndex; // only 8 bits! if (mcpGpioIndex > 7) { throw new InvalidGpioOperationException(string.Format("Invalid gpio index:{0}", gpioIndex)); } int gppu = this._i2c.Send1ByteRead1Byte(MCP230XX_GPPU); if (gppu == -1) { throw new InvalidGpioOperationException(string.Format("Command MCP230XX_GPPU({0}) failed gpio index:{1}", MCP230XX_GPPU, gpioIndex)); } if (d == GPIO.PinState.High) { // set the pin and direction gppu |= (byte)(1 << mcpGpioIndex); } else { gppu &= (byte)(~(1 << mcpGpioIndex)); } // write the new GPIO this._i2c.Send2BytesCommand(MCP230XX_GPPU, (byte)gppu); }
public override void DigitalWrite(int gpioIndex, MadeInTheUSB.GPIO.PinState d) { var gpio = VerifyGpioIndex(gpioIndex); if (gpio.Mode != PinMode.Output) { throw new ArgumentException(string.Format("GPIO {0} is not configured as ouput", gpioIndex)); } this.SetGpioMask(ComputeMask(GetGpioMask(), gpioIndex, d)); }
//public void SetGpioMask(byte mask) //{ // SetGPIOMask(mask); //} public byte ComputeMask(byte mask, int gpioIndex, MadeInTheUSB.GPIO.PinState d) { var mcpIndex = gpioIndex - this.GpioStartIndex; // only 8 bits! if (mcpIndex > 7) { return(mask); } int gpio = mask; // set the pin and direction if (d == GPIO.PinState.High) { gpio |= (byte)(1 << mcpIndex); } else { gpio &= (byte)(~(1 << mcpIndex)); } return((byte)gpio); }
public virtual void SetPullUp(int p, MadeInTheUSB.GPIO.PinState d) { }
public virtual void DigitalWrite(int p, MadeInTheUSB.GPIO.PinState d) { }