Keypad Reference

Version 1.1


1. Overview

In order to facilitate the user to use the matrix buttons, the demo board has 14 IO ports, which supports up to 7x7 keyboards with a total of 49 buttons. The key info is directly processed by the underlying hardware to reduce the burden on the cpu.


2. UBOOT Config


2.1. Key Value Modification

Modify the following two-dimensional array in kernel/drivers/mstar/keypad/mdrv_keypad.c to change the reported key value.


2.2. Keypad Size Modification

Modify the size of the keyboard used in uboot.

1: keypad7*7, use KP_E_STANDARD_MODE1

2: keypad4*4, use KP_E_STANDARD_MODE2

3: keypad3*3, use KP_E_STANDARD_MODE3

The keyboard7*7 is used by default, and padmux is automatically switched during initialization.


2.3. Open Keypad Config

Open the keypad config configured by Mstar drivers.

Select SSTAR_KEYPAD to make the keyboard driver enter uboot.


2.4. Scan Key Value in Uboot

Judge whether the key is pressed during uboot startup in boot/common/board_r.c. If it is, and processing time is too long, the watchdog needs to be triggered. The key is not in the func of main_loop(), so uboot cmd cannot detect it. It only supports detecting whether the key is pressed during uboot startup, and completing the customized operation.


3. Kernel Config


3.1. Keypad Padmux Supported by Demo Board

KeyPad Group Mode GPIO DEV
7x7 1 PAD_KEY0 ~ PAD_KEY13 /dev/input/event0 or /dev/input/event1
4x4 2 PAD_KEY0 ~ PAD_KEY7
3x3 3 PAD_KEY8 ~ PAD_KEY13

3.2. KeyPad dts Config

  1. Pioneer.dtsi

    1. Standard: Choose the matrix keyboard.

      1. keypad7*7, use PINMUX_FOR_BT1120_MODE_1

      2. keypad4*4, use PINMUX_FOR_BT1120_MODE_2

      3. keypad3*3, use PINMUX_FOR_BT1120_MODE_3

    2. Keypadmode: Press the key to trigger the interrupt type.

      1. Occur Irq in key Pressed or release. Keep all press and all release key status.

        release result will be store R17-1e->{64:128}

      2. Occur Irq in key Pressed.Keep current press and last time press status.

        last time pressd result store R17-1e->{64:128}

      3. Occur Irq in key release. Keep current release and last time release status.

        last time relsase result store R17-1e->{64:128}

      4. Occur Irq in key Pressed. Support press single key.(Not support)

    3. Keypad-rowX: User-defined key.

  2. Set Keypad mode, modify pioneer3-ssc020a-s01a-demo-padmux.dtsi, choose one of three.

    1. Keypad 7x7, set mode to PINMUX_FOR_BT1120_MODE_1

    2. Keypad 4x4, set mode to PINMUX_FOR_BT1120_MODE_2

    3. Keypad 3x3, set mode to PINMUX_FOR_BT1120_MODE_3


3.3. Kernel Config

Open the SStar I2C Keypad configure.


4. Keypad Short Circuit Cap Config

  • When using a 7x7 keypad, all short circuit caps are connected to the left

  • When using a 4x4 keypad, SW1 ~ SW8 are connected to the right

  • When using a 3x3 keypad, SW9 ~ SW14 are connected to the right


5. Keypad Test


5.1. Test Keypad in Kernel

Take 7x7Keypad as an example, please make sure that the corresponding pin is not occupied.

Check the current keypad mode.

7x7 Keys: mode1; 4x4 Keys: mode2; 3x3 Keys: mode3.

The reg address corresponding to Keypad mode is 103ce4 (e4 is shifted one bit to the right when reading a 16-bit address, which is 72).

Read that the mode is 1, use the 7x7 keys setting.

Check the Keypad device node, which corresponds to event0.

Test:

Press/release the button will display the key value and event info.


6. Demo


6.1. Kernel Demo

Test code test_keypad.c.

Use 7x7 Keypad to test:

  1. Compile code to generate a test bin.

    arm-linux-gnueabihf-gcc –o test_keypad test_keypad.c
    
  2. Mount it to the board and execute the test bin file.

    Print the value of the key pressed/released: