OSDN Git Service

[UI][USER_CH] Add slow-middle-fast changeing CHs.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 26 Aug 2013 12:19:28 +0000 (21:19 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 26 Aug 2013 12:19:28 +0000 (21:19 +0900)
eepromutil.c
i2c_eeprom.c
menu.h
menu_memoryfreq.c
nbproject/Makefile-genesis.properties
nbproject/configurations.xml

index b48180f..62dfb85 100644 (file)
@@ -113,7 +113,7 @@ char load_frequencies(unsigned int page, unsigned char check_only)
     unsigned int i;
 
 //    if(addr > 0x0fff) return -1; // Address error
-
+    if(page > USER_MEMORY_BANKS) return -1; // Address Error
     p = &freqset_temp;
     c = i2c_eeprom_burstread(0xa0, addr, (unsigned char *)p, sizeof(__freqset_t));
     // Pass 1 Read OK?
@@ -145,37 +145,16 @@ void save_frequencies(void)
     unsigned int addr = (setup.pagenum <<7) + 512;
     __freqset_t *p = &freqset;
     unsigned char i;
-    unsigned char flg;
-    unsigned char *q, *r;
     unsigned int sum;
 
-   // if(addr > 0x0fff) return;
+    if(setup.pagenum > USER_MEMORY_BANKS) return; // Address Error
     // Pass 0 Calc checksum
     freqset.magic = 0xfabc;
     freqset.version = 0x0001;
     sum = calcsum_frequencies(&freqset, 0xa5a5);
     freqset.checksum = sum;
-    // Pass 1 check storaged page
-    if(load_frequencies(setup.pagenum, 0xff) < 0) {
-        // Sum ERROR = Force rewrite
-        c = i2c_eeprom_burstwrite(0xa0, addr, (unsigned char *)p, sizeof(__freqset_t));
-        return;
-    }
-    // Pass 2 compare
-    flg = 0x00;
-//    flg = 0xff;
-    q = (unsigned char *)(&freqset_temp);
-    r = (unsigned char *)(&freqset);
-    for(i = 0; i < sizeof(__freqset_t); i++) {
-        if(*q != *r) flg |= 0xff;
-        q++;
-        r++;
-    }
-    if(flg != 0x00){ // Changed
-        c = i2c_eeprom_burstwrite(0xa0, addr, (unsigned char *)p, sizeof(__freqset_t));
-        return;
-    }
-    // Not Need to read.
+    // Pass 1 write to rom.
+    c = i2c_eeprom_burstwrite(0xa0, addr, (unsigned char *)p, sizeof(__freqset_t));
     return;
 }
 
@@ -202,7 +181,7 @@ void check_frequencies(void)
 {
     unsigned int i;
     _CLS();
-    for(i = 0; i < 24; i++){
+    for(i = 0; i < USER_MEMORY_BANKS; i++){
         printstr("Check ExtROM:");
         print_numeric_nosupress(i, 2);
        _HOME();
@@ -247,7 +226,6 @@ unsigned char load_eeprom(void)
 void check_eeprom(void)
 {
     unsigned char c;
-    unsigned int bank;
 
     switch(load_eeprom()) {
         case 0x01: // No magic-word
@@ -261,7 +239,6 @@ void check_eeprom(void)
             printstr("Save defaults  ");
             setdefault();
             save_eeprom();
-//            format_frequencies();
             break;
         case 0x00: // Checksum error
            idle_time_ms(2000);
@@ -271,12 +248,10 @@ void check_eeprom(void)
             _LOCATE(0,0);
             printstr("Formatting...");
             format_eeprom(2,250);
-//            writeword_eeprom(0, &sum, 0x1298);
             _LOCATE(0,0);
             printstr("Save defaults");
             setdefault();
             save_eeprom();
-//            format_frequencies();
             break;
         case 0xff: // Success
             check_frequencies();
index c91c654..e1cd425 100644 (file)
@@ -28,6 +28,9 @@
 
 #include "i2c_eeprom.h"
 
+#define I2C_ROM_PAGE_SIZE 32
+
+
 static unsigned char i2c_eeprom_write_1block(unsigned char i2caddr, unsigned char page_hi, unsigned char page_lo, unsigned char *data)
 {
     unsigned char i;
@@ -49,27 +52,38 @@ static unsigned char i2c_eeprom_write_1block(unsigned char i2caddr, unsigned cha
     SSPADD = 0x5;
     IdleI2C();
     StartI2C();
- //   while (SSPCON2bits.SEN);
+    while(SSPCON2bits.SEN);
+
     WriteI2C(i2caddr & 0xfe);
-//    while(SSPCON2bits.SEN);
+    while(SSPCON2bits.ACKSTAT);
+
     WriteI2C(page_hi);
-//    while(SSPCON2bits.SEN);
+    while(SSPCON2bits.ACKSTAT);
+
     WriteI2C(page_lo);
+    while(SSPCON2bits.ACKSTAT);
 
-//   IdleI2C();
-   for(i = 0; i < 32; i++){
-        WriteI2C(*p);
-        IdleI2C();
-        p++;
+    if(!SSPCON2bits.ACKSTAT){
+        for(i = 0; i < I2C_ROM_PAGE_SIZE; i++){
+            if(SSPCON1bits.SSPM3) {
+                WriteI2C(*p);
+                while(SSPCON2bits.ACKSTAT);
+//            IdleI2C();
+            p++;
+            }
+        }
     }
     StopI2C();
-    do {
-        StartI2C();
-        WriteI2C(i2caddr & 0xfe);
-        idle_time_ms(1);
-    } while(SSPCON2bits.ACKSTAT);
+    while (SSPCON2bits.PEN);
+//    idle_time_ms(10);
+//    do {
+//        StartI2C();
+//        WriteI2C(i2caddr & 0xfe);
+//        idle_time_ms(1);
+//    } while(SSPCON2bits.ACKSTAT);
 //    StopI2C();
 //    while (SSPCON2bits.PEN);
+
     CloseI2C();
 #endif  //    i2c_idle();
     return 0xff;
@@ -94,23 +108,30 @@ unsigned char i2c_eeprom_bytewrite(unsigned char i2caddr, unsigned int addr, uns
     OpenI2C(MASTER, SLEW_ON);
     SSPADD = 5; // 100KHz
     IdleI2C();
-//    StartI2C();
-//    do {
-//        idle_time_ms(1);
-        StartI2C();
-        while(SSPCON2bits.SEN);
-        WriteI2C(i2caddr & 0xfe);
-        while(SSPCON2bits.ACKSTAT);
-//    WriteI2C(i2caddr & 0xfe);
+    StartI2C();
+    while(SSPCON2bits.SEN);
+
+    WriteI2C(i2caddr & 0xfe);
+    while(SSPCON2bits.ACKSTAT);
+
     WriteI2C(page_hi);
     while(SSPCON2bits.ACKSTAT);
+
     WriteI2C(page_lo);
     while(SSPCON2bits.ACKSTAT);
+
     WriteI2C(data);
     while(SSPCON2bits.ACKSTAT);
+
     StopI2C();
     while(SSPCON2bits.PEN);
-   // idle_time_ms(1);
+    do {
+        StartI2C();
+        WriteI2C(i2caddr & 0xfe);
+        idle_time_ms(1);
+    } while(SSPCON2bits.ACKSTAT);
+    StopI2C();
+    while (SSPCON2bits.PEN);
     CloseI2C();
 #endif  //    i2c_idle();
     return 0xff;
@@ -124,11 +145,11 @@ unsigned char i2c_eeprom_burstwrite(unsigned char i2caddr, unsigned int addr, un
     int b = bytes;
 
     while(b > 0){
-//        page_hi = addr >> 8;
-//        page_lo = addr & 0xff;
+        page_hi = addr >> 8;
+        page_lo = addr & 0xff;
 //        i2c_eeprom_write_1block(i2caddr,  page_hi, page_lo, data);
         i2c_eeprom_bytewrite(i2caddr,  addr, *data);
-        idle_time_ms(15);
+//        idle_time_ms(15);
 
         addr += 1;
         data += 1;
@@ -153,41 +174,53 @@ static unsigned char i2c_eeprom_read_1block(unsigned char addr, unsigned char pa
 //   delay100tcy(2);
     I2C_START();
     i2c_writechar(addr | 0x01);
-    for(i = 0; i < 64; i++){
+    for(i = 0; i < I2C_ROM_PAGE_SIZE - 1 ; i++){
         *p = i2c_readchar();
         p++;
         I2C_ACK();
     }
+    *p = i2c_readchar();
+    I2C_NACK();
     I2C_STOP();
     i2c_close();
 #else
     OpenI2C(MASTER, SLEW_ON);
     SSPADD = 0x5;
     StartI2C();
+    while(SSPCON2bits.SEN);
     WriteI2C(addr & 0xfe);
   //  delay1ktcy(8);
+    while(SSPCON2bits.SEN);
     WriteI2C(page_hi);
+    while(SSPCON2bits.SEN);
     WriteI2C(page_lo);
+  //  delay1ktcy(8);
+    StopI2C();
+
     IdleI2C();
-    RestartI2C();
-    WriteI2C(addr | 0x01);
-//    IdleI2C();
-    for(i = 0; i < 32; i++){
-        if(!SSPCON2bits.ACKSTAT){
-              SSPCON2bits.RCEN = 1;
-              while(SSPCON2bits.RCEN);
-               NotAckI2C();
-               while (SSPCON2bits.ACKEN);
-               StopI2C();
-               while (SSPCON2bits.PEN);
-          }
-        *p = SSPBUF;
-        p++;
-        if(i < 31) AckI2C();
+    StartI2C();
+    WriteI2C(addr | 1);
+    for(i = 0; i < I2C_ROM_PAGE_SIZE - 1 ;i++){
+        if (!SSPCON2bits.ACKSTAT){
+          SSPCON2bits.RCEN = 1;
+          while(SSPCON2bits.RCEN);
+          AckI2C();
+//          while (!SSPCON2bits.ACKEN);
+          *data = SSPBUF;
+          data++;
+       }
     }
-    NotAckI2C();
-//    IdleI2C();
-    StopI2C();
+
+    if (!SSPCON2bits.ACKSTAT){
+      SSPCON2bits.RCEN = 1;
+      while(SSPCON2bits.RCEN);
+      NotAckI2C();
+      while (SSPCON2bits.ACKEN);
+      StopI2C();
+      while (SSPCON2bits.PEN);
+    }
+    *data = SSPBUF;
+
     CloseI2C();
 #endif
     //    CLOSEASMASTER();
@@ -223,12 +256,10 @@ unsigned char i2c_eeprom_byteread(unsigned char i2caddr, unsigned int addr)
     StartI2C();
     while(SSPCON2bits.SEN);
     WriteI2C(i2caddr);
-  //  delay1ktcy(8);
     while(SSPCON2bits.SEN);
     WriteI2C(page_hi);
     while(SSPCON2bits.SEN);
     WriteI2C(page_lo);
-  //  delay1ktcy(8);
     StopI2C();
     IdleI2C();
     StartI2C();
@@ -242,8 +273,6 @@ unsigned char i2c_eeprom_byteread(unsigned char i2caddr, unsigned int addr)
       while (SSPCON2bits.PEN);
     }
     c = SSPBUF;
-  //  delay1ktcy(8);
- //   delay1ktcy(8);
     CloseI2C();
 #endif
     //    CLOSEASMASTER();
@@ -258,15 +287,15 @@ unsigned char i2c_eeprom_burstread(unsigned char i2caddr, unsigned int addr, uns
     int b = bytes;
 
     while(b > 0){
//       page_hi = addr >> 8;
//       page_lo = addr & 0xff;
-        *data = i2c_eeprom_byteread(i2caddr,  addr);
-//        i2c_eeprom_read_1block(i2caddr, page_hi, page_lo, data);
+        page_hi = addr >> 8;
+        page_lo = addr & 0xff;
+//        *data = i2c_eeprom_byteread(i2caddr,  addr);
+        i2c_eeprom_read_1block(i2caddr, page_hi, page_lo, data);
         idle_time_ms(1);
 
-        addr += 1;
-        data += 1;
-        b -= 1;
+        addr += I2C_ROM_PAGE_SIZE;
+        data += I2C_ROM_PAGE_SIZE;
+        b -= I2C_ROM_PAGE_SIZE;
     }
 
     return 0xff;
diff --git a/menu.h b/menu.h
index af3ae6e..2424c1f 100644 (file)
--- a/menu.h
+++ b/menu.h
@@ -63,6 +63,7 @@ extern "C" {
     } _userband_t;
     
 #define USER_MEMORY_NUM 28
+#define USER_MEMORY_BANKS 24
     typedef struct {
         unsigned char band;
         unsigned char fm;
index 5df32aa..0cadf42 100644 (file)
@@ -40,7 +40,7 @@ void call_freqbank(unsigned int num)
     unsigned int bank = num / USER_MEMORY_NUM;
     unsigned int n = num % USER_MEMORY_NUM;
 
-    if(num >= (USER_MEMORY_NUM * 24)) return;
+    if(num >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) return;
 
     if(bank != setup.pagenum){ // Swap memory
 //        save_frequencies();
@@ -70,8 +70,9 @@ void set_freqbank(unsigned int num)
     unsigned char _userband;
     unsigned int _freq;
     unsigned int bank = num / USER_MEMORY_NUM;
+    unsigned int n = num % USER_MEMORY_NUM;
 
-    if(num >= (USER_MEMORY_NUM * 24)) return;
+    if(num >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) return;
 
      if(bank != setup.pagenum){ // Save now bank, and load using bank
         save_frequencies();
@@ -87,9 +88,9 @@ void set_freqbank(unsigned int num)
         _band = setup.fmband;
         _freq = setup.fmfreq;
     }
-    freqset.memoryfreqs[num].fm = _fm;
-    freqset.memoryfreqs[num].band = (_userband << 5) | (_band & 0x1f);
-    freqset.memoryfreqs[num].freq = _freq;
+    freqset.memoryfreqs[n].fm = _fm;
+    freqset.memoryfreqs[n].band = (_userband << 5) | (_band & 0x1f);
+    freqset.memoryfreqs[n].freq = _freq;
 
     save_frequencies();
 }
@@ -97,7 +98,7 @@ void set_freqbank(unsigned int num)
 
 void on_call_userfreq(void)
 {
-    unsigned int val = USER_MEMORY_NUM * 24;
+    unsigned int val = USER_MEMORY_NUM * USER_MEMORY_BANKS;
     _CLS();
     _LOCATE(0,0);
     printstr("Mem: 000-");
@@ -108,7 +109,7 @@ void on_call_userfreq(void)
 
 void on_set_userfreq(void)
 {
-    unsigned int val = USER_MEMORY_NUM * 24;
+    unsigned int val = USER_MEMORY_NUM * USER_MEMORY_BANKS;
     unsigned char n;
     unsigned char c;
     _CLS();
@@ -158,29 +159,64 @@ void on_updown_userfreq(void)
         _HOME();
         c = pollkey_single_timeout(44, 1); // About 1s
        switch(c) {
-           case charcode_8: // UP CH
+           case charcode_7: // UP 1CH
                 setup.memorynum++;
-                if(setup.memorynum >= (USER_MEMORY_NUM * 24)) setup.memorynum = 0;
-                call_freqbank(setup.memorynum);
-                break;
-           case charcode_2: // Down CH
-                if(setup.memorynum == 0) setup.memorynum = USER_MEMORY_NUM * 24;
-                setup.memorynum--;
+                if(setup.memorynum >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) setup.memorynum = 0;
                 call_freqbank(setup.memorynum);
                 break;
-            case charcode_d: // Reset
-                if(_fm) { // AM
+           case charcode_1: // Down 1CH
+               if(setup.memorynum == 0) setup.memorynum = USER_MEMORY_NUM * USER_MEMORY_BANKS;
+               setup.memorynum--;
+               call_freqbank(setup.memorynum);
+               break;
+           case charcode_9: // Up CH FAST
+               setup.memorynum += 100;
+               if(setup.memorynum > (USER_MEMORY_NUM * USER_MEMORY_BANKS)) {
+                    setup.memorynum = setup.memorynum % 100;
+               }
+               call_freqbank(setup.memorynum);
+               break;
+           case charcode_3: // Down CH FAST
+               if(setup.memorynum < 100) {
+                    setup.memorynum = (((USER_MEMORY_NUM * USER_MEMORY_BANKS) / 100 - 1) * 100) + (setup.memorynum % 100);
+               } else {
+                    setup.memorynum -= 100;
+               }
+               call_freqbank(setup.memorynum);
+               break;
+           case charcode_8: // Up CH FAST
+               setup.memorynum += USER_MEMORY_NUM;
+               if(setup.memorynum >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) {
+                    setup.memorynum = setup.memorynum - USER_MEMORY_NUM * USER_MEMORY_BANKS;
+               }
+               call_freqbank(setup.memorynum);
+               break;
+           case charcode_2: // Down CH FAST
+               if(setup.memorynum < USER_MEMORY_NUM) {
+                    setup.memorynum = (USER_MEMORY_NUM * USER_MEMORY_BANKS) - USER_MEMORY_NUM + setup.memorynum;
+               } else {
+                    setup.memorynum -= USER_MEMORY_NUM;
+               }
+               call_freqbank(setup.memorynum);
+               break;
+            case charcode_5: // Reset
+               if(_fm) { // AM
                     setup.fmband = _band;
                     setup.fm_userbandnum = _userband;
                     setup.fmfreq = _freq;
-                } else {
+               } else {
                     setup.amband = _band;
                     setup.am_userbandnum = _userband;
                     setup.amfreq = _freq;
-                }
-                akc6955_chg_fm(_fm, _freq);
-                break;
-           case charcode_5: // exit
+               }
+               akc6955_chg_fm(_fm, _freq);
+               break;
+           case charcode_4:
+               on_call_userfreq();
+               break;
+           case charcode_6:
+               on_set_userfreq();
+               break;
            case charcode_a:
                 goto _l0;
                 break;
index ccb4b2e..c15b3f0 100644 (file)
@@ -1,5 +1,5 @@
 #
-#Mon Aug 26 12:32:00 JST 2013
+#Mon Aug 26 20:04:37 JST 2013
 default.languagetoolchain.dir=/opt/microchip/xc8/v1.20/bin
 com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=1c49f19f6a43b876c317e0d8d41c0854
 default.languagetoolchain.version=1.20
index a478674..986c662 100644 (file)
         <property key="programoptions.uselvpprogramming" value="false"/>
         <property key="voltagevalue" value="3.25"/>
       </PICkit3PlatformTool>
-      <SDCCToolchain>
-      </SDCCToolchain>
       <XC8-config-global>
       </XC8-config-global>
       <item path="akc6955.c" ex="false" overriding="false">
         <XC8-config-global>
         </XC8-config-global>
       </item>
-      <sdcc>
-        <property key="V-show-commands-compiler" value="false"/>
-        <property key="Werror" value="false"/>
-        <property key="debug-xtra14" value="false"/>
-        <property key="debug-xtra16" value="false"/>
-        <property key="extended" value="true"/>
-        <property key="no-c-code-in-asm" value="false"/>
-        <property key="no-optimize-goto" value="false"/>
-        <property key="no-pcode-opt" value="false"/>
-        <property key="obanksel" value="2"/>
-        <property key="optimize-cmp" value="true"/>
-        <property key="optimize-df" value="true"/>
-        <property key="pcode-verbose" value="false"/>
-        <property key="pno-banksel" value="false"/>
-        <property key="pstack-model" value="small"/>
-        <property key="use-non-free" value="true"/>
-        <property key="verbose" value="false"/>
-        <appendMe value="libio18f45k20.lib libc18f.lib"/>
-      </sdcc>
     </conf>
   </confs>
 </configurationDescriptor>