OSDN Git Service

[Doc] GITLOG to v1.0beta1.1.
[openi2cradio/OpenI2CRadio.git] / akc6955.c
index 33534df..181cea9 100644 (file)
--- a/akc6955.c
+++ b/akc6955.c
 #include "idle.h"
 #include "power.h"
 #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)
 {
@@ -117,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);
 
 }
@@ -239,7 +171,7 @@ void akc6955_set_tune(unsigned char mode_3k, unsigned int ch)
     } while(comp == 0x00);
     f.byte = akc6955_readcmd(AKC6955_POWER);
     band = 0;
-    if(f.b6 == 0){
+    if(!f.b6){
         akc6955_get_amband(band);
     }
 
@@ -358,20 +290,20 @@ 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;
         }
         ch = freq - 3000;
-        ch = (ch * 4) / 10;
+        ch = (ch << 2) / 10;
     } else {
         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;
@@ -560,9 +492,9 @@ void akc6955_setphase(unsigned char flag)
     __bitops_t c;
     c.byte = akc6955_readcmd(AKC6955_VOLUME);
 
-    c.b0 = 0;
-    if(flag != 0) {
-        c.b0 = 1; //
+    c.b0 = 1;
+    if(flag == 0) {
+        c.b0 = 0; //
     }
     akc6955_writecmd(AKC6955_VOLUME, c.byte);
 }
@@ -571,9 +503,9 @@ void akc6955_setline(unsigned char flag)
 {
     __bitops_t c;
     c.byte = akc6955_readcmd(AKC6955_VOLUME);
-    c.b1 = 0;
-    if(flag != 0) {
-        c.b1 = 1;
+    c.b1 = 1;
+    if(flag == 0) {
+        c.b1 = 0;
     }
     akc6955_writecmd(AKC6955_VOLUME, c.byte);
 }
@@ -582,9 +514,9 @@ void akc6955_set_lowboost(unsigned char flag)
 {
     __bitops_t c;
     c.byte = akc6955_readcmd(AKC6955_STEREO);
-    c.b3 = 0;
-    if(flag != 0) {
-        c.b3 = 1;
+    c.b3 = 1;
+    if(flag == 0) {
+        c.b3 = 0;
     }
     akc6955_writecmd(AKC6955_STEREO, c.byte);
 }
@@ -619,3 +551,41 @@ unsigned int akc6955_get_battery(void)
     return batt;
 }
 
+void akc6955_set_thresh_fmstereo(unsigned char a)
+{
+    unsigned char b;
+    a = a & 0x03;
+    setup.threshold_fmstereo = a;
+    b = akc6955_readcmd(AKC6955_THRESH) & 0xfc;
+    akc6955_writecmd(AKC6955_THRESH, a | b);
+}
+
+void akc6955_set_thresh_width(unsigned char a)
+{
+    unsigned char b;
+    a = a & 0x03;
+    setup.threshold_width = a;
+    a = a << 2; // << 2
+    b = akc6955_readcmd(AKC6955_THRESH) & 0xf3;;
+    akc6955_writecmd(AKC6955_THRESH, a | b);
+}
+
+void akc6955_set_thresh_amcnr(unsigned char a)
+{
+    unsigned char b;
+    a = a & 0x03;
+    setup.threshold_amcnr = a;
+    a = a << 4; // << 4
+    b = akc6955_readcmd(AKC6955_THRESH) & 0xcf;
+    akc6955_writecmd(AKC6955_THRESH, a | b);
+}
+
+void akc6955_set_thresh_fmcnr(unsigned char a)
+{
+    unsigned char b;
+    a = a & 0x03;
+    setup.threshold_fmcnr = a;
+    a = a << 6; // << 4
+    b = akc6955_readcmd(AKC6955_THRESH) & 0x3f;
+    akc6955_writecmd(AKC6955_THRESH, a | b);
+}