nlgplay for mbed

Dependencies:   SDFileSystemEx mbed

Files at this revision

API Documentation at this revision

Comitter:
bkc_mbed
Date:
Mon Aug 18 22:32:46 2014 +0000
Parent:
6:e48296dca6bb
Child:
8:88c89fd324bd
Commit message:
NBV3 support

Changed in this revision

SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
lcd.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/SDFileSystem.lib	Mon Aug 18 00:59:38 2014 +0000
+++ b/SDFileSystem.lib	Mon Aug 18 22:32:46 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/mbed/code/SDFileSystem/#7b35d1709458
+http://mbed.org/teams/mbed/code/SDFileSystem/#e6b0a24df912
--- a/lcd.cpp	Mon Aug 18 00:59:38 2014 +0000
+++ b/lcd.cpp	Mon Aug 18 22:32:46 2014 +0000
@@ -1,6 +1,5 @@
 #include "mbed.h"
 
-
 I2C i2c(dp5, dp27); // sda, scl
 
 const int AQM0802_addr = 0x7C;
@@ -29,6 +28,21 @@
   i2c.write(AQM0802_addr, data, 2);
 }
 
+void lcd_printStrFill(const char *s)
+{
+  int idx = 0;
+  for(idx = 0; idx < 8; idx++)
+  {
+    if(idx < 7) {
+      lcd_contdata(*s);
+    } else {
+      lcd_lastdata(*s);
+    }
+    if (*s) s++;
+  }
+}
+
+
 void lcd_printStr(const char *s)
 {
   int idx = 0;
@@ -83,8 +97,8 @@
 
 void lcd_printStrY(int y,const char *s)
 {
-  lcd_setCursor(0,y);
-  lcd_printStr(s);
+  lcd_setCursor(0, y);
+  lcd_printStrFill(s);
 }
 
 void lcd_printStrYscr(int y,const char *s)
@@ -105,16 +119,16 @@
 void lcd_printStr2(const char *s, const char *s2)
 {
   lcd_setCursor(0,0);
-  lcd_printStr(s);
+  lcd_printStrFill(s);
   lcd_setCursor(0,1);
-  lcd_printStr(s2);
+  lcd_printStrFill(s2);
 }
 
 void lcd_cls(void)
 {
     lcd_setCursor(0, 0);
-    lcd_printStr("        ");
+    lcd_printStrFill("");
     lcd_setCursor(0, 1);
-    lcd_printStr("        ");
+    lcd_printStrFill("");
 }
     
--- a/main.cpp	Mon Aug 18 00:59:38 2014 +0000
+++ b/main.cpp	Mon Aug 18 22:32:46 2014 +0000
@@ -2,6 +2,8 @@
 #include "SDFileSystem.h"
 #include "lcd.h"
 
+// #define USE_NBV3
+
 // (pinname, initial value)
 DigitalOut io01(dp13, 0);
 DigitalOut io02(dp26, 0);
@@ -55,10 +57,14 @@
 #define DBS io01
 #define CTS io02
 
+#define IO_A0 io05
+#define IO_WR io06
+
+
 #define _WAIT for(int wcnt=0; wcnt < 2; wcnt++)
 
 // 16bit output
-void ioShiftOut(unsigned int data)
+inline void ioShiftOut(unsigned int data)
 {
     int i;
     
@@ -101,8 +107,29 @@
 /* アクティブローの制御信号 */
 #define ACTLOW (CS_PSG | CS_FM1 | CS_FM2 | WR | ICL)
 
+#ifdef USE_NBV3
+/* 16bit出力 */
+void regOutBase(int addr, int data,int select)
+{
+    /* アドレスを出力 */
+    /* A0をローにして待つ */
+    IO_A0 = 0;
+    ioShiftOut((addr << 8) | (ACTLOW & ~(select | WR)));
+    ioShiftOut((addr << 8) | (ACTLOW));
+    
+    
+    /* チップ側の処理を待つ */
+    
+    /* データを出力 */
+    /* A0をハイにして待つ */
+    IO_A0 = 1;
+    ioShiftOut((data << 8) | (ACTLOW & ~(select | WR)));
+    ioShiftOut((data << 8) | (ACTLOW));
 
-/* 出力 */
+    /* 処理を待つ */
+}
+#else
+/* NBV2互換出力 */
 void regOutBase(int addr, int data,int select)
 {
     /* アドレスを出力 */
@@ -111,11 +138,7 @@
     ioShiftOut((addr << 8) | (ACTLOW & ~(select | WR)));
     ioShiftOut((addr << 8) | (ACTLOW));
     
-    
-    /* チップ側の処理を待つ */
-    // if (!(select & CS_PSG))
-    //    wait_us(10);
-        
+    /* チップ処理待ち */        
     
     /* データを出力 */
     /* A0をハイにして待つ */
@@ -123,10 +146,9 @@
     ioShiftOut((data << 8) | A0 | (ACTLOW & ~(select | WR)));
     ioShiftOut((data << 8) | A0 | (ACTLOW));
 
-    /* wait if FM */
-    // if (!(select & CS_PSG))
-    //    wait_us(10);
+    /* チップ処理待ち */
 }
+#endif
 
 /* PSG出力 */
 void regPSGOut(int addr, int data)
@@ -161,19 +183,26 @@
     regPSGOut(0x09, 0x00); // CH.B 0
     regPSGOut(0x0a, 0x00); // CH.C 0
     
-    /* FM音源初期化 */
+    /* MUTE(disable) */
     for(i = 0x20; i < 0x28; i++)
     {
         regFMOut(i, 0x00);
         regFM2Out(i, 0x00);
     }
     
-    // key off
+    // KEYOFF
     for(i = 0x00; i < 0x08; i++)
     {
         regFMOut(0x08, i & 0x07);
         regFM2Out(0x08, i & 0x07);
     }
+    
+    // FORCE RELEASE
+    for(i= 0x00; i < 0x20; i++)
+    {
+        regFMOut(0xE0 + i, 0x0f);        
+        regFM2Out(0xE0 + i, 0x0f);
+    }
 }
 
 
@@ -691,9 +720,7 @@
        /* NLGの初期化 */
     if (initNLG(&n, nlg_file) < 0)
     {
-        lcd_setCursor(0,1);
-        lcd_printStr("ERROR!!");
-
+        lcd_printStrY(1, " ERROR!!");
         printf("Failed to init.\n");
         return -1;
     }
@@ -768,8 +795,8 @@
 //
 void putTitle()
 {
-        lcd_printStr2("NBCTRL", "Ver 1.10");
-        wait(3);
+        lcd_printStr2("NBCTRL", "Ver 1.11");
+        wait(1.5);
 }
 
 //
@@ -786,7 +813,7 @@
     wait_ms(20);
 
     // reset SHIFT REGISTER
-    ioShiftOut(( 0xFF << 8) | (ACTLOW));
+    ioShiftOut((0xFF << 8) | (ACTLOW));
     
     lcd_init();
     
@@ -810,13 +837,8 @@
         t.reset();
         t.start();
                 
-        ioShiftOut(( 0x68 << 8) | (ACTLOW));
-        ioShiftOut(( 0x68 << 8) | (ACTLOW));
-        ioShiftOut(( 0x68 << 8) | (ACTLOW));
-        
-        ioShiftOut(( 0x68 << 8) | (ACTLOW));
-        ioShiftOut(( 0x68 << 8) | (ACTLOW));
-        ioShiftOut(( 0x68 << 8) | (ACTLOW));
+        // actual timing
+        regFMOut(0x20, 0x00);
         
         result_us = t.read_us();
         t.stop();
@@ -835,7 +857,6 @@
         lcd_printStrY(1, buf);
         wait(3);
 
-
         if (files < 0)
             lcd_printStrY(1, "NO FILES");
         else
@@ -848,6 +869,7 @@
         lcd_cls();
     }
     
+    bool repeat_flag = false;
     int idx = 0;
     while(files > 0)
     {
@@ -883,13 +905,20 @@
             // wait any button is pressed
             waitButtonPress();
             
-            if (!sw_play) {
+            // 
+            if (!sw_prev) {
                 lcd_printStrY(1, "  PREV  ");
                 g_prev = true;
             }
-            else
+            if (!sw_play)
+            {
+                lcd_printStrY(1, "  PLAY  ");
+                repeat_flag = true;
+            }
+            if (!sw_next)
             {
                 lcd_printStrY(1, "  NEXT  ");
+                repeat_flag = false;
             }
             
             // wait release
@@ -908,13 +937,17 @@
                 idx--;
             else
                 idx = files - 1;
+
+            continue;
         }
-        else
+        
+        if (!repeat_flag) 
         {
             if (idx + 1 < files)
                 idx++;
             else
                 idx = 0;
         }
+        repeat_flag = false;
     }
 }