Rockbox Development > Feature Ideas

Disable the backlight when charging in the bootloader

(1/1)

rockbox_dev123:
On my iPod 6G very occasionally I manage to completely exhaust the battery and must charge the iPod via the bootloader. I can't help but think that keeping the backlight on while it is charging makes it charge slower.

Does anyone know if this makes any significant difference to charging speeds?

I have created a patch for the bootloader, but would like someone more knowledgable with the codebase to tell me if it would work before I try to test it (as I don't know a better way than depleting my battery!):

--- Code: ---@@ -209,6 +209,17 @@
         if (power_input_status() != POWER_INPUT_NONE) {
             lcd_set_foreground(LCD_RBYELLOW);
             printf("Low battery: %d mV, charging...     ", vbat);
+            if (button_hold()) {
+                if(is_backlight_on()) {
+                    backlight_off() // Turn the backlight OFF when charging if the hold switch is ON.
+                }
+            }
+            else
+            {
+                if(is_backlight_on() != 1) {
+                    backlight_on() // Turn the backlight ON when charging if the hold switch is OFF.
+                }
+            }
             sleep(HZ*3);
         }
         else {

--- End code ---

saratoga:
It probably does make it a little slower since bootloader mode USB current is limited to 100mA, while the backlight is 23mA at max brightness (so maybe 10-12mA at the reduced brightness in the bootloader?).   

rockbox_dev123:
I made the following change and recompiled the bootloader:


--- Code: ---    /* Wait until USB is plugged */
    while (usb_detect() != USB_INSERTED)
    {
        printf("Plug USB cable");
        line--;
+        backlight_off(); // Turn the backlight OFF
        sleep(HZ/10);
    }

--- End code ---

This way, I could test the code in the bootloader without actually needing to deplete the battery.

Unfortunately, the backlight stays on while the bootloader is in this loop waiting for a USB connection.

saratoga: Do you know how I might achieve disabling the backlight in the bootloader?

rockbox_dev123:
UPDATE:


--- Code: ---        if (button_hold()) {
            if(is_backlight_on(true)) {
                backlight_hw_off(); // Turn the backlight OFF when charging if the hold switch is ON.
            }
        }
        else
        {
            if(!is_backlight_on(true)) {
                backlight_init(); // Turn the backlight ON when charging if the hold switch is OFF.
                //backlight_hw_on(); // Turn the backlight ON when charging if the hold switch is OFF.
            }
        }

--- End code ---

Switching to using the function backlight_hw_off() works. When I put the hold switch on the backlight completely disables. However, when taking the hold switch off, neither backlight_init() or backlight_hw_on() seem to re-enable the backlight.

UPDATE2:


--- Code: ---        if (button_hold()) {
            if(is_backlight_on(true)) {
                printf("Attempting to disable the backlight.");
                backlight_hw_off(); // Turn the backlight OFF when charging if the hold switch is ON.
            }
        }
        else
        {
            if(!is_backlight_on(true)) {
                printf("Attempting to enable the backlight.");
                backlight_init(); // Turn the backlight ON when charging if the hold switch is OFF.
                backlight_hw_on(); // Turn the backlight ON when charging if the hold switch is OFF.
            }
        }
--- End code ---

Adding printf statements shows that once the backlight is disabled, the check to see if the backlight is on or not isn't working. As it must be returning true ("Attempting to enable the backlight." is never printed after disabling).

UPDATE3:


--- Code: ---        if (button_hold()) {
            backlight_hw_off(); // Turn the backlight OFF when charging if the hold switch is ON.
        }
        else
        {
            backlight_hw_on(); // Turn the backlight ON when charging if the hold switch is OFF.
        }
--- End code ---

The code above that doesn't use is_backlight_on() works perfectly. I'm going to call it quits at this point unless I can get some advice on why the function is not returning the correct state of the backlight. For how rarely I empty the battery, I think I can live with the fact that it constantly unconditionally sets the backlight state.

rockbox_dev123:
Here are my final code changes:


--- Code: ------ Documents/GitHub/rockbox/bootloader/ipod6g.c 2023-02-08 18:36:18
+++ /Volumes/tank/Docker/rbclient/rockbox/bootloader/ipod6g.c 2023-02-11 19:45:41
@@ -189,6 +189,8 @@
 
     usb_charging_maxcurrent_change(100);
 
+    int backlight_on = true;
+
     while (1)
     {
         vbat = _battery_voltage();
@@ -209,6 +211,21 @@
         if (power_input_status() != POWER_INPUT_NONE) {
             lcd_set_foreground(LCD_RBYELLOW);
             printf("Low battery: %d mV, charging...     ", vbat);
+            if (button_hold()) {
+                if (backlight_on)
+                {
+                    backlight_on = false;
+                    backlight_hw_off(); // Turn the backlight OFF when charging if the hold switch is ON.
+                }
+            }
+            else
+            {
+                if (!backlight_on)
+                {
+                    backlight_on = true;
+                    backlight_hw_on(); // Turn the backlight ON when charging if the hold switch is OFF.
+                }
+            }
             sleep(HZ*3);
         }
         else {

--- End code ---

I just use my own variable instead of relying on any functions.

Navigation

[0] Message Index

Go to full version