public override void DigitalWrite(int gpioIndex, MadeInTheUSB.GPIO.PinState d) { this.SetGpioMask(ComputeMask(GetGpioMask(), gpioIndex, d)); }
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 virtual void SetPullUp(int p, MadeInTheUSB.GPIO.PinState 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 DigitalWrite(int p, MadeInTheUSB.GPIO.PinState d) { }
public void SetPinMode(byte gpioIndex, MadeInTheUSB.GPIO.PinMode mode) { var k = MCP230XX_Base.BuildGpioName(gpioIndex); if (this.GPIOS.ContainsKey(k)) this.GPIOS[k].Mode = mode; else throw new ArgumentException(string.Format("Gpio {0} not available", gpioIndex)); var mcpIndex = gpioIndex - this.GpioStartIndex; if (mcpIndex > (this.GetMaxGPIO()-1)) throw new ArgumentException(string.Format("Gpio {0} not available", gpioIndex)); int iodir = this._i2c.Send1ByteRead1Byte(MCP230XX_IODIR); if (iodir == -1) throw new ArgumentException(string.Format("Cannot read state of MCP230XX")); if (mode == GPIO.PinMode.Input) iodir |= (byte)(1 << mcpIndex); else iodir &= (byte)(~(1 << mcpIndex)); if (!this._i2c.Send2BytesCommand(MCP230XX_IODIR, (byte)iodir)) throw new ArgumentException(string.Format("Cannot set state of MCP230XX")); }
public void SetPinMode(int p, MadeInTheUSB.GPIO.PinMode mode) { SetPinMode((byte)p, mode); }
public void SetPinMode(string gpio, MadeInTheUSB.GPIO.PinMode mode) { SetPinMode(McpGpio.ExtractGpioIndex(gpio), mode); }
public bool ValidateOperation(MadeInTheUSB.spi.SPIEngine.SPIResult result, ADDRESS address, COMMAND command, int? value = null) { var r = false; // See datasheet http://exploringarduino.com/wp-content/uploads/2013/06/MCP4231-datasheet.pdf // Page 48 // Value Function MOSI (SDI pin) MISO (SDO pin) (2) // 00h Volatile Wiper 0 Write Data nn nnnn nnnn 0000 00nn nnnn nnnn 1111 1111 1111 1111 // Read Data nn nnnn nnnn 0000 11nn nnnn nnnn 1111 111n nnnn nnnn // Increment Wiper — 0000 0100 1111 1111 // Decrement Wiper — 0000 1000 1111 1111 // 01h Volatile Wiper 1 Write Data nn nnnn nnnn 0001 00nn nnnn nnnn 1111 1111 1111 1111 // Read Data nn nnnn nnnn 0001 11nn nnnn nnnn 1111 111n nnnn nnnn // Increment Wiper — 0001 0100 1111 1111 // Decrement Wiper — 0001 1000 1111 1111 // 02h Reserved — — — — // 03h Reserved — — — — // 04h Volatile // TCON Register // Write Data nn nnnn nnnn 0100 00nn nnnn nnnn 1111 1111 1111 1111 // Read Data nn nnnn nnnn 0100 11nn nnnn nnnn 1111 111n nnnn nnnn // 05h Status Register Read Data nn nnnn nnnn 0101 11nn nnnn nnnn 1111 111n nnnn nnnn // 06h-0Fh Reserved — — — — // Note 1: The Data Memory is only 9-bits wide, so the MSb is ignored by the device. // 2: All these Address/Command combinations are valid, so the CMDERR bit is s switch (command) { case COMMAND.WRITE : r = (result.ReadBuffer.Count == 2) && (result.ReadBuffer[0] == 255) && result.ReadBuffer[1] == 255; break; case COMMAND.DECREMENT : case COMMAND.INCREMENT : r = (result.ReadBuffer.Count == 1) && (result.ReadBuffer[0] == 255); break; case COMMAND.READ : r = (result.ReadBuffer.Count == 2) && (result.ReadBuffer[0] >= 254); if(r) result.Value = result.ReadBuffer[1]; break; } return r; }