How to detect one of the SYS_WAKE button of minimorph development board is pressed?

This topic contains 6 replies, has 2 voices, and was last updated by  abhilashtuse 4 years, 3 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #31350

    I am using SDK 1r9. I want to know how the interrupt mechanism works on SYS_WAKE buttons. How can I call a function on SYS_WAKE button press event.

    #37706

    Sean
    Moderator

    Are you writing a C program? In what environment do you want to detect it?

    Sean.

    #37707

    Yes In c program only.

    #37708

    Sean
    Moderator

    Good news, I wrote some basic code to do the same last year:


    #include
    #include
    #include
    #include

    int main(int argc, char **argv)
    {
    int fd, state;
    fd = open("/dev/input/event0", O_RDONLY);
    state = 0;
    struct input_event ev;

    while (1)
    {
    read(fd, &ev, sizeof(struct input_event));

    if(ev.type == 1) {
    printf("key %i state %in", ev.code, ev.value);
    }
    }
    }

    Bad news, I’m not in the position to test it right now … could you let me know if it’s ok with r1.9?

    I was experementing at the time so you probably don’t need all those includes, can’t remember which one gives you struct input_event.

    Sean.

    #37709

    I tried to run your program on board but it does not print anything on sys_wake button press.
    Could you explain me how interrupts on these buttons can be handled using GPIO?

    #37710

    Sean
    Moderator

    Apologies – try event 1 rather than event 0!
    fd = open("/dev/input/event1", O_RDONLY);

    This is how the GPIO events for the keys are reported in Linux.

    Pressing the 3 buttons in turn:

    # cat /dev/input/event1 | hexdump
    0000000 ab58 387b 611c 0002 0001 006d 0001 0000
    0000010 ab58 387b 616d 0002 0000 0000 0000 0000
    0000020 ab58 387b ab03 0004 0001 006d 0000 0000
    0000030 ab58 387b ab75 0004 0000 0000 0000 0000
    0000040 ab58 387b e87d 000c 0001 006e 0001 0000
    0000050 ab58 387b e8cf 000c 0000 0000 0000 0000
    0000060 ab58 387b e42f 000e 0001 006e 0000 0000
    0000070 ab58 387b e47b 000e 0000 0000 0000 0000
    0000080 ab59 387b 0682 0008 0001 0068 0001 0000
    0000090 ab59 387b 06d2 0008 0000 0000 0000 0000
    00000a0 ab59 387b 776d 000a 0001 0068 0000 0000
    00000b0 ab59 387b 77b7 000a 0000 0000 0000 0000

    Here there is an event ID, a value and a code that relates to the button that has been pressed.

    This is what is stored in the struct input_event in the code above.

    #37711

    Thanks a lot.. Its working. 🙂

    Abhilash.

Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic.