common:application_note:app_launch_via_gpio_on_android

'ODROID-N2' on this page refers to the ODROID-N2 series (N2, N2+, N2L).

Application launching with GPIO trigger on Android

You must install the Android release V2.9(C2)/V4.5(XU4)/20190425(N2) or higher to launch app via GPIO.
In that case you can skip step 1 ~ 7 for your easier life LOL

If you installed higher version of the Android Marshmallow version v2.9, Please do just step 3 and 4, and skip to 7
Please check the revision of PCB. This page is based on the board revision 0.2.(ODROID-C2)

This page explains how to launch an app via GPIO input.

1. Enable the GPIO key driver as a built-in.

...
CONFIG_KEYBOARD_GPIO_POLLED=y
...

2. Add gpio key mapping to device tree blob.

(path: arch/arm64/boot/dts/meson64_odroidc2.dts)
GPIO Pin description
commit

gpio_keys_polled {
   status = "disabled";
   compatible =
    "gpio-keys-polled";
   #address-cells = <1>;
   #size-cells = <0>;
   poll-interval = <100>;
   autorepeat;
   button@1 {
    label = "GPIO Key F7";
    linux,code = <65>;
    gpios = <&gpio GPIOX_19 1>;
   };
   button@2 {
    label = "GPIO Key F8";
    linux,code = <66>;
    gpios = <&gpio GPIOX_11 1>;
   };
   button@3 {
    label = "GPIO Key F9";
    linux,code = <67>;
    gpios = <&gpio GPIOX_9 1>;
   };
   button@4 {
    label = "GPIO Key F10";
    linux,code = <68>;
    gpios = <&gpio GPIOX_7 1>;
   };
 };

(path: arch/arm/boot/dts/exynos5422-odroidxu3.dts)
GPIO Pin description
Shift shield GPIO map
commit1
commit2

gpio_keys_polled {
   status = "disabled";
   compatible =
    "gpio-keys-polled";
   #address-cells = <1>;
   #size-cells = <0>;
   poll-interval = <100>;
   autorepeat;
   button@1 {
    label = "GPIO Key F7";
    linux,code = <65>;
    gpios = <&gpx1 2 0xf>;
   };
   button@2 {
    label = "GPIO Key F8";
    linux,code = <66>;
    gpios = <&gpx1 5 0xf>;
   };
   button@3 {
    label = "GPIO Key F9";
    linux,code = <67>;
    gpios = <&gpx1 6 0xf>;
   };
   button@4 {
    label = "GPIO Key F10";
    linux,code = <68>;
    gpios = <&gpx1 3 0xf>;
   };
 };

(path: arch/arm64/boot/dts/amlogic/overlays/odroidn2/gpio_shortcut.dts)
GPIO Pin description

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/meson-g12a-gpio.h>
#include <dt-bindings/gpio/gpio.h>
/{
	fragmetn@0 {
		target-path ="/";

		__overlay__ {
			gpio_keys_polled {
				status = "okay";
				compatible =
					"gpio-keys-polled";
				#address-cells = <1>;
				#size-cells = <0>;
				poll-interval = <100>;
				autorepeat;
				button@1 {
					label = "GPIO Key F7";
					linux,code = <65>;
					gpios = <&gpio GPIOX_4 1>;
				};
				button@2 {
					label = "GPIO Key F8";
					linux,code = <66>;
					gpios = <&gpio GPIOX_7 1>;
				};
				button@3 {
					label = "GPIO Key F9";
					linux,code = <67>;
					gpios = <&gpio GPIOX_0 1>;
				};
				button@4 {
					label = "GPIO Key F10";
					linux,code = <68>;
					gpios = <&gpio GPIOX_1 1>;
				};
			};
		};
	};
};

(path: arch/arm64/boot/dts/amlogic/overlays/odroidc4/gpio_shortcut.dts)
GPIO Pin description

/dts-v1/;
/plugin/;

/{
	fragmetn@0 {
		target-path ="/";

		__overlay__ {
			gpio_keys_polled {
				status = "okay";
				compatible =
					"gpio-keys-polled";
				#address-cells = <1>;
				#size-cells = <0>;
				poll-interval = <100>;
				autorepeat;
				button@1 {
					label = "GPIO Key F7";
					linux,code = <65>;
					gpios = <&gpio GPIOX_4 1>;
				};
				button@2 {
					label = "GPIO Key F8";
					linux,code = <66>;
					gpios = <&gpio GPIOX_7 1>;
				};
				button@3 {
					label = "GPIO Key F9";
					linux,code = <67>;
					gpios = <&gpio GPIOX_0 1>;
				};
				button@4 {
					label = "GPIO Key F10";
					linux,code = <68>;
					gpios = <&gpio GPIOX_1 1>;
				};
			};
		};
	};
};

3. Enable GPIO Key map.

gpio_keys_polled {
   status = "okay";
   .
   .
};

4. Build the kernel source. and flash the kernel image to the board.

host
$ cd kernel
$ export ARCH=arm64
$ export CROSS_COMPILE=aarch64-linux-gnu-
$ make odroidc2_i2c_defconfig  #(or make odroidc2_defconfig)
$ make -j8
$ adb reboot fastboot
$ fastboot flash dtb arch/arm64/boot/dts/meson64_odroidc2.dtb
$ fastboot flash boot arch/arm64/boot/uImage
$ fastboot reboot
host
$ cd common
$ export ARCH=arm64
$ export CROSS_COMPILE=aarch64-linux-gnu-
$ make odroidn2_android_defconfig
$ make -j8
$ adb reboot fastboot
$ fastboot flash dtb arch/arm64/boot/dts/amlogic/meson64_odroidn2_android.dtb
$ fastboot reboot
host
$ cd common
$ export ARCH=arm64
$ export CROSS_COMPILE=aarch64-linux-gnu-
$ make odroidc4_android_defconfig
$ make -j8
$ adb reboot fastboot
$ fastboot flash dtb arch/arm64/boot/dts/amlogic/meson64_odroidc4_android.dtb
$ fastboot reboot

5. Add key event keycode to system/usr/keylayout/Vendor_0001_Product_0001.kl file.
You can find keycode table from reference
ODROID-C2
commit
ODROID-XU3/XU4
commit

...
key 65 F7
key 66 F8
key 67 F9
key 68 F10
...

6. Apply the patch that intercept key event to frameworks/base & ODROID Utility App.
ODROID-C2
frameworks/base commit
ODROID Utility commit
ODROID-XU3/XU4
frameworks/base commit
ODROID Utility commit
7. Build the Android image and flash it.
ODROID-C2 build method ODROID-XU3/4 install method

host
$ cd <PATH_TO_ANDROID_ROOT>
$ cd out/target/product/odroidc2/
$ adb reboot fastboot
$ fastboot flash system rootsystem.img
$ fastboot reboot


ODROID-N2/C4

$ su
# vi /odm/env.ini
add gpio_shortcut
overlays="i2c0 i2c1 spi0 uart0 gpio_shortcut"

8. Connect a few buttons to the GPIOs with 10KOhm pull-up resistors. Click images to enlarge it.

9. Set the launch app by using ODROID Utility or Odroid-Settings app.

  • common/application_note/app_launch_via_gpio_on_android.txt
  • Last modified: 2022/11/08 14:31
  • by luke.go