Package com.diozero.devices.mcp23xxx
Class MCP23xxx
java.lang.Object
com.diozero.internal.spi.AbstractDeviceFactory
com.diozero.devices.mcp23xxx.MCP23xxx
- All Implemented Interfaces:
DeviceEventConsumer<DigitalInputEvent>
,GpioExpander
,DeviceFactoryInterface
,GpioDeviceFactoryInterface
,PwmOutputDeviceFactoryInterface
,Closeable
,AutoCloseable
,Consumer<DigitalInputEvent>
public abstract class MCP23xxx extends AbstractDeviceFactory implements GpioDeviceFactoryInterface, PwmOutputDeviceFactoryInterface, DeviceEventConsumer<DigitalInputEvent>, GpioExpander
Support for both MCP23008 and MCP23017 GPIO expansion boards.
-
Field Summary
Fields Modifier and Type Field Description static int
INTERRUPT_GPIO_NOT_SET
Fields inherited from class com.diozero.internal.spi.AbstractDeviceFactory
closed, deviceStates
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description void
accept(DigitalInputEvent event)
void
close()
Close this device factory including all devices that have been provisioned by it.void
closeGpio(int gpio)
GpioDigitalInputDeviceInterface
createDigitalInputDevice(String key, PinInfo pin_info, GpioPullUpDown pud, GpioEventTrigger trigger)
GpioDigitalInputOutputDeviceInterface
createDigitalInputOutputDevice(String key, PinInfo pin_info, DeviceMode mode)
GpioDigitalOutputDeviceInterface
createDigitalOutputDevice(String key, PinInfo pin_info, boolean initialValue)
PwmOutputDeviceInterface
createPwmOutputDevice(String key, PinInfo pinInfo, int pwmFrequency, float initialValue)
int
getBoardPwmFrequency()
protected abstract int
getDefValReg(int port)
protected abstract int
getGPIntEnReg(int port)
protected abstract int
getGPIOReg(int port)
protected abstract int
getGPPullUpReg(int port)
protected abstract int
getIntCapReg(int port)
protected abstract int
getIntConReg(int port)
protected abstract int
getIntFReg(int port)
protected abstract int
getIOConReg(int port)
protected abstract int
getIODirReg(int port)
protected abstract int
getIPolReg(int port)
String
getName()
Get the name of this device factoryprotected abstract int
getOLatReg(int port)
boolean
getValue(int gpio)
byte
getValues(int port)
protected void
initialise()
protected abstract byte
readByte(int register)
void
setBoardPwmFrequency(int frequency)
void
setDirections(int port, byte directions)
Set the directions for all pins on this port using the specified directions bit mask.protected void
setInputMode(int gpio, GpioPullUpDown pud, GpioEventTrigger trigger)
protected void
setOutputMode(int gpio)
void
setValue(int gpio, boolean value)
void
setValues(int port, byte values)
Set the output value for a pins on this port.protected abstract void
writeByte(int register, byte value)
Methods inherited from class com.diozero.internal.spi.AbstractDeviceFactory
createI2CKey, createPinKey, createSerialKey, createSpiKey, deviceClosed, deviceOpened, getDevice, isClosed, isDeviceOpened, reopen
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.diozero.internal.spi.DeviceFactoryInterface
createI2CKey, createPinKey, createSerialKey, createSpiKey, deviceClosed, deviceOpened, getBoardPinInfo, getDevice, isClosed, isDeviceOpened, reopen, start
Methods inherited from interface com.diozero.internal.spi.GpioDeviceFactoryInterface
provisionDigitalInputDevice, provisionDigitalInputOutputDevice, provisionDigitalOutputDevice
Methods inherited from interface com.diozero.internal.spi.PwmOutputDeviceFactoryInterface
provisionPwmOutputDevice
-
Field Details
-
INTERRUPT_GPIO_NOT_SET
public static final int INTERRUPT_GPIO_NOT_SET- See Also:
- Constant Field Values
-
-
Constructor Details
-
MCP23xxx
- Throws:
RuntimeIOException
-
MCP23xxx
- Throws:
RuntimeIOException
-
MCP23xxx
public MCP23xxx(int numPorts, String deviceName, int interruptGpioA, int interruptGpioB) throws RuntimeIOException- Throws:
RuntimeIOException
-
-
Method Details
-
getName
Description copied from interface:DeviceFactoryInterface
Get the name of this device factory- Specified by:
getName
in interfaceDeviceFactoryInterface
- Returns:
- the name of this device factory
-
initialise
protected final void initialise() -
createDigitalInputDevice
public GpioDigitalInputDeviceInterface createDigitalInputDevice(String key, PinInfo pin_info, GpioPullUpDown pud, GpioEventTrigger trigger)- Specified by:
createDigitalInputDevice
in interfaceGpioDeviceFactoryInterface
-
createDigitalOutputDevice
public GpioDigitalOutputDeviceInterface createDigitalOutputDevice(String key, PinInfo pin_info, boolean initialValue)- Specified by:
createDigitalOutputDevice
in interfaceGpioDeviceFactoryInterface
-
createDigitalInputOutputDevice
public GpioDigitalInputOutputDeviceInterface createDigitalInputOutputDevice(String key, PinInfo pin_info, DeviceMode mode)- Specified by:
createDigitalInputOutputDevice
in interfaceGpioDeviceFactoryInterface
-
createPwmOutputDevice
public PwmOutputDeviceInterface createPwmOutputDevice(String key, PinInfo pinInfo, int pwmFrequency, float initialValue)- Specified by:
createPwmOutputDevice
in interfacePwmOutputDeviceFactoryInterface
-
getBoardPwmFrequency
public int getBoardPwmFrequency()- Specified by:
getBoardPwmFrequency
in interfacePwmOutputDeviceFactoryInterface
-
setBoardPwmFrequency
public void setBoardPwmFrequency(int frequency)- Specified by:
setBoardPwmFrequency
in interfacePwmOutputDeviceFactoryInterface
-
setInputMode
-
setOutputMode
protected void setOutputMode(int gpio) -
getValue
- Throws:
RuntimeIOException
-
setValue
- Throws:
RuntimeIOException
-
close
Description copied from interface:DeviceFactoryInterface
Close this device factory including all devices that have been provisioned by it.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceDeviceFactoryInterface
- Specified by:
close
in interfaceGpioExpander
- Overrides:
close
in classAbstractDeviceFactory
- Throws:
RuntimeIOException
-
closeGpio
- Throws:
RuntimeIOException
-
accept
- Specified by:
accept
in interfaceConsumer<DigitalInputEvent>
-
getIODirReg
protected abstract int getIODirReg(int port) -
getIPolReg
protected abstract int getIPolReg(int port) -
getGPIntEnReg
protected abstract int getGPIntEnReg(int port) -
getDefValReg
protected abstract int getDefValReg(int port) -
getIntConReg
protected abstract int getIntConReg(int port) -
getIOConReg
protected abstract int getIOConReg(int port) -
getGPPullUpReg
protected abstract int getGPPullUpReg(int port) -
getIntFReg
protected abstract int getIntFReg(int port) -
getIntCapReg
protected abstract int getIntCapReg(int port) -
getGPIOReg
protected abstract int getGPIOReg(int port) -
getOLatReg
protected abstract int getOLatReg(int port) -
readByte
protected abstract byte readByte(int register) -
writeByte
protected abstract void writeByte(int register, byte value) -
setDirections
public final void setDirections(int port, byte directions)Description copied from interface:GpioExpander
Set the directions for all pins on this port using the specified directions bit mask. 0 = output, 1 = input- Specified by:
setDirections
in interfaceGpioExpander
- Parameters:
port
- the bank of up to 8 GPIOsdirections
- bit mask specifying the directions for up to 8 GPIOs. 0 = output, 1 = input
-
getValues
public byte getValues(int port) -
setValues
public final void setValues(int port, byte values)Description copied from interface:GpioExpander
Set the output value for a pins on this port.- Specified by:
setValues
in interfaceGpioExpander
- Parameters:
port
- the bank of up to 8 GPIOsvalues
- bit mask specifying on/off values. 1 = on, 0 = off
-