freemyipod r960 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r959‎ | r960 | r961 >
Date:21:09, 19 July 2014
Author:theseven
Status:new
Tags:
Comment:
emCORE: iPod Classic: Properly detect external power and charging state
Modified paths:
  • /emcore/trunk/target/ipodnano3g/power.c (modified) (history)

Diff [purge]

Index: emcore/trunk/target/ipodnano3g/power.c
@@ -45,17 +45,17 @@
4646
4747 bool charging_state(void)
4848 {
49 - return false;
 49+ return (PDAT(11) & 0x10) ? false : true;
5050 }
5151
52 -bool external_power_state(void)
 52+bool vbus_state(void)
5353 {
54 - return (PDAT(12) & 8) ? false : true;
 54+ return (PDAT(11) & 0x20) ? false : true;
5555 }
5656
57 -bool vbus_state(void)
 57+bool external_power_state(void)
5858 {
59 - return (PDAT(12) & 8) ? false : true;
 59+ return vbus_state();
6060 }
6161
6262 int read_battery_voltage(int battery)
@@ -85,7 +85,7 @@
8686 int read_battery_mwh_current(int battery)
8787 {
8888 // TODO: Approximate that better
89 - if (battery == 0) return (read_battery_voltage(0) - 3600) * 3;
 89+ if (battery == 0) return MAX(0, (read_battery_voltage(0) - 3600) * 3);
9090 return -1;
9191 }
9292
@@ -97,6 +97,7 @@
9898 enum battery_state read_battery_state(int battery)
9999 {
100100 if (battery != 0) return BATTERY_STATE_INVALID;
 101+ if (read_battery_voltage(0) < 100) return BATTERY_STATE_NONPRESENT;
101102 if (charging_state()) return BATTERY_STATE_CHARGING;
102103 if (external_power_state()) return BATTERY_STATE_IDLE;
103104 return BATTERY_STATE_DISCHARGING;
@@ -123,3 +124,4 @@
124125 if (external_power_state()) return INPUT_STATE_ACTIVE;
125126 return INPUT_STATE_NONPRESENT;
126127 }
 128+