aukondk
Posts: 2
Joined: Wed Feb 20, 2019 9:48 am
Contact: Website

Trouble using gpio-matrix-keypad

Wed Feb 20, 2019 10:00 am

I'm trying to get my ZX Spectrum membrane keyboard to work as a gpio-matrix-keypad device overlay on my Pi Zero. The wiring is based on this project and I followed this guide to write the dts script.

It's nearly working apart from the last row which seems to be jammed on at boot. The last key of the row is constantly pressed when running "input-events 0" until I press a key on another row. Then the last row doesn't give any feedback but the terminal on the Pi itself acts as if ctrl is being pressed (ctrl is one of the keys in that last row).

Anyone with an Idea what I can try next? I suspect gpio 4 is doing something odd. The hardware connections seem ok with a multi meter and I've used the same hardware before with a python script reading the pins as in the original project and that still works.

DTS script below:

Code: Select all

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

           fragment@0 {
              target-path = "/";
              __overlay__ {
                 keypad: SPECCYPI {
                    compatible = "gpio-matrix-keypad";
                    debounce-delay-ms = <10>;
                    col-scan-delay-us = <10>;
                    wakeup-source = <1>;
                    drive-inactive-cols = <1>;
                    /* 
		       try to use GPIO only lines
                       to keep SPI and I2C usable
                    */
                    col-gpios = <&gpio 26 0  
                                 &gpio 19 0  
                                 &gpio 13 0  
                                 &gpio 6 0	
                                 &gpio 5 0>;  
                    row-gpios = <&gpio 25 0   
                                 &gpio 24 0   
                                 &gpio 23 0   
                                 &gpio 22 0   
                                 &gpio 27 0   
                                 &gpio 18 0   
                                 &gpio 17 0   
                                 &gpio 4 0>; 
                    /*
                      Keycodes from /usr/include/linux/input-event-codes.h
                      converted to hex using printf '%02x\n'
                    */
                    linux,keymap = <			0x00000002
								0x00010003
								0x00020004
								0x00030005
								0x00040006
								0x01000010
								0x01010011
								0x01020012
								0x01030013
								0x01040014
								0x0200001e
								0x0201001f
								0x02020020
								0x02030021
								0x02040022
								0x0300000b
								0x0301000a
								0x03020009
								0x03030008
								0x03040007
								0x04000019
								0x04010018
								0x04020017
								0x04030016
								0x04040015
								0x0500002a
								0x0501002c
								0x0502002d
								0x0503002e
								0x0504002f
								0x0600001c
								0x06010026
								0x06020025
								0x06030024
								0x06040023
								0x07000039
								0x0701001d
								0x07020032
								0x07030031
								0x07040030>;

                 };
              };
           };
      };

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2158
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Trouble using gpio-matrix-keypad

Wed Feb 20, 2019 4:20 pm

Can you run "raspi-gpio get" while in the stuck row state? I'm wondering if your problems are with GPIOs 4, 5 and 6, which naturally pull high unless told otherwise. You can override the default pulls, and prevent other uses of those pins, using a pinctrl node - something like this:

Code: Select all

        fragment@1 {
                target = <&gpio>;
                __overlay__ {
                        keypad_pins: keypad_pins {
                                brcm,pins = < 4 5 6 13 17 18 19 22 23 24 26 27 >;
                                brcm,function = <0>; // input
                                brcm,pull = <1>; // 0=off, 1=down, 2=up
                        };
                };
        };
You will also need to refer to it from your keypad device node:

Code: Select all

...
                        keypad: SPECCYPI {
                                compatible = "gpio-matrix-keypad";
                                pinctrl-names = "default";
                                pinctrl-0 = <&keypad_pins>;
...
                        };


aukondk
Posts: 2
Joined: Wed Feb 20, 2019 9:48 am
Contact: Website

Re: Trouble using gpio-matrix-keypad

Wed Feb 20, 2019 7:08 pm

Many thanks! That worked. I had a feeling it was something like that but my Google-fu was failing me.

Next I need to look into switching keymaps. The way the keys are now work fine inside a Spectrum emuator but the masochist in me would like to fully use the linux terminal with it.

Return to “Device Tree”