common:application_note:gpio:gpio_keypad_matrix

How to use Keypad matrix on the ANDROID

You must install the Android release 20220901(N2)/20220901(C4) or higher to use this feature.

  • This sections is based on the ODROID-N2. But it also works on the ODROID-C4.

Make sure that you have these products:

For the wiring, you should wire a total number of cols and rows gpios.
You can choose empty GPIO like a pin 13 on the 40 pins.

Default Pin State GPIO & Export No Net Name Pin Number Pin Number Net Name GPIO & Export No Default Pin State
- - 3.3V 1 2 5.0V - -
I(P/D) GPIOX.17 (#493) I2C0_SDA 3 4 5.0V - -
I(P/U) GPIOX.18 (#494) I2C0_SCL 5 6 GND - -
I(P/D) GPIOA.13 (#473) 7 8 TXD1 GPIOX.12 (#488) I(P/U)
- - GND 9 10 RXD1 GPIOX.13 (#489) I(P/U)
I(P/U) GPIOX.3 (#479) 11 12 PWM_E GPIOX.16 (#492) I(P/U)
I(P/U) GPIOX.4 (#480) 13 14 GND - -
I(P/U) GPIOX.7 (#483) PWM_F 15 16 GPIOX.0 (#476) I(P/U)
- - 3.3V 17 18 GPIOX.1 (#477) I(P/U)
I(P/U) GPIOX.8 (#484) SPI0_MOSI 19 20 GND - -
I(P/U) GPIOX.9 (#485) SPI0_MISO 21 22 GPIOX.2 (#478) I(P/U)
I(P/U) GPIOX.11 (#487) SPI0_CLK 23 24 SPI0_SS0 GPIOX.10 (#486) I(P/U)
- - GND 25 26 SPI0_SS1 GPIOA.4 (#464) I(P/D)
I(P/U) GPIOA.14 (#474) I2C1_SDA 27 28 I2C1_SCL GPIOA.15 (#475) I(P/U)
I(P/U) GPIOX.14 (#490) 29 30 GND - -
I(P/U) GPIOX.15 (#491) 31 32 GPIOA.12 (#472) I(P/D)
I(P/U) GPIOX.5 (#481) PWM_C 33 34 GND - -
I(P/D) GPIOX.6 (#482) PWM_D 35 36 GPIOX.19 (#495) -
ADC.AIN3 37 38 REF 1.8V
- - GND 39 40 ADC.AIN2

2018/12/17 12:20 · luke.go

ODROID-C4

Default Pin State GPIO & Export No Net Name Pin Number Pin Number Net Name GPIO & Export No Default Pin State
- - 3.3V 1 2 5.0V - -
I(P/D) GPIOX.17 (#493) I2C0_SDA 3 4 5.0V - -
I(P/U) GPIOX.18 (#494) I2C0_SCL 5 6 GND - -
I(P/D) GPIOX.5 (#481) PWM_C 7 8 TXD1 GPIOX.12 (#488) I(P/U)
- - GND 9 10 RXD1 GPIOX.13 (#489) I(P/U)
I(P/U) GPIOX.3 (#479) PWM_D 11 12 PWM_E GPIOX.16 (#492) I(P/U)
I(P/U) GPIOX.4 (#480) 13 14 GND - -
I(P/U) GPIOX.7 (#483) PWM_F 15 16 GPIOX.0 (#476) I(P/U)
- - 3.3V 17 18 GPIOX.1 (#477) I(P/U)
I(P/U) GPIOX.8 (#484) SPI0_MOSI 19 20 GND - -
I(P/U) GPIOX.9 (#485) SPI0_MISO 21 22 GPIOX.2 (#478) I(P/U)
I(P/U) GPIOX.11 (#487) SPI0_SCLK 23 24 SPI0_CS0 GPIOX.10 (#486) I(P/U)
- - GND 25 26 SPI0_CS1 GPIOH.6 (#433) I(P/D)
I(P/U) GPIOA.14 (#474) I2C1_SDA 27 28 I2C1_SCL GPIOA.15 (#475) I(P/U)
I(P/U) GPIOX.14 (#490) 29 30 GND - -
I(P/U) GPIOX.15 (#491) 31 32 GPIOH.7 (#434) I(P/D)
I(P/U) GPIOX.6 (#482) PWM_A 33 34 GND - -
I(P/D) GPIOX.19 (#495) PWM_B 35 36 GPIOH.5 (#432) -
ADC.AIN2 37 38 REF 1.8V
- - GND 39 40 ADC.AIN0

2019/10/29 16:27 · luke.go

keypad matrix use gpio matrix keypad driver. So to use the driver, you should make dtbo based on this driver.

https://github.com/hardkernel/linux/blob/odroidg12-4.9.y/Documentation/devicetree/bindings/input/matrix-keymap.txt

As you can see the document, you need two value. gpio key and input event code.

GPIO Key can be found above of the table.

You can find event code from here.

And, you should check 3 timing properties. debounce-delay-ms, col-scan-delay-us and col-switch-delay-ms.

first two properties are explained on the Documents.

col-switch-delay-ms is polling period property for keypad matrix.

Example dtbo file is already included to dtbs partition.keymatrix.dts

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/meson-g12a-gpio.h>
#include <dt-bindings/gpio/gpio.h>

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

		__overlay__ {
			matrix_keypad: matrix-keypad {
				compatible = "gpio-matrix-keypad";
				col-gpios = <
					&gpio GPIOA_13 GPIO_ACTIVE_HIGH
					&gpio GPIOX_3 GPIO_ACTIVE_HIGH
					&gpio GPIOX_4 GPIO_ACTIVE_HIGH
					&gpio GPIOX_0 GPIO_ACTIVE_HIGH
					>;
				row-gpios = <
					&gpio GPIOX_1 GPIO_ACTIVE_HIGH
					&gpio GPIOX_2  GPIO_ACTIVE_HIGH
					&gpio GPIOX_14 GPIO_ACTIVE_HIGH
					&gpio GPIOX_15 GPIO_ACTIVE_HIGH
					>;
				/* sample keymap */
				linux,keymap = <
					0x00000074 /* row 0, col 0, KEY_POWER */
					0x00010052 /* row 0, col 1, KEY_KP0 */
					0x0002004f /* row 0, col 2, KEY_KP1 */
					0x00030050 /* row 0, col 3, KEY_KP2 */
					0x01000051 /* row 1, col 0, KEY_KP3 */
					0x0101004b /* row 1, col 1, KEY_KP4 */
					0x0102004c /* row 1, col 2, KEY_KP5 */
					0x0103004d /* row 1, col 3, KEY_KP6 */
					0x02000047 /* row 2, col 0, KEY_KP7 */
					0x02010048 /* row 2, col 1, KEY_KP8 */
					0x02020049 /* row 2, col 2, KEY_KP9 */
					>;
				gpio-activelow;
				debounce-delay-ms = <100>;
				col-scan-delay-us = <500>;
				col-switch-delay-ms = <20>;
				linux,no-autorepeat;
			};
		};
	};
};

You can find way to create customized dtbo file and way to apply from here

  • common/application_note/gpio/gpio_keypad_matrix.txt
  • Last modified: 2022/09/01 16:55
  • by luke.go