Skip Headers
Oracle® Java ME Embedded Device Access API Guide
Release 3.4
E35134-03
  Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
 
Next
Next
 

A Migrating from Device Access Version 3.2

The Device Access APIs have changed between Oracle Java ME Embedded version 3.2 and version 3.3 to add more flexibility for new devices. As such, many of the techniques used to access peripherals have changed as well. This appendix provides a brief description of the most common changes that programmers are likely to encounter: the use of the PeripheralManager class. For more information, please see the Device Access 3.2 and 3.3 specifications.

The PeripheralManager Class

With earlier versions of the Device Access APIs, each bus had its own singleton "manager" class that programmers would call upon to access the devices connected to the embedded board. With the 3.3 version of the Oracle Java ME Embedded platform, each of these managers has been coalesced into the PeripheralManager class.

Here is sample code from the 3.2 version of the Device Access API used to access the General Purpose I/O (GPIO) pins:

GPIOPin switchPin = null;
GPIOPin ledPin = null;
 
try {

    switchPin = GPIOManager.getPin("SWITCH_PIN", GPIOPin.class, null); 
    ledPin = GPIOManager.getPin("LED_PIN", GPIOPin.class, null); 

    if(switchPin != null && ledPin != null){
        switchPin.setInputPinListener(listener);
    }

} catch (Exception e) {
    //  Handle exceptions
}

Here is the equivalent version with version 3.3 of the Device Access APIs:

  GPIOPin switchPin = null;
  GPIOPin ledPin = null;

  try {

    switchPin=(GPIOPin)PeripheralManager.open("SWITCH_PIN", GPIOPin.class, null);
    ledPin=(GPIOPin)PeripheralManager.open("LED_PIN", GPIOPin.class, null););
      
    if(switchPin != null && ledPin != null){
        switchPin.setInputPinListener(listener);
    }
  
  } catch (Exception ex) {
        //  Handle exceptions
    }

Note that the newer version uses the PeripheralManager class to obtain access to the GPIO pins. The PeripheralManager class returns an object which is then cast to the appropriate type. In addition, here is a short example of how to access the MMIO bus using version 3.2 of the Device Access APIs:

 MMIODevice rtc = null;

 try {

     rtc = MMIOManager.getDevice("RTC");

     RawByte seconds = rtc.getByteRegister("Seconds");
     RawByte secAlarm = rtc.getByteRegister("SecAlarm");
     RawByte minutes = rtc.getByteRegister("Minutes");
     RawByte minAlarm = rtc.getByteRegister("MinAlarm");
     ...
 } catch (Exception e) {
     //  Handle exceptions
 }

Here is the equivalent code using version 3.3:

 MMIODevice rtc = null;

 try {

     rtc = (MMIODevice) PeripheralManager.open("RTC",
         MMIODevice.class, (String[]) null);

     RawByte seconds = rtc.getByteRegister("Seconds");
     RawByte secAlarm = rtc.getByteRegister("SecAlarm");
     RawByte minutes = rtc.getByteRegister("Minutes");
     RawByte minAlarm = rtc.getByteRegister("MinAlarm");
     ...
 } catch (Exception e) {
     //  Handle exceptions
 }

The important thing to remember is to use the correctly overloaded version of the PeripheralManager.open() method to obtain access to the respective device on the appropriate bus. See the examples at the beginning of each chapter for information on how to format each call for the respective API, or the equivalent Javadoc for more precise usage.