public final class GPIOPortConfig extends java.lang.Object implements DeviceConfig<GPIOPort>
GPIOPortConfig
class encapsulates the hardware addressing information, and static and
dynamic configuration parameters of a GPIO port.
Some hardware addressing, static or dynamic configuration parameters may be
set to UNASSIGNED
or null
(see
Unassigned, Default or Unused Parameter Values).
An instance of GPIOPortConfig
can be passed to the
open(DeviceConfig, ...)
and
open(Class, DeviceConfig, ...)
methods of the DeviceManager
to open the designated GPIO port
with the specified configuration. A InvalidDeviceConfigException
is thrown when
attempting to open a device with an invalid or unsupported configuration.
The value change notification trigger of a GPIO port is defined by the interrupt trigger(s) configured
for its pins (see GPIOPinConfig.getTrigger
). Any of
the GPIOPin
s configured with an interrupt trigger (other than GPIOPinConfig.TRIGGER_NONE
)
that compose a GPIOPort
may trigger a notification for that GPIOPort
.
The following sample code illustrates how a 4-pin GPIO port configuration may be built with pins from the same GPIO controller:
GPIOPinConfig.Builder builder = new GPIOPinConfig.Builder() .setControllerNumber(1) .setDirection(GPIOPinConfig.DIR_OUTPUT_ONLY) .setDriveMode(GPIOPinConfig.MODE_OUTPUT_PUSH_PULL); GPIOPortConfig config = new GPIOPortConfig(GPIOPortConfig.DIR_OUTPUT_ONLY, 0x0, builder.setPinNumber(0).build(), builder.setPinNumber(1).build(), builder.setPinNumber(2).build(), builder.setPinNumber(3).build() );
DeviceConfig.HardwareAddressing
Modifier and Type | Field and Description |
---|---|
static int |
DIR_BOTH_INIT_INPUT
Bidirectional port direction with initial input direction.
|
static int |
DIR_BOTH_INIT_OUTPUT
Bidirectional port direction with initial output direction.
|
static int |
DIR_INPUT_ONLY
Input port direction.
|
static int |
DIR_OUTPUT_ONLY
Output port direction.
|
DEFAULT, UNASSIGNED
Constructor and Description |
---|
GPIOPortConfig(int direction,
int initValue,
GPIOPinConfig... pins)
Creates a new
GPIOPortConfig with the specified hardware addressing information and
configuration parameters. |
Modifier and Type | Method and Description |
---|---|
static GPIOPortConfig |
deserialize(java.io.InputStream in)
Creates a new
GPIOPortConfig whose state is deserialized from the specified InputStream . |
boolean |
equals(java.lang.Object obj)
Checks two
GPIOPortConfig objects for equality. |
int |
getDirection()
Gets the configured port direction.
|
int |
getInitValue()
Gets the configured initial value of the port, if configured for output.
|
GPIOPinConfig[] |
getPinConfigs()
Gets the configured configurations of the pins composing the port (in the exact same order
they compose the port).
|
GPIOPin[] |
getPins()
Deprecated.
As of 1.1, replaced by
GPIOPort.getPins . |
int |
hashCode()
Returns the hash code value for this object.
|
int |
serialize(java.io.OutputStream out)
Serializes the state of this
GPIOPortConfig object to the specified OutputStream . |
public static final int DIR_BOTH_INIT_INPUT
public static final int DIR_BOTH_INIT_OUTPUT
public static final int DIR_INPUT_ONLY
public static final int DIR_OUTPUT_ONLY
public GPIOPortConfig(int direction, int initValue, GPIOPinConfig... pins)
GPIOPortConfig
with the specified hardware addressing information and
configuration parameters.
If the access modes (exclusive or shared) supported by the designated
GPIOPin
s are incompatible with those required by the underlying GPIOPort
device or device driver, attempting to open
the GPIOPort
device using this configuration may result in a
InvalidDeviceConfigException
to be thrown.
direction
- the allowed and initial direction of the port, one of: DIR_INPUT_ONLY
,
DIR_OUTPUT_ONLY
, DIR_BOTH_INIT_INPUT
,
DIR_BOTH_INIT_OUTPUT
.initValue
- the initial value of the port when initially set for output.pins
- the pin configurations in the exact same order they compose the port.java.lang.IllegalArgumentException
- if any of the following is true:
direction
is not one of the defined values;pins.length
is 0
;direction
is DIR_BOTH_INIT_INPUT
or
DIR_BOTH_INIT_OUTPUT
and any of the provided pin
configurations' direction is GPIOPinConfig.DIR_INPUT_ONLY
or GPIOPinConfig.DIR_OUTPUT_ONLY
;direction
is DIR_INPUT_ONLY
and any of the provided pin
configurations' direction is GPIOPinConfig.DIR_OUTPUT_ONLY
;direction
is DIR_OUTPUT_ONLY
and any of the provided pin
configurations' direction is GPIOPinConfig.DIR_INPUT_ONLY
;java.lang.NullPointerException
- if pins
is null
.public static GPIOPortConfig deserialize(java.io.InputStream in) throws java.io.IOException
GPIOPortConfig
whose state is deserialized from the specified InputStream
.
This method may be invoked to restore the state of a GPIOPortConfig
object from a persistent store.in
- the stream to read from.GPIOPortConfig
instance.java.io.IOException
- if an I/O error occurs or if the provided stream does not
contain a representation of a GPIOPortConfig
object.public int serialize(java.io.OutputStream out) throws java.io.IOException
GPIOPortConfig
object to the specified OutputStream
.
This method may be invoked by the DeviceManager
to save the state of this GPIOPortConfig
object to a persistent store.serialize
in interface DeviceConfig<GPIOPort>
out
- the stream to write to.java.io.IOException
- if an I/O error occurs.DeviceProvider.deserialize(java.io.InputStream)
public int getDirection()
DIR_INPUT_ONLY
, DIR_OUTPUT_ONLY
,
DIR_BOTH_INIT_INPUT
, DIR_BOTH_INIT_OUTPUT
.public int getInitValue()
public GPIOPinConfig[] getPinConfigs()
@Deprecated public GPIOPin[] getPins()
GPIOPort.getPins
.
A concurrent runtime change of the
dynamic configuration parameters of any of the pins composing the port (such as of its direction) may result in
IOException
being thrown by port operations.
null
if this GPIOPortConfig
instance is not associated to an actual GPIOPort
instance -
that is the GPIOPortConfig
instance was not retrieved from a call to
getDescriptor().getConfiguration()
on the GPIOPort
instance.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
GPIOPortConfig
objects for equality.equals
in class java.lang.Object
obj
- the object to test for equality with this object.true
if obj
is a GPIOPortConfig
and has
the same configuration parameter values as this GPIOPortConfig
object; false
otherwise.Copyright © 2012, 2015, Oracle and/or its affiliates. All rights reserved.
Legal Notices