freemyipod r734 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r733‎ | r734 | r735 >
Date:00:03, 12 July 2011
Author:theseven
Status:new
Tags:
Comment:
emCORE: Add Vbus detection for iPod Nano 4G
Modified paths:
  • /emcore/trunk/target/ipodnano4g/power.c (modified) (history)

Diff [purge]

Index: emcore/trunk/target/ipodnano4g/power.c
@@ -22,9 +22,15 @@
2323
2424
2525 #include "global.h"
 26+#include "i2c.h"
 27+#include "timer.h"
2628 #include "power.h"
2729
2830
 31+long power_last_update;
 32+bool power_last_state;
 33+
 34+
2935 void reset();
3036
3137
@@ -35,6 +41,7 @@
3642
3743 void power_init(void)
3844 {
 45+ power_last_update = 0;
3946 }
4047
4148 bool charging_state(void)
@@ -44,12 +51,17 @@
4552
4653 bool external_power_state(void)
4754 {
48 - return false;
 55+ return vbus_state();
4956 }
5057
5158 bool vbus_state(void)
5259 {
53 - return true;
 60+ if (TIMEOUT_EXPIRED(power_last_update, 200000))
 61+ {
 62+ power_last_update = USEC_TIMER;
 63+ power_last_state = !!(i2c_recvbyte(0, 0xe6, 4) & 0x40);
 64+ }
 65+ return power_last_state;
5466 }
5567
5668 int read_battery_voltage(int battery)