[[PageOutline]] = Gateworks Utility Library = == Overview == In order to provide users with easy access to the ventana family's low level linux functionality, Gateworks has composed a java library that exposes some simple methods for interacting with LEDs, GPIOs, PWMs, and hardware monitors that have been exported and registered in the android property system. The source for the library is available on Github at [https://github.com/Gateworks/android_packages_apps_gateworksutil ​Gateworks/android_packatges_apps_gateworksutil] and the javadoc created api documentation can be found [http://dev.gateworks.com/docs/android/GateworksUtil/ here]. == Requirements == In order for the library to function as intended, all low level controllers must be both '''exported''' and '''registered''' prior to runtime. Note that this is done by the Gateworks Android init script ​/device/gateworks/ventana/init.sh which is installed to /system/bin/init.sh and run as root on bootup for the standard resources on the various Ventana boards. === Exporting === Since the GateworksUtil library depends on access to the controller's associated sysfs structure, all GPIOs, PWMs, and LEDs must first be exported to userspace before they can be used. For further information on exporting see the following pages: * [wiki:gpio#gpiolib_sysfs GPIO] * [wiki:linux/pwm PWM] * [wiki:gpio#led LED] === Registering === In addition, the low level controllers being used must also be registered in the Android System Property list. This can be done a number of ways: 1. The command line tool setprop via {{{setprop my.property}}} value 2. Modifying the ​[https://github.com/Gateworks/android_device_gateworks/blob/imx_kk4.4.3_2.0.0-beta/ventana/init.sh /device/gateworks/ventana/init.sh] script of the device to register a new controller 3. With native C function {{{property_get}}} from system/core/include/cutils/properties.h 4. With the java class {{{android.os.SystemProperties}}} (see ​[https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/os/SystemProperties.java Android Google Source]) * Note: the {{{android.os.SystemProperties}}} class is only accessible to the internal android source SDK. For further information on registering see the [wiki:Android/OSDevelopment#AndroidProperties Android Properties] section of the [wiki:Android/OSDevelopment Android OS Development] page. == Code Examples == While the full source for the library is available on Github at [https://github.com/Gateworks/android_packages_apps_gateworksutil ​Gateworks/android_packatges_apps_gateworksutil] and the javadoc created api documentation can be found ​[http://dev.gateworks.com/docs/android/GateworksUtil/ here] sometimes a few simple examples can be extremely helpful. Code snippets and notes: * be sure add the GateworksUtil.jar library to your project (copy it to the libs directory and tell Android Studio to add it as a library) * be sure to import it's classes so that your code has access to them: {{{ import com.gateworks.gateworksutil.*; }}} * Hardware monitor values: - to see available hwmon values: {{{#!bash adb shell getprop | grep hw.hwmon [hw.hwmon.gsc_3p3]: [/sys/class/hwmon/hwmon1/device/in1_input] [hw.hwmon.gsc_5p0]: [/sys/class/hwmon/hwmon1/device/in3_input] [hw.hwmon.gsc_bat]: [/sys/class/hwmon/hwmon1/device/in2_input] [hw.hwmon.gsc_core]: [/sys/class/hwmon/hwmon1/device/in4_input] [hw.hwmon.gsc_cpu1]: [/sys/class/hwmon/hwmon1/device/in5_input] [hw.hwmon.gsc_cpu2]: [/sys/class/hwmon/hwmon1/device/in6_input] [hw.hwmon.gsc_current]: [/sys/class/hwmon/hwmon1/device/in12_input] [hw.hwmon.gsc_dram]: [/sys/class/hwmon/hwmon1/device/in7_input] [hw.hwmon.gsc_ext_bat]: [/sys/class/hwmon/hwmon1/device/in8_input] [hw.hwmon.gsc_io1]: [/sys/class/hwmon/hwmon1/device/in9_input] [hw.hwmon.gsc_io2]: [/sys/class/hwmon/hwmon1/device/in10_input] [hw.hwmon.gsc_pci2]: [/sys/class/hwmon/hwmon1/device/in11_input] [hw.hwmon.gsc_temp]: [/sys/class/hwmon/hwmon1/device/temp0_input] [hw.hwmon.gsc_vin]: [/sys/class/hwmon/hwmon1/device/in0_input] [hw.hwmon.imx_cpu_crit_temp]: [/sys/class/hwmon/hwmon2/temp1_crit] [hw.hwmon.imx_cpu_temp]: [/sys/class/hwmon/hwmon2/temp1_input] }}} - to get value of the Gateworks System Controller provided 'vin' (Voltage Input): {{{ int vin = HardwareMonitor.getHwmonValue("gsc_vin")); }}} - to get value of the IMX6 provided 'cpu_temp' (CPU temperature): {{{ int vin = HardwareMonitor.getHwmonValue("imx_cpu_temp")); }}} * GPIO values: - to see available exported/registered GPIOs: {{{#!bash adb shell getprop | grep hw.gpio [hw.gpio.can_stby]: [/sys/class/gpio/gpio2/] [hw.gpio.dio0]: [/sys/class/gpio/gpio9/] [hw.gpio.dio1]: [/sys/class/gpio/gpio19/] [hw.gpio.dio2]: [/sys/class/gpio/gpio41/] }}} - to set DIO0 direction and read its value: {{{ setGpioDirection("dio0", IN); int getGpioValue("dio0"); }}} - to set DIO1 as an output level high: {{{ setGpioDirection("dio1", OUT); setGpioValue("dio1", 1); }}} * LED values: - to see available exported/registered LEDs: {{{ adb shell getprop | grep hw.led [hw.led.frontgreen]: [/sys/class/leds/user1/] [hw.led.frontred]: [/sys/class/leds/user2/] [hw.led.local]: [/sys/class/leds/user3/] }}} - to set the front panel green LED to no automatic trigger and off state: {{{ setLedtrigger("none", 0); setLedValue("frontgreen", 0); }}} - to set the front panel green LED to an automatic 'heartbeat' trigger: {{{ setLedTrigger("frontgreen", "heartbeat"); }}} * PWM values: - to see available exported/registered PWMs: {{{ adb shell getprop | grep hw.pwm [hw.pwm.pwm2]: [/sys/class/pwm/pwmchip0/pwm0/] }}} - to set pwm2 for a 1000ns period and 50% duty cycle and enable it: {{{ setPeriod("pwm2", 1000); setDutyCycle("pwm2", 50); setPolarity("pwm2", NORMAL); setEnabled("pwm2", 1); }}}