summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-07-04 16:09:23 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-07-04 16:09:23 +0000
commit7cafe7aa2f2aa671a39bd82dfd227e2aa22ef30f (patch)
tree3545a3fc894bfed825d1dba1ffbe269de821d4a3
parentbd84ff4d785a597fe4110cb1565d80b948b1f210 (diff)
downloadrockbox-7cafe7aa2f2aa671a39bd82dfd227e2aa22ef30f.tar.gz
rockbox-7cafe7aa2f2aa671a39bd82dfd227e2aa22ef30f.zip
First version
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1333 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/drivers/power.c93
-rw-r--r--firmware/drivers/power.h35
2 files changed, 128 insertions, 0 deletions
diff --git a/firmware/drivers/power.c b/firmware/drivers/power.c
new file mode 100644
index 0000000000..9ddbbdbbb2
--- /dev/null
+++ b/firmware/drivers/power.c
@@ -0,0 +1,93 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "sh7034.h"
20#include <stdbool.h>
21#include "config.h"
22#include "adc.h"
23#include "power.h"
24
25#ifndef SIMULATOR
26
27bool charger_inserted(void)
28{
29#ifdef ARCHOS_RECORDER
30 return adc_read(ADC_BATTERY) > 0x200;
31#else
32 return (PADR & 1) == 0;
33#endif
34}
35
36/* Returns battery level in percent */
37int battery_level(void)
38{
39 int level;
40
41 level = adc_read(ADC_UNREG_POWER) - BATTERY_LEVEL_SHUTDOWN;
42 if(level < 0)
43 level = 0;
44
45 if(level > BATTERY_LEVEL_FULL)
46 level = BATTERY_LEVEL_FULL;
47
48 return (level * 100) / BATTERY_RANGE;
49}
50
51void charger_enable(bool on)
52{
53#ifdef ARCHOS_RECORDER
54 if(on)
55 PBDR &= ~0x20;
56 else
57 PBDR |= 0x20;
58#else
59 on = on;
60#endif
61}
62
63void ide_power_enable(bool on)
64{
65#ifdef ARCHOS_RECORDER
66 if(on)
67 PADR |= 0x20;
68 else
69 PADR &= ~0x20;
70#else
71 on = on;
72#endif
73}
74
75#else
76
77bool charger_inserted(void)
78{
79 return false;
80}
81
82/* Returns battery level in percent */
83int battery_level(void)
84{
85 return 100;
86}
87
88void charger_enable(bool on)
89{
90 on = on;
91}
92
93#endif /* SIMULATOR */
diff --git a/firmware/drivers/power.h b/firmware/drivers/power.h
new file mode 100644
index 0000000000..819c1983d9
--- /dev/null
+++ b/firmware/drivers/power.h
@@ -0,0 +1,35 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#ifndef _POWER_H_
20#define _POWER_H_
21
22#define BATTERY_LEVEL_SHUTDOWN (4500000 / BATTERY_SCALE_FACTOR) /* 4.5V */
23#define BATTERY_LEVEL_DANGEROUS (4750000 / BATTERY_SCALE_FACTOR) /* 4.75V */
24#define BATTERY_LEVEL_FULL (5550000 / BATTERY_SCALE_FACTOR) /* 5.55V */
25
26#define BATTERY_RANGE (BATTERY_LEVEL_FULL - BATTERY_LEVEL_SHUTDOWN)
27
28bool charger_inserted(void);
29void charger_enable(bool on);
30void ide_power_enable(bool on);
31
32/* Returns battery level in percent */
33int battery_level(void);
34
35#endif