New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Matrix Keyboard support #2150

Open
wants to merge 1 commit into
base: rpi-4.9.y
from

Conversation

Projects
None yet
4 participants
@giggls

giggls commented Aug 6, 2017

Hello,

Matrix Keyboard support is not enabled by default. However it does work well using a device three overwrite file and has the advantage of linux input device compatibility compared to the widely used userland solutions.

I can provide a dts example file if desired.

Sven

@popcornmix

This comment has been minimized.

Show comment
Hide comment
@popcornmix

popcornmix Aug 7, 2017

Collaborator

Yes, please provide the dts file too.

Collaborator

popcornmix commented Aug 7, 2017

Yes, please provide the dts file too.

@giggls

This comment has been minimized.

Show comment
Hide comment
@giggls

giggls Aug 8, 2017

OK, I made up a DTS file for this type of Keyboard as an Example:
4x5matrix

    /dts-v1/;
    /plugin/;
    / {
           compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

           fragment@0 {
              target-path = "/";
              __overlay__ {
                 keypad: MATRIX4x5 {
                    compatible = "gpio-matrix-keypad";
                    debounce-delay-ms = <10>;
                    col-scan-delay-us = <10>;
                    /* 
		       try to use GPIO only lines
                       to keep SPI and I2C usable
                    */
                    row-gpios = <&gpio 27 0    // 1
                                 &gpio 22 0    // 2
                                 &gpio 10 0    // 3
                                 &gpio 9 0>;   // 4

                    col-gpios = <&gpio 13 0    // 5
                                 &gpio 26 0    // 6
                                 &gpio 16 0    // 7
                                 &gpio 20 0    // 8
                                 &gpio 21 0>;  // 9
                    /*
                      Keycodes from /usr/include/linux/input-event-codes.h
                      converted to hex using printf '%02x\n'
                    */

                    linux,keymap = <
                                    // col0 row0 KEY_LEFT
                                    0x00000069
                                    // col0 row1 KEY_KP0
                                    0x01000052
                                    // col0 row2 KEY_RIGHT
                                    0x0200006a
                                    // col0 row3 KEY_KPENTER
                                    0x03000060
				    // col1 row0 KEY_KP7
                                    0x00010047
                                    // col1 row1 KEY_KP8
                                    0x01010048
                                    // col1 row2 KEY_KP9
                                    0x02010049
                                    // col1 row3 KEY_ESC
                                    0x03010001
                                    // col2 row0 KEY_KP4
                                    0x0002004b
                                    // col2 row1 KEY_KP5
                                    0x0102004c
                                    // col2 row2 KEY_KP6
                                    0x0202004d
                                    // col2 row3 KEY_DOWN
                                    0x0302006c
                                    // col3 row0 KEY_KP1
                                    0x0003004f
                                    // col3 row1 KEY_KP2
                                    0x01030050
                                    // col3 row2 KEY_KP3
                                    0x02030051
                                    // col3 row3 KEY_UP
                                    0x03030067
                                    // col4 row0 KEY_F1
                                    0x0004003b
                                    // col4 row1 KEY_F2
                                    0x0104003c
                                    // col4 row2 KEY_KPSLASH there is no KP_#
                                    0x02040062
                                    // col4 row3 KEY_KPASTERISK
                                    0x03040037>;

                 };
              };
           };
      };

To compile use the following command:
./scripts/dtc/dtc -W no-unit_address_vs_reg -I dts -O dtb -o 4x5matrix.dtbo 4x5matrix.dts

Then copy the resulting dtbo file to /boot/overlays/4x5matrix.dtbo and add the following to /boot/config.txt

dtoverlay=4x5matrix

Regards

Sven

giggls commented Aug 8, 2017

OK, I made up a DTS file for this type of Keyboard as an Example:
4x5matrix

    /dts-v1/;
    /plugin/;
    / {
           compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

           fragment@0 {
              target-path = "/";
              __overlay__ {
                 keypad: MATRIX4x5 {
                    compatible = "gpio-matrix-keypad";
                    debounce-delay-ms = <10>;
                    col-scan-delay-us = <10>;
                    /* 
		       try to use GPIO only lines
                       to keep SPI and I2C usable
                    */
                    row-gpios = <&gpio 27 0    // 1
                                 &gpio 22 0    // 2
                                 &gpio 10 0    // 3
                                 &gpio 9 0>;   // 4

                    col-gpios = <&gpio 13 0    // 5
                                 &gpio 26 0    // 6
                                 &gpio 16 0    // 7
                                 &gpio 20 0    // 8
                                 &gpio 21 0>;  // 9
                    /*
                      Keycodes from /usr/include/linux/input-event-codes.h
                      converted to hex using printf '%02x\n'
                    */

                    linux,keymap = <
                                    // col0 row0 KEY_LEFT
                                    0x00000069
                                    // col0 row1 KEY_KP0
                                    0x01000052
                                    // col0 row2 KEY_RIGHT
                                    0x0200006a
                                    // col0 row3 KEY_KPENTER
                                    0x03000060
				    // col1 row0 KEY_KP7
                                    0x00010047
                                    // col1 row1 KEY_KP8
                                    0x01010048
                                    // col1 row2 KEY_KP9
                                    0x02010049
                                    // col1 row3 KEY_ESC
                                    0x03010001
                                    // col2 row0 KEY_KP4
                                    0x0002004b
                                    // col2 row1 KEY_KP5
                                    0x0102004c
                                    // col2 row2 KEY_KP6
                                    0x0202004d
                                    // col2 row3 KEY_DOWN
                                    0x0302006c
                                    // col3 row0 KEY_KP1
                                    0x0003004f
                                    // col3 row1 KEY_KP2
                                    0x01030050
                                    // col3 row2 KEY_KP3
                                    0x02030051
                                    // col3 row3 KEY_UP
                                    0x03030067
                                    // col4 row0 KEY_F1
                                    0x0004003b
                                    // col4 row1 KEY_F2
                                    0x0104003c
                                    // col4 row2 KEY_KPSLASH there is no KP_#
                                    0x02040062
                                    // col4 row3 KEY_KPASTERISK
                                    0x03040037>;

                 };
              };
           };
      };

To compile use the following command:
./scripts/dtc/dtc -W no-unit_address_vs_reg -I dts -O dtb -o 4x5matrix.dtbo 4x5matrix.dts

Then copy the resulting dtbo file to /boot/overlays/4x5matrix.dtbo and add the following to /boot/config.txt

dtoverlay=4x5matrix

Regards

Sven

@giggls

This comment has been minimized.

Show comment
Hide comment
@giggls

giggls Mar 10, 2018

Not enabled in raspberrypi-kernel 1.20171029-1

giggls commented Mar 10, 2018

Not enabled in raspberrypi-kernel 1.20171029-1

@w022a

This comment has been minimized.

Show comment
Hide comment
@w022a

w022a May 9, 2018

+1 for default Matrix Keyboard support. My project would really benefit from this.

w022a commented May 9, 2018

+1 for default Matrix Keyboard support. My project would really benefit from this.

pelwell added a commit that referenced this pull request May 20, 2018

config: Add KEYBOARD_MATRIX=m
See: #2150

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
@pelwell

This comment has been minimized.

Show comment
Hide comment
@pelwell

pelwell May 20, 2018

Contributor

My problem with this PR was the overlay, and the problem with the overlay was the lack of flexibility - it is a fixed size and a fixed key layout. But it is much easier for a user to install or change an overlay than it is to build a module, so that shouldn't be a barrier.

It's enabled in the 4.14 tree now.

Contributor

pelwell commented May 20, 2018

My problem with this PR was the overlay, and the problem with the overlay was the lack of flexibility - it is a fixed size and a fixed key layout. But it is much easier for a user to install or change an overlay than it is to build a module, so that shouldn't be a barrier.

It's enabled in the 4.14 tree now.

pelwell added a commit that referenced this pull request May 20, 2018

config: Add KEYBOARD_MATRIX=m
See: #2150

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

pelwell added a commit that referenced this pull request May 20, 2018

config: Add KEYBOARD_MATRIX=m
See: #2150

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

pelwell added a commit that referenced this pull request May 20, 2018

config: Add KEYBOARD_MATRIX=m
See: #2150

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this pull request May 21, 2018

config: Add KEYBOARD_MATRIX=m
See: #2150

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit to raspberrypi/firmware that referenced this pull request May 21, 2018

kernel: Bump to 4.14.42
kernel: config: Add CONFIG_MTD_BLOCK2MTD=m
See: raspberrypi/linux#2163

kernel: config: Add KEYBOARD_MATRIX=m
See: raspberrypi/linux#2150

popcornmix added a commit to Hexxeh/rpi-firmware that referenced this pull request May 21, 2018

kernel: Bump to 4.14.42
kernel: config: Add CONFIG_MTD_BLOCK2MTD=m
See: raspberrypi/linux#2163

kernel: config: Add KEYBOARD_MATRIX=m
See: raspberrypi/linux#2150

popcornmix added a commit that referenced this pull request May 25, 2018

config: Add KEYBOARD_MATRIX=m
See: #2150

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this pull request May 29, 2018

config: Add KEYBOARD_MATRIX=m
See: #2150

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this pull request Jun 5, 2018

config: Add KEYBOARD_MATRIX=m
See: #2150

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment