Index: apps/recorder/radio.c =================================================================== --- apps/recorder/radio.c (revision 19194) +++ apps/recorder/radio.c (working copy) @@ -50,7 +50,6 @@ #include "recording.h" #endif #include "talk.h" -#include "tuner.h" #include "power.h" #include "sound.h" #include "screen_access.h" @@ -110,11 +109,9 @@ #define RADIO_PRESET_MODE 1 static int curr_preset = -1; -static int curr_freq; -static int radio_mode = RADIO_SCAN_MODE; static int search_dir = 0; +static int radio_mode = RADIO_SCAN_MODE; -static int radio_status = FMRADIO_OFF; static bool in_screen = false; #define MAX_PRESETS 64 @@ -148,116 +145,11 @@ return ret; } -void radio_init(void) -{ - tuner_init(); - radio_stop(); -} - -int get_radio_status(void) -{ - return radio_status; -} - bool in_radio_screen(void) { return in_screen; } -/* TODO: Move some more of the control functionality to firmware - and clean up the mess */ - -/* secret flag for starting paused - prevents unmute */ -#define FMRADIO_START_PAUSED 0x8000 -void radio_start(void) -{ - const struct fm_region_data *fmr; - bool start_paused; - - if(radio_status == FMRADIO_PLAYING) - return; - - fmr = &fm_region_data[global_settings.fm_region]; - - start_paused = radio_status & FMRADIO_START_PAUSED; - /* clear flag before any yielding */ - radio_status &= ~FMRADIO_START_PAUSED; - - if(radio_status == FMRADIO_OFF) - tuner_power(true); - - curr_freq = global_status.last_frequency * fmr->freq_step + fmr->freq_min; - - tuner_set(RADIO_SLEEP, 0); /* wake up the tuner */ - - if(radio_status == FMRADIO_OFF) - { -#ifdef HAVE_RADIO_REGION - tuner_set(RADIO_REGION, global_settings.fm_region); -#endif - tuner_set(RADIO_FORCE_MONO, global_settings.fm_force_mono); - } - - tuner_set(RADIO_FREQUENCY, curr_freq); - -#ifdef HAVE_RADIO_MUTE_TIMEOUT - { - unsigned long mute_timeout = current_tick + HZ; - if (radio_status != FMRADIO_OFF) - { - /* paused */ - mute_timeout += HZ; - } - - while(!tuner_get(RADIO_STEREO) && !tuner_get(RADIO_TUNED)) - { - if(TIME_AFTER(current_tick, mute_timeout)) - break; - yield(); - } - } -#endif - - /* keep radio from sounding initially */ - if(!start_paused) - tuner_set(RADIO_MUTE, 0); - - radio_status = FMRADIO_PLAYING; -} /* radio_start */ - -void radio_pause(void) -{ - if(radio_status == FMRADIO_PAUSED) - return; - - if(radio_status == FMRADIO_OFF) - { - radio_status |= FMRADIO_START_PAUSED; - radio_start(); - } - - tuner_set(RADIO_MUTE, 1); - tuner_set(RADIO_SLEEP, 1); - - radio_status = FMRADIO_PAUSED; -} /* radio_pause */ - -void radio_stop(void) -{ - if(radio_status == FMRADIO_OFF) - return; - - tuner_set(RADIO_MUTE, 1); - tuner_set(RADIO_SLEEP, 1); /* low power mode, if available */ - radio_status = FMRADIO_OFF; - tuner_power(false); /* status update, power off if avail. */ -} /* radio_stop */ - -bool radio_hardware_present(void) -{ - return tuner_get(RADIO_PRESENT); -} - /* Keep freq on the grid for the current region */ static int snap_freq_to_grid(int freq) { @@ -323,15 +215,13 @@ static void remember_frequency(void) { - const struct fm_region_data * const fmr = - &fm_region_data[global_settings.fm_region]; - global_status.last_frequency = (curr_freq - fmr->freq_min) - / fmr->freq_step; + global_status.last_frequency = radio_get_station(); status_save(); } static void next_preset(int direction) { + int curr_freq = radio_get_frequency(); if (num_presets < 1) return; @@ -342,8 +232,7 @@ /* Must stay on the current grid for the region */ curr_freq = snap_freq_to_grid(presets[curr_preset].frequency); - - tuner_set(RADIO_FREQUENCY, curr_freq); + radio_set_frequency(curr_freq); remember_frequency(); } @@ -369,6 +258,7 @@ /* Step to the next or previous station */ static void next_station(int direction) { + int curr_freq = radio_get_frequency(); if (direction != 0 && radio_mode != RADIO_SCAN_MODE) { next_preset(direction); @@ -377,13 +267,13 @@ curr_freq = step_freq(curr_freq, direction); - if (radio_status == FMRADIO_PLAYING) - tuner_set(RADIO_MUTE, 1); + if (radio_get_status() == FMRADIO_PLAYING) + radio_mute(true); - tuner_set(RADIO_FREQUENCY, curr_freq); + radio_set_frequency(curr_freq); - if (radio_status == FMRADIO_PLAYING) - tuner_set(RADIO_MUTE, 0); + if (radio_get_status() == FMRADIO_PLAYING) + radio_mute(false); curr_preset = find_preset(curr_freq); remember_frequency(); @@ -392,8 +282,8 @@ /* Ends an in-progress search */ static void end_search(void) { - if (search_dir != 0 && radio_status == FMRADIO_PLAYING) - tuner_set(RADIO_MUTE, 0); + if (search_dir != 0 && radio_get_status() == FMRADIO_PLAYING) + radio_mute(false); search_dir = 0; } @@ -437,6 +327,7 @@ bool keep_playing = false; bool statusbar = global_settings.statusbar; bool talk = false; + int curr_freq; #ifdef FM_RECORD_DBLPRE int lastbutton = BUTTON_NONE; unsigned long rec_lastclick = 0; @@ -491,8 +382,9 @@ radio_load_presets(global_settings.fmr_file); } - if(radio_status == FMRADIO_OFF) + if(radio_get_status() == FMRADIO_OFF) audio_stop(); + curr_freq = radio_get_frequency(); #ifndef SIMULATOR #if CONFIG_CODEC != SWCODEC @@ -520,10 +412,10 @@ /* turn on radio */ #if CONFIG_CODEC == SWCODEC audio_set_input_source(AUDIO_SRC_FMRADIO, - (radio_status == FMRADIO_PAUSED) ? + (radio_get_status() == FMRADIO_PAUSED) ? SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING); #else - if (radio_status == FMRADIO_OFF) + if (radio_get_status() == FMRADIO_OFF) radio_start(); #endif @@ -547,10 +439,11 @@ { if(search_dir != 0) { + curr_freq = radio_get_frequency(); curr_freq = step_freq(curr_freq, search_dir); update_screen = true; - if(tuner_set(RADIO_SCAN_FREQUENCY, curr_freq)) + if(radio_scan_frequency(curr_freq)) { curr_preset = find_preset(curr_freq); remember_frequency(); @@ -710,7 +603,7 @@ break; case ACTION_FM_PLAY: - if (radio_status == FMRADIO_PLAYING) + if (radio_get_status() == FMRADIO_PLAYING) radio_pause(); else radio_start(); @@ -876,7 +769,7 @@ #endif /* CONFIG_CODEC == SWCODEC */ /* keep "mono" from always being displayed when paused */ - if (radio_status != FMRADIO_PAUSED) + if (radio_get_status() != FMRADIO_PAUSED) { stereo = tuner_get(RADIO_STEREO) && !global_settings.fm_force_mono; @@ -968,7 +861,7 @@ update_screen = false; if (global_settings.talk_file && talk - && radio_status == FMRADIO_PAUSED) + && radio_get_status() == FMRADIO_PAUSED) { talk = false; bool enqueue = false; @@ -1161,7 +1054,7 @@ struct fmstation * const fms = &presets[num_presets]; buf[MAX_FMPRESET_LEN] = '\0'; strcpy(fms->name, buf); - fms->frequency = curr_freq; + fms->frequency = radio_get_frequency(); num_presets++; presets_changed = true; presets_loaded = num_presets > 0; @@ -1382,7 +1275,7 @@ break; case ACTION_STD_OK: curr_preset = gui_synclist_get_sel_pos(&lists); - curr_freq = presets[curr_preset].frequency; + radio_set_frequency(presets[curr_preset].frequency); next_station(0); remember_frequency(); result = 1; @@ -1403,19 +1296,11 @@ return result - 1; } -void toggle_mono_mode(bool mono) -{ - tuner_set(RADIO_FORCE_MONO, mono); -} - void set_radio_region(int region) { -#ifdef HAVE_RADIO_REGION - tuner_set(RADIO_REGION, region); -#endif + radio_set_region(region); next_station(0); remember_frequency(); - (void)region; } MENUITEM_SETTING(set_region, &global_settings.fm_region, NULL); @@ -1455,6 +1340,7 @@ if(do_scan) { + int curr_freq; const struct fm_region_data * const fmr = &fm_region_data[global_settings.fm_region]; @@ -1475,7 +1361,7 @@ splashf(0, str(LANG_FM_SCANNING), freq, frac); - if(tuner_set(RADIO_SCAN_FREQUENCY, curr_freq)) + if(radio_scan_frequency(curr_freq)) { /* add preset */ presets[num_presets].name[0] = '\0'; @@ -1486,7 +1372,7 @@ curr_freq += fmr->freq_step; } - if (radio_status == FMRADIO_PLAYING) + if (radio_get_status() == FMRADIO_PLAYING) tuner_set(RADIO_MUTE, 0); presets_changed = true; @@ -1499,7 +1385,7 @@ if(num_presets > 0) { - curr_freq = presets[0].frequency; + radio_set_frequency(presets[0].frequency); radio_mode = RADIO_PRESET_MODE; presets_loaded = true; next_station(0); Index: apps/recorder/radio.h =================================================================== --- apps/recorder/radio.h (revision 19194) +++ apps/recorder/radio.h (working copy) @@ -27,13 +27,8 @@ #if CONFIG_TUNER void radio_load_presets(char *filename); -void radio_init(void); -int radio_screen(void); -void radio_start(void); -void radio_pause(void); -void radio_stop(void); -bool radio_hardware_present(void); bool in_radio_screen(void); +int radio_screen(void); /* callbacks for the radio settings */ void set_radio_region(int region); void toggle_mono_mode(bool mono); Index: apps/recorder/recording.c =================================================================== --- apps/recorder/recording.c (revision 19194) +++ apps/recorder/recording.c (working copy) @@ -995,7 +995,7 @@ * 2) 1) and the source was never changed to something else */ int radio_status = (global_settings.rec_source != AUDIO_SRC_FMRADIO) ? - FMRADIO_OFF : get_radio_status(); + FMRADIO_OFF : radio_get_status(); #endif #if (CONFIG_LED == LED_REAL) bool led_state = false; Index: apps/settings_list.c =================================================================== --- apps/settings_list.c (revision 19194) +++ apps/settings_list.c (working copy) @@ -47,6 +47,7 @@ #endif #include "menus/eq_menu.h" #if CONFIG_TUNER +#include "fmradio.h" #include "radio.h" #endif @@ -602,7 +603,7 @@ /* tuner */ #if CONFIG_TUNER OFFON_SETTING(0,fm_force_mono, LANG_FM_MONO_MODE, - false, "force fm mono", toggle_mono_mode), + false, "force fm mono", radio_mono_mode), SYSTEM_SETTING(NVRAM(4),last_frequency,0), #endif Index: apps/status.c =================================================================== --- apps/status.c (revision 19194) +++ apps/status.c (working copy) @@ -46,7 +46,7 @@ #endif #include "usb.h" #if CONFIG_TUNER -#include "radio.h" +#include "fmradio.h" #endif #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC #include "pcm_record.h" @@ -99,7 +99,7 @@ #endif #if CONFIG_TUNER - audio_stat = get_radio_status(); + audio_stat = radio_get_status(); if(audio_stat & FMRADIO_PLAYING) return STATUS_RADIO; Index: firmware/export/tuner.h =================================================================== --- firmware/export/tuner.h (revision 19194) +++ firmware/export/tuner.h (working copy) @@ -63,15 +63,6 @@ TUNER_NUM_REGIONS }; -struct fm_region_data -{ - int freq_min; - int freq_max; - int freq_step; -}; - -extern const struct fm_region_data fm_region_data[TUNER_NUM_REGIONS]; - #if CONFIG_TUNER #ifdef SIMULATOR Index: firmware/export/fmradio.h =================================================================== --- firmware/export/fmradio.h (revision 19194) +++ firmware/export/fmradio.h (working copy) @@ -6,7 +6,7 @@ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id$ - * Driver to control the (Samsung) tuner via port-banging SPI + * Generic radio layer between apps and radio driver * * Copyright (C) 2002 by Linus Nielsen Feltzing * @@ -22,18 +22,36 @@ #ifndef FMRADIO_H #define FMRADIO_H -/** declare some stuff here so powermgmt.c can properly tell if the radio is - actually playing and not just paused. This break in heirarchy is allowed - for audio_status(). **/ +#include "tuner.h" +struct fm_region_data +{ + int freq_min; + int freq_max; + int freq_step; +}; +extern const struct fm_region_data fm_region_data[TUNER_NUM_REGIONS]; /* set when radio is playing or paused within fm radio screen */ #define FMRADIO_OFF 0x0 #define FMRADIO_PLAYING 0x1 #define FMRADIO_PAUSED 0x2 +#define FMRADIO_START_PAUSED 0x8000 -extern int get_radio_status(void); +void radio_init(void); +int radio_get_status(void); +void radio_set_region(int region); +void radio_mono_mode(bool mono); +void radio_start(void); +void radio_pause(void); +void radio_stop(void); +bool radio_hardware_present(void); -extern int fmradio_read(int addr); -extern void fmradio_set(int addr, int data); +void radio_mute(bool mute); +void radio_set_station(int station); +int radio_get_station(void); +int radio_get_frequency(void); +void radio_set_frequency(int freq); +bool radio_scan_frequency(int freq); + #endif Index: firmware/export/fmradio_serial.h =================================================================== --- firmware/export/fmradio_serial.h (revision 19194) +++ firmware/export/fmradio_serial.h (working copy) @@ -19,21 +19,10 @@ * KIND, either express or implied. * ****************************************************************************/ -#ifndef FMRADIO_H -#define FMRADIO_H +#ifndef FMRADIO_SERIAL_H +#define FMRADIO_SERIAL_H -/** declare some stuff here so powermgmt.c can properly tell if the radio is - actually playing and not just paused. This break in heirarchy is allowed - for audio_status(). **/ +extern int fmradio_serial_read(int addr); +extern void fmradio_serial_set(int addr, int data); -/* set when radio is playing or paused within fm radio screen */ -#define FMRADIO_OFF 0x0 -#define FMRADIO_PLAYING 0x1 -#define FMRADIO_PAUSED 0x2 - -extern int get_radio_status(void); - -extern int fmradio_read(int addr); -extern void fmradio_set(int addr, int data); - #endif Property changes on: firmware/export/fmradio_serial.h ___________________________________________________________________ Added: svn:mergeinfo Index: firmware/SOURCES =================================================================== --- firmware/SOURCES (revision 19194) +++ firmware/SOURCES (working copy) @@ -168,12 +168,13 @@ /* Tuner */ #if CONFIG_TUNER tuner.c +fmradio.c #ifndef SIMULATOR #if (CONFIG_TUNER & LV24020LP) drivers/tuner/lv24020lp.c #endif /* (CONFIG_TUNER & LV24020LP) */ #if (CONFIG_TUNER & S1A0903X01) -drivers/fmradio.c +target/sh/fmradio_serial.c drivers/tuner/s1a0903x01.c #endif /* (CONFIG_TUNER & S1A0903X01) */ #if (CONFIG_TUNER & TEA5767) Property changes on: firmware/target/sh/fmradio_serial.c ___________________________________________________________________ Added: svn:mergeinfo Index: firmware/powermgmt.c =================================================================== --- firmware/powermgmt.c (revision 19194) +++ firmware/powermgmt.c (working copy) @@ -443,7 +443,7 @@ if(timeout && #if CONFIG_TUNER && !defined(BOOTLOADER) - (!(get_radio_status() & FMRADIO_PLAYING)) && + (!(radio_get_status() & FMRADIO_PLAYING)) && #endif !usb_inserted() && ((audio_stat == 0) || Index: firmware/drivers/fmradio.c =================================================================== --- firmware/drivers/fmradio.c (revision 19194) +++ firmware/drivers/fmradio.c (working copy) @@ -1,121 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Linus Nielsen Feltzing - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ -#include "lcd.h" -#include "sh7034.h" -#include "kernel.h" -#include "thread.h" -#include "debug.h" -#include "system.h" -#include "fmradio.h" - -#if CONFIG_TUNER - -/* Signals: - DI (Data In) - PB0 (doubles as data pin for the LCD) - CL (Clock) - PB1 (doubles as clock for the LCD) - CE (Chip Enable) - PB3 (also chip select for the LCD, but active low) - DO (Data Out) - PB4 -*/ - -/* cute little functions */ -#define CE_LO and_b(~0x08, PBDRL_ADDR) -#define CE_HI or_b(0x08, PBDRL_ADDR) -#define CL_LO and_b(~0x02, PBDRL_ADDR) -#define CL_HI or_b(0x02, PBDRL_ADDR) -#define DO (PBDR & 0x10) -#define DI_LO and_b(~0x01, PBDRL_ADDR) -#define DI_HI or_b(0x01, PBDRL_ADDR) - -#define START or_b((0x08 | 0x02), PBDRL_ADDR) - -/* delay loop */ -#define DELAY do { int _x; for(_x=0;_x<10;_x++);} while (0) - - -int fmradio_read(int addr) -{ - int i; - int data = 0; - - START; - - /* First address bit */ - CL_LO; - if(addr & 2) - DI_HI; - else - DI_LO; - DELAY; - CL_HI; - DELAY; - - /* Second address bit */ - CL_LO; - if(addr & 1) - DI_HI; - else - DI_LO; - DELAY; - CL_HI; - DELAY; - - for(i = 0; i < 21;i++) - { - CL_LO; - DELAY; - data <<= 1; - data |= (DO)?1:0; - CL_HI; - DELAY; - } - - CE_LO; - - return data; -} - -void fmradio_set(int addr, int data) -{ - int i; - - /* Include the address in the data */ - data |= addr << 21; - - START; - - for(i = 0; i < 23;i++) - { - CL_LO; - DELAY; - if(data & (1 << 22)) - DI_HI; - else - DI_LO; - - data <<= 1; - CL_HI; - DELAY; - } - - CE_LO; -} - -#endif Index: firmware/drivers/tuner/s1a0903x01.c =================================================================== --- firmware/drivers/tuner/s1a0903x01.c (revision 19194) +++ firmware/drivers/tuner/s1a0903x01.c (working copy) @@ -25,7 +25,7 @@ #include "config.h" #include "kernel.h" #include "tuner.h" /* tuner abstraction interface */ -#include "fmradio.h" /* physical interface driver */ +#include "fmradio_serial.h" /* physical interface driver */ #include "sound.h" #include "mas.h" @@ -49,8 +49,8 @@ { /* wakeup: just unit */ fm_in1 = DEFAULT_IN1; fm_in2 = DEFAULT_IN2; - fmradio_set(1, fm_in1); - fmradio_set(2, fm_in2); + fmradio_serial_set(1, fm_in1); + fmradio_serial_set(2, fm_in2); } /* else we have no sleep mode? */ break; @@ -92,7 +92,7 @@ ** 0x000002 == Microprocessor controlled Mute */ fm_in1 = (fm_in1 & 0xfff00007) | (pll_cnt << 3); - fmradio_set(1, fm_in1); + fmradio_serial_set(1, fm_in1); break; } @@ -102,31 +102,31 @@ sleep(1); /* Start IF measurement */ fm_in1 |= 4; - fmradio_set(1, fm_in1); + fmradio_serial_set(1, fm_in1); sleep(1); val = s1a0903x01_get(RADIO_TUNED); break; case RADIO_MUTE: fm_in1 = (fm_in1 & 0xfffffffe) | (value?1:0); - fmradio_set(1, fm_in1); + fmradio_serial_set(1, fm_in1); break; case RADIO_FORCE_MONO: fm_in2 = (fm_in2 & 0xfffffffb) | (value?0:4); - fmradio_set(2, fm_in2); + fmradio_serial_set(2, fm_in2); break; /* NOTE: These were only zeroed when starting the tuner from OFF but the default values already set them to 0. */ #if 0 case S1A0903X01_IF_MEASUREMENT: fm_in1 = (fm_in1 & 0xfffffffb) | (value?4:0); - fmradio_set(1, fm_in1); + fmradio_sserial_et(1, fm_in1); break; case S1A0903X01_SENSITIVITY: fm_in2 = (fm_in2 & 0xffff9fff) | ((value & 3) << 13); - fmradio_set(2, fm_in2); + fmradio_serial_set(2, fm_in2); break; #endif default: @@ -149,8 +149,8 @@ bool fmstatus = tuner_power(true); #endif /* 5kHz, 7.2MHz crystal, test mode 1 */ - fmradio_set(2, 0x140885); - fm_present = (fmradio_read(0) == 0x140885); + fmradio_serial_set(2, 0x140885); + fm_present = (fmradio_serial_read(0) == 0x140885); #ifdef HAVE_TUNER_PWR_CTRL if (!fmstatus) tuner_power(false); @@ -161,12 +161,12 @@ break; case RADIO_TUNED: - val = fmradio_read(3); + val = fmradio_serial_read(3); val = abs(10700 - ((val & 0x7ffff) / 8)) < 50; /* convert to kHz */ break; case RADIO_STEREO: - val = fmradio_read(3); + val = fmradio_serial_read(3); val = ((val & 0x100000) ? true : false); break; } Index: firmware/tuner.c =================================================================== --- firmware/tuner.c (revision 19194) +++ firmware/tuner.c (working copy) @@ -25,15 +25,6 @@ #include "tuner.h" #include "fmradio.h" -/* General region information */ -const struct fm_region_data fm_region_data[TUNER_NUM_REGIONS] = -{ - [REGION_EUROPE] = { 87500000, 108000000, 50000 }, - [REGION_US_CANADA] = { 87900000, 107900000, 200000 }, - [REGION_JAPAN] = { 76000000, 90000000, 100000 }, - [REGION_KOREA] = { 87500000, 108000000, 100000 } -}; - #ifndef SIMULATOR /* Tuner-specific region information */