1
0
Fork 0
forked from len0rd/rockbox

tuner cleanup + improvements:

- use sleep and powerdown for those who can
- philips station search works now


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5306 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jörg Hohensohn 2004-10-19 08:20:38 +00:00
parent 2d6eca7e66
commit ef8d508d5a
7 changed files with 70 additions and 32 deletions

View file

@ -196,6 +196,10 @@ void init(void)
powermgmt_init();
#ifdef CONFIG_TUNER
radio_init();
#endif
#ifdef HAVE_CHARGING
if (coldstart && charger_inserted() && !global_settings.car_adapter_mode)
{
@ -288,9 +292,6 @@ void init(void)
global_settings.superbass);
mpeg_init();
talk_init();
#ifdef CONFIG_TUNER
radio_init();
#endif
#ifdef AUTOROCK
if (!usb_detect())

View file

@ -20,7 +20,6 @@
#include "config.h"
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include "sprintf.h"
#include "lcd.h"
#include "mas.h"
@ -116,11 +115,14 @@ void radio_init(void)
radio_get = samsung_get;
}
#endif
radio_set(RADIO_SLEEP, 1); /* low power mode, if available */
}
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. */
}
bool radio_hardware_present(void)
@ -128,7 +130,7 @@ bool radio_hardware_present(void)
#ifdef HAVE_TUNER_PWR_CTRL
bool ret;
int fmstatus = radio_get_status(); /* get current state */
radio_set_status(FMRADIO_PLAYING); /* power it up */
radio_set_status(FMRADIO_POWERED); /* power it up */
ret = radio_get(RADIO_PRESENT);
radio_set_status(fmstatus); /* restore previous state */
return ret;
@ -161,7 +163,7 @@ bool radio_screen(void)
bool done = false;
int button;
int freq;
int freq_diff;
bool tuned;
bool stereo = false;
int search_dir = 0;
int fw, fh;
@ -222,7 +224,7 @@ bool radio_screen(void)
curr_freq = global_settings.last_frequency * FREQ_STEP + MIN_FREQ;
radio_set(RADIO_INIT, 0);
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);
@ -255,10 +257,10 @@ bool radio_screen(void)
sleep(1);
/* Now check how close to the IF frequency we are */
freq_diff = radio_get(RADIO_DEVIATION);
tuned = radio_get(RADIO_TUNED);
/* Stop searching if the tuning is close */
if(abs(freq_diff) < 50)
if(tuned)
{
search_dir = 0;
curr_preset = find_preset(curr_freq);
@ -283,7 +285,6 @@ bool radio_screen(void)
else
#endif
{
radio_stop();
done = true;
}
update_screen = true;
@ -416,7 +417,6 @@ bool radio_screen(void)
if(mpeg_status() != MPEG_STATUS_RECORD)
{
default_event_handler(SYS_USB_CONNECTED);
radio_set_status(0);
screen_freeze = true; /* Cosmetic: makes sure the
radio screen doesn't redraw */
done = true;
@ -540,15 +540,19 @@ bool radio_screen(void)
sound_settings_apply();
radio_set_status(0);
if(keep_playing)
{
/* Enable the Left and right A/D Converter */
mpeg_set_recording_gain(mpeg_sound_default(SOUND_LEFT_GAIN),
mpeg_sound_default(SOUND_RIGHT_GAIN), false);
mas_codec_writereg(6, 0x4000);
radio_set_status(FMRADIO_POWERED); /* leave it powered */
}
else
{
radio_stop();
}
#endif
return have_recorded;
}
@ -848,12 +852,16 @@ static bool toggle_mono_mode(void)
bool radio_menu(void)
{
struct menu_item items[3];
struct menu_item items[4];
int m;
bool result;
m = menu_init(items, 0, NULL, NULL, NULL, NULL);
#if CONFIG_KEYPAD == ONDIO_PAD /* Ondio has no key for presets, put it in menu */
/* fixme: make a real string table entry */
menu_insert(m, -1, ID2P(LANG_FM_BUTTONBAR_PRESETS), handle_radio_presets_menu);
#endif
create_monomode_menu();
menu_insert(m, -1, monomode_menu_string, toggle_mono_mode);
menu_insert(m, -1, ID2P(LANG_SOUND_SETTINGS), sound_menu);

View file

@ -31,7 +31,10 @@ bool ide_powered(void);
void power_off(void);
#ifdef CONFIG_TUNER
#define FMRADIO_PLAYING 1
/* 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);
#endif

View file

@ -21,7 +21,7 @@
#define __TUNER_SAMSUNG_H__
/* settings to the tuner layer */
#define RADIO_INIT 0
#define RADIO_SLEEP 0
#define RADIO_FREQUENCY 1
#define RADIO_MUTE 2
#define RADIO_IF_MEASUREMENT 3
@ -29,8 +29,9 @@
#define RADIO_FORCE_MONO 5
/* readback from the tuner layer */
#define RADIO_PRESENT 0
#define RADIO_DEVIATION 1
#define RADIO_TUNED 1
#define RADIO_STEREO 2
#define RADIO_ALL 3 /* debug */
#ifdef CONFIG_TUNER

View file

@ -322,7 +322,7 @@ static void handle_auto_poweroff(void)
if(timeout &&
#ifdef CONFIG_TUNER
!radio_get_status() &&
(radio_get_status() != FMRADIO_PLAYING) &&
#endif
!usb_inserted() &&
(mpeg_stat == 0 ||

View file

@ -20,6 +20,8 @@
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include "kernel.h"
#include "tuner.h" /* tuner abstraction interface */
#include "fmradio_i2c.h" /* physical interface driver */
@ -31,8 +33,17 @@ void philips_set(int setting, int value)
{
switch(setting)
{
case RADIO_INIT:
memset(write_bytes, 0, sizeof(write_bytes));
case RADIO_SLEEP:
/* init values */
write_bytes[0] = 0x80; /* mute */
write_bytes[1] = 0x00;
write_bytes[2] = 0x00;
write_bytes[3] = 0x0A; /* soft mute, stereo noise cancelling */
write_bytes[4] = 0x00;
if (value) /* sleep */
{
write_bytes[3] |= 0x40; /* standby mode */
}
break;
case RADIO_FREQUENCY:
@ -53,8 +64,6 @@ void philips_set(int setting, int value)
fmradio_i2c_write(I2C_ADR, write_bytes, sizeof(write_bytes));
break;
case RADIO_IF_MEASUREMENT:
case RADIO_SENSITIVITY:
default:
return;
}
@ -75,14 +84,25 @@ int philips_get(int setting)
val = 1; /* true */
break;
case RADIO_DEVIATION:
val = read_bytes[2] & 0x7F;
val = 222 - val*4; /* convert to kHz */
case RADIO_TUNED:
val = 0;
if (read_bytes[0] & 0x80) /* ready */
{
val = read_bytes[2] & 0x7F; /* IF counter */
val = (abs(val - 0x36) < 2); /* close match */
}
break;
case RADIO_STEREO:
val = read_bytes[2] >> 7;
break;
case RADIO_ALL: /* debug query */
val = read_bytes[0] << 24
| read_bytes[1] << 16
| read_bytes[2] << 8
| read_bytes[3];
break;
}
return val;
}

View file

@ -19,6 +19,7 @@
****************************************************************************/
#include <stdbool.h>
#include <stdlib.h>
#include "tuner.h" /* tuner abstraction interface */
#include "fmradio.h" /* physical interface driver */
@ -35,11 +36,15 @@ void samsung_set(int setting, int value)
{
switch(setting)
{
case RADIO_INIT:
case RADIO_SLEEP:
if (!value)
{ /* wakeup: just unit */
fm_in1 = DEFAULT_IN1;
fm_in2 = DEFAULT_IN2;
fmradio_set(1, fm_in1);
fmradio_set(2, fm_in2);
}
/* else we have no sleep mode? */
break;
case RADIO_FREQUENCY:
@ -96,9 +101,9 @@ int samsung_get(int setting)
val = (val == 0x140885);
break;
case RADIO_DEVIATION:
case RADIO_TUNED:
val = fmradio_read(3);
val = 10700 - ((val & 0x7ffff) / 8); /* convert to kHz */
val = abs(10700 - ((val & 0x7ffff) / 8)) < 50; /* convert to kHz */
break;
case RADIO_STEREO: