[Nothing Phone 2] watchound:
Hey all, been lurking on XDA for a long time but this is actually my first post. Thought I'd put this out for folks to use as a way to give back to the community.

I got a NP2 a couple weeks back and was interested to see what could be done for custom Glyph usage since NOTHING offers... well... nothing as far as actual control besides their composer and some pre-made integrations. So, I did some digging and found the following as a jumping off point.

Glyph Quick Settings Toggle for Phone(1)

Custom Glyph animation

glyph-api

The last one on rec0de's GitHub made it pretty clear that there isn't a way to properly do this via API, but the first two Reddit pages seemed promising. Problem is that the NP2 is obviously a pretty different piece of hardware. So I started poking around things in a terminal. I figured it couldn't be that bad; I've done plenty of embedded hardware kernel integration in my professional life. Well, it certainly took a bit longer than I'd have liked, but I'm happy to report success.

First, I started trying to find where I could control the lights under the sysfs (/sys/...) similarly to the NP1. I found some paths, but the easiest ended up being under "/sys/class/leds/led_strips", which is symlinked to other sysfs paths going through I2C that are just harder to remember. I found promising items in there, but only "all_brightness" and "factory_test" seemed to do anything when I echo'ed to them. I wanted single LED control, so that was not good.

Alright, so I went to find what was controlling the LEDs. After going through the logs, I discovered that the LEDs are controlled via an "aw20036" controller on the I2C bus. Its made by a Chinese company named Awinic. Long story short, they're pretty obscure on western shores, and when I tried to download their driver I found I needed an account which seems to be impossible to make outside of China. I emailed their support too- radio silence.

OK then, they're useless, so I pulled down the NP2's kernel off GitHub and started pouring through what was in there. I found the device tree definitions as well as the driver itself, and it was decently enough commented in the code. So using what was there as a basis, I started poking around more and watching the kernel logs to see what I could find. That's when I hit pay-dirt. After seeing how NP2's code / Google's light management service interacted with the chip, I figured out that the mode has to be set and then everything is gravy.

In short, I have the basics here below. To be clear: this is used at your own risk! I am not responsible for irreparable damage to your phone, your life, the stock market, or the Earth's orbital axis!

As the title states, you need root to do this at all. The below has to be run as such (su -) or you'll get permission denied errors. There's no negotiating around this right now.

First, you have to set the operating mode for the controller correctly. This is the important part!

echo 1 > /sys/class/leds/led_strips/operating mode

The existing code / glyph service does this when its running its effects, and then sets it back to 2 afterward. In practice, I see no harm in leaving it in mode 1 because it gets reset the next time something lights up anyway.

UPDATE 12/15/23-

After perusing the datasheet for the aw20036 again, I believe this mode actually controls power for the IC. In this case, 2 = "standby" mode, 1 = "active" mode, and 0 is either unused or is "shutdown" mode. Assuming it is shutdown mode, I'd avoid using it as that clears the chip's registers, fully disables the clock, clears configuration, etc. That might cause it to desync with the kernel and cause undefined behavior.

END UPDATE

Next, to actually control brightness, you need to do this.

echo [LED ID] [brightness 0-254] > /sys/class/leds/led_strips/single_brightness

Where the LED ID corresponds to a number 0-35 (some are not used) and the brightness is... Well, the brightness.

Although this is far from the ideal way to control things, it opens up some options if one wants to use Tasker or the like to automate some of their own patterns. Time consuming to make, but more useful than the limited options before. Its worth noting the ID mappings are odd and definitely not in order, but as I've been going through this little project I've been noting it all down on my SuperNote and will attach the diagram I drew up while I figured the IDs out. If you can suffer my poor drawing skills and engineer's handwriting then it should help figuring out what ID to use for what light. And yes, before someone asks, you can also control the little red "recording" LED as well.

View attachment 6044118

I'd like to make a better integrated app for this, but my Android programming experience is limited. I do mostly C++ with Qt, and I'm not sure how well I could hook that in to create a root application to achieve any usefulness. Regardless, I hope this helps someone, and I'm happy to answer any questions I can!