2002-07-04 16:09:23 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Linus Nielsen Feltzing
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "sh7034.h"
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "config.h"
|
|
|
|
#include "adc.h"
|
|
|
|
#include "power.h"
|
|
|
|
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
|
|
|
bool charger_inserted(void)
|
|
|
|
{
|
|
|
|
#ifdef ARCHOS_RECORDER
|
|
|
|
return adc_read(ADC_BATTERY) > 0x200;
|
|
|
|
#else
|
|
|
|
return (PADR & 1) == 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns battery level in percent */
|
|
|
|
int battery_level(void)
|
|
|
|
{
|
|
|
|
int level;
|
|
|
|
|
2002-07-17 11:13:56 +00:00
|
|
|
level = adc_read(ADC_UNREG_POWER);
|
2002-07-04 16:09:23 +00:00
|
|
|
if(level < 0)
|
|
|
|
level = 0;
|
|
|
|
|
|
|
|
if(level > BATTERY_LEVEL_FULL)
|
|
|
|
level = BATTERY_LEVEL_FULL;
|
2002-07-17 11:13:56 +00:00
|
|
|
|
2002-07-26 14:54:25 +00:00
|
|
|
if(level < BATTERY_LEVEL_EMPTY)
|
|
|
|
level = BATTERY_LEVEL_EMPTY;
|
2002-07-22 15:33:14 +00:00
|
|
|
|
2002-07-26 14:54:25 +00:00
|
|
|
return ((level-BATTERY_LEVEL_EMPTY) * 100) / BATTERY_RANGE;
|
2002-07-04 16:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void charger_enable(bool on)
|
|
|
|
{
|
|
|
|
#ifdef ARCHOS_RECORDER
|
|
|
|
if(on)
|
|
|
|
PBDR &= ~0x20;
|
|
|
|
else
|
|
|
|
PBDR |= 0x20;
|
|
|
|
#else
|
|
|
|
on = on;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void ide_power_enable(bool on)
|
|
|
|
{
|
|
|
|
#ifdef ARCHOS_RECORDER
|
|
|
|
if(on)
|
|
|
|
PADR |= 0x20;
|
|
|
|
else
|
|
|
|
PADR &= ~0x20;
|
|
|
|
#else
|
|
|
|
on = on;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-07-05 07:10:22 +00:00
|
|
|
void power_off(void)
|
|
|
|
{
|
|
|
|
#ifdef ARCHOS_RECORDER
|
|
|
|
PBDR &= ~PBDR_BTN_OFF;
|
|
|
|
PBIOR |= PBDR_BTN_OFF;
|
|
|
|
#else
|
|
|
|
PADR &= ~0x800;
|
|
|
|
PAIOR |= 0x800;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-07-04 16:09:23 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
bool charger_inserted(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns battery level in percent */
|
|
|
|
int battery_level(void)
|
|
|
|
{
|
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
void charger_enable(bool on)
|
|
|
|
{
|
|
|
|
on = on;
|
|
|
|
}
|
|
|
|
|
2002-07-05 07:10:22 +00:00
|
|
|
void power_off(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-07-04 16:09:23 +00:00
|
|
|
#endif /* SIMULATOR */
|