Subversion Repositories freemyipod

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
273 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
427 farthen 6
//    This file is part of emCORE.
273 theseven 7
//
427 farthen 8
//    emCORE is free software: you can redistribute it and/or
273 theseven 9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
427 farthen 13
//    emCORE is distributed in the hope that it will be useful,
273 theseven 14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
427 farthen 19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
273 theseven 20
//
21
//
22
 
23
 
24
#include "global.h"
25
#include "s5l8702.h"
26
#include "power.h"
27
#include "pmu.h"
28
 
29
 
30
void reset();
31
 
32
 
33
void power_off(void)
34
{
35
    pmu_set_wake_condition(0x42); /* USB inserted or EXTON1 */
36
    pmu_enter_standby();
37
 
38
    reset();
39
}
40
 
41
void power_init(void)
42
{
43
    pmu_init();
44
}                          
45
 
46
bool charging_state(void)
47
{
960 theseven 48
    return (PDAT(11) & 0x10) ? false : true;
273 theseven 49
}
50
 
960 theseven 51
bool vbus_state(void)
273 theseven 52
{
960 theseven 53
    return (PDAT(11) & 0x20) ? false : true;
273 theseven 54
}
55
 
960 theseven 56
bool external_power_state(void)
273 theseven 57
{
960 theseven 58
    return vbus_state();
273 theseven 59
}
622 theseven 60
 
61
int read_battery_voltage(int battery)
62
{
63
    if (battery == 0) return pmu_read_battery_voltage();
64
    return -1;
65
}
66
 
67
int read_battery_current(int battery)
68
{
69
    if (battery == 0) return pmu_read_battery_current();
70
    return -1;
71
}
72
 
73
int read_battery_mwh_design(int battery)
74
{
75
    if (battery == 0) return 2035;
76
    return -1;
77
}
78
 
79
int read_battery_mwh_full(int battery)
80
{
81
    if (battery == 0) return 2035;
82
    return -1;
83
}
84
 
85
int read_battery_mwh_current(int battery)
86
{
87
    // TODO: Approximate that better
960 theseven 88
    if (battery == 0) return MAX(0, (read_battery_voltage(0) - 3600) * 3);
622 theseven 89
    return -1;
90
}
91
 
92
int read_battery_mw(int battery)
93
{
94
    return -1;
95
}
96
 
97
enum battery_state read_battery_state(int battery)
98
{
99
    if (battery != 0) return BATTERY_STATE_INVALID;
960 theseven 100
    if (read_battery_voltage(0) < 100) return BATTERY_STATE_NONPRESENT;
622 theseven 101
    if (charging_state()) return BATTERY_STATE_CHARGING;
102
    if (external_power_state()) return BATTERY_STATE_IDLE;
103
    return BATTERY_STATE_DISCHARGING;
104
}
845 theseven 105
 
106
int read_input_voltage(int input)
107
{
108
    return -1;
109
}
110
 
111
int read_input_current(int input)
112
{
113
    return -1;
114
}
115
 
116
int read_input_mw(int input)
117
{
118
    return -1;
119
}
120
 
121
enum input_state read_input_state(int input)
122
{
123
    if (input != 0) return INPUT_STATE_INVALID;
124
    if (external_power_state()) return INPUT_STATE_ACTIVE;
125
    return INPUT_STATE_NONPRESENT;
126
}
960 theseven 127