CurtisMJ / LogoPlus

Open Source Implementation of Lighting Effects for Razer Phone 2
Apache License 2.0
20 stars 3 forks source link

How do you send commands to the LED? #13

Closed IngwiePhoenix closed 2 years ago

IngwiePhoenix commented 2 years ago

Hello!

I have a Razer Phone 2 myself and am currently in the process of finding my way around all kinds of topics related to Android. Right now, I am considering to move to LineageOS 18.1 and found this app on XDA-Developers.

Since I am more of a C guy, I wanted to ask where I should look to learn how exactly you are sending commands to the LED? Might be interesting to learn!

Thank you and kind regards, Ingwie

CurtisMJ commented 2 years ago

Hi, So first off I did sort of keep a journal of my findings in this thread The controller driver mostly communicates in sysfs paths, which of course requires root but Razer did implement a system service in their ROMs called "THS" which access them on behalf of the Chroma app. The controller can be told to directly illuminate certain LEDs by writing to the paths in /sys/class/leds/lp5523:channel[0-8]/* (9 total LEDs, 3 colors for each "snake head"). The controller also supports uploading a microcode program which it will loop on it's own without interrupting the main processor (3 "hyperthreads"). The thread I linked goes into a bit more detail on this, but think typical assembly. The most relevant code in this project is MicroCodeManager.java which is a sort of assembler. There is also a small C program to fade out the lights which I don't know why I made a separate program, I think the overhead of echoing a lot of sequential values through a shell had something to do with it.

IngwiePhoenix commented 2 years ago

Awesome! Thank you so much for the information :)

So I take it lp5523 is the specifier in sysfs for that particular chip? It looks pretty generic, will see what a random Google search brings up. Interesting that THS provides the userland control - the name feels kinda misleading...

Again, thank you a lot for that info, will read that journal later as well!

Closing for now, as I have no more questions, and this isn't really an "issue" :)

IngwiePhoenix commented 2 years ago

Huh, that was fast. https://www.ti.com/product/LP5523

IngwiePhoenix commented 2 years ago

Looking at the C source (thought I'd start there as this is more of my forte), I noticed you were communicating with a channel 10, whilst you had just mentioned only 0-8 (and so does the TI spec sheet, as far as I read it).

Is 10 a special device soley for fading?

Point of reference: https://github.com/CurtisMJ/LogoPlus/blob/df9f5081ae636d11a7934d2f05c2db9ef8bce534/native/fadeout/jni/fadeout.c#L5-L8

CurtisMJ commented 2 years ago

Is 10 a special device soley for fading?

Channel 0, but the lowercase L looks like a 1, but yeah some paths are symlinks to global controls