guh.me - gustavo's personal blog

Manually configuring ASUS TUF Keyboard lighting on Linux

βΈ»

During the pandemic, I decided to buy a new laptop. I wanted a ThinkPad - I already had one once, and have always missing its trackpoint - but they were not available, so I settled for an ASUS TUF. It is actually a pretty decent device, and works mostly well on Linux - the big downside is controlling the RGB lit keyboard. If I happen to forget the laptop on until the battery drains out, the keyboard blinks and changes colors like a disco, and I need to boot into Windows to use some proprietary ASUS Aura software to re-configure it. I tried using OpenRGB in the past, but there was no support for my device.

Back to today - I forgot my laptop on again, and the keyboard is blinking and already causing me micro seizures like that forbidden Pokemon episode. I want to solve this now, from Linux 🐧. OpenRGB now supports my device, so I decided peek at its implementation here. I was thinking it would be very contrived, but its actually very simple - it just writes the configuration to sysfs.

By listing the files exposed by the keyboard driver, I see:

$ ls /sys/devices/platform/asus-nb-wmi/leds/asus::kbd_backlight`
-rw-r--r-- 1 root root 4096 Sep 12 21:14 brightness
-r--r--r-- 1 root root 4096 Sep 12 21:14 brightness_hw_changed
lrwxrwxrwx 1 root root    0 Sep 12 21:53 device -> ../../../asus-nb-wmi
--w------- 1 root root 4096 Sep 12 21:53 kbd_rgb_mode
-r--r--r-- 1 root root 4096 Sep 12 21:53 kbd_rgb_mode_index
--w------- 1 root root 4096 Sep 12 21:53 kbd_rgb_state
-r--r--r-- 1 root root 4096 Sep 12 21:53 kbd_rgb_state_index
-r--r--r-- 1 root root 4096 Sep 12 21:14 max_brightness
drwxr-xr-x 2 root root    0 Sep 12 21:53 power
lrwxrwxrwx 1 root root    0 Sep 12 21:14 subsystem -> ../../../../../class/leds
-rw-r--r-- 1 root root    0 Sep 12 21:53 trigger
-rw-r--r-- 1 root root 4096 Sep 12 21:14 uevent

The files I am interested at is brightness and kbd_rgb_mode. I can already use the fn + ↑/↓ key combination, thus by simply pressing them and cating brightness I could see it was changing. Just by doing that, I could see the valid values are [0, 1, 2, 3], where the increasing values correspond to increased brightness.

Now to the colors and mode. I saw these interesting kbd_rgb_mode_index file, and decided to take a look at it:

$ cat kbd_rgb_mode_index
cmd mode red green blue speed

This describes the order of the options when you want to change them via kbd_rgb_mode. cmd is apparently meaningless. OpenRGB has it set as either 1 or 0, but further research and a few tries with different values corroborated the hypothesis that its value does not matter. Weird as heck. mode is either static (0), breathing (1), or disco (2). red/green/blue is obvious: a number from 0 to 255 representing each color in the RGB color model. speed is a value between 0 and 2, and is self-explanatory.

I wanted to change the color to some light blue and have it static. I tried then the following command:

$ echo '1 0 0 100 250 0' > sudo tee kbd_rgb_mode

Then, lo and behold, the disco stopped and a pleasant light hue of blue shone under my fingers - and it didn’t even brick my hardware! My next step will be adding some keyboard shortcuts to do this, but that is a problem for another day.