OSDN Git Service

[v1.0] Fix not up-freq on MW1/MW4@5KHz, fix to 10KHz up/down.
[openi2cradio/OpenI2CRadio.git] / akc6955.c
index 170027b..765618c 100644 (file)
--- a/akc6955.c
+++ b/akc6955.c
 #include "commondef.h"
 #include "menu.h"
 
-void akc6955_writecmd(unsigned char reg, unsigned char data)
-{
-#ifdef __SDCC
-    i2c_open(I2C_MASTER, I2C_SLEW_ON, 5);
-    I2C_START();
-    i2c_writechar(0x20);
-    i2c_writechar(reg);
-    i2c_writechar(data);
-    I2C_STOP();
-    i2c_close();
-    delay100tcy(2);
-#else
-    OpenI2C(MASTER, SLEW_OFF);
-    StartI2C();
-    WriteI2C(0x20);
-    //delay1ktcy(8);
-    WriteI2C(reg);
-    //delay1ktcy(8);
-    WriteI2C(data);
-    //delay1ktcy(8);
-    StopI2C();
- //   delay1ktcy(8);
-    CloseI2C();
-//    CLOSEASMASTER();
-#endif  //    i2c_idle();
-}
-
-unsigned char akc6955_readcmd(unsigned char reg)
-{
-    unsigned char c;
-    //    OPENASMASTER();
-#ifdef __SDCC
-    i2c_open(I2C_MASTER, I2C_SLEW_ON, 5);
-#else
-    OpenI2C(MASTER, SLEW_OFF);
-#endif
-#ifdef __SDCC
-    I2C_START();
-    i2c_writechar(0x20);
-    i2c_writechar(reg);
-    I2C_STOP();
-    delay100tcy(2);
-    I2C_START();
-    i2c_writechar(0x21);
-    c = i2c_readchar();
-    I2C_ACK();
-    I2C_STOP();
-    i2c_close();
-#else
-    StartI2C();
-    WriteI2C(0x20);
-  //  delay1ktcy(8);
-    WriteI2C(reg);
-  //  delay1ktcy(8);
-    StopI2C();
-    __delay_us(13);
-    StartI2C();
-    WriteI2C(0x21);
-  //  delay1ktcy(8);
-    c = ReadI2C();
-    AckI2C();
-    StopI2C();
- //   delay1ktcy(8);
-    CloseI2C();
-#endif
-    //    CLOSEASMASTER();
-
-    return c;
-}
 
 void akc6955_chg_fm(unsigned char f, unsigned int freq)
 {
@@ -118,13 +49,13 @@ void akc6955_chg_fm(unsigned char f, unsigned int freq)
     b.b6 = 0;
     if(f != 0){
         b.b6 = 1;
-        akc6955_set_fmband(fmband);
+        akc6955_set_fmband(setup.fmband);
         akc6955_writecmd(AKC6955_POWER, b.byte);
         akc6955_set_freq(freq);
         return;
     }
     akc6955_writecmd(AKC6955_POWER, b.byte);
-    akc6955_set_amband(amband);
+    akc6955_set_amband(setup.amband);
     akc6955_set_freq(freq);
 
 }
@@ -216,6 +147,9 @@ unsigned char akc6955_tune(void)
 void akc6955_mode3k(unsigned char flag)
 {
     __bitops_t b;
+    b.byte = akc6955_readcmd(AKC6955_CH_LO);
+    akc6955_writecmd(AKC6955_CH_LO, b.byte);
+
     b.byte = akc6955_readcmd(AKC6955_CH_HI);
     b.b5 = 0;
     if(flag != 0){
@@ -223,7 +157,6 @@ void akc6955_mode3k(unsigned char flag)
     }
     akc6955_writecmd(AKC6955_CH_HI, b.byte);
     akc6955_do_tune();
-    _AKC6955_WAIT_62_5MS();
 }
 
 void akc6955_set_tune(unsigned char mode_3k, unsigned int ch)
@@ -268,21 +201,34 @@ void akc6955_set_tune(unsigned char mode_3k, unsigned int ch)
 void akc6955_do_scan(unsigned char up)
 {
     __bitops_t b;
- //   akc6955_do_tune();
+
+    //20130823 Need wait for scan/tune completed w/o SDCC 3.3.x.
+#ifndef __SDCC
+    while(akc6955_chk_donescan() == 0)
+    {
+        idle_time_ms(5);
+    }
+#endif
     b.byte = akc6955_readcmd(AKC6955_POWER);
     b.b3 = 0;
     b.b4 = 0;
-    b.b5 = 0;
+// 20130823 : Is this collect?
+#ifdef __SDCC
+     b.b5 = 0;
     akc6955_writecmd(AKC6955_POWER, b.byte);
+    idle_time_ms(35);
+#endif
+
     b.b5 = 1; // Tune 0->1.
-    idle_time_35ms();
     akc6955_writecmd(AKC6955_POWER, b.byte);
-    idle_time_35ms();
+    idle_time_ms(35);
+
+    b.b4 = 1;
     if(up != 0) {
         b.b3= 1;
     }
-    b.b4 = 1;
     akc6955_writecmd(AKC6955_POWER, b.byte); // Raise seek bit to '1'.
+    idle_time_ms(35);
 }
 
 void akc6955_abort_scan(void)
@@ -359,8 +305,8 @@ void akc6955_set_freq(unsigned int freq)
         akc6955_get_fmband(band);
 //        band &= 7;
         if(band == AKC6955_BAND_FMUSER){
-            start = fm_usrbands[fm_userbandnum].start * 32;
-            stop = fm_usrbands[fm_userbandnum].stop * 32;
+            start = setup.fm_usrbands[setup.fm_userbandnum].start * 32;
+            stop = setup.fm_usrbands[setup.fm_userbandnum].stop * 32;
         } else {
             start = fmbands[band].start;
             stop = fmbands[band].end;
@@ -371,8 +317,8 @@ void akc6955_set_freq(unsigned int freq)
         akc6955_get_amband(band);
 //        if(band >= AKC6955_BAND_AMEND) band = AKC6955_BAND_AMEND - 1;
         if(band == AKC6955_BAND_AMUSER){
-            start = am_usrbands[am_userbandnum].start * 32;
-            stop = am_usrbands[am_userbandnum].stop * 32;
+            start = setup.am_usrbands[setup.am_userbandnum].start * 32;
+            stop = setup.am_usrbands[setup.am_userbandnum].stop * 32;
         } else {
             start = ambands[band].start;
             stop = ambands[band].end;
@@ -486,8 +432,9 @@ void akc6955_up_freq(unsigned int step)
 
     freq = akc6955_get_channel();
     freq += step;
-    mode3k.byte = akc6955_readcmd(AKC6955_CNR_AM);
-    akc6955_set_tune(mode3k.b7, freq);
+//    mode3k.byte = akc6955_readcmd(AKC6955_CNR_AM);
+//    akc6955_set_tune(mode3k.b7, freq);
+    akc6955_set_tune(setup.am_mode3k, freq);
 }
 
 
@@ -499,8 +446,9 @@ void akc6955_down_freq(unsigned int step)
     freq = akc6955_get_channel();
     if(freq <= step) return;
     freq -= step;
-    mode3k.byte = akc6955_readcmd(AKC6955_CNR_AM);
-    akc6955_set_tune(mode3k.b7, freq);
+//    mode3k.byte = akc6955_readcmd(AKC6955_CNR_AM);
+//    akc6955_set_tune(mode3k.b7, freq);
+    akc6955_set_tune(setup.am_mode3k, freq);
 }
 
 void akc6955_setvolumemode(unsigned char flag)
@@ -624,7 +572,7 @@ void akc6955_set_thresh_fmstereo(unsigned char a)
 {
     unsigned char b;
     a = a & 0x03;
-    threshold_fmstereo = a;
+    setup.threshold_fmstereo = a;
     b = akc6955_readcmd(AKC6955_THRESH) & 0xfc;
     akc6955_writecmd(AKC6955_THRESH, a | b);
 }
@@ -633,7 +581,7 @@ void akc6955_set_thresh_width(unsigned char a)
 {
     unsigned char b;
     a = a & 0x03;
-    threshold_width = a;
+    setup.threshold_width = a;
     a = a << 2; // << 2
     b = akc6955_readcmd(AKC6955_THRESH) & 0xf3;;
     akc6955_writecmd(AKC6955_THRESH, a | b);
@@ -643,7 +591,7 @@ void akc6955_set_thresh_amcnr(unsigned char a)
 {
     unsigned char b;
     a = a & 0x03;
-    threshold_amcnr = a;
+    setup.threshold_amcnr = a;
     a = a << 4; // << 4
     b = akc6955_readcmd(AKC6955_THRESH) & 0xcf;
     akc6955_writecmd(AKC6955_THRESH, a | b);
@@ -653,7 +601,7 @@ void akc6955_set_thresh_fmcnr(unsigned char a)
 {
     unsigned char b;
     a = a & 0x03;
-    threshold_fmcnr = a;
+    setup.threshold_fmcnr = a;
     a = a << 6; // << 4
     b = akc6955_readcmd(AKC6955_THRESH) & 0x3f;
     akc6955_writecmd(AKC6955_THRESH, a | b);