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

[Feature Request] The ability to use hidraw instead of i2c #224

Open
Stivux opened this issue Dec 2, 2024 · 27 comments
Open

[Feature Request] The ability to use hidraw instead of i2c #224

Stivux opened this issue Dec 2, 2024 · 27 comments
Assignees
Labels
enhancement New feature or request

Comments

@Stivux
Copy link

Stivux commented Dec 2, 2024

Short Description

I am using ASUS Zenbook UM3402YA (up5401ea layout) I noticed that brightness setting via i2c change report 13 feature of /dev/hidraw0

You can use https://github.com/hidutils/hid-feature to check your own.

It looks like:
13 │ Vendor Defined Page FF00 / Vendor Usage 0xc4 │ 8 │ 8..=15 │ 0..=255 │ 1 │ 112 │ 70
13 │ Vendor Defined Page FF00 / Vendor Usage 0xc4 │ 8 │ 16..=23 │ 0..=255 │ 1 │ 3 │ 03
13 │ Vendor Defined Page FF00 / Vendor Usage 0xc4 │ 8 │ 24..=31 │ 0..=255 │ 1 │ 0 │ 00
13 │ Vendor Defined Page FF00 / Vendor Usage 0xc4 │ 8 │ 32..=39 │ 0..=255 │ 1 │ 81 │ 51

When I turn numpad on, 0 goes into 1
When I change brightness level 81 is changing to other number (81 is 0x41 + 16)

Advantages of such a change are independence from i2c-dev and ability to recognize the latest brightness after reboot.

New dependencies

No response

Additional Info

No response

@Stivux Stivux added the enhancement New feature or request label Dec 2, 2024
@ldrahnik
Copy link
Member

ldrahnik commented Dec 2, 2024

@Stivux What I do wrong I see no change for device with id 1 when I activate/deactivate NumberPad. Laptop UP5401EA:

drahnik@Zenbook-UP5401EA:~/projects/hid-feature$ sudo apt install -y cargo && cargo build

drahnik@Zenbook-UP5401EA:~/projects/hid-feature/target/debug$ ./hid-feature list-devices
Available HID devices:
hidraw0       - ELAN9009:00 04F3:2E36
hidraw1       - ASUE140D:00 04F3:31B9
hidraw2       - hid-ishtp 8087:0AC2

drahnik@Zenbook-UP5401EA:~/projects/hid-feature/target/debug$ sudo ./hid-feature list /dev/hidraw1
Report ┃                      Usage                       ┃ Bits ┃ Bit Range ┃ Value Range ┃ Count ┃ Value ┃ Bytes
...
...
  13   │ Vendor Defined Page FF00 / Vendor Usage 0xc4     │  8   │   8..=15  │    0..=255  │   1   │     0 │ 00
  13   │ Vendor Defined Page FF00 / Vendor Usage 0xc4     │  8   │  16..=23  │    0..=255  │   1   │     0 │ 00
  13   │ Vendor Defined Page FF00 / Vendor Usage 0xc4     │  8   │  24..=31  │    0..=255  │   1   │   233 │ e9
  13   │ Vendor Defined Page FF00 / Vendor Usage 0xc4     │  8   │  32..=39  │    0..=255  │   1   │   233 │ e9
Error: unexpected end of file

@ldrahnik
Copy link
Member

ldrahnik commented Dec 3, 2024

@Stivux For laptop UX3405 I do not see these rows at all:

drahnikl@Zenbook-UX3405MA:~/projects/hid-feature/target/debug$ sudo ./hid-feature list /dev/hidraw1
Report ┃                      Usage                       ┃ Bits ┃ Bit Range ┃ Value Range ┃ Count ┃ Value ┃ Bytes
━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━
  2    │ Digitizers / Contact Count Maximum               │  8   │   8..=15  │    0..=5    │   1   │     5 │ 05
  6    │ Digitizers / Pad Type                            │  8   │   8..=15  │    0..=15   │   1   │     0 │ 00
Error: unexpected end of file
drahnikl@Zenbook-UX3405MA:~/projects/hid-feature/target/debug$ sudo ./hid-feature list-devices
Available HID devices:
hidraw0       - ELAN9008:00 04F3:4213
hidraw1       - ASUP1415:00 093A:300C
hidraw2       - hid-ishtp 8087:0AC2
hidraw3       - E-Signal/A-One USB Gaming Mouse
hidraw4       - E-Signal/A-One USB Gaming Mouse
drahnikl@Zenbook-UX3405MA:~/projects/hid-feature/target/debug$ sudo ./hid-feature list /dev/hidraw1
Report ┃                      Usage                       ┃ Bits ┃ Bit Range ┃ Value Range ┃ Count ┃ Value ┃ Bytes
━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━
  2    │ Digitizers / Contact Count Maximum               │  8   │   8..=15  │    0..=5    │   1   │     5 │ 05
  6    │ Digitizers / Pad Type                            │  8   │   8..=15  │    0..=15   │   1   │     0 │ 00
Error: unexpected end of file
drahnikl@Zenbook-UX3405MA:~/projects/hid-feature/target/debug$ 

@Stivux
Copy link
Author

Stivux commented Dec 3, 2024

@ldrahnik what kernel version are you using? I tested it on Fedora with 6.11.4. On new kernel asus-hid is cool improved. Looks like it doesnt work on older kernel.

I found other util to dump hid values: https://pypi.org/project/hid-tools
You can try it.

How it looks to me:

Before numberpad led enabling:

sudo hid-feature list /dev/hidraw0 --fetch-values | grep d000  
d0000 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 112  
d0001 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 3  
d0002 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 0  
d0003 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 80

After numberpad led enabling:

sudo hid-feature list /dev/hidraw0 --fetch-values | grep d000  
d0000 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 112  
d0001 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 3  
d0002 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 1  
d0003 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 80

After setting 0x41 brightness (via i2ctransfer for example):

sudo hid-feature list /dev/hidraw0 --fetch-values | grep d000  
d0000 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 112  
d0001 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 3  
d0002 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 1  
d0003 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 81

After setting 0x48 brightness:

sudo hid-feature list /dev/hidraw0 --fetch-values | grep d000  
d0000 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 112  
d0001 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 3  
d0002 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 1  
d0003 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 88

@ldrahnik
Copy link
Member

ldrahnik commented Dec 3, 2024

@Stivux I use EOS 7.1:

ldrahnik@Zenbook-UP5401EA:~$ uname -r
6.8.0-48-generic

and EOS 8:

ldrahnik@Zenbook-UX3405MA:~$ uname -r
6.8.0-49-generic

@ldrahnik
Copy link
Member

ldrahnik commented Dec 3, 2024

@Stivux What a python3 version do you use for pypi.org/project/hid-tools? I received these errors:

ldrahnik@Zenbook-UP5401EA:~/projects/hid-tools$ sudo pip3 install .
Processing /home/ldrahnik/projects/hid-tools
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [14 lines of output]
      Traceback (most recent call last):
        File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
          main()
        File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 164, in prepare_metadata_for_build_wheel
          return hook(metadata_directory, config_settings)
        File "/tmp/pip-build-env-z4ji7nmq/overlay/local/lib/python3.10/dist-packages/hatchling/build.py", line 117, in prepare_metadata_for_build_wheel
          f.write(builder.config.core_metadata_constructor(builder.metadata))
        File "/tmp/pip-build-env-z4ji7nmq/overlay/local/lib/python3.10/dist-packages/hatchling/metadata/spec.py", line 460, in construct_metadata_file_2_3
          if metadata.core.license:
        File "/tmp/pip-build-env-z4ji7nmq/overlay/local/lib/python3.10/dist-packages/hatchling/metadata/core.py", line 677, in license
          from packaging.licenses import canonicalize_license_expression
      ModuleNotFoundError: No module named 'packaging.licenses'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

and

ldrahnik@Zenbook-UP5401EA:~/projects/hid-tools$ sudo ./hid-feature
Traceback (most recent call last):
  File "/home/ldrahnik/projects/hid-tools/./hid-feature", line 21, in <module>
    import hidtools.cli.feature
  File "/home/ldrahnik/projects/hid-tools/hidtools/cli/feature.py", line 24, in <module>
    from hidtools.hidraw import HidrawDevice
  File "/home/ldrahnik/projects/hid-tools/hidtools/hidraw.py", line 27, in <module>
    from hidtools.hid import ReportDescriptor
  File "/home/ldrahnik/projects/hid-tools/hidtools/hid.py", line 26, in <module>
    from hidtools.hut import HUT, U8, U16, U32
  File "/home/ldrahnik/projects/hid-tools/hidtools/hut.py", line 23, in <module>
    import parse
ModuleNotFoundError: No module named 'parse'
ldrahnik@Zenbook-UP5401EA:~/projects/hid-tools$ python3 --version
Python 3.10.12

I will try your version via virtualenv.

@Stivux
Copy link
Author

Stivux commented Dec 3, 2024

@ldrahnik Since I'm on Fedora 41, Python 3.13
Why don't you do sudo pip3 install hid-tools?

@Stivux
Copy link
Author

Stivux commented Dec 3, 2024

I tested it on Elementary OS 8.0. It works too.
screenshot

Maybe in your case led properties are in other registers?
Try this:

hid-feature list /your/hidraw/path --fetch-values > hid_old

Don't touch touchpad! Probably hid contains also x, y tap position. Change brightness/led status via i2ctransfer for example.
Then

hid-feature list /your/hidraw/path --fetch-values > hid_new

and

diff hid_old hid_new

@ldrahnik
Copy link
Member

ldrahnik commented Dec 4, 2024

@Stivux How you installed hid-feature? I will try tommorow and let you know.

@Stivux
Copy link
Author

Stivux commented Dec 4, 2024

@ldrahnik hid-feature is part of hid-tools
I install it on ElementaryOS via virtualenv.
In virtualenv:

pip install hid-tools

Then activate virtualenv as root.

One more observation: if I disable the i2c-dev module I can't see changing of led feature values. They will be constant. But I can enable and disable led setting all d000* features one time.
Like:

hid-feature set /dev/hidraw0 -f d0000 112 -f d0000 3 -f d0000 1 -f d0000 83 # led on, brightness 0x43. 

In this case I can change values (enable/disable led, set brightness), but can't see new value of d0003 for example. Looks like i2c-dev is used to communicate with hidraw devices.

It is still useful. You can opt out of using smbus2 package
To be honest now you also can use python built-in fcntl.ioctl instead smbus2

@ldrahnik
Copy link
Member

ldrahnik commented Dec 4, 2024

@Stivux Looks like the same values are displayed to me 0, 0, 233 and 233. Steps:

ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature$ pyenv install 3.9.19
ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature$ pyenv global 3.9.19
ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature$ python3 --version
Python 3.9.19       
(.penv) ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature$ pip install hid-tools
Collecting hid-tools
  Downloading hid_tools-0.8-py3-none-any.whl (106 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 106.5/106.5 KB 279.3 kB/s eta 0:00:00
Collecting pyyaml
  Downloading PyYAML-6.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (751 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 751.2/751.2 KB 133.6 kB/s eta 0:00:00
Collecting pyroute2
  Downloading pyroute2-0.7.12-py3-none-any.whl (460 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 460.5/460.5 KB 252.9 kB/s eta 0:00:00
Collecting typing-extensions
  Using cached typing_extensions-4.12.2-py3-none-any.whl (37 kB)
Collecting click
  Using cached click-8.1.7-py3-none-any.whl (97 kB)
Collecting libevdev
  Using cached libevdev-0.11-py3-none-any.whl
Collecting parse
  Using cached parse-1.20.2-py2.py3-none-any.whl (20 kB)
Installing collected packages: pyroute2, parse, typing-extensions, pyyaml, libevdev, click, hid-tools
Successfully installed click-8.1.7 hid-tools-0.8 libevdev-0.11 parse-1.20.2 pyroute2-0.7.12 pyyaml-6.0.2 typing-extensions-4.12.2
ldrahnik@Zenbook-UP5401EA:~$ sudo chown ldrahnik:ldrahnik /dev/hidraw*
[sudo] password for ldrahnik:  
ldrahnik@Zenbook-UP5401EA:~$ ls -la /dev/hidraw*
crw------- 1 ldrahnik ldrahnik 241, 0 Dec  4 16:28 /dev/hidraw0
crw------- 1 ldrahnik ldrahnik 241, 1 Dec  4 16:28 /dev/hidraw1
crw------- 1 ldrahnik ldrahnik 241, 2 Dec  4 16:28 /dev/hidraw2
(.penv) ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature$ hid-feature list-devices
Available devices:
/dev/hidraw0: ELAN9009:00 04F3:2E36
/dev/hidraw1: ASUE140D:00 04F3:31B9
/dev/hidraw2: hid-ishtp 8087:0AC2
(.penv) ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature$ hid-feature list /dev/hidraw1 --fetch-values | grep d000 
  d0000 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 0
  d0001 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 0
  d0002 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 233
  d0003 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 233

@ldrahnik
Copy link
Member

ldrahnik commented Dec 4, 2024

(.penv) ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature$ hid-feature list /dev/hidraw2 --fetch-values > values2
(.penv) ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature$ hid-feature list /dev/hidraw1 --fetch-values > values1
(.penv) ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature$ hid-feature list /dev/hidraw0 --fetch-values > values0
(.penv) ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature$ hid-feature list /dev/hidraw0 --fetch-values > values0_new
(.penv) ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature$ hid-feature list /dev/hidraw1 --fetch-values > values1_new
(.penv) ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature$ hid-feature list /dev/hidraw2 --fetch-values > values2_new
(.penv) ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature$ diff values2 values2_new 
(.penv) ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature$ diff values1 values1_new 
(.penv) ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature$ diff values0 values0_new 
(.penv) ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature$ 

@ldrahnik
Copy link
Member

ldrahnik commented Dec 4, 2024

@Stivux What is your output?

ldrahnik@Zenbook-UP5401EA:~$ cat /sys/class/hidraw/hidraw1/device/uevent 
DRIVER=hid-multitouch
HID_ID=0018:000004F3:000031B9
HID_NAME=ASUE140D:00 04F3:31B9
HID_PHYS=i2c-ASUE140D:00
HID_UNIQ=
MODALIAS=hid:b0018g0004v000004F3p000031B9
```

@ldrahnik
Copy link
Member

ldrahnik commented Dec 4, 2024

@Stivux What do you see in journal journalctl | grep hid?

@Stivux
Copy link
Author

Stivux commented Dec 5, 2024

@ldrahnik
journalctl | grep hid

Dec 05 16:14:34 elementary kernel: AMD-Vi: ivrs, add hid:AMDI0020, uid:\_SB.FUR0, rdevid:160
Dec 05 16:14:34 elementary kernel: AMD-Vi: ivrs, add hid:AMDI0020, uid:\_SB.FUR1, rdevid:160
Dec 05 16:14:34 elementary kernel: AMD-Vi: ivrs, add hid:AMDI0020, uid:\_SB.FUR2, rdevid:160
Dec 05 16:14:34 elementary kernel: AMD-Vi: ivrs, add hid:AMDI0020, uid:\_SB.FUR3, rdevid:160
Dec 05 16:14:34 elementary kernel: hid: raw HID events driver (C) Jiri Kosina
Dec 05 16:14:34 elementary kernel: hid-generic 0018:04F3:31B9.0001: input,hidraw0: I2C HID v1.00 Mouse [ASUE140D:00 04F3:31B9] on i2c-ASUE140D:00
Dec 05 16:14:34 elementary kernel: hid-multitouch 0018:04F3:31B9.0001: input,hidraw0: I2C HID v1.00 Mouse [ASUE140D:00 04F3:31B9] on i2c-ASUE140D:00
Dec 05 16:15:42 elementary io.elementary.w[3728]: GFileInfo created without standard::is-hidden
Dec 05 16:15:42 elementary io.elementary.w[3728]: file ../../../gio/gfileinfo.c: line 1632 (g_file_info_get_is_hidden): should not be reached
Dec 05 16:15:42 elementary io.elementary.w[3728]: GFileInfo created without standard::is-hidden
Dec 05 16:15:42 elementary io.elementary.w[3728]: file ../../../gio/gfileinfo.c: line 1632 (g_file_info_get_is_hidden): should not be reached
Dec 05 16:16:47 elementary io.elementary.w[3728]: GFileInfo created without standard::is-hidden
Dec 05 16:16:47 elementary io.elementary.w[3728]: file ../../../gio/gfileinfo.c: line 1632 (g_file_info_get_is_hidden): should not be reached
Dec 05 16:16:47 elementary io.elementary.w[3728]: GFileInfo created without standard::is-hidden
Dec 05 16:16:47 elementary io.elementary.w[3728]: file ../../../gio/gfileinfo.c: line 1632 (g_file_info_get_is_hidden): should not be reached
Dec 05 16:16:47 elementary io.elementary.w[3728]: GFileInfo created without standard::is-hidden
Dec 05 16:16:47 elementary io.elementary.w[3728]: file ../../../gio/gfileinfo.c: line 1632 (g_file_info_get_is_hidden): should not be reached
Dec 05 16:16:47 elementary io.elementary.w[3728]: GFileInfo created without standard::is-hidden
Dec 05 16:16:47 elementary io.elementary.w[3728]: file ../../../gio/gfileinfo.c: line 1632 (g_file_info_get_is_hidden): should not be reached
Dec 05 16:16:49 elementary io.elementary.w[3728]: GFileInfo created without standard::is-hidden
Dec 05 16:16:49 elementary io.elementary.w[3728]: file ../../../gio/gfileinfo.c: line 1632 (g_file_info_get_is_hidden): should not be reached
Dec 05 16:16:49 elementary io.elementary.w[3728]: GFileInfo created without standard::is-hidden
Dec 05 16:16:49 elementary io.elementary.w[3728]: file ../../../gio/gfileinfo.c: line 1632 (g_file_info_get_is_hidden): should not be reached
Dec 05 16:16:49 elementary io.elementary.w[3728]: GFileInfo created without standard::is-hidden
Dec 05 16:16:49 elementary io.elementary.w[3728]: file ../../../gio/gfileinfo.c: line 1632 (g_file_info_get_is_hidden): should not be reached
Dec 05 16:16:49 elementary io.elementary.w[3728]: GFileInfo created without standard::is-hidden
Dec 05 16:16:49 elementary io.elementary.w[3728]: file ../../../gio/gfileinfo.c: line 1632 (g_file_info_get_is_hidden): should not be reached

Also

elementary@elementary:~$ cat /sys/class/hidraw/hidraw0/device/uevent 
DRIVER=hid-multitouch
HID_ID=0018:000004F3:000031B9
HID_NAME=ASUE140D:00 04F3:31B9
HID_PHYS=i2c-ASUE140D:00
HID_UNIQ=
MODALIAS=hid:b0018g0004v000004F3p000031B9
elementary@elementary:~$ 

I tested it on EOS 8.0 Live ISO

Do you have the i2c-dev module enabled?

@ldrahnik
Copy link
Member

ldrahnik commented Dec 5, 2024

@Stivux Yes, I use it for example for NumberPad

@Stivux
Copy link
Author

Stivux commented Dec 6, 2024

@Stivux Yes, I use it for example for NumberPad

I don't have any more ideas why it doesn't work for you. Looks like this issue can be closed.

@ldrahnik
Copy link
Member

ldrahnik commented Dec 6, 2024

@Stivux I am now flashing USB disk and will try live iso OS8 also. On laptop UP5401EA with installed 7.1. I will let you know.

@ldrahnik
Copy link
Member

ldrahnik commented Dec 6, 2024

@Stivux Unfortuntelly the same. Not replicated change of these values 0, 0, 233, 233. I am skipping some important step maybe but rather I think you have different .dsdt table because another laptop model or something like that. You can post here .dsdt if you want and we can compare touchpad block.

@ldrahnik ldrahnik closed this as completed Dec 6, 2024
@ldrahnik
Copy link
Member

ldrahnik commented Dec 6, 2024

IMG_20241206_215347

@ldrahnik
Copy link
Member

ldrahnik commented Dec 6, 2024

$ sudo apt-get install iasl
$ cd <work-dir>
$ sudo cp /sys/firmware/acpi/tables/DSDT DSDT
$ sudo iasl -d DSDT
$ sudo gedit DSDT.dsl

@Stivux
Copy link
Author

Stivux commented Dec 6, 2024

@ldrahnik
Can you try do as experiment this:
hid-feature set /dev/hidraw1 -f d0000 112 -f d0001 3 -f d0002 1 -f d0003 83
dsdt.txt

@ldrahnik
Copy link
Member

ldrahnik commented Dec 7, 2024

@Stivux

ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature/target/debug$ ./hid-feature --version
hid-feature 0.1.0
ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature/target/debug$ ./hid-feature set /dev/hidraw1 -f d0000 112 -f d0001 3 -f d0002 1 -f d0003 83
error: unexpected argument '-f' found

  tip: to pass '-f' as a value, use '-- -f'

Usage: hid-feature set [OPTIONS] <PATH> [BYTES]...

For more information, try '--help'.
ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature/target/debug$ 

EDIT: with different I2C registers I was wrong, I deleted these messages and others I did not compare.

So is the same:

                  I2cSerialBusV2 (0x0015, ControllerInitiated, 0x00061A80,
                        AddressingMode7Bit, "\\_SB.I2CA",
                        0x00, ResourceConsumer, , Exclusive,
                        )

Your block:

Scope (_SB.I2CA)
    {
        Device (TPDD)
        {
            Name (_CID, "PNP0C50" /* HID Protocol Device (I2C bus) */)  // _CID: Compatible ID
            Name (_UID, 0x05)  // _UID: Unique ID
            Name (ETPH, Package (0x16)
            {
                "ASUE120C", 
                "ASUE140D", 
                "ELAN1203", 
                "ELAN1300", 
                "ELAN1301", 
                "ELAN1400", 
                "ELAN140C"
            })
            Method (_HID, 0, NotSerialized)  // _HID: Hardware ID
            {
                If ((TPDT == One))
                {
                    Return (DerefOf (ETPH [Zero]))
                }

                If ((TPDT == 0x02))
                {
                    Return (DerefOf (ETPH [One]))
                }

                Return (0x500CD041)
            }

            Method (_CRS, 0, NotSerialized)  // _CRS: Current Resource Settings
            {
                Name (RBUF, ResourceTemplate ()
                {
                    I2cSerialBusV2 (0x0015, ControllerInitiated, 0x00061A80,
                        AddressingMode7Bit, "\\_SB.I2CA",
                        0x00, ResourceConsumer, , Exclusive,
                        )
                    GpioInt (Level, ActiveLow, ExclusiveAndWake, PullNone, 0x0000,
                        "\\_SB.GPIO", 0x00, ResourceConsumer, ,
                        )
                        {   // Pin list
                            0x0009
                        }
                })
                Return (RBUF) /* \_SB_.I2CA.TPDD._CRS.RBUF */
            }

            Method (_STA, 0, NotSerialized)  // _STA: Status
            {
                If (((TPOS >= 0x60) & (THPD == Zero)))
                {
                    If (((TPDT == One) | (TPDT == 0x02)))
                    {
                        Return (0x0F)
                    }
                    Else
                    {
                        Return (Zero)
                    }
                }
                Else
                {
                    Return (Zero)
                }
            }

            Method (_DSW, 3, NotSerialized)  // _DSW: Device Sleep Wake
            {
                If (Arg0){}
                Else
                {
                }
            }

            Method (_PS0, 0, NotSerialized)  // _PS0: Power State 0
            {
            }

            Method (_PS3, 0, NotSerialized)  // _PS3: Power State 3
            {
            }

            Method (_DSM, 4, Serialized)  // _DSM: Device-Specific Method
            {
                If ((Arg0 == ToUUID ("3cdff6f7-4267-4555-ad05-b30a3d8938de") /* HID I2C Device */))
                {
                    Switch (ToInteger (Arg2))
                    {
                        Case (Zero)
                        {
                            Switch (ToInteger (Arg1))
                            {
                                Case (One)
                                {
                                    Return (Buffer (One)
                                    {
                                         0x03                                             // .
                                    })
                                }
                                Default
                                {
                                    Return (Buffer (One)
                                    {
                                         0x00                                             // .
                                    })
                                }

                            }
                        }
                        Case (One)
                        {
                            Return (One)
                        }
                        Default
                        {
                            Return (Zero)
                        }

                    }
                }
                Else
                {
                    Return (Buffer (One)
                    {
                         0x00                                             // .
                    })
                }
            }
        }

        Device (ELTP)
        {
            Name (_HID, EisaId ("PNP0C50") /* HID Protocol Device (I2C bus) */)  // _HID: Hardware ID
            Name (_CID, "PNP0C50" /* HID Protocol Device (I2C bus) */)  // _CID: Compatible ID
            Name (_UID, 0x05)  // _UID: Unique ID
            Method (_CRS, 0, NotSerialized)  // _CRS: Current Resource Settings
            {
                Name (RBUF, ResourceTemplate ()
                {
                    I2cSerialBusV2 (0x0015, ControllerInitiated, 0x00061A80,
                        AddressingMode7Bit, "\\_SB.I2CA",
                        0x00, ResourceConsumer, , Exclusive,
                        )
                    GpioInt (Level, ActiveLow, ExclusiveAndWake, PullUp, 0x0000,
                        "\\_SB.GPIO", 0x00, ResourceConsumer, ,
                        )
                        {   // Pin list
                            0x0009
                        }
                })
                Return (RBUF) /* \_SB_.I2CA.ELTP._CRS.RBUF */
            }

            Method (_STA, 0, NotSerialized)  // _STA: Status
            {
                If (((TPOS >= 0x60) & (THPD == 0x20)))
                {
                    Return (0x0F)
                }
                Else
                {
                    Return (Zero)
                }
            }

            Method (_DSW, 3, NotSerialized)  // _DSW: Device Sleep Wake
            {
                If (Arg0){}
                Else
                {
                }
            }

            Method (_PS0, 0, NotSerialized)  // _PS0: Power State 0
            {
            }

            Method (_PS3, 0, NotSerialized)  // _PS3: Power State 3
            {
            }

            Method (_DSM, 4, Serialized)  // _DSM: Device-Specific Method
            {
                If ((Arg0 == ToUUID ("3cdff6f7-4267-4555-ad05-b30a3d8938de") /* HID I2C Device */))
                {
                    Switch (ToInteger (Arg2))
                    {
                        Case (Zero)
                        {
                            Switch (ToInteger (Arg1))
                            {
                                Case (One)
                                {
                                    Return (Buffer (One)
                                    {
                                         0x03                                             // .
                                    })
                                }
                                Default
                                {
                                    Return (Buffer (One)
                                    {
                                         0x00                                             // .
                                    })
                                }

                            }
                        }
                        Case (One)
                        {
                            Return (One)
                        }
                        Default
                        {
                            Return (Zero)
                        }

                    }
                }
                Else
                {
                    Return (Buffer (One)
                    {
                         0x00                                             // .
                    })
                }
            }
        }
    }

Mine block:

    Scope (_SB.PC00.I2C1)
    {
        Device (ETPD)
        {
            Name (_ADR, One)  // _ADR: Address
            Name (ETPH, Package (0x23)
            {
                "ELAN1200", 
                "ELAN1201", 
                "ELAN1203", 
                "ELAN1200", 
                "ELAN1201", 
                "ELAN1300", 
                "ELAN1301", 
                "ELAN1300", 
                "ELAN1301", 
                "ELAN1000", 
                "ELAN1200", 
                "ELAN1200", 
                "ELAN1200", 
                "ELAN1200", 
                "ELAN1200", 
                "ELAN1203", 
                "ELAN1203", 
                "ELAN1201", 
                "ELAN1300", 
                "ELAN1300", 
                "ELAN1200", 
                "ELAN1300", 
                "ELAN1201", 
                "ELAN1200", 
                "ELAN1201", 
                "ELAN1200", 
                "ELAN1401", 
                "ELAN1200", 
                "ELAN1401", 
                "ELAN1401", 
                "ELAN1401", 
                "ELAN1206", 
                "ASUE1407", 
                "ASUE140A", 
                "ASUE140D"
            })
            Name (FTPH, Package (0x0C)
            {
                "FTE1001", 
                "FTE1200", 
                "FTE1200", 
                "FTE1300", 
                "FTE1300", 
                "FTE1201", 
                "FTE1200", 
                "FTE1200", 
                "FTE1201", 
                "FTE1201", 
                "FTE1200", 
                "FTE1200"
            })
            Name (GTPH, Package (0x05)
            {
                "GDX1505", 
                "GDX1300", 
                "GDX1200", 
                "GDX1301", 
                "GDX1515"
            })
            Method (_HID, 0, NotSerialized)  // _HID: Hardware ID
            {
                If ((TPDI & 0x04))
                {
                    Return (DerefOf (ETPH [TPHI]))
                }

                If ((TPDI & 0x10))
                {
                    Return (DerefOf (FTPH [TPHI]))
                }

                If ((TPDI & 0x40))
                {
                    Return (DerefOf (GTPH [TPHI]))
                }

                Return ("ELAN1010")
            }

            Name (_CID, "PNP0C50" /* HID Protocol Device (I2C bus) */)  // _CID: Compatible ID
            Name (_UID, One)  // _UID: Unique ID
            Name (_S0W, 0x03)  // _S0W: S0 Device Wake State
            Method (_DSM, 4, NotSerialized)  // _DSM: Device-Specific Method
            {
                If ((Arg0 == ToUUID ("3cdff6f7-4267-4555-ad05-b30a3d8938de") /* HID I2C Device */))
                {
                    If ((Arg2 == Zero))
                    {
                        If ((Arg1 == One))
                        {
                            Return (Buffer (One)
                            {
                                 0x03                                             // .
                            })
                        }
                        Else
                        {
                            Return (Buffer (One)
                            {
                                 0x00                                             // .
                            })
                        }
                    }

                    If ((Arg2 == One))
                    {
                        Return (One)
                    }
                }
                Else
                {
                    Return (Buffer (One)
                    {
                         0x00                                             // .
                    })
                }
            }

            Method (_STA, 0, NotSerialized)  // _STA: Status
            {
                If (((TPIF != One) || (DSYN && One)))
                {
                    Return (Zero)
                }

                Return (0x0F)
            }

            Method (_CRS, 0, Serialized)  // _CRS: Current Resource Settings
            {
                Name (SBFI, ResourceTemplate ()
                {
                    I2cSerialBusV2 (0x0015, ControllerInitiated, 0x00061A80,
                        AddressingMode7Bit, "\\_SB.PC00.I2C1",
                        0x00, ResourceConsumer, , Exclusive,
                        )
                    Interrupt (ResourceConsumer, Level, ActiveLow, Exclusive, ,, )
                    {
                        0x00000039,
                    }
                })
                Return (SBFI) /* \_SB_.PC00.I2C1.ETPD._CRS.SBFI */
            }
        }
    }

@Stivux
Copy link
Author

Stivux commented Dec 7, 2024

ldrahnik@Zenbook-UP5401EA:/projects/hid-feature/target/debug$ ./hid-feature --version
hid-feature 0.1.0
ldrahnik@Zenbook-UP5401EA:
/projects/hid-feature/target/debug$ ./hid-feature set /dev/hidraw1 -f d0000 112 -f d0001 3 -f d0002 1 -f d0003 83
error: unexpected argument '-f' found

tip: to pass '-f' as a value, use '-- -f'

Usage: hid-feature set [OPTIONS] [BYTES]...

For more information, try '--help'.
ldrahnik@Zenbook-UP5401EA:~/projects/hid-feature/target/debug$

Sorry. I forgot to mention, that here hid-feature from https://pypi.org/project/hid-tools

How can we understand from dsdt what i2c register need we use?

@ldrahnik
Copy link
Member

ldrahnik commented Dec 8, 2024

@Stivux Your command enabled the backlight of my NumberPad, so thank you for creating this feature issue! So the question is now how it works and could it be replacement of implemented i2c because some benefit gains. Could you summarize what you know in one post again, please?

@ldrahnik ldrahnik reopened this Dec 8, 2024
@ldrahnik
Copy link
Member

ldrahnik commented Dec 8, 2024

@Stivux Hm, read values after setting up I can not:

$ hid-feature list /dev/hidraw1 --fetch-values | grep d000
  d0000 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 0
  d0001 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 0
  d0002 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 233
  d0003 |     13 | Vendor Defined Page 1     | 0xff0000c4                                 | [ 0, 255] |     1 |   8  | 233

But this command works:

$ hid-feature set /dev/hidraw1 -f d0000 112 -f d0001 3 -f d0002 1 -f d0003 [81-87]

@ldrahnik
Copy link
Member

ldrahnik commented Dec 8, 2024

@Stivux

How can we understand from dsdt what i2c register need we use?

Sorry for the mystification. From DSDT we only know the address where we need to send something via i2c. In the numberpad.py is the code below that contains variable device_addr with value 0x0015 or 0x38 depends on the touchpad device:

             I2cSerialBusV2 (**0x0015**, ControllerInitiated, 0x00061A80,
                        AddressingMode7Bit, "\\_SB.I2CA",
                        0x00, ResourceConsumer, , Exclusive,
                        )

numberpad.py:

...
...
                # https://github.com/asus-linux-drivers/asus-numberpad-driver/issues/161
                if ("ASUF1416" in line or "ASUF1205" in line or "ASUF1204" in line):
                  device_addr = 0x38
                else:
                  device_addr = 0x15
...
...
    try:
        with SMBus(int(device_id)) as bus:
            data = [0x05, 0x00, 0x3d, 0x03, 0x06, 0x00, 0x07, 0x00, 0x0d, 0x14, 0x03, int(value, 16), 0xad]
            msg = i2c_msg.write(device_addr, data)
            bus.i2c_rdwr(msg)
    except Exception as e:
        log.error('Error during sending via i2c: \"%s\"', e)
...

Values send to this address are sniffed on the windows via i2c sniffer tool (someone posted these values on the ubuntu issue page created for Numberpad, it was not sniffed by me)

link to ubuntu issue https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1810183?comments=all
link to comment attachment of sniffed i2c communication https://launchpadlibrarian.net/527767773/ProbeLog.txt
rows:

00::03/13/2021-22:23:06.173 [SimplePeripheralBusProbe]Marking SPB request 00003BF8EEF082E8 for reuse, and completing client request 00003BF8EE838318 with STATUS_SUCCESS and bytes=13
[0]0000.0000::03/13/2021-22:23:06.173 [SimplePeripheralBusProbe]device   5: ##00 write   13 -  0000: **05 00 3d 03 06 00 07 00 0d 14 03 01 ad**
[0]0000.0000::03/13/2021-22:23:06.173 [SimplePeripheralBusProbe] [SpbPeripheralCompleteRequestPair] <--
[0]0000.0000::03/13/2021-22:23:06.173 [SimplePeripheralBusProbe] [SpbPeripheralOnCompletion] <--
[3]0004.00F8::03/13/2021-22:23:06.179 [SimplePeripheralBusProbe] [OnRead] --> entry

@Stivux
Copy link
Author

Stivux commented Dec 8, 2024

@ldrahnik

  1. You can communicate with numpad led via /dev/hidraw* file. You need to know which file matches your touchpad.
    Looks like it can be found out from the /proc/bus/input/devices
    For example Sysfs for my touchpad is:
    /devices/platform/AMDI0010:00/i2c-0/i2c-ASUE140D:00/0018:04F3:31B9.0001/input/input8
    At /sys/devices/platform/AMDI0010:00/i2c-0/i2c-ASUE140D:00/0018:04F3:31B9.0001/input/input8/device/hidraw/ I found hidraw0 directory, so /dev/hidraw0 matches touchpad.
  2. You need to know what hid feature report is used to set led state. In our case it is report 13. In other cases it may be different. I haven't figured out how to define it yet. For some reason you can't see any changes of feature reports. At the same time I can
  3. Now you can send report to hid device.
    In Python it looks like:
# Part of code from https://github.com/vpelletier/python-ioctl-opt/blob/master/ioctl_opt/__init__.py
import fcntl # built-in
import ctypes # built-in

_IOC_NRBITS = 8
_IOC_TYPEBITS = 8
_IOC_SIZEBITS = 14
_IOC_DIRBITS = 2

_IOC_NRMASK = (1 << _IOC_NRBITS) - 1
_IOC_TYPEMASK = (1 << _IOC_TYPEBITS) - 1
_IOC_SIZEMASK = (1 << _IOC_SIZEBITS) - 1
_IOC_DIRMASK = (1 << _IOC_DIRBITS) - 1

_IOC_NRSHIFT = 0
_IOC_TYPESHIFT = _IOC_NRSHIFT + _IOC_NRBITS
_IOC_SIZESHIFT = _IOC_TYPESHIFT + _IOC_TYPEBITS
_IOC_DIRSHIFT = _IOC_SIZESHIFT + _IOC_SIZEBITS

IOC_NONE = 0
IOC_WRITE = 1
IOC_READ = 2

def IOC(dir, type, nr, size):
    assert dir <= _IOC_DIRMASK, dir
    assert type <= _IOC_TYPEMASK, type
    assert nr <= _IOC_NRMASK, nr
    assert size <= _IOC_SIZEMASK, size
    return (dir << _IOC_DIRSHIFT) | (type << _IOC_TYPESHIFT) | (nr << _IOC_NRSHIFT) | (size << _IOC_SIZESHIFT)



HIDIOCSFEATURE = lambda len: IOC(IOC_WRITE|IOC_READ, ord('H'), 0x06, len)
HIDIOCGFEATURE = lambda len: IOC(IOC_WRITE|IOC_READ, ord('H'), 0x07, len)
file_handler = open("/dev/hidraw0", 'wb')
report = bytearray([0] * 256)
report[0] = 13 # report number
report_arr = (ctypes.c_char * len(report)).from_buffer(report)

report_size = fcntl.ioctl(file_handler, HIDIOCGFEATURE(len(report)), report_arr, True)
# after read report I can get current brightness at report[4]. I don't understand why you can't :(
report[1] = 112 # it is magic number now
report[2] = 3 # it is magic number now
report[3] = 1 # or 0 to disable led
report[4] = 81 # is 0x41 + 16. 16 is magic number now

report_arr = (ctypes.c_char * len(report)).from_buffer(report)
fcntl.ioctl(file_handler, HIDIOCSFEATURE(report_size), report_arr, True) # enable led with 0x41 brightness

The advantage is that it works even if i2c_dev and i2c_smbus modules are blacklisted.
Of course we need some research to understand hid report specification.
To be honest, I haven't figured it out yet. I just shared my observations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants