| 1 | {{{#!html |
| 2 | <div id="wikipage" class="trac-content"><p> |
| 3 | </p><div class="wiki-toc"> |
| 4 | <ol> |
| 5 | <li> |
| 6 | <a href="#GateworksUtilityLibrary">Gateworks Utility Library</a> |
| 7 | <ol> |
| 8 | <li> |
| 9 | <a href="#Overview">Overview</a> |
| 10 | </li> |
| 11 | <li> |
| 12 | <a href="#Requirements">Requirements</a> |
| 13 | <ol> |
| 14 | <li> |
| 15 | <a href="#Exporting">Exporting</a> |
| 16 | </li> |
| 17 | <li> |
| 18 | <a href="#Registering">Registering</a> |
| 19 | </li> |
| 20 | </ol> |
| 21 | </li> |
| 22 | <li> |
| 23 | <a href="#CodeExamples">Code Examples</a> |
| 24 | </li> |
| 25 | <li> |
| 26 | <a href="#Attachments">Attachments</a> |
| 27 | </li> |
| 28 | </ol> |
| 29 | </li> |
| 30 | </ol> |
| 31 | </div><p> |
| 32 | </p> |
| 33 | <h1 id="GateworksUtilityLibrary">Gateworks Utility Library</h1> |
| 34 | <p> |
| 35 | <span class="wikianchor" id="overview"></span> |
| 36 | </p> |
| 37 | <h2 id="Overview">Overview</h2> |
| 38 | <p> |
| 39 | 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. |
| 40 | </p> |
| 41 | <p> |
| 42 | The source for the library is available on Github at <a class="ext-link" href="https://github.com/Gateworks/android_packages_apps_gateworksutil"><span class="icon"></span>Gateworks/android_packatges_apps_gateworksutil</a> and the javadoc created api documentation can be found <a class="ext-link" href="http://dev.gateworks.com/docs/android/GateworksUtil/"><span class="icon"></span>here</a>. |
| 43 | </p> |
| 44 | <p> |
| 45 | <span class="wikianchor" id="requirements"></span> |
| 46 | </p> |
| 47 | <h2 id="Requirements">Requirements</h2> |
| 48 | <p> |
| 49 | In order for the library to function as intended, all low level controllers must be both <strong>exported</strong> and <strong>registered</strong> prior to runtime. |
| 50 | </p> |
| 51 | <p> |
| 52 | Note that this is done by the Gateworks Android init script <a class="ext-link" href="https://github.com/Gateworks/android_device_gateworks/blob/imx_kk4.4.3_2.0.0-beta/ventana/init.sh"><span class="icon"></span>/device/gateworks/ventana/init.sh</a> which is installed to /system/bin/init.sh and run as root on bootup for the standard resources on the various Ventana boards. |
| 53 | </p> |
| 54 | <p> |
| 55 | <span class="wikianchor" id="exporting"></span> |
| 56 | </p> |
| 57 | <h3 id="Exporting">Exporting</h3> |
| 58 | <p> |
| 59 | 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: |
| 60 | </p> |
| 61 | <ul><li><a class="wiki" href="/wiki/gpio#gpiolib_sysfs">GPIO</a> |
| 62 | </li><li><a class="wiki" href="/wiki/linux/pwm">PWM</a> |
| 63 | </li><li><a class="wiki" href="/wiki/gpio#led">LED</a> |
| 64 | </li></ul><p> |
| 65 | <span class="wikianchor" id="registering"></span> |
| 66 | </p> |
| 67 | <h3 id="Registering">Registering</h3> |
| 68 | <p> |
| 69 | 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: |
| 70 | </p> |
| 71 | <ol><li>The command line tool setprop via <tt>setprop my.property value</tt> |
| 72 | </li><li>Modifying the <a class="ext-link" href="https://github.com/Gateworks/android_device_gateworks/blob/imx_kk4.4.3_2.0.0-beta/ventana/init.sh"><span class="icon"></span>/device/gateworks/ventana/init.sh</a> script of the device to register a new controller |
| 73 | </li><li>With native C function <tt>property_get</tt> from system/core/include/cutils/properties.h |
| 74 | </li><li>With the java class <tt>android.os.SystemProperties</tt> (see <a class="ext-link" href="https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/os/SystemProperties.java"><span class="icon"></span>Android Google Source</a>) |
| 75 | </li></ol><p> |
| 76 | *Note: the android.os.SystemProperties class is only accessible to the internal android source SDK. |
| 77 | </p> |
| 78 | <p> |
| 79 | For further information on registering see the <a class="wiki" href="/wiki/Android/OSDevelopment#AndroidProperties">Android Properties</a> section of the <a class="wiki" href="/wiki/Android/OSDevelopment">Android OS Development</a> page. |
| 80 | </p> |
| 81 | <h2 id="CodeExamples">Code Examples</h2> |
| 82 | <p> |
| 83 | While the full source for the library is available on Github at <a class="ext-link" href="https://github.com/Gateworks/android_packages_apps_gateworksutil"><span class="icon"></span>Gateworks/android_packatges_apps_gateworksutil</a> and the javadoc created api documentation can be found <a class="ext-link" href="http://dev.gateworks.com/docs/android/GateworksUtil/"><span class="icon"></span>here</a> sometimes a few simple examples can be extremely helpful. |
| 84 | </p> |
| 85 | <p> |
| 86 | Code snippets and notes: |
| 87 | </p> |
| 88 | <ul><li>be sure add the <a class="wiki" href="/wiki/Android/GateworksUtil">GateworksUtil</a>.jar library to your project (copy it to the <tt>libs</tt> directory and tell Android Studio to add it as a library) |
| 89 | </li><li>be sure to import it's classes so that your code has access to them: |
| 90 | <div class="code"><pre><span class="kn">import</span> <span class="nn">com.gateworks.gateworksutil.*</span><span class="o">;</span> |
| 91 | </pre></div></li><li>Hardware monitor values: |
| 92 | <ul><li>to see available hwmon values: |
| 93 | <div class="code"><pre> adb shell getprop | grep hw.hwmon |
| 94 | <span class="o">[</span>hw.hwmon.gsc_3p3<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in1_input<span class="o">]</span> |
| 95 | <span class="o">[</span>hw.hwmon.gsc_5p0<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in3_input<span class="o">]</span> |
| 96 | <span class="o">[</span>hw.hwmon.gsc_bat<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in2_input<span class="o">]</span> |
| 97 | <span class="o">[</span>hw.hwmon.gsc_core<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in4_input<span class="o">]</span> |
| 98 | <span class="o">[</span>hw.hwmon.gsc_cpu1<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in5_input<span class="o">]</span> |
| 99 | <span class="o">[</span>hw.hwmon.gsc_cpu2<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in6_input<span class="o">]</span> |
| 100 | <span class="o">[</span>hw.hwmon.gsc_current<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in12_input<span class="o">]</span> |
| 101 | <span class="o">[</span>hw.hwmon.gsc_dram<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in7_input<span class="o">]</span> |
| 102 | <span class="o">[</span>hw.hwmon.gsc_ext_bat<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in8_input<span class="o">]</span> |
| 103 | <span class="o">[</span>hw.hwmon.gsc_io1<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in9_input<span class="o">]</span> |
| 104 | <span class="o">[</span>hw.hwmon.gsc_io2<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in10_input<span class="o">]</span> |
| 105 | <span class="o">[</span>hw.hwmon.gsc_pci2<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in11_input<span class="o">]</span> |
| 106 | <span class="o">[</span>hw.hwmon.gsc_temp<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/temp0_input<span class="o">]</span> |
| 107 | <span class="o">[</span>hw.hwmon.gsc_vin<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in0_input<span class="o">]</span> |
| 108 | <span class="o">[</span>hw.hwmon.imx_cpu_crit_temp<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon2/temp1_crit<span class="o">]</span> |
| 109 | <span class="o">[</span>hw.hwmon.imx_cpu_temp<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon2/temp1_input<span class="o">]</span> |
| 110 | </pre></div></li><li>to get value of the Gateworks System Controller provided 'vin' (Voltage Input): |
| 111 | <div class="code"><pre><span class="kt">int</span> vin <span class="o">=</span> HardwareMonitor<span class="o">.</span><span class="na">getHwmonValue</span><span class="o">(</span><span class="s">"gsc_vin"</span><span class="o">));</span> |
| 112 | </pre></div></li><li>to get value of the IMX6 provided 'cpu_temp' (CPU temperature): |
| 113 | <div class="code"><pre><span class="kt">int</span> vin <span class="o">=</span> HardwareMonitor<span class="o">.</span><span class="na">getHwmonValue</span><span class="o">(</span><span class="s">"imx_cpu_temp"</span><span class="o">));</span> |
| 114 | </pre></div></li></ul></li><li>GPIO values: |
| 115 | <ul><li>to see available exported/registered GPIOs: |
| 116 | <div class="code"><pre>adb shell getprop | grep hw.gpio |
| 117 | <span class="o">[</span>hw.gpio.can_stby<span class="o">]</span>: <span class="o">[</span>/sys/class/gpio/gpio2/<span class="o">]</span> |
| 118 | <span class="o">[</span>hw.gpio.dio0<span class="o">]</span>: <span class="o">[</span>/sys/class/gpio/gpio9/<span class="o">]</span> |
| 119 | <span class="o">[</span>hw.gpio.dio1<span class="o">]</span>: <span class="o">[</span>/sys/class/gpio/gpio19/<span class="o">]</span> |
| 120 | <span class="o">[</span>hw.gpio.dio2<span class="o">]</span>: <span class="o">[</span>/sys/class/gpio/gpio41/<span class="o">]</span> |
| 121 | </pre></div></li><li>to set DIO0 direction and read its value: |
| 122 | <div class="code"><pre>setGpioDirection<span class="o">(</span><span class="s">"dio0"</span><span class="o">,</span> IN<span class="o">);</span> |
| 123 | <span class="kt">int</span> <span class="nf">getGpioValue</span><span class="o">(</span><span class="s">"dio0"</span><span class="o">);</span> |
| 124 | </pre></div></li><li>to set DIO1 as an output level high: |
| 125 | <div class="code"><pre>setGpioDirection<span class="o">(</span><span class="s">"dio1"</span><span class="o">,</span> OUT<span class="o">);</span> |
| 126 | setGpioValue<span class="o">(</span><span class="s">"dio1"</span><span class="o">,</span> <span class="mi">1</span><span class="o">);</span> |
| 127 | </pre></div></li></ul></li><li>LED values: |
| 128 | <ul><li>to see available exported/registered LEDs: |
| 129 | <div class="code"><pre>adb shell getprop | grep hw.led |
| 130 | <span class="o">[</span>hw.led.frontgreen<span class="o">]</span>: <span class="o">[</span>/sys/class/leds/user1/<span class="o">]</span> |
| 131 | <span class="o">[</span>hw.led.frontred<span class="o">]</span>: <span class="o">[</span>/sys/class/leds/user2/<span class="o">]</span> |
| 132 | <span class="o">[</span>hw.led.local<span class="o">]</span>: <span class="o">[</span>/sys/class/leds/user3/<span class="o">]</span> |
| 133 | </pre></div></li><li>to set the front panel green LED to no automatic trigger and off state: |
| 134 | <div class="code"><pre>setLedtrigger<span class="o">(</span><span class="s">"none"</span><span class="o">,</span> <span class="mi">0</span><span class="o">);</span> |
| 135 | setLedValue<span class="o">(</span><span class="s">"frontgreen"</span><span class="o">,</span> <span class="mi">0</span><span class="o">);</span> |
| 136 | </pre></div></li><li>to set the front panel green LED to an automatic 'heartbeat' trigger |
| 137 | <div class="code"><pre>setLedTrigger<span class="o">(</span><span class="s">"frontgreen"</span><span class="o">,</span> <span class="s">"heartbeat"</span><span class="o">);</span> |
| 138 | </pre></div></li></ul></li><li>PWM values: |
| 139 | <ul><li>to see available exported/registered PWMs: |
| 140 | <div class="code"><pre>adb shell getprop | grep hw.pwm |
| 141 | <span class="o">[</span>hw.pwm.pwm2<span class="o">]</span>: <span class="o">[</span>/sys/class/pwm/pwmchip0/pwm0/<span class="o">]</span> |
| 142 | </pre></div></li><li>to set pwm2 for a 1000ns period and 50% duty cycle and enable it: |
| 143 | <div class="code"><pre>setPeriod<span class="o">(</span><span class="s">"pwm2"</span><span class="o">,</span> <span class="mi">1000</span><span class="o">);</span> |
| 144 | setDutyCycle<span class="o">(</span><span class="s">"pwm2"</span><span class="o">,</span> <span class="mi">50</span><span class="o">);</span> |
| 145 | setPolarity<span class="o">(</span><span class="s">"pwm2"</span><span class="o">,</span> NORMAL<span class="o">);</span> |
| 146 | setEnabled<span class="o">(</span><span class="s">"pwm2"</span><span class="o">,</span> <span class="mi">1</span><span class="o">);</span> |
| 147 | </pre></div></li></ul></li></ul><p> |
| 148 | <span class="wikianchor" id="attachments"></span> |
| 149 | </p> |
| 150 | <h2 id="Attachments">Attachments</h2> |
| 151 | <p> |
| 152 | The file links below include the following: |
| 153 | </p> |
| 154 | <ul><li><a class="attachment" href="/attachment/wiki/Android/GateworksUtil/GateworksUtil.jar" title="Attachment 'GateworksUtil.jar' in Android/GateworksUtil">GateworksUtil.jar</a><a class="trac-rawlink" href="/raw-attachment/wiki/Android/GateworksUtil/GateworksUtil.jar" title="Download"></a> - The precompiled binary for importing into an android project |
| 155 | </li></ul |
| 156 | }}} |