Page 1 of 1

CM3588 NAS Kit - User Button

Posted: Sat Apr 20, 2024 5:40 pm
by ppsx
Does anyone know how to access user button programatically?
According to the doc it should be connected to GPIO0 D5 but I cannot see any change in returned data from

Code: Select all

sudo gpioinfo gpio0
when the button is pressed and when it's not.

Re: CM3588 NAS Kit - User Button

Posted: Fri Apr 26, 2024 1:24 pm
by yaazzz
First you need to identify the proper pin :

Code: Select all

GPIO0_D5 => Bank 1 pin
bank=0 => 0*32
group ∈ {(A=0), (B=1), (C=2), (D=3)} => group = 8*3 = 24

pin = 0*32 + 8*3 + 0 = 24


What is the output of :
cat /sys/class/gpio/gpio24/direction

if you have this not existing, you need to create the proper pin config:

Code: Select all

echo 24 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio24/direction
cat /sys/class/gpio/gpio24/value
=>when button is pressed and not pressed.

You can use my post for the fan as it is similar mechanism except that for button it is input whereas for fan it is output pin.

Re: CM3588 NAS Kit - User Button

Posted: Sat Apr 27, 2024 6:06 pm
by ppsx
Thanks.

1. I believe you forgot to add 5 to the final result, so the pin is 29.
2. I'm using Armbian and there's no /sys/class/gpio directory (no sysfs for gpio), so the only way to access gpio is to use gpiod tool. It's miserable, I know :(

Long story short - I've found a way to read the status of the key.
First - this button is defined in device overlay as button@1 located in gpio-keys section. Its label is K1 which pointed me to the wrong direction because in the doc K1 is Power button and User button is named K5. I realized that this definition in dtb is actually for User button only because of the successful test (see below).
Second - every time I was trying to read the state of the button using gpioget, I was getting the message that the resource is busy and cannot be read. Well... I've tried a lot of different things, rebooted the server dozen of times and then... YES :)
I could read the state ONLY after unloading gpio_keys kernel module:

Code: Select all

sudo rmmod gpio_keys
while true; do sudo gpioget gpio0 29; sleep 1; done
1
1
...
1
0    <--- key pressed
0
...
0
1    <--- key released

1 - key released
0 - key pressed (and hold)

I wonder if there is any other method of getting the state without removing kernel module but rather to make use of them... From CLI at least...

Re: CM3588 NAS Kit - User Button

Posted: Sat Apr 27, 2024 7:24 pm
by ppsx
Answering myself.
Yes, there is a quite nice method.
There's an event associated with this button.
/dev/input/by-path/platform-gpio-keys-event points to an event (number 5 in my case).
This is the script (Python3):

Code: Select all

import struct
with open(f'/dev/input/by-path/platform-gpio-keys-event', "rb") as f:
  while True:
    raw_data = f.read(24)
    data = struct.unpack('4IHHI', raw_data)
    if data[4] == 1:
      if data[6] == 1:
        print("Key pressed")
      elif data[6] == 0:
        print("Key released")

Re: CM3588 NAS Kit - User Button

Posted: Wed May 08, 2024 9:36 am
by yaazzz
ppsx wrote:
Thanks.

1. I believe you forgot to add 5 to the final result, so the pin is 29.
2. I'm using Armbian and there's no /sys/class/gpio directory (no sysfs for gpio), so the only way to access gpio is to use gpiod tool. It's miserable, I know :(

Long story short - I've found a way to read the status of the key.
First - this button is defined in device overlay as button@1 located in gpio-keys section. Its label is K1 which pointed me to the wrong direction because in the doc K1 is Power button and User button is named K5. I realized that this definition in dtb is actually for User button only because of the successful test (see below).
Second - every time I was trying to read the state of the button using gpioget, I was getting the message that the resource is busy and cannot be read. Well... I've tried a lot of different things, rebooted the server dozen of times and then... YES :)
I could read the state ONLY after unloading gpio_keys kernel module:

Code: Select all

sudo rmmod gpio_keys
while true; do sudo gpioget gpio0 29; sleep 1; done
1
1
...
1
0    <--- key pressed
0
...
0
1    <--- key released

1 - key released
0 - key pressed (and hold)

I wonder if there is any other method of getting the state without removing kernel module but rather to make use of them... From CLI at least...

Correct, sorry for the mistake : I ansered too fast ;)

Re: CM3588 NAS Kit - User Button

Posted: Thu Jun 13, 2024 1:40 pm
by ppsx
FYI: Armbian 24.5.1 re-enabled GPIOFS, so the possiblitiy of using well known method of playing with gpio pins (/sys/class/gpio/) is back and there's no reason to use miserable gpiod toolset :)

Re: CM3588 NAS Kit - User Button

Posted: Tue Jan 07, 2025 7:21 pm
by EABASE
ppsx wrote:
FYI: Armbian 24.5.1 re-enabled GPIOFS, so the possiblitiy of using well known method of playing with gpio pins (/sys/class/gpio/) is back and there's no reason to use miserable gpiod toolset :)


How do you check?