minor touchup, to make the tuner interface independent from the IF


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5302 a1c6a512-1295-4272-9138-f99709370657
diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c
index 9eac63a..d60d1bd 100644
--- a/apps/recorder/radio.c
+++ b/apps/recorder/radio.c
@@ -20,6 +20,7 @@
 #include "config.h"
 #include <stdio.h>
 #include <stdbool.h>
+#include <stdlib.h>
 #include "sprintf.h"
 #include "lcd.h"
 #include "mas.h"
@@ -160,7 +161,7 @@
     bool done = false;
     int button;
     int freq;
-    int i_freq;
+    int freq_diff;
     bool stereo = false;
     int search_dir = 0;
     int fw, fh;
@@ -254,10 +255,10 @@
             sleep(1);
 
             /* Now check how close to the IF frequency we are */
-            i_freq = radio_get(RADIO_IF_MEASURED);
+            freq_diff = radio_get(RADIO_DEVIATION);
 
-            /* Stop searching if the IF frequency is close to 10.7MHz */
-            if(i_freq > 1065 && i_freq < 1075)
+            /* Stop searching if the tuning is close */
+            if(abs(freq_diff) < 50)
             {
                 search_dir = 0;
                 curr_preset = find_preset(curr_freq);
diff --git a/firmware/export/tuner.h b/firmware/export/tuner.h
index ae31c6d..c399bb3 100644
--- a/firmware/export/tuner.h
+++ b/firmware/export/tuner.h
@@ -29,7 +29,7 @@
 #define RADIO_FORCE_MONO 5
 /* readback from the tuner layer */
 #define RADIO_PRESENT 0
-#define RADIO_IF_MEASURED 1
+#define RADIO_DEVIATION 1
 #define RADIO_STEREO 2
 
 #ifdef CONFIG_TUNER
diff --git a/firmware/tuner_philips.c b/firmware/tuner_philips.c
index e63d063..3fdf0f7 100644
--- a/firmware/tuner_philips.c
+++ b/firmware/tuner_philips.c
@@ -29,7 +29,6 @@
 /* tuner abstraction layer: set something to the tuner */
 void philips_set(int setting, int value)
 {
-    (void)value;
     switch(setting)
     {
         case RADIO_INIT:
@@ -42,33 +41,31 @@
                 n = (4 * (value - 225000)) / 50000;
                 write_bytes[0] = (write_bytes[0] & 0xC0) | (n >> 8);
                 write_bytes[1] = n & 0xFF;
-                fmradio_i2c_write(I2C_ADR, write_bytes, sizeof(write_bytes));
             }
             break;
 
         case RADIO_MUTE:
             write_bytes[0] = (write_bytes[0] & 0x7F) | (value ? 0x80 : 0);
-            fmradio_i2c_write(I2C_ADR, write_bytes, sizeof(write_bytes));
-            break;
-
-        case RADIO_IF_MEASUREMENT:
-            break;
-
-        case RADIO_SENSITIVITY:
             break;
 
         case RADIO_FORCE_MONO:
             write_bytes[2] = (write_bytes[2] & 0xF7) | (value ? 0x08 : 0);
             fmradio_i2c_write(I2C_ADR, write_bytes, sizeof(write_bytes));
             break;
+
+        case RADIO_IF_MEASUREMENT:
+        case RADIO_SENSITIVITY:
+        default:
+            return;
     }
+    fmradio_i2c_write(I2C_ADR, write_bytes, sizeof(write_bytes));
 }
 
 /* tuner abstraction layer: read something from the tuner */
 int philips_get(int setting)
 {
     unsigned char read_bytes[5];
-    int val = -1;
+    int val = -1; /* default for unsupported query */
 
     fmradio_i2c_read(I2C_ADR, read_bytes, sizeof(read_bytes));
 
@@ -78,9 +75,9 @@
             val = 1; /* true */
             break;
 
-        case RADIO_IF_MEASURED:
+        case RADIO_DEVIATION:
             val = read_bytes[2] & 0x7F;
-            val = 1070 + (val-55)/2;
+            val = 222 - val*4; /* convert to kHz */
             break;
 
         case RADIO_STEREO:
diff --git a/firmware/tuner_samsung.c b/firmware/tuner_samsung.c
index 781a4bc..98166e1 100644
--- a/firmware/tuner_samsung.c
+++ b/firmware/tuner_samsung.c
@@ -96,9 +96,9 @@
             val = (val == 0x140885);
             break;
 
-        case RADIO_IF_MEASURED:
+        case RADIO_DEVIATION:
             val = fmradio_read(3);
-            val = (val & 0x7ffff) / 80; /* convert to kHz */
+            val = 10700 - ((val & 0x7ffff) / 8); /* convert to kHz */
             break;
 
         case RADIO_STEREO: