DAAPI B (b02)
- Java ME Embedded 3.3 Release

Package com.oracle.deviceaccess.gpio

Interfaces and classes for reading and writing from/to GPIO (General Purpose Input Output) pins and ports of the device.

See: Description

Package com.oracle.deviceaccess.gpio Description

Interfaces and classes for reading and writing from/to GPIO (General Purpose Input Output) pins and ports of the device.

A GPIO port is a platform-defined grouping of GPIO pins that may be configured for output or input. Note that GPIO pins that are part of a GPIO port cannot be retrieved nor controlled individually as 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:

Once a pin opened, an application can obtain the current value of a GPIO pin by calling the GPIOPin.getValue() method and set its value by calling the GPIOPin.setValue(boolean) method.
Once a port opened, an application can obtain the current value of a GPIO port by calling the GPIOPort.getValue() method and set its value by calling the GPIOPort.setValue(int) method.
 pin.setValue(true);
 port.setValue(0xFF);
 
When done, the application should call the GPIOPin.close() or GPIOPort.close() method to release the pin or port, respectively.
 pin.close();
 port.close();
 
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.
 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) {
         }
     }
 }
 

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.

Security

GPIO pins and ports are opened by invoking one of the 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
DAAPI B (b02)
5-February-2013 04:40

Copyright (c) 2012, Oracle and/or its affiliates. All Rights Reserved. Use of this specification is subject to license terms.