Skip to main content
Jump to: navigation, search

Kura GPIO Support

DRAFT NOTE - THIS IS WORK IN PROGRESS

Introduction

Eclipse Kura is planning to add GPIO and I2C support by adapting the excellent pi4j library. The idea is to retain the user's facing pi4j APIs with small adaptations to the OSGi model. In the internals, we will remove pi4j dependency on wiringPi and replace it with a more generic implementation. Eclipse Kura requirements on the underlying system will be for a Linux-based system with:

Kura's Adoption Plan of Pi4j

The plan is the following:

  • com.pi4j.io.gpio: Migrate the following classes to the package org.eclipse.kura.io.gpio into the kura-api bundle:
    • GpioController - this will become the make Kura's GpioService interface
    • GpioFactory.java - this is not needed as the GpioController implementation will be determining the provider to use
    • GpioPin.java
    • GpioPinAnalog.java
    • GpioPinAnalogInput.java
    • GpioPinAnalogOutput.java
    • GpioPinDigital.java
    • GpioPinDigitalInput.java
    • GpioPinDigitalMultipurpose.java
    • GpioPinDigitalOutput.java
    • GpioPinInput.java
    • GpioPinOutput.java
    • GpioPinPwm.java
    • GpioPinPwmOutput.java
    • GpioPinShutdown.java
    • GpioProvider.java
    • GpioProviderBase.java
    • GpioProviderPinCache.java
    • PiFacePin.java - Replaced by a generic Pins class
    • Pin.java
    • PinDirection.java
    • PinEdge.java
    • PinMode.java
    • PinPullResistance.java
    • PinState.java
    • RaspiGpioProvider.java - Replaced by a generic LinuxSysfsGpioProvider class
    • RaspiPin.java - Replaced by a generic Pins class
  • com.pi4j.io.gpio.event: Migrate the following classes to the package org.eclipse.kura.io.gpio.event into the kura-api bundle:
    • GpioPinAnalogValueChangeEvent.java
    • GpioPinDigitalStateChangeEvent.java
    • GpioPinEvent.java
    • GpioPinListener.java
    • GpioPinListenerAnalog.java
    • GpioPinListenerDigital.java
    • PinAnalogValueChangeEvent.java
    • PinDigitalStateChangeEvent.java
    • PinEvent.java
    • PinEventType.java
    • PinListener.java
  • com.pi4j.io.gpio.exception: Migrate the following classes to the package org.eclipse.kura.io.gpio.exception into the kura-api bundle and make them subclass from KuraException:
    • GpioPinExistsException.java
    • GpioPinNotProvisionedException.java
    • InvalidPinException.java
    • InvalidPinModeException.java
    • PinProviderException.java
    • UnsupportedPinModeException.java
    • UnsupportedPinPullResistanceException.java
  • com.pi4j.io.i2c: Migrate the following classes to the package org.eclipse.kura.io.i2c into the kura-api bundle:
    • I2CBus.java
    • I2CDevice.java
    • I2CFactory.java
  • com.pi4j.io.gpio.impl: The implementation classes will be moved into the org.eclipse.kura.core bundle under the package org.eclipse.kura.core.io.gpio:
    • GpioControllerImpl.java
    • GpioEventMonitorExecutorImpl.java
    • GpioEventMonitorImpl.java
    • GpioPinImpl.java
    • GpioPinShutdownImpl.java
    • GpioScheduledExecutorImpl.java
    • PinImpl.java
  • KURA ADDED - the Linux Sysfs implementation of GpioProvider will be created into a new bundle org.eclipse.kura.linux.io under the package org.eclipse.kura.linux.io.gpio.impl
    • KURA ADDED: LinuxSysfsGpioProvider.java - it will become the default GpioProvider
  • com.pi4j.io.i2c.impl: The implementation classes will be moved to a new bundle org.eclipse.kura.linux.io under the package org.eclipse.kura.linux.io.i2c.impl:
    • I2CBusImpl.java
    • I2CDeviceImpl.java
  • com.pi4j.concurrent: the classes under this package will be replaced by the org.eclipse.kura.core.util.ExecutorUtil
  • com.pi4j.io.serial: this package and its implementation will not be migrated as Kura already has serial support through the javax.comm APIs.
  • The classes under the following packages will be moved in the implementation bundle org.eclipse.kura.linux.io on a needed basis
    • com.pi4j.io.gpio.trigger
    • com.pi4j.jni
    • com.pi4j.system - - it will not be migrated as already covered by the Eclipse SystemService and NetworkService
    • com.pi4j.temperature - it will not be migrated as out of scope
    • com.pi4j.wiringpi - it will not be migrated as it will be replaced by new implementation based on accessing Linux sysfs

Kura's LinuxSysfsGpioProvider Design

The LinuxSysfsGpioProvider class will implement the GpioProvider interface and upon activation will load PIN configuration data based on a properties file.

The org.eclipse.kura.linux.io bundle will expose LinuxSysfsGpioProvider as a declarative service in order to have it as the default GpioProvider implementation if the bundle is running in the OSGi container.

The org.eclipse.kura.core bundle will provide a GpioController implementation wich will be used to perform operations on the GPIOs and will choose its default GpioProvider from the available services.

LinuxSysfsGpioProvider will then be used by any device that works on its GPIOs using Linux Sysfs. When custom implementations are needed for devices using GPIOs in different ways, the developer will have to implement his own implementation of GpioProvider, expose it as a declarative service and remove the org.eclipse.kura.linux.io bundle from the OSGi container.

The ideal bundle structure could be summarized as follows:

- org.eclipse.kura.core
   |
   \___ org.eclipse.kura.core.io.gpio
         |
         \___ GpioControllerImpl

- org.eclipse.kura.linux.io (Default implementation for all Linux Sysfs based GPIO)
   |
   \___ org.eclipse.kura.linux.io.gpio.impl
         |
         \___ LinuxSysfsGpioProvider

- com.foo.bar (Custom implementation for native GPIO)
   |
   \___ com.a.package
         |
         \___ NonSysfsImplementation

When instantiated LinuxSysfsGpioProvider will initialize its internals basing on a configuration file that will be different for each platform specific build, and that will contain all the default GPIO pinout of the relative hardware platform.

The properties file will follow a platform-specific naming convention so to make it more readable. I.e. the file org.eclipse.kura.io.gpio.raspberry-pi properties inside the resource folder of the bundle will contain the default pinout data for a Rapsberry-Pi board.

An example of the properties file contents can be as follows:

#GPIO_XX.number -> GPIO number
#GPIO_XX.pinMode -> list of available modes for the XX GPIO (Digital Input, Digital Output, PWM Output...)
#GPIO_XX.pinPullResistance -> Pull Resistance associated with the XX Pin

GPIO_38.number=3
GPIO_38.pinMode=DIGITAL_INPUT,DIGITAL_OUTPUT
GPIO_38.pinPullResistance=LOW,HIGH

GPIO_39.number=4
GPIO_39.pinMode=DIGITAL_INPUT,DIGITAL_OUTPUT
GPIO_39.pinPullResistance=LOW,HIGH

GPIO_08.number=24
GPIO_08.pinMode=DIGITAL_INPUT,DIGITAL_OUTPUT
GPIO_08.pinPullResistance=HIGH

Back to the top