Control PWM pin 35 with brightness setting on Android 14

Which system do you use? Android, Ubuntu, OOWOW or others?

**Android.** VIM4

Which version of system do you use? Please provide the version of the system here:

**Android-14-V251224.**

Currenly I have PWM pin 35 constantly output 180hz pwm at 53.2% duty. I want to control this duty with the brightness slider on android. Please share someone who has done this before.

@Support_Account_1 You can directly replace the corresponding node through the source code. Alternatively, you can link to the /sys/class/backlight/aml-bl/brightness node using the softlink command.

vim4-android14-sdk/hardware/amlogic$ git log -p dd68a3e52f39c586731ac9dd88abe801cae3d242
commit dd68a3e52f39c586731ac9dd88abe801cae3d242
Author: goenjoy <goenjoy@khadas.com>
Date:   Tue Dec 14 20:22:57 2021 +0800

    backlight: modify for vim4 [2/3]
    
    Signed-off-by: goenjoy <goenjoy@khadas.com>
    Change-Id: Ieb9b6b2a0c2adc2b3e8c97a5f6d7808cd69d75aa

diff --git a/lights/lights.cpp b/lights/lights.cpp
index e8e60c8..3417eed 100644
--- a/lights/lights.cpp
+++ b/lights/lights.cpp
@@ -48,8 +48,9 @@ static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
 //char const* const RED_LED_FILE = "";
 //char const* const BLUE_LED_FILE = "";
 char const* const ARRAY_LED_DEVICE = "/sys/class/leds/i2c_leds/single_colors" ;
-char const* BACKLIGHT_DEVICE = "/sys/class/backlight/aml-bl/brightness";
-
+//char const* BACKLIGHT_DEVICE = "/sys/class/backlight/aml-bl/brightness";
+char const* const BACKLIGHT_DEVICE0 = "/sys/class/backlight/aml-bl/brightness"; //mipi edp backlight
+char const* const BACKLIGHT_DEVICE1 = "/sys/class/backlight/aml-bl1/brightness"; //vbo backlight
 
 static int sys_write_int(int fd, int value) {
     char buffer[16];
@@ -111,7 +112,7 @@ class Lights : public BnLights {
     }
 
     void writeControlSysfs(const char* path, int color) {
-        LOG(ERROR) << "writeLed test:" << path << ",color:"<< color;
+        //LOG(ERROR) << "writeLed test:" << path << ",color:"<< color;
         int fd = open(path, O_WRONLY);
         if (fd < 0) {
             LOG(ERROR) << "COULD NOT OPEN LED_DEVICE " << path;
@@ -131,7 +132,10 @@ class Lights : public BnLights {
   public:
     Lights() : BnLights() {
         pthread_mutex_init(&g_lock, NULL);
-      if (isLightSupport(BACKLIGHT_DEVICE)) {
+      if (isLightSupport(BACKLIGHT_DEVICE0)) {
+            LOG(ERROR) << "LIGHTS:BACKGROUND is supported";
+            addLight(LightType::BACKLIGHT, 0);
+      } else if (isLightSupport(BACKLIGHT_DEVICE1)) {
             LOG(ERROR) << "LIGHTS:BACKGROUND is supported";
             addLight(LightType::BACKLIGHT, 0);
       } else
@@ -174,7 +178,11 @@ class Lights : public BnLights {
                 LOG(DEBUG) <<  "Light BLUETOOTH is not supported by now.";
                 break;
             case LightType::BACKLIGHT:
-                writeControlSysfs(BACKLIGHT_DEVICE, state.color);
+                               if (isLightSupport(BACKLIGHT_DEVICE0)) {
+                                   writeControlSysfs(BACKLIGHT_DEVICE0, state.color);
+                               } else {
+                                   writeControlSysfs(BACKLIGHT_DEVICE1, state.color);
+                               }
                 LOG(DEBUG) << "setLightState, light:" << light.ordinal << ", color:" << state.color ;
                 break;
             default:
diff --git a/lights/lights.rc b/lights/lights.rc
index 919e870..4523750 100644
--- a/lights/lights.rc
+++ b/lights/lights.rc
@@ -1,6 +1,10 @@
 on init
     chmod 0666 /sys/class/leds/i2c_leds/single_colors
     chown system system /sys/class/leds/i2c_leds/single_colors
+    chmod 0666 /sys/class/backlight/aml-bl/brightness
+    chown system system /sys/class/backlight/aml-bl/brightness
+    chmod 0666 /sys/class/backlight/aml-bl1/brightness
+    chown system system /sys/class/backlight/aml-bl1/brightness
 
 service vendor.lights  /vendor/bin/hw/lights
     class hal

Is there anyway I can do it without rebuilding Android ? Is it possible to do within the OS ?

@Support_Account_1 Alternatively, you can link to the /sys/class/backlight/aml-bl/brightness node using the softlink command.

We have tried this and nothing has changed:
echo 0 > /sys/class/backlight/aml-bl/brightness
echo 255 > /sys/class/backlight/aml-bl/brightness

We are measuring duty with an oscilliscope on pin 35

@Support_Account_1 If this method doesn’t work, then you can use AI to write an app control.