Characteristic | Locus |
---|---|
Inheritance | System.Object > Mcp23xxx > Mcp23x0x > Mcp23x1x |
Namespace | Meadow.Foundation.ICs.IOExpanders |
Assembly | Mcp23xxx.dll |
Syntax
public abstract class Mcp23xxx : IDigitalInputOutputController
Constructors
Mcp23xxx(II2cBus, Byte, IDigitalInputPort, IDigitalOutputPort)
Mcpxxx base class contructor
Declaration
protected Mcp23xxx(II2cBus i2cBus, byte address, IDigitalInputPort interruptPort = null, IDigitalOutputPort resetPort = null)
Parameters
Type | Name | Description |
---|---|---|
II2cBus | i2cBus | The I2C bus |
System.Byte | address | The I2C address |
IDigitalInputPort | interruptPort | Optional interupt port, needed for input interrupts (pins 1-8) |
IDigitalOutputPort | resetPort | Optional Meadow output port used to reset the mcp expander |
Mcp23xxx(ISpiBus, IDigitalOutputPort, IDigitalInputPort, IDigitalOutputPort)
Mcpxxx base class contructor
Declaration
protected Mcp23xxx(ISpiBus spiBus, IDigitalOutputPort chipSelectPort, IDigitalInputPort interruptPort = null, IDigitalOutputPort resetPort = null)
Parameters
Type | Name | Description |
---|---|---|
ISpiBus | spiBus | The SPI bus |
IDigitalOutputPort | chipSelectPort | Chip select port |
IDigitalInputPort | interruptPort | Optional interupt port, needed for input interrupts (pins 1-8) |
IDigitalOutputPort | resetPort | Optional Meadow output port used to reset the mcp expander |
Fields
_lock
object for using lock() to do thread sync
Declaration
protected object _lock
Field Value
Type | Description |
---|---|
System.Object |
Properties
NumberOfPins
The number of IO pins avaliable on the device
Declaration
public abstract int NumberOfPins { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
CreateDigitalInputPort(IPin)
Creates a new DigitalInputPort using the specified pin
Declaration
public IDigitalInputPort CreateDigitalInputPort(IPin pin)
Parameters
Type | Name | Description |
---|---|---|
IPin | pin | The pin representing the port |
Returns
Type | Description |
---|---|
IDigitalInputPort | IDigitalInputPort |
CreateDigitalInputPort(IPin, InterruptMode, ResistorMode)
Creates a new DigitalInputPort using the specified pin
Declaration
public IDigitalInputPort CreateDigitalInputPort(IPin pin, InterruptMode interruptMode = null, ResistorMode resistorMode = null)
Parameters
Type | Name | Description |
---|---|---|
IPin | pin | The pin representing the port |
InterruptMode | interruptMode | The port interrupt mode |
ResistorMode | resistorMode | The port resistor mode |
Returns
Type | Description |
---|---|
IDigitalInputPort | IDigitalInputPort |
CreateDigitalInputPort(IPin, InterruptMode, ResistorMode, TimeSpan)
Creates a new DigitalInputPort using the specified pin
Declaration
public IDigitalInputPort CreateDigitalInputPort(IPin pin, InterruptMode interruptMode, ResistorMode resistorMode, TimeSpan debounceDuration)
Parameters
Type | Name | Description |
---|---|---|
IPin | pin | The pin representing the port |
InterruptMode | interruptMode | The port interrupt mode |
ResistorMode | resistorMode | The port resistor mode |
TimeSpan | debounceDuration | The debounce duration |
Returns
Type | Description |
---|---|
IDigitalInputPort | IDigitalInputPort |
CreateDigitalInputPort(IPin, InterruptMode, ResistorMode, TimeSpan, TimeSpan)
Creates a new DigitalInputPort using the specified pin
Declaration
public IDigitalInputPort CreateDigitalInputPort(IPin pin, InterruptMode interruptMode, ResistorMode resistorMode, TimeSpan debounceDuration, TimeSpan glitchDuration)
Parameters
Type | Name | Description |
---|---|---|
IPin | pin | The pin representing the port |
InterruptMode | interruptMode | The port interrupt mode |
ResistorMode | resistorMode | The port resistor mode |
TimeSpan | debounceDuration | The debounce duration |
TimeSpan | glitchDuration | The clitch duration - not configurable on Mcpxxxx |
Returns
Type | Description |
---|---|
IDigitalInputPort | IDigitalInputPort |
CreateDigitalOutputPort(IPin, Boolean, OutputType)
Creates a new DigitalOutputPort using the specified pin and initial state
Declaration
public virtual IDigitalOutputPort CreateDigitalOutputPort(IPin pin, bool initialState = false, OutputType outputType = null)
Parameters
Type | Name | Description |
---|---|---|
IPin | pin | The pin representing the port |
System.Boolean | initialState | Whether the pin is initially high or low |
OutputType | outputType | The output type |
Returns
Type | Description |
---|---|
IDigitalOutputPort | IDigitalOutputPort |
GetAddressFromPins(Boolean, Boolean, Boolean)
Help method to get address from address pin configuation
Declaration
public static byte GetAddressFromPins(bool pinA0, bool pinA1, bool pinA2)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | pinA0 | State of A0 address pin - true if high |
System.Boolean | pinA1 | State of A1 address pin - true if high |
System.Boolean | pinA2 | State of A2 address pin - true if high |
Returns
Type | Description |
---|---|
System.Byte | The device address |
GetPin(String)
Get Pin by name
Declaration
public abstract IPin GetPin(string pinName)
Parameters
Type | Name | Description |
---|---|---|
System.String | pinName | The pin name |
Returns
Type | Description |
---|---|
IPin | IPin object if found |
Initialize()
Initializes the Mcp23xxx
Declaration
protected virtual void Initialize()
IsValidPin(IPin)
Checks if a pin exists on the Mcpxxxxx
Declaration
protected abstract bool IsValidPin(IPin pin)
Parameters
Type | Name | Description |
---|---|---|
IPin | pin |
Returns
Type | Description |
---|---|
System.Boolean |
ReadFromPorts(Mcp23xxx.PortBank)
Reads a byte value from all of the pins. little-endian; the least significant bit is the value of GP0. So a byte value of 0x60, or 0110 0000, means that pins GP5 and GP6 are high.
Declaration
public byte ReadFromPorts(Mcp23xxx.PortBank bank = Mcp23xxx.PortBank.A)
Parameters
Type | Name | Description |
---|---|---|
Mcp23xxx.PortBank | bank |
Returns
Type | Description |
---|---|
System.Byte | A little-endian byte mask of the pin values. |
ReadPort(IPin)
Gets the value of a particular port. If the port is currently configured as an output, this will change the configuration.
Declaration
public bool ReadPort(IPin pin)
Parameters
Type | Name | Description |
---|---|---|
IPin | pin |
Returns
Type | Description |
---|---|
System.Boolean |
ResetMcp()
Reset the MCPxxxx expander Requires using a reset port
Declaration
public void ResetMcp()
ResetPin(IPin)
Sets the pin back to an input
Declaration
protected void ResetPin(IPin pin)
Parameters
Type | Name | Description |
---|---|---|
IPin | pin |
SetPortDirection(IPin, PortDirectionType)
Sets the direction of a port
Declaration
public void SetPortDirection(IPin pin, PortDirectionType direction)
Parameters
Type | Name | Description |
---|---|---|
IPin | pin | The pin representing the port |
PortDirectionType | direction | The port direction (input or output) |
WriteToPort(IPin, Boolean)
Sets a particular pin's value. If that pin is not in output mode, this method will first set its mode to output.
Declaration
public void WriteToPort(IPin pin, bool value)
Parameters
Type | Name | Description |
---|---|---|
IPin | pin | The pin to write to. |
System.Boolean | value | The value to write. True for high, false for low. |
WriteToPorts(Byte)
Outputs a byte value across all of the pins by writing directly to the output latch (OLAT) register
Declaration
public void WriteToPorts(byte mask)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | mask |
Events
InputChanged
Raised when the value of any pin configured for input interrupts changes This provides raw port state data from the MCP23xxx It's highly recommended to prefer using the events exposed on the digital input ports instead.
Declaration
public event EventHandler<IOExpanderInputChangedEventArgs> InputChanged
Event Type
Type | Description |
---|---|
EventHandler<IOExpanderInputChangedEventArgs> |