FS#8157: H10 RTC alarm with some changes by me. The settings keymap had to be changed slightly, but it seems to work better for all setting screens with the new keymap. Thanks to

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15620 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Barry Wardell 2007-11-14 16:53:31 +00:00
parent e18125eec2
commit 34288fea43
5 changed files with 141 additions and 9 deletions

View file

@ -117,10 +117,10 @@ static const struct button_mapping button_context_settings[] = {
{ ACTION_SETTINGS_INCREPEAT,BUTTON_SCROLL_UP|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_SETTINGS_DEC, BUTTON_SCROLL_DOWN, BUTTON_NONE },
{ ACTION_SETTINGS_DECREPEAT,BUTTON_SCROLL_DOWN|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_STD_PREV, BUTTON_LEFT, BUTTON_NONE },
{ ACTION_STD_PREVREPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_STD_NEXT, BUTTON_RIGHT, BUTTON_NONE },
{ ACTION_STD_NEXTREPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_STD_PREV, BUTTON_FF, BUTTON_NONE },
{ ACTION_STD_PREVREPEAT, BUTTON_FF|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_STD_NEXT, BUTTON_REW, BUTTON_NONE },
{ ACTION_STD_NEXTREPEAT, BUTTON_REW|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_SETTINGS_RESET, BUTTON_PLAY, BUTTON_NONE },
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD),

View file

@ -4740,11 +4740,13 @@
*: none
alarm: "PLAY=Set OFF=Cancel"
ipod*: "SELECT=Set MENU=Cancel"
h10,h10_5gb: "SELECT=Set PREV=Cancel"
</source>
<dest>
*: none
alarm: "PLAY=Set OFF=Cancel"
ipod*: "SELECT=Set MENU=Cancel"
h10,h10_5gb: "SELECT=Set PREV=Cancel"
</dest>
<voice>
*: none

View file

@ -7,7 +7,8 @@
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Linus Nielsen Feltzing, Uwe Freese, Laurent Baum
* Copyright (C) 2002 by Linus Nielsen Feltzing, Uwe Freese, Laurent Baum,
* Przemyslaw Holubowski
*
* 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.
@ -25,12 +26,27 @@
#include <stdbool.h>
/* RTC registers */
#define RTC_CTRL1 0x00
#define RTC_CTRL2 0x01
#define RTC_CTRL1 0x00
#define RTC_CTRL2 0x01
#define RTC_ALARM_MINUTES 0x09
#define RTC_ALARM_HOURS 0x0A
#define RTC_ALARM_DAY 0x0B
#define RTC_ALARM_WDAY 0x0C
#define RTC_TIMER_CTRL 0x0E
#define RTC_TIMER 0x0F
/* Control 2 register flags */
#define RTC_TF 0x04
#define RTC_AF 0x08
#define RTC_TIE 0x01
#define RTC_AIE 0x02
#define RTC_TF 0x04
#define RTC_AF 0x08
#define RTC_TI_TP 0x10
/* Alarm registers flags */
#define RTC_AE 0x80
/* Timer register flags */
#define RTC_TE 0x80
void rtc_init(void)
{
@ -82,3 +98,115 @@ int rtc_write_datetime(unsigned char* buf)
return 1;
}
void rtc_set_alarm(int h, int m)
{
unsigned char buf[4]={0};
int rv=0;
int i=0;
/* clear alarm interrupt */
rv = i2c_readbytes(0x51,RTC_CTRL2,1,buf);
buf[0] &= RTC_AF;
pp_i2c_send(0x51, RTC_CTRL2,buf[0]);
/* prepare new alarm */
if( m >= 0 )
buf[0] = (((m/10) << 4) | m%10);
else
/* ignore minutes comparison query */
buf[0] = RTC_AE;
if( h >= 0 )
buf[1] = (((h/10) << 4) | h%10);
else
/* ignore hours comparison query */
buf[1] = RTC_AE;
/* ignore day and wday */
buf[2] = RTC_AE;
buf[3] = RTC_AE;
/* write new alarm */
for(;i<4;i++)
pp_i2c_send(0x51, RTC_ALARM_MINUTES+i,buf[i]);
/* note: alarm is not enabled at the point */
}
void rtc_get_alarm(int *h, int *m)
{
unsigned char buf[4]={0};
/* get alarm preset */
i2c_readbytes(0x51, RTC_ALARM_MINUTES,4,buf);
*m = ((buf[0] >> 4) & 0x7)*10 + (buf[0] & 0x0f);
*h = ((buf[1] >> 4) & 0x3)*10 + (buf[1] & 0x0f);
}
bool rtc_enable_alarm(bool enable)
{
unsigned char tmp=0;
int rv=0;
if(enable)
{
/* enable alarm interrupt */
rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp);
tmp |= RTC_AIE;
pp_i2c_send(0x51, RTC_CTRL2,tmp);
}
else
{
/* disable alarm interrupt */
rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp);
tmp &= ~RTC_AIE;
pp_i2c_send(0x51, RTC_CTRL2,tmp);
}
return false;
}
bool rtc_check_alarm_started(bool release_alarm)
{
static bool alarm_state, run_before = false;
unsigned char tmp=0;
bool started;
int rv=0;
if (run_before)
{
started = alarm_state;
alarm_state &= ~release_alarm;
}
else
{
/* read Control 2 register which contains alarm flag */
rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp);
alarm_state = started = tmp & (RTC_AF | RTC_AIE);
if(release_alarm)
{
rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp);
/* clear alarm interrupt enable and alarm flag */
tmp &= ~(RTC_AF | RTC_AIE);
pp_i2c_send(0x51, RTC_CTRL2,tmp);
}
run_before = true;
}
return started;
}
bool rtc_check_alarm_flag(void)
{
unsigned char tmp=0;
int rv=0;
/* read Control 2 register which contains alarm flag */
rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp);
return (tmp & RTC_AF);
}

View file

@ -68,6 +68,7 @@
/* define this if you have a real-time clock */
#ifndef BOOTLOADER
#define CONFIG_RTC RTC_E8564
#define HAVE_RTC_ALARM
#endif
/* Define this if you have a software controlled poweroff */

View file

@ -54,6 +54,7 @@
/* define this if you have a real-time clock */
#ifndef BOOTLOADER
#define CONFIG_RTC RTC_E8564
#define HAVE_RTC_ALARM
#endif
/* Define this if you have a software controlled poweroff */