Skip to content
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

kscan-composite not waking up device from deep sleep. #2654

Closed
svek1 opened this issue Nov 17, 2024 · 9 comments
Closed

kscan-composite not waking up device from deep sleep. #2654

svek1 opened this issue Nov 17, 2024 · 9 comments

Comments

@svek1
Copy link
Contributor

svek1 commented Nov 17, 2024

I'm using the kscan-composite driver to merge a kscan-gpio-matrix and kscan-gpio-direct driver, due to the way some keys are wired on my board.
Both drivers have the wakeup-source property configured in my device tree overlay.
When the board goes to sleep, pressing one of the keys does not wake it up.
If I change my chosen kscan to the kscan-gpio-matrix or kscan-gpio-direct driver, wakeup works as expected.

I'm not experienced with Zephyr or ZMK, but as far as I can see the kscan-composite.c driver just handles the kscan events from its children and turns them on / off if requested. Maybe the issue is that wakeup events from the children drivers don't get passed along? Or the children get disabled even though they shouldn't be, when the board goes into deep sleep?

Maybe someone can point me in the right direction.

@svek1
Copy link
Contributor Author

svek1 commented Nov 25, 2024

Related PR #2682

@agrippa
Copy link

agrippa commented Dec 1, 2024

i ran into this feature gap this week as well, but applying the linked diff didn't seem to fix it. i've confirmed deep sleep wakeup works for my keyboard when i just have a kscan-matrix-gpio, but when i use a composite to combine two matrix-gpio kscans then it does not wake from deep sleep (with or without the linked patch).

@svek1
Copy link
Contributor Author

svek1 commented Dec 1, 2024

Do you have wakeup-source; set for composite and child nodes?

@agrippa
Copy link

agrippa commented Dec 1, 2024

yep, for all 3 kscans. the linked patch is working well for you?

   kscan: kscan {
        compatible = "zmk,kscan-composite";
        wakeup-source; // for deep sleep
        rows = <17>;
        columns = <8>;
        keys {
            kscan = <&kscan_keys>;
        };
        switch {
            row-offset = <12>;
            kscan = <&kscan_switch>;
        };
    };

    // determines which GPIO pins to scan for key press events
    kscan_keys: kscan_keys {
            compatible = "zmk,kscan-gpio-matrix";
            diode-direction = "row2col";
            wakeup-source; // for deep sleep

            // 12 rows
            row-gpios
                    = <&gpio0 12 GPIO_ACTIVE_HIGH>
                    , <&gpio0 4 GPIO_ACTIVE_HIGH>
                    , <&gpio0 17 GPIO_ACTIVE_HIGH>
                    , <&gpio0 8 GPIO_ACTIVE_HIGH>
                    , <&gpio0 29 GPIO_ACTIVE_HIGH>
                    , <&gpio0 6 GPIO_ACTIVE_HIGH>
                    , <&gpio0 31 GPIO_ACTIVE_HIGH>
                    , <&gpio0 5 GPIO_ACTIVE_HIGH>
                    , <&gpio0 30 GPIO_ACTIVE_HIGH>
                    , <&gpio1 9 GPIO_ACTIVE_HIGH>
                    , <&gpio1 2 GPIO_ACTIVE_HIGH>
                    , <&gpio1 4 GPIO_ACTIVE_HIGH>
                    ;
            // 8 columns
            col-gpios
                    = <&gpio1 11 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
                    , <&gpio1 10 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
                    , <&gpio0 28 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
                    , <&gpio0  3 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
                    , <&gpio0 20 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
                    , <&gpio1  6 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
                    , <&gpio0 22 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
                    , <&gpio1  0 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
                    ;
    };

    kscan_switch: kscan_switch {
        compatible = "zmk,kscan-gpio-matrix";
        diode-direction = "col2row";
        wakeup-source; // for deep sleep
        toggle-mode;

        // 5 rows
        row-gpios
                =  <&extra_gpio 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>
                 , <&extra_gpio 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>
                 , <&extra_gpio 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>
                 , <&extra_gpio 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>
                 , <&extra_gpio 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>
                ;
        // 1 column
        col-gpios
                = <&extra_gpio 8 (GPIO_ACTIVE_LOW)>
                ;
    };

@svek1
Copy link
Contributor Author

svek1 commented Dec 1, 2024

I wrote the linked patch, it works on my keyboard™

@agrippa
Copy link

agrippa commented Dec 1, 2024

heh weird, do you have the board that it works on published anywhere? I'm curious just to see other differences.

@Nick-Munnich
Copy link
Contributor

There are two linked patches, @agrippa please make sure you're using the correct one

@svek1
Copy link
Contributor Author

svek1 commented Dec 1, 2024

heh weird, do you have the board that it works on published anywhere? I'm curious just to see other differences.
If you need more I can send you other files, but I think you might just have the "wrong" patch.

#include <physical_layouts.dtsi>

/ {
    chosen {
        zmk,kscan = &kscan0;
        zmk,battery = &vbatt;
        zmk,physical-layout = &default_layout;
    };

    default_layout: default_layout {
        compatible = "zmk,physical-layout";
        display-name = "Default";
        transform = <&transform0>;
        kscan = <&kscan0>;
        keys  //                     w   h    x    y     rot    rx    ry
            = <&key_physical_attrs 100 100    0    0       0     0     0>
            , <&key_physical_attrs 100 100  100    0       0     0     0>
            , <&key_physical_attrs 100 100  200    0       0     0     0>
            , <&key_physical_attrs 100 100  300    0       0     0     0>
            , <&key_physical_attrs 100 100    0  100       0     0     0>
            , <&key_physical_attrs 100 100  100  100       0     0     0>
            , <&key_physical_attrs 100 100  200  100       0     0     0>
            , <&key_physical_attrs 0   0    300  100       0     0     0>
            , <&key_physical_attrs 100 100    0  200       0     0     0>
            , <&key_physical_attrs 100 100  100  200       0     0     0>
            , <&key_physical_attrs 100 100  200  200       0     0     0>
            , <&key_physical_attrs 0   0    300  200       0     0     0>
            ;
    };

    transform0: keymap_transform {
        compatible = "zmk,matrix-transform";

        rows = <3>;
        columns = <4>;

        map = <RC(0,0) RC(0,1) RC(0,2)  RC(0,3)
               RC(1,0) RC(1,1) RC(1,2)  RC(1,3)
               RC(2,0) RC(2,1) RC(2,2)  RC(2,3)
        >;
    };

    kscan0: kscan0 {
        compatible = "zmk,kscan-composite";
        wakeup-source;
        rows = <3>;
        columns = <4>;

        matrix {
            kscan = <&kscan1>;
        };
    
        encoder {
            kscan = <&kscan2>;
            col-offset = <3>;
        };
    };

    kscan1: kscan1 {
        compatible = "zmk,kscan-gpio-matrix";
        wakeup-source;
        diode-direction = "col2row";

        row-gpios
            = <&gpio1 15 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
            , <&gpio1 13 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
            , <&gpio1 11 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
            ;
        col-gpios
            = <&gpio0 10 (GPIO_ACTIVE_HIGH)>
            , <&gpio0 9 (GPIO_ACTIVE_HIGH)>
            , <&gpio0 6 (GPIO_ACTIVE_HIGH)>
            ;
    };

    kscan2: kscan2 {
        compatible = "zmk,kscan-gpio-direct";
        wakeup-source;
    
        input-gpios
        = <&gpio0 31 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>
        ;
    };

    encoder0: encoder0 {
        compatible = "alps,ec11";
        a-gpios = <&gpio0 29 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>;
        b-gpios = <&gpio0 2 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>;
        steps = <80>;
        status = "okay";
    };

    sensors0: sensors {
        compatible = "zmk,keymap-sensors";
        sensors = <&encoder0>;
        triggers-per-rotation = <20>;
    };

};

@agrippa
Copy link

agrippa commented Dec 1, 2024

ah thanks @Nick-Munnich ! missed the second patch, that one seems to be working.

@svek1 svek1 closed this as completed Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants