freemyipod r622 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r621‎ | r622 | r623 >
Date:00:48, 17 February 2011
Author:theseven
Status:new
Tags:
Comment:
emCORE: More sophisticated power monitoring API
Modified paths:
  • /emcore/trunk/power.h (modified) (history)
  • /emcore/trunk/target/ipodnano2g/power.c (modified) (history)
  • /emcore/trunk/target/ipodnano3g/pmu.c (modified) (history)
  • /emcore/trunk/target/ipodnano3g/power.c (modified) (history)
  • /emcore/trunk/target/ipodnano4g/power.c (modified) (history)

Diff [purge]

Index: emcore/trunk/target/ipodnano2g/power.c
@@ -67,3 +67,53 @@
6868 {
6969 return (PDAT14 & 8) ? false : true;
7070 }
 71+
 72+int read_battery_voltage(int battery)
 73+{
 74+ if (battery == 0) return pmu_read_battery_voltage();
 75+ return -1;
 76+}
 77+
 78+int read_battery_current(int battery)
 79+{
 80+ if (battery == 0) return pmu_read_battery_current();
 81+ return -1;
 82+}
 83+
 84+int read_battery_mwh_design(int battery)
 85+{
 86+ if (battery == 0) return 1480;
 87+ return -1;
 88+}
 89+
 90+int read_battery_mwh_full(int battery)
 91+{
 92+ if (battery == 0) return 1480;
 93+ return -1;
 94+}
 95+
 96+int read_battery_mwh_current(int battery)
 97+{
 98+ // TODO: Approximate that better
 99+ if (battery == 0) return (read_battery_voltage(0) - 3600) * 2;
 100+ return -1;
 101+}
 102+
 103+int read_battery_mw(int battery)
 104+{
 105+ if (battery == 0) return read_battery_current(0) * 3700 / 1000;
 106+ return -1;
 107+}
 108+
 109+int read_input_mw(int battery)
 110+{
 111+ return -1;
 112+}
 113+
 114+enum battery_state read_battery_state(int battery)
 115+{
 116+ if (battery != 0) return BATTERY_STATE_INVALID;
 117+ if (charging_state()) return BATTERY_STATE_CHARGING;
 118+ if (external_power_state()) return BATTERY_STATE_IDLE;
 119+ return BATTERY_STATE_DISCHARGING;
 120+}
Index: emcore/trunk/target/ipodnano3g/pmu.c
@@ -80,7 +80,7 @@
8181 /* milliamps */
8282 int pmu_read_battery_current(void)
8383 {
84 - return pmu_read_adc(2);
 84+ return -1;
8585 }
8686
8787 void pmu_ldo_on_in_standby(unsigned int ldo, int onoff)
Index: emcore/trunk/target/ipodnano3g/power.c
@@ -57,3 +57,52 @@
5858 {
5959 return (PDAT(12) & 8) ? false : true;
6060 }
 61+
 62+int read_battery_voltage(int battery)
 63+{
 64+ if (battery == 0) return pmu_read_battery_voltage();
 65+ return -1;
 66+}
 67+
 68+int read_battery_current(int battery)
 69+{
 70+ if (battery == 0) return pmu_read_battery_current();
 71+ return -1;
 72+}
 73+
 74+int read_battery_mwh_design(int battery)
 75+{
 76+ if (battery == 0) return 2035;
 77+ return -1;
 78+}
 79+
 80+int read_battery_mwh_full(int battery)
 81+{
 82+ if (battery == 0) return 2035;
 83+ return -1;
 84+}
 85+
 86+int read_battery_mwh_current(int battery)
 87+{
 88+ // TODO: Approximate that better
 89+ if (battery == 0) return (read_battery_voltage(0) - 3600) * 3;
 90+ return -1;
 91+}
 92+
 93+int read_battery_mw(int battery)
 94+{
 95+ return -1;
 96+}
 97+
 98+int read_input_mw(int battery)
 99+{
 100+ return -1;
 101+}
 102+
 103+enum battery_state read_battery_state(int battery)
 104+{
 105+ if (battery != 0) return BATTERY_STATE_INVALID;
 106+ if (charging_state()) return BATTERY_STATE_CHARGING;
 107+ if (external_power_state()) return BATTERY_STATE_IDLE;
 108+ return BATTERY_STATE_DISCHARGING;
 109+}
Index: emcore/trunk/target/ipodnano4g/power.c
@@ -51,3 +51,44 @@
5252 {
5353 return true;
5454 }
 55+
 56+int read_battery_voltage(int battery)
 57+{
 58+ return -1;
 59+}
 60+
 61+int read_battery_current(int battery)
 62+{
 63+ return -1;
 64+}
 65+
 66+int read_battery_mwh_design(int battery)
 67+{
 68+ return -1;
 69+}
 70+
 71+int read_battery_mwh_full(int battery)
 72+{
 73+ return -1;
 74+}
 75+
 76+int read_battery_mwh_current(int battery)
 77+{
 78+ return -1;
 79+}
 80+
 81+int read_battery_mw(int battery)
 82+{
 83+ return -1;
 84+}
 85+
 86+int read_input_mw(int battery)
 87+{
 88+ return -1;
 89+}
 90+
 91+enum battery_state read_battery_state(int battery)
 92+{
 93+ if (battery != 0) return BATTERY_STATE_INVALID;
 94+ return BATTERY_STATE_UNKNOWN;
 95+}
Index: emcore/trunk/power.h
@@ -27,11 +27,31 @@
2828
2929 #include "global.h"
3030
 31+
 32+enum battery_state
 33+{
 34+ BATTERY_STATE_UNKNOWN,
 35+ BATTERY_STATE_INVALID,
 36+ BATTERY_STATE_NONPRESENT,
 37+ BATTERY_STATE_IDLE,
 38+ BATTERY_STATE_CHARGING,
 39+ BATTERY_STATE_DISCHARGING
 40+};
 41+
 42+
3143 void power_off(void);
3244 void power_init(void) INITCODE_ATTR;
3345 bool charging_state(void);
3446 bool external_power_state(void);
3547 bool vbus_state(void);
 48+int read_battery_voltage(int battery);
 49+int read_battery_current(int battery);
 50+int read_battery_mwh_design(int battery);
 51+int read_battery_mwh_full(int battery);
 52+int read_battery_mwh_current(int battery);
 53+int read_battery_mw(int battery);
 54+int read_input_mw(int battery);
 55+enum battery_state read_battery_state(int battery);
3656
3757
3858 #endif