A Device I/O Preconfigured List

This appendix describes the proper ID and names for the various peripheral ports and buses for the Raspberry Pi embedded board, which are accessible using the Device I/O APIs.

Note that any IMlet that accesses the Device I/O APIs must be digitally signed using a trusted certificate authority. An IMlet that is not signed will encounter an authentication error when attempting to access the Device I/O APIs.

To access any device from the preconfigured peripheral list, the following permission is required:

jdk.dio.DeviceMgmtPermission(%Name%:%ID%);

You can find the names and IDs for specific devices in the tables that follow in this appendix. You must also specify an action. An empty string means open.

The tables use the following legend:

  • Device ID: an integer identifier that can be used to open the device with the methods of the DeviceManager class.

  • Device Name: the string name of a device that can be used to open it by name with the methods of the DeviceManager class.

  • Mapped: all hardware-related information regarding a peripheral, such as physical location, mapping, or port. This information enables the user to determine the peripheral's location on a target board.

  • Configuration: properties that are passed to the specific DeviceConfig constructor to open the peripheral by ID or name. The configuration can be used to open the peripheral using the DeviceManager with the appropriate configuration.

Note the following items for Device I/O in the Raspberry Pi board:

  • The interface DeviceConfig.HardwareAddressing supports device names only with UART devices. Do not use the DeviceConfig.HardwareAddressing.getDeviceName() method.

  • The PulseCounter instance cannot be opened by the PulseCounterConfig instance with the GPIOPinConfig instance specified.

  • The PWMChannel instance cannot be opened by the PWMChannelConfig class with the GPIOPinConfig instance specified.

GPIO Pins

The following GPIO pins are preconfigured.


Devicel ID Device Name Mapped Configuration

1

GPIO4

GPIO 4

controllerNumber = 0

pinNumber = 4

direction = GPIOPinConfig.DIR_INPUT_ONLY

mode = DeviceConfig.DEFAULT

trigger = GPIOPinConfig.TRIGGER_BOTH_EDGES

initValue - ignored

2

GPIO7

GPIO 7

controllerNumber = 0

pinNumber = 7

direction = GPIOPinConfig.DIR_OUTPUT_ONLY

mode = GPIOPinConfig.MODE_OUTPUT_PUSH_PULL

trigger = GPIOPinConfig.TRIGGER_BOTH_EDGES

initValue = false

3

GPIO17

GPIO 17

controllerNumber = 0

pinNumber = 17

direction = GPIOPinConfig.DIR_INPUT_ONLY

mode = DeviceConfig.DEFAULT

trigger = GPIOPinConfig.TRIGGER_BOTH_EDGES

initValue - ignored

4

GPIO18

GPIO 18

controllerNumber = 0

pinNumber = 18

direction = GPIOPinConfig.DIR_OUTPUT_ONLY

mode = GPIOPinConfig.MODE_OUTPUT_PUSH_PULL

trigger - ignored

initValue = false

5

GPIO22

GPIO 22

controllerNumber = 0

pinNumber = 22

direction = GPIOPinConfig.DIR_INPUT_ONLY

mode = DeviceConfig.DEFAULT

trigger = GPIOPinConfig.TRIGGER_BOTH_EDGES

initValue - ignored

6

GPIO23

GPIO 23

controllerNumber = 0

pinNumber = 23

direction = GPIOPinConfig.DIR_OUTPUT_ONLY

mode = GPIOPinConfig.MODE_OUTPUT_PUSH_PULL

trigger = GPIOPinConfig.TRIGGER_BOTH_EDGES

initValue = false

7

GPIO24

GPIO 24

controllerNumber = 0

pinNumber = 24

direction = GPIOPinConfig.DIR_OUTPUT_ONLY

mode = GPIOPinConfig.MODE_OUTPUT_PUSH_PULL

trigger = GPIOPinConfig.TRIGGER_BOTH_EDGES

initValue = false

8

GPIO25

GPIO 25

controllerNumber = 0

pinNumber = 25

direction = GPIOPinConfig.DIR_OUTPUT_ONLY

mode = GPIOPinConfig.MODE_OUTPUT_PUSH_PULL

trigger = GPIOPinConfig.TRIGGER_BOTH_EDGES

initValue = false

9

GPIO27

GPIO 27

controllerNumber = 0

pinNumber = 27

direction = GPIOPinConfig.DIR_INPUT_ONLY

mode = DeviceConfig.DEFAULT

trigger = GPIOPinConfig.TRIGGER_BOTH_EDGES

initValue - ignored


Please note the following items concerning GPIO on the Raspberry Pi board.

  • The value of DeviceConfig.DEFAULT when applied to the controllerNumber is 0.

  • The value of DeviceConfig.DEFAULT when applied to the mode means that the GPIO pin be configured in the default mode, as per the table above.

  • GPIO modes are not software-configurable. All GPIO pins in the preceding table are given with the only mode that is supported on the Raspberry Pi. If an application attempts to configure a GPIO pin to use an unsupportable mode, an exception will be thrown.

  • For GPIO pins that are configured as input pins, the initValue parameter is ignored.

  • The trigger modes TRIGGER_HIGH_LEVEL, TRIGGER_LOW_LEVEL, and TRIGGER_BOTH_LEVELS are not supported on the Raspberry Pi.

  • For all GPIO pins, the application should pass in a 0 for the GPIO port when necessary.

  • The following diagram represents the pin positions of the Raspberry Pi, Revision 1 and 2.

I2C

There is no static I2C configuration with the Raspberry Pi because there is no connected hardware. In comparison with SPI, I2C does not allow any communication with a loopback device.


Device ID Device Name Mapped Configuration

NONE

 

GPIO 2 (SDA)

GPIO 3 (SCL)

 

Please note the following items about I2C on the Raspberry Pi.

  • I2CDevicePermission is necessary.

  • For revision 1 boards, I2C is provided by default on GPIO 0 and 1 (bus 0), and for revision 2 boards, I2C is provided on GPIO 2 and 3 (bus 1.)

  • The value of DeviceConfig.DEFAULT when applied to the busNumber is 0.

  • The value of DeviceConfig.DEFAULT when applied to the addressSize is 7.

  • The only supported value for the clockFrequency field is DeviceConfig.UNASSIGNED.

  • Before using I2C, you will have to load two I2C modules: i2c-bcm2708 and i2c-dev. Add the following two lines to the /etc/modules file and reboot to apply the changes.

    i2c-bcm2708
    i2c-dev
    

MMIO

The following MMIO peripherals are available:


Device ID Device Name Mapped Configuration

900

PWM

   

The MMIO peripherals include CTL, STA, RNG1, DAT1, and FIF1 registers (all of them are of type INT) with no event support.

Note:

MMIO devices are only available if Java ME runtime runs with superuser privileges as shown in the following example.
pi@raspberry ~ /pi/bin $ sudo ./usertest.sh

Due to nature of memory organization of the Raspberry Pi, programmers can create a custom MMIODeviceConfig to access the memory range {0x20000000, 0x21000000}. Please note that not all addresses are accessible in the range and some of them may cause a board reboot. Please check the documentation for SFR addresses and its behavior. The end addresses are not inclusive.

SPI

The SPI has a single static configuration with the following parameters:


Device ID Device Name Mapped Configuration

300

SPI_Slave

GPIO10 (MOSI)

GPIO9 (MISO)

GPIO11 (SCLK)

GPIO8 (CE0)

SPI bus number: 0 (SPI1)

Chip Enable: 0 (CE0/GPIO8)

The number of bit of slave's word: 8

Clock frequency in Hz: 2000000

Clock polarity and phase: 1 (CPOL_Low, CPHA_2Edge)

Bit ordering of the slave device: 1 (BIG_ENDIAN)


Please note the following items about SPI on the Raspberry Pi.

  • The value of DeviceConfig.DEFAULT when applied to the busNumber is 0.

  • The value of DeviceConfig.DEFAULT when applied to the clockFrequency is 2000000 Hz.

  • The value of DeviceConfig.DEFAULT when applied to the wordLength is 8.

  • The value of DeviceConfig.DEFAULT when applied to the bitOrdering is 1 (big-endian).

  • Before using SPI, you will have to load the SPI modules by running the following command: $ modprobe spi_bcm2708, or by using the same method as I2C: uncomment the appropriate line in the etc/modprob.d/raspi-blacklist.conf file and reboot the board.

  • Only 8-bit word lengths are supported on the Raspberry Pi board.

  • No real hardware is connected by default.

Note:

You can connect MISO and MOSI pins to get a simple loopback device for testing your code.

UART

The following UART devices are preconfigured:


Device ID Device Name Mapped Configuration

100

UART

GPIO 14 (TXD)

GPIO 15 (RXD)

controllerName = ttyAMA0

baudRate = 19200

dataBits = DATABITS_8

parity = PARITY_NONE

stopBits = STOPBITS_1

flowcontrol = FLOWCONTROL_NONE

inputBufferSize - ignored

outputBufferSize - ignored


Please note the following items about UART on the Raspberry Pi.

  • By default, the Raspberry Pi uses the UART as a serial console. Before using UART, make sure that /dev/ttyAMA0 is not being used as a console. This can be done by changing the boot command line by editing the /boot/cmdline.txt file and removing the line "console=ttyAMA0,115200 kgdboc=ttyAMA0,115200" from the boot arguments. Also, comment out the following line: "2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100" in the file /etc/inittab.

    In the case when the /boot is mounted as a read-only partition, it must be remounted with write permissions to enable modifying the cmdline.txt file.

    sudo mount -n -o remount,rw /boot
    

    Then edit the cmdline.txt file and reboot the Raspberry Pi board.

  • By default, the pi user is in the dialout group. That gives pi the ability to access /dev/ttyAMA0 (and, consequently, UART from Java) without administrator rights.

Watchdog

The following watchdog devices are pre-configured:


Device ID Device Name Mapped Configuration

1100

WDG

Platform Watchdog

 

1101

WWDG

   

ATCmdDevice

The following ATCmd device is preconfigured:


Device ID Device Name Mapped Configuration

800

EMUL

 

A simple ATCmd device emulator. Returns OK for every command request. No async notification is supported. For debug purpose only.


Structure of the Device I/O Configuration File

Device I/O configuration file structure is based on the JSON data interchange format with a few distinctions.

General File Data Format

The device I/O configuration file resides in the /appdb directory and has the name daapi_config.json. Based on the JSON data interchange format, the Device I/O configuration file has the following distinctions:
  • A string is quoted only if it contains a space.

  • A value can be only a string, object, or array.

  • UTF–8 is the only supported encoding.

For more information about the JSON data interchange format, see www.json.org.

Configuration Hierarchy

The configuration fie has three sections.
  1. An unnamed global object that contains two other sections. It begins with { (left brace) and ends with } (right brace).

  2. configs: a container for all configuration objects

  3. defaults: a container for default properties grouped by peripheral packages

All the sections are mandatory even if there is no content as shown in the following example.

{
configs: {}
defaults: {}
}

The configs Section

The configs section contains a collection of key/value pairs named properties, where the key is an ID assigned to a configuration (see Device I/O 1.1 API specification) and the value is an object that contains information specific for the described configuration. The configuration must contain at least the deviceType property that points to the peripheral class to which this configuration applies. The value of the deviceType property is a shortened form of the peripheral class name. The rest of the properties are device specific. Property names must conform with the Device I/O 1.1 API specification. The name field can be an array of names to support name aliases.

Example A-1 Example of GPIOPin Device Configuration

An example below shows a valid configuration description. Note that it is mandatory that the deviceType and name field values are set.

10 : {
deviceType : gpio.GPIOPin,
id:1,
deviceNumber : 1,
pinNumber : 5,
direction : 1,
mode:4,
name :[LED_1,GPIO6.6,GPIO0]
initValue:0,
}

The defaults Section

The defaults section provides default values for some properties and also additional information required for the construction of a peripheral instance. The main purpose of this section is to reduce the amount of information provided by the configs section and thus to decrease the file size. The same requirement for key naming applies to the . The properties are grouped by the shortened name of peripheral class for which they may be used. For example, uart.UARTConfig is a group for the com.oracle.deviceaccess.uart.UARTConfig property object.

Example A-2 Example of the daapi_config.json File

Refer to the following daapi_config.json file example.

{
configs: {
    13: {
        deviceType: atcmd.ATDevice,
        name: EMUL,
        properties : [“com.oracle.sms=true”]
        },
    15: {
        deviceType: uart.ModemUART,
        deviceNumber: 1,
        name: COM1,
        baudRate: 9600,
        dataBits: 7,
        },
},
defaults: {
    uart.UARTConfig: {             
    baudRate:115200,
    parity:0,
    dataBits:8,
    stopBits:1,
    flowControl:0,
},
}