Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Welcome to the Rockbox Technical Forums!

+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Feature Ideas
| | |-+  Disable the backlight when charging in the bootloader
« previous next »
  • Print
Pages: [1]

Author Topic: Disable the backlight when charging in the bootloader  (Read 235 times)

Offline rockbox_dev123

  • Member
  • *
  • Posts: 74
Disable the backlight when charging in the bootloader
« on: February 08, 2023, 04:50:55 PM »
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: [Select]
@@ -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 {
Logged

Offline saratoga

  • Developer
  • Member
  • *
  • Posts: 9214
Re: Disable the backlight when charging in the bootloader
« Reply #1 on: February 08, 2023, 10:33:26 PM »
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?).   
Logged

Offline rockbox_dev123

  • Member
  • *
  • Posts: 74
Re: Disable the backlight when charging in the bootloader
« Reply #2 on: February 11, 2023, 01:33:00 PM »
I made the following change and recompiled the bootloader:

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

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?
Logged

Offline rockbox_dev123

  • Member
  • *
  • Posts: 74
Re: Disable the backlight when charging in the bootloader
« Reply #3 on: February 11, 2023, 01:57:33 PM »
UPDATE:

Code: [Select]
        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.
            }
        }

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: [Select]
        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.
            }
        }

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: [Select]
        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.
        }

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.
« Last Edit: February 11, 2023, 02:35:47 PM by bobba_mosfet »
Logged

Offline rockbox_dev123

  • Member
  • *
  • Posts: 74
Re: Disable the backlight when charging in the bootloader
« Reply #4 on: February 11, 2023, 02:46:50 PM »
Here are my final code changes:

Code: [Select]
--- 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 {

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

  • Print
Pages: [1]
« previous next »
+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Feature Ideas
| | |-+  Disable the backlight when charging in the bootloader
 

  • SMF 2.0.19 | SMF © 2021, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.081 seconds with 21 queries.