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. |
GPIOPortConfig |
The
GPIOPortConfig class encapsulates the hardware addressing information, and static and dynamic
configuration parameters of a GPIO port. |
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 release 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 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.GPIOPin switchPin = null; GPIOPin ledPin = null; try { switchPin = (GPIOPin) PeripheralManager.open(1); ledPin = (GPIOPin) PeripheralManager.open(3); switchPin.setInputListener(new PinListener() { public void valueChanged(PinEvent event) { try { ((GPIOPin) event.getPeripheral()).setValue(event.getValue()); // turn LED on or off } catch (IOException ex) { // Ignored } catch (PeripheralNotAvailableException ex) { // Ignored } } }); } catch (IOException ex) { // Handle exception } catch (PeripheralNotFoundException ex) { // Handle exception } catch (PeripheralNotAvailableException ex) { // Handle exception } finally { if (switchPin != null) { try { switchPin.close(); } catch (IOException ex) { } } if (ledPin != null) { try { ledPin.close(); } catch (IOException ex) { } } }
com.oracle.deviceaccess.PeripheralManager.open
methods. The permissions below allow access to be granted to GPIO
pins and ports as a whole as well as to to some of their protected functions.
Permission | Function |
---|---|
"com.oracle.deviceaccess.gpio" |
Access to GPIO pins and ports (as a whole) |
"com.oracle.deviceaccess.gpio.GPIOPin.setDirection" |
Changing the direction of a GPIO pin |
"com.oracle.deviceaccess.gpio.GPIOPort.setDirection" |
Changing the direction of a GPIO port |
Copyright (c) 1990, 2013, Oracle and/or its affiliates. All rights reserved.