summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Oleynikov <len0x@rockbox.org>2005-11-19 19:23:44 +0000
committerAnton Oleynikov <len0x@rockbox.org>2005-11-19 19:23:44 +0000
commitc94557e0b9415fdfe31154b75d320bf2ebd39168 (patch)
tree336234e1f3f3b09edcd047c19d5b1d4dccf54654
parenta51a5b711db09848ca9c569d2975ff8217a17261 (diff)
downloadrockbox-c94557e0b9415fdfe31154b75d320bf2ebd39168.tar.gz
rockbox-c94557e0b9415fdfe31154b75d320bf2ebd39168.zip
refactored radio status code
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7999 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/playback.c3
-rw-r--r--apps/recorder/radio.c45
-rw-r--r--apps/recorder/radio.h5
-rw-r--r--firmware/drivers/power.c18
-rw-r--r--firmware/export/power.h8
-rw-r--r--firmware/powermgmt.c2
6 files changed, 46 insertions, 35 deletions
diff --git a/apps/playback.c b/apps/playback.c
index d895716359..b662d0329b 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -61,7 +61,6 @@
#include "talk.h"
#ifdef CONFIG_TUNER
#include "radio.h"
-#include "power.h"
#endif
#include "splash.h"
@@ -1707,7 +1706,7 @@ void audio_thread(void)
#ifdef CONFIG_TUNER
/* check if radio is playing */
- if (radio_get_status() != FMRADIO_OFF) {
+ if (get_radio_status() != FMRADIO_OFF) {
radio_stop();
}
#endif
diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c
index 3dc74cd2ce..ff1d49bd2a 100644
--- a/apps/recorder/radio.c
+++ b/apps/recorder/radio.c
@@ -56,6 +56,7 @@
#include "textarea.h"
#include "splash.h"
#include "yesno.h"
+#include "power.h"
#ifdef CONFIG_TUNER
@@ -122,6 +123,8 @@ static int curr_preset = -1;
static int curr_freq;
static int radio_mode = RADIO_SCAN_MODE;
+static int radio_status = FMRADIO_OFF;
+
#define MAX_PRESETS 64
static bool presets_loaded = false;
static struct fmstation presets[MAX_PRESETS];
@@ -172,21 +175,26 @@ void radio_init(void)
radio_stop();
}
+int get_radio_status(void)
+{
+ return radio_status;
+}
+
void radio_stop(void)
{
radio_set(RADIO_MUTE, 1);
radio_set(RADIO_SLEEP, 1); /* low power mode, if available */
- radio_set_status(FMRADIO_OFF); /* status update, power off if avail. */
+ radio_status = FMRADIO_OFF;
+ radio_power(false); /* status update, power off if avail. */
}
bool radio_hardware_present(void)
{
#ifdef HAVE_TUNER_PWR_CTRL
bool ret;
- int fmstatus = radio_get_status(); /* get current state */
- radio_set_status(FMRADIO_POWERED); /* power it up */
+ bool fmstatus = radio_power(true); /* power it up */
ret = radio_get(RADIO_PRESENT);
- radio_set_status(fmstatus); /* restore previous state */
+ radio_power(fmstatus); /* restore previous state */
return ret;
#else
return radio_get(RADIO_PRESENT);
@@ -352,15 +360,16 @@ bool radio_screen(void)
curr_freq = global_settings.last_frequency * FREQ_STEP + MIN_FREQ;
- if(radio_get_status() == FMRADIO_OFF){
+ if(radio_status != FMRADIO_PLAYING){
+ radio_power(true);
radio_set(RADIO_SLEEP, 0); /* wake up the tuner */
radio_set(RADIO_FREQUENCY, curr_freq);
radio_set(RADIO_IF_MEASUREMENT, 0);
radio_set(RADIO_SENSITIVITY, 0);
radio_set(RADIO_FORCE_MONO, global_settings.fm_force_mono);
radio_set(RADIO_MUTE, 0);
+ radio_status = FMRADIO_PLAYING;
}
- radio_set_status(FMRADIO_PLAYING);
curr_preset = find_preset(curr_freq);
#ifdef FM_MODE
@@ -577,18 +586,18 @@ bool radio_screen(void)
)
break;
#endif
- if(radio_get_status() != FMRADIO_PLAYING)
+ if(radio_status != FMRADIO_PLAYING)
{
radio_set(RADIO_SLEEP, 0);
radio_set(RADIO_FREQUENCY, curr_freq);
radio_set(RADIO_MUTE, 0);
- radio_set_status(FMRADIO_PLAYING);
+ radio_status = FMRADIO_PLAYING;
}
else
{
radio_set(RADIO_MUTE, 1);
radio_set(RADIO_SLEEP, 1);
- radio_set_status(FMRADIO_POWERED);
+ radio_status = FMRADIO_PAUSED;
}
update_screen = true;
break;
@@ -848,7 +857,6 @@ bool radio_screen(void)
sound_default(SOUND_RIGHT_GAIN), AUDIO_GAIN_LINEIN);
mas_codec_writereg(6, 0x4000);
#endif
- radio_set_status(FMRADIO_POWERED); /* leave it powered */
}
else
{
@@ -954,11 +962,13 @@ bool radio_add_preset(void)
buf[27] = 0;
strcpy(presets[num_presets].name, buf);
presets[num_presets].frequency = curr_freq;
+#ifdef FM_PRESET_ADD /* only for archos */
menu_insert(preset_menu, -1,
presets[num_presets].name, 0);
/* We must still rebuild the menu table, since the
item name pointers must be updated */
rebuild_preset_menu();
+#endif
num_presets++;
radio_save_presets();
}
@@ -1183,11 +1193,10 @@ static bool toggle_mono_mode(void)
return false;
}
-
static bool scan_presets(void)
{
bool tuned = false;
- char buf[32];
+ char buf[27];
int freq, i;
char *lines[]={str(LANG_FM_CLEAR_PRESETS)};
struct text_message message={lines, 1};
@@ -1202,7 +1211,7 @@ static bool scan_presets(void)
break;
freq = curr_freq /100000;
- snprintf(buf, 32, str(LANG_FM_SCANNING), freq/10, freq % 10);
+ snprintf(buf, 27, str(LANG_FM_SCANNING), freq/10, freq % 10);
gui_syncsplash(0, true, buf);
/* Tune in and delay */
@@ -1218,11 +1227,9 @@ static bool scan_presets(void)
/* add preset */
if(tuned){
- snprintf(buf, 32, str(LANG_FM_DEFAULT_PRESET_NAME),freq/10, freq % 10);
- strcpy(presets[num_presets].name, buf);
+ snprintf(buf, 27, str(LANG_FM_DEFAULT_PRESET_NAME),freq/10, freq % 10);
+ strcpy(presets[num_presets].name,buf);
presets[num_presets].frequency = curr_freq;
- menu_insert(preset_menu, -1,
- presets[num_presets].name, 0);
num_presets++;
}
@@ -1230,13 +1237,15 @@ static bool scan_presets(void)
}
- rebuild_preset_menu();
radio_save_presets();
if(num_presets > 0 ){
curr_freq = presets[0].frequency;
radio_set(RADIO_FREQUENCY, curr_freq);
remember_frequency();
+#ifdef FM_MODE
+ radio_mode = RADIO_PRESET_MODE;
+#endif
}
}
return true;
diff --git a/apps/recorder/radio.h b/apps/recorder/radio.h
index 127bea0723..b4f4da2f4f 100644
--- a/apps/recorder/radio.h
+++ b/apps/recorder/radio.h
@@ -19,11 +19,16 @@
#ifndef RADIO_H
#define RADIO_H
+#define FMRADIO_OFF 0
+#define FMRADIO_PLAYING 1
+#define FMRADIO_PAUSED 2
+
#ifdef CONFIG_TUNER
void radio_init(void);
bool radio_screen(void);
void radio_stop(void);
bool radio_hardware_present(void);
+int get_radio_status(void);
struct fmstation
{
diff --git a/firmware/drivers/power.c b/firmware/drivers/power.c
index 055ca07ab7..830270d08a 100644
--- a/firmware/drivers/power.c
+++ b/firmware/drivers/power.c
@@ -34,11 +34,17 @@ bool charger_enabled;
#ifdef CONFIG_TUNER
-static int fmstatus = 0;
+static bool powered = false;
-void radio_set_status(int status)
+bool radio_powered()
{
- fmstatus = status;
+ return powered;
+}
+
+bool radio_power(bool status)
+{
+ bool old_status = powered;
+ powered = status;
#ifdef HAVE_TUNER_PWR_CTRL
if (status)
{
@@ -48,11 +54,7 @@ void radio_set_status(int status)
else
or_b(0x04, &PADRL); /* drive PA2 high for tuner disable */
#endif
-}
-
-int radio_get_status(void)
-{
- return fmstatus;
+ return old_status;
}
#endif /* #ifdef CONFIG_TUNER */
diff --git a/firmware/export/power.h b/firmware/export/power.h
index f0c4c302ea..bf645522ef 100644
--- a/firmware/export/power.h
+++ b/firmware/export/power.h
@@ -35,12 +35,8 @@ void spdif_power_enable(bool on);
#endif
#ifdef CONFIG_TUNER
-/* status values */
-#define FMRADIO_OFF 0 /* switched off */
-#define FMRADIO_POWERED 1 /* left powered, but idle */
-#define FMRADIO_PLAYING 2 /* actively in use */
-extern void radio_set_status(int status);
-extern int radio_get_status(void);
+extern bool radio_power(bool status);
+extern bool radio_powered(void);
#endif
#endif
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index cdf29f53b1..ed3f42287c 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -385,7 +385,7 @@ static void handle_auto_poweroff(void)
if(timeout &&
#ifdef CONFIG_TUNER
- (radio_get_status() != FMRADIO_PLAYING) &&
+ (!radio_powered()) &&
#endif
!usb_inserted() &&
((audio_stat == 0) ||