See: Description
Interface | Description |
---|---|
GPIOPin |
The
GPIOPin interface provides methods for controlling a GPIO pin. |
GPIOPort |
The
GPIOPort interface provides methods for controlling a GPIO port. |
PinListener |
The
PinListener interface defines methods for getting notified of GPIO pin value changes. |
PortListener |
The
PortListener interface defines methods for getting notified of GPIO port value changes. |
Class | Description |
---|---|
GPIOPinConfig |
The
GPIOPinConfig class encapsulates the hardware addressing information, and static and dynamic
configuration parameters of a GPIO pin. |
GPIOPinPermission |
The
GPIOPinPermission class defines permissions for GPIO pin access. |
GPIOPortConfig |
The
GPIOPortConfig class encapsulates the hardware addressing information, and static and dynamic
configuration parameters of a GPIO port. |
GPIOPortPermission |
The
GPIOPortPermission class defines permissions for GPIO port access. |
PinEvent |
The
PinEvent class encapsulates GPIO pin value changes. |
PortEvent |
The
PortEvent class encapsulates GPIO port value changes. |
GPIOPin
instances.
In order to use a specific pin or port, an application should first open and obtain and obtain a
GPIOPin
instance or GPIOPort
instance,
respectively, for the pin or port it wants to use using its numerical ID, name, type (interface) and/or properties:
GPIOPin pin = (GPIOPin) PeripheralManager.open(1); GPIOPort port = (GPIOPort) PeripheralManager.open(0);
GPIOPin pin = (GPIOPin) PeripheralManager.open("LED_PIN", GPIOPin.class, null); GPIOPort port = (GPIOPort) PeripheralManager.open("LCD_DATA_PORT", GPIOPort.class, null);
GPIOPin.getValue()
method and set its value by calling the
GPIOPin.setValue(boolean)
method. GPIOPort.getValue()
method and set its value by calling the
GPIOPort.setValue(int)
method. When done, the application should call thepin.setValue(true); port.setValue(0xFF);
GPIOPin.close()
or GPIOPort.close()
method to close the pin or
port, respectively. The following sample code gives an example of using the GPIO API. It shows how to control GPIO Pins. It registers a pin listener for the GPIO input pin a switch button is attached to. When the button is pressed the listener is notified to turn the LED on or off by setting accordingly the GPIO output pin the LED is attached to.pin.close(); port.close();
Note that the preceding example is using a try-with-resources statement and that thetry (GPIOPin switchPin = (GPIOPin) PeripheralManager.open(1); GPIOPin ledPin = (GPIOPin) PeripheralManager.open(3)) { switchPin.setInputListener(new PinListener() { public void valueChanged(PinEvent event) { try { ledPin.setValue(event.getValue()); // turn LED on or off } catch (IOException ioe) { // handle exception } } }); } catch (IOException ioe) { // handle exception }
GPIOPin.close()
method is automatically invoked by the platform
at the end of the statement.
Note that the underlying platform configuration may allow for some GPIO pins or ports to be set by an application for
either output or input while others may be used for input only or output only and that their direction can not be
changed by an application. Note also that asynchronous notification of pin or port value changes is only loosely tied
to hardware-level interrupt requests. The platform does not guarantee notification in a deterministic/timely manner.
Because of performance issue, procedures handling GPIO pins, and especially event listeners, should be implemented to
be as fast as possible.
Unless otherwise noted, passing a null
argument to a constructor or method in any class
or interface in this package will cause a NullPointerException
to be thrown.Copyright © 2012, 2013, Oracle and/or its affiliates. All rights reserved.
Legal Notices