OSDN Git Service

[AKC6955] Remove #define type function, re-decl.function to save memory.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 27 Sep 2013 07:42:42 +0000 (16:42 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 27 Sep 2013 07:42:42 +0000 (16:42 +0900)
akc6955.c
akc6955.h
eeprom_util.h
eepromutil.c
lcd_acm1602.c
lcd_acm1602.h
menu_setup.c
menu_userband.c
radio_getstat.c
ui.c
ui.h

index 24f3581..355a7d3 100644 (file)
--- a/akc6955.c
+++ b/akc6955.c
 #include "commondef.h"
 #include "menu.h"
 
+unsigned char akc6955_readcmd(unsigned char reg)
+{
+   return i2c_read_byte(AKC6955_ADDRESS, reg);
+}
+
+void akc6955_writecmd(unsigned char reg,unsigned char data)
+{
+    i2c_send_byte(AKC6955_ADDRESS, reg, data);
+}
+
+unsigned char akc6955_get_amband(void)
+{
+   return akc6955_get_band() >> 3; 
+}
+
+unsigned char akc6955_get_fmband(void)
+{
+   return akc6955_get_band() & 0x07; 
+}
+
 
 void akc6955_chg_fm(unsigned char f, unsigned int freq)
 {
@@ -175,7 +195,7 @@ void akc6955_set_tune(unsigned char mode_3k, unsigned int ch)
     f.byte = akc6955_readcmd(AKC6955_POWER);
     band = 0;
     if(!f.b6){
-        akc6955_get_amband(band);
+        band = akc6955_get_amband();
         start = ambands[band].start;
         stop  = ambands[band].end;
         if(band == AKC6955_BAND_AMUSER){
@@ -191,7 +211,7 @@ void akc6955_set_tune(unsigned char mode_3k, unsigned int ch)
             }
         }
     } else {
-        akc6955_get_fmband(band);
+        band = akc6955_get_fmband();
         start = ((fmbands[band].start - 3000) * 2) / 5;
         stop = ((fmbands[band].end - 3000) * 2) / 5;;
         if(band == AKC6955_BAND_FMUSER){
@@ -308,7 +328,7 @@ unsigned int akc6955_get_freq(void)
         freq = (i * 5) / 2 + 3000; // freq' = 25*i[KHz] = (25 / 10) *i [10KHz]
     } else { // 5K
        b.byte = akc6955_readcmd(AKC6955_CH_HI);
-       akc6955_get_amband(band);
+       band = akc6955_get_amband();
        freq = i * 5;
        if((band == AKC6955_BAND_MW2) || (b.b5)){
            freq = i * 3;
@@ -323,20 +343,18 @@ void akc6955_set_freq(unsigned int freq)
     __bitops_t f;
     __bitops_t mode3k;
     unsigned char band;
-    unsigned int start, stop;
+    unsigned char q;
 
     f.byte = akc6955_readcmd(AKC6955_POWER);
     if(f.b6) { // FM
-        akc6955_get_fmband(band);
-//        band &= 7;
-        ch = ((freq - 3000) * 4) / 10;
+       band = akc6955_get_fmband();
+       //        band &= 7;
+       ch = ((freq - 3000) * 4) / 10;
     } else {
-        akc6955_get_amband(band);
+        band = akc6955_get_amband();
 //        if(band >= AKC6955_BAND_AMEND) band = AKC6955_BAND_AMEND - 1;
         mode3k.byte = akc6955_readcmd(AKC6955_CNR_AM);
-        if(band == AKC6955_BAND_MW2) {
-            ch = (freq / 9) * 3; // See datasheet.
-        } else  if(mode3k.b7){
+        if((band == AKC6955_BAND_MW2) || (mode3k.b7)){
             ch = freq / 3;
         } else {
             ch = freq / 5;
@@ -573,6 +591,23 @@ unsigned int akc6955_get_battery(void)
     return batt;
 }
 
+/*
+ * Misc
+ */
+void akc6955_set_fmbandwidth(unsigned char bw)
+{
+   unsigned char c = akc6955_readcmd(AKC6955_STEREO);
+   c = (c & 0xfc) | (bw & 0x03);
+   akc6955_writecmd(AKC6955_STEREO, c);
+}
+
+unsigned char akc6955_get_fmbandwidth(void)
+{
+    return (akc6955_readcmd(AKC6955_STEREO) & 0x03);
+}
+
+
+
 void akc6955_set_thresh_fmstereo(unsigned char a)
 {
     unsigned char b;
index 143627f..48584c6 100644 (file)
--- a/akc6955.h
+++ b/akc6955.h
@@ -151,15 +151,11 @@ extern const banddesc fmbands[AKC6955_BAND_FMEND];
 #define _AKC6955_WAIT_12_5uS()     __delay_us(13)
 #endif
 
-#define akc6955_get_amband(b) { \
-    b = akc6955_get_band() >> 3; \
-    }
-
-#define akc6955_get_fmband(b) { \
-    b = akc6955_get_band() & 0x07; \
-    }
-
+extern unsigned char akc6955_readcmd(unsigned char reg);
+extern void akc6955_writecmd(unsigned char reg,unsigned char data);
 extern unsigned char akc6955_getband(void);
+extern unsigned char akc6955_get_amband(void);
+extern unsigned char akc6955_get_fmband(void);
 extern void akc6955_chg_fm(unsigned char fm, unsigned int freq);
 extern unsigned char akc6955_get_fm(void);
 extern unsigned char akc6955_get_band(void);
@@ -208,26 +204,12 @@ extern void akc6955_set_thresh_fmstereo(unsigned char a);
 extern void akc6955_set_thresh_fmcnr(unsigned char a);
 extern void akc6955_set_thresh_amcnr(unsigned char a);
 extern void akc6955_set_thresh_width(unsigned char a);
+extern void akc6955_set_fmbandwidth(unsigned char bw);
+extern unsigned char akc6955_get_fmbandwidth(void);
 
 
 
 
-#define akc6955_set_fmbandwidth(bw) { \
-    unsigned char c = akc6955_readcmd(AKC6955_STEREO); \
-    c = (c & 0xfc) | (bw & 0x03); \
-    akc6955_writecmd(AKC6955_STEREO, c); \
-} \
-
-#define akc6955_get_fmbandwidth(c) { \
-    c = akc6955_readcmd(AKC6955_STEREO) & 0x03; \
-} \
-
-#define akc6955_writecmd(reg,data) {\
-    i2c_send_byte(AKC6955_ADDRESS, reg, data);\
-}
-
-#define akc6955_readcmd(reg) i2c_read_byte(AKC6955_ADDRESS, reg)
-
 
 #ifdef __cplusplus
 }
index df5d073..f2a6522 100644 (file)
@@ -59,13 +59,13 @@ extern "C" {
 /*
  * Frequency utils
  */
-extern void format_frequencies(unsigned int page);
-extern void check_frequencies(void);
-extern void save_frequencies(void);
-extern char load_frequencies(unsigned int page, unsigned char check_only);
-extern char load_userbands(void);
-extern void save_userbands(void);
-extern void format_userbands(void);   
+   extern void format_frequencies(unsigned int page);
+   extern void check_frequencies(void);
+   extern void save_frequencies(void);
+   extern int load_frequencies(unsigned int page, unsigned char check_only);
+   extern int load_userbands(void);
+   extern void save_userbands(void);
+   extern void format_userbands(void);   
 /*
  * Constants
  */
index 9fe5616..77332f8 100644 (file)
@@ -101,7 +101,7 @@ unsigned int calcsum_frequencies(__freqset_t *p, unsigned int start)
  *  0x0fff : User frequencies ( 12*2*28 = 672chs Max.)
  *  0x1000- : Reserve.
  */
-char load_frequencies(unsigned int page, unsigned char check_only)
+int load_frequencies(unsigned int page, unsigned char check_only)
 {
 
     __freqset_t *p;
@@ -213,7 +213,7 @@ static unsigned int calcsum_userband(__userband_t_t *p, unsigned int start)
     return sum;
 }
 
-char load_userbands(void)
+int load_userbands(void)
 {
 
     __userband_t_t *p = &userband;
index 1484272..5def4b4 100644 (file)
@@ -109,7 +109,11 @@ unsigned char acm1602_getchar(unsigned char addr)
 #else // Parallel
 static void _ACM1602_TC_WAIT(void)
 {
-    __delay_us(5);
+#ifdef __SDCC
+   delay10tcy(4)
+#else
+   __delay_us(5);
+#endif
 }
 
 static unsigned char lcd_busychk(unsigned char addr)
@@ -424,11 +428,11 @@ void acm1602_setdataramaddress(unsigned char addr, unsigned char pos)
 }
 
 
-void acm1602_locate_16x2(unsigned char addr, char x, char y)
+void acm1602_locate_16x2(unsigned char addr, unsigned char x, unsigned char y)
 {
     unsigned char ramaddr;
-    if((x < 0) || (x >= 16)) return;
-    if((y < 0) || (y > 1)) return;
+    if(x > 16) return;
+    if(y > 1) return;
     ramaddr = (y == 0)? x  : (x  | 0x40);
     acm1602_setdataramaddress(addr, ramaddr);
 }
@@ -436,11 +440,11 @@ void acm1602_locate_16x2(unsigned char addr, char x, char y)
 /*
  * For using
  */
-void acm1602_locate_8x2(unsigned char addr, char x, char y)
+void acm1602_locate_8x2(unsigned char addr, unsigned char x, unsigned char y)
 {
     unsigned char ramaddr;
-    if((x < 0) || (x >= 8)) return;
-    if((y < 0) || (y > 1)) return;
+    if(x > 8) return;
+    if(y > 1) return;
     ramaddr = (y == 0)? x : x | 0x40;
     acm1602_setdataramaddress(addr, ramaddr);
 }
index f7b53fc..1d229b9 100644 (file)
@@ -53,7 +53,7 @@ extern "C" {
 // Notes: Master clock = 8MHz(0.125uS)
 // Wait 5us
 #ifdef __SDCC
-#define _ACM1602_TC_WAIT()     delay10tcy(4)
+//#define _ACM1602_TC_WAIT()     delay10tcy(4)
 // Wait 50us
 #define _ACM1602_SHORT_WAIT()     delay100tcy(4)
 // Wait 5ms
@@ -78,8 +78,8 @@ extern "C" {
 
 extern void acm1602_cls(unsigned char addr);
 extern void acm1602_putchar(unsigned char addr, unsigned char c);
-extern void acm1602_locate_16x2(unsigned char addr, char x, char y);
-extern void acm1602_locate_8x2(unsigned char addr, char x, char y);
+extern void acm1602_locate_16x2(unsigned char addr, unsigned char x, unsigned char y);
+extern void acm1602_locate_8x2(unsigned char addr, unsigned char x, unsigned char y);
 extern void acm1602_home(unsigned char addr);
 extern void acm1602_cursordir(unsigned char addr, unsigned char right);
 extern void acm1602_dispcursor(unsigned char addr, unsigned char flag);
index c34ea8c..7668cbb 100644 (file)
@@ -86,7 +86,7 @@ void setup_menu(void)
             break;
         case charcode_4:
             printstr("FM Bandwidth:");
-            akc6955_get_fmbandwidth(c);
+            c = akc6955_get_fmbandwidth();
             setup.fmbandwidth = pollkey_numeric(c) & 3;
             akc6955_set_fmbandwidth(setup.fmbandwidth);
             break;
index ebc2438..f6157cc 100644 (file)
@@ -126,7 +126,7 @@ void set_userband(void)
         if(cc == charcode_0){
             pp = 96;
             mode3k = 0xff;
-        } else if(cc = charcode_1) {
+        } else if(cc == charcode_1) {
             pp = 160;
             mode3k = 0;
         }
index 221a2af..3e2cad1 100644 (file)
@@ -66,13 +66,13 @@ void update_status(void)
     setup.prevolume = akc6955_get_prevolume();
         if(setup.fm != 0){
             setup.fmfreq = akc6955_get_freq();
-            akc6955_get_fmband(setup.fmband);
+            setup.fmband = akc6955_get_fmband();
             setup.fmfreq_bank[setup.fmband] = setup.fmfreq;
             stereoflag = akc6955_get_stereo();
-            akc6955_get_fmbandwidth(setup.fmbandwidth);
+            setup.fmbandwidth = akc6955_get_fmbandwidth();
         } else {
             setup.amfreq = akc6955_get_freq();
-            akc6955_get_amband(setup.amband);
+            setup.amband = akc6955_get_amband();
             setup.amfreq_bank[setup.amband] = setup.amfreq;
             c.byte = akc6955_readcmd(AKC6955_CNR_AM);
             if(c.b7) {
diff --git a/ui.c b/ui.c
index aad5747..cd5bba0 100644 (file)
--- a/ui.c
+++ b/ui.c
@@ -135,7 +135,7 @@ void push_keyinfifo(char b)
     keyin_fifo[keyin_nowp] = b;
     keyin_nowp++;
     keyin_counter++;
-    if((keyin_nowp > 31) || (keyin_nowp < 0)) keyin_nowp = 0;
+    if(keyin_nowp > 31) keyin_nowp = 0;
 }
 
 /*
@@ -155,11 +155,11 @@ char pop_keyinfifo(void)
     c = keyin_fifo[keyin_readp];
     keyin_readp++;
     keyin_counter--;
-    if((keyin_readp > 31) || (keyin_readp < 0)) keyin_readp = 0;
+    if(keyin_readp > 31) keyin_readp = 0;
     return c;
 }
 
-void printstr(char *s)
+void printstr(const char *s)
 {
     int p = 0;
 //    _CURSOR_RIGHT();
diff --git a/ui.h b/ui.h
index cf94de2..662b6ca 100644 (file)
--- a/ui.h
+++ b/ui.h
@@ -71,7 +71,7 @@ extern char pop_keyinfifo(void);
 #endif
 extern unsigned char readkey_compare(void);
 
-extern void printstr(char *s);
+extern void printstr(const char *s);
 extern void print_numeric(int i, unsigned char supressf);
 extern void setsignal_tune(unsigned char flag);
 extern void set_backlight(unsigned char flag, unsigned int val);