Use keypad for wakeup (kbd_matrix) from deep sleep (sys_poweroff)

I am having issues using a keypad to wakeup an nrf52840 and am unclear on if the GPIO sample is relevant if using a kbd_matrix device definition.

I would like to use "sys_poweroff()" for power savings but have not been able to wake it up again.  Is it possible to use this device?  Do I need to change to a GPIO interrupt or something?

Currently, a callback is registered for the keypad events:

Fullscreen
1
INPUT_CALLBACK_DEFINE(DEVICE_DT_GET(DT_NODELABEL(keymap)), input_button_raw_cb);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


I have added "wakeup-source" to the device tree and the definition is:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
· · kbd_matrix: kbd_matrix {
· · · · compatible = "gpio-kbd-matrix";
· · · · zephyr,deferred-init; // Init at runtime depending on the board
· · · · wakeup-source;
· · · · row-gpios = <&gpio1 1 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
· · · · · · · · · · <&gpio1 2 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
· · · · · · · · · · <&gpio1 3 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
· · · · · · · · · · <&gpio1 4 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
· · · · col-gpios = <&gpio1 5 GPIO_ACTIVE_LOW>,
· · · · · · · · · · <&gpio1 6 GPIO_ACTIVE_LOW>,
· · · · · · · · · · <&gpio1 7 GPIO_ACTIVE_LOW>;
· · · · keymap: keymap {
· · · · · · compatible = "input-keymap";
· · · · · · keymap = <
· · · · · · · · MATRIX_KEY(3, 0, 100)
· · · · · · · · MATRIX_KEY(3, 1, 101)
· · · · · · · · MATRIX_KEY(3, 2, 102)
· · · · · · · · MATRIX_KEY(2, 0, 103)
· · · · · · · · MATRIX_KEY(2, 1, 104)
· · · · · · · · MATRIX_KEY(2, 2, 105)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  • Hi,

    For low power interrupt and wakeup, I recommend to use sense-edge-mask for those pins, e.g.:

    &gpio0 { // Depend on the port.

        ...

        sense-edge-mask = <0xFFFFFFFF>; // Set to "1" for those pins that are used for interrupt and wakeup.

    };

    Can you try this?

    Kenneth

  • Sure, I can try.  One point of clarification, I have no other GPIO except for gpio1 as described for the keymap.  Is it possible to overload them in this way?  At runtime I would just define it as interrupt?

  • Not sure what you mean by overload, but I can't think of reasons that this should fail no, unless the changes occur so fast that they are simply missed by the software.

    Kenneth

  • Hello Kenneth - sorry for the very long delay on this response.  

    I have added the suggested sense-edge-mask and still do not wake up the device.  The kbd_matrix is same as before.  I have gpio1 as:

    &gpio1 {
        status = "okay";
        sense-edge-mask = <0xFFFFFFFF>; // Set to "1" for those pins that are used for interrupt and wakeup.
    };




  • Apologies, somewhere between posts my prj.conf had reverted.  The above suggestion from  works.  Ensure prj.conf has:

    CONFIG_PM=y
    CONFIG_PM_DEVICE=y