echoplayer: add charger detection and USB current limit setting

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit bc32d43c17aaa793a7ec933304b9b1a004168184
Author: Aidan MacDonald <[email protected]>
Date:   Tue Jan 13 13:57:34 2026 +0000

    echoplayer: add charger detection and USB current limit setting
    
    Note that USB current limiting is more or less wishful
    thinking; only the charge current is limited, but the
    system could easily draw more than 100 mA by itself.
    
    Change-Id: I1083b015f0abea5a39a602ca8d7b142d3613b46b

diff --git a/firmware/export/config/echor1.h b/firmware/export/config/echor1.h
index 3316b2b731..6a6bba342f 100644
--- a/firmware/export/config/echor1.h
+++ b/firmware/export/config/echor1.h
@@ -108,9 +108,7 @@
 #define USB_PRODUCT_ID 0xEC01
 #define USB_DEVBSS_ATTR __attribute__((aligned(32)))
 #define HAVE_USB_POWER
-//#define HAVE_USB_CHARGING_ENABLE
-//#define HAVE_USB_CHARGING_IN_THREAD
-//#define TARGET_USB_CHARGING_DEFAULT USB_CHARGING_FORCE
+#define HAVE_USB_CHARGING_ENABLE
 #define HAVE_BOOTLOADER_USB_MODE
 #endif
 
diff --git a/firmware/target/arm/stm32/echoplayer/power-echoplayer.c b/firmware/target/arm/stm32/echoplayer/power-echoplayer.c
index 7e4b2e78a3..667cd99731 100644
--- a/firmware/target/arm/stm32/echoplayer/power-echoplayer.c
+++ b/firmware/target/arm/stm32/echoplayer/power-echoplayer.c
@@ -25,6 +25,7 @@
 static struct mutex power_1v8_lock;
 static int power_1v8_refcount;
 
+/* TODO: calibrate battery curve */
 unsigned short battery_level_disksafe = 3500;
 unsigned short battery_level_shutoff = 3400;
 
@@ -87,14 +88,31 @@ void system_reboot(void)
     power_off();
 }
 
+#ifdef HAVE_USB_CHARGING_ENABLE
+void usb_charging_maxcurrent_change(int maxcurrent)
+{
+    const int conf_500ma = GPIOF_OUTPUT(0, GPIO_TYPE_PUSH_PULL,
+                                        GPIO_SPEED_LOW, GPIO_PULL_DISABLED);
+    const int conf_100ma = GPIOF_INPUT(GPIO_PULL_DISABLED);
+
+    if (maxcurrent > 100)
+        gpio_configure_single(GPIO_CHARGER_CHARGING, conf_500ma);
+    else
+        gpio_configure_single(GPIO_CHARGER_CHARGING, conf_100ma);
+}
+#endif
+
 unsigned int power_input_status(void)
 {
-    return POWER_INPUT_USB_CHARGER;
+    if (gpio_get_level(GPIO_USB_VBUS))
+        return POWER_INPUT_USB_CHARGER;
+
+    return POWER_INPUT_NONE;
 }
 
 bool charging_state(void)
 {
-    return true;
+    return gpio_get_level(GPIO_CHARGER_CHARGING) == 0;
 }
 
 int _battery_voltage(void)
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.