nlgplay for mbed
Dependencies: SDFileSystemEx mbed
Diff: main.cpp
- Revision:
- 2:f0b7779b03c7
- Parent:
- 1:ec416e6d5739
- Child:
- 3:aed228fa3ae4
--- a/main.cpp Mon May 19 03:10:50 2014 +0000 +++ b/main.cpp Tue May 20 09:24:55 2014 +0000 @@ -56,6 +56,8 @@ CTS = 0; } +#define _WAIT for(int wcnt=0; wcnt < 5; wcnt++) + // 16bit output void ioShiftOut(unsigned int data) { @@ -77,11 +79,61 @@ data <<= 1; SCK = 1; + _WAIT; SCK = 0; + _WAIT; } RCK = 1; + _WAIT; RCK = 0; + _WAIT; +} + + +// 16bit output +void ioShiftOutTest(unsigned int data) +{ + int i; + int ta = 0; + int tb = 0; + Timer t; + + t.start(); + + for(i = 0; i < 8; i++) + { + /* 2ビット分のデータをそれぞれ出力 */ + if (data & 0x80) + CTS = 1; + else + CTS = 0; + + if (data & 0x8000) + DBS = 1; + else + DBS = 0; + + data <<= 1; + + SCK = 1; + _WAIT; + SCK = 0; + _WAIT; + } + + ta = t.read_us(); + + RCK = 1; + _WAIT; + RCK = 0; + _WAIT; + + tb = t.read_us(); + + t.stop(); + + printf("test result ta=%d tb=%d\n", ta, tb); } /* 制御信号定義 */ @@ -256,6 +308,8 @@ return 0; } +#if 0 + // 書き込み用NLGファイルを開く int CreateNLG(const char *file) { @@ -285,19 +339,6 @@ return 0; } -// ファイルを閉じる -void CloseNLG(void) -{ - if (!nlg_file) - return; - - fclose(nlg_file); -#if defined(__MICROLIB) && defined(__ARMCC_VERSION) // with microlib and ARM compiler - free(nlg_file); -#endif - - nlg_file = NULL; -} // コマンドの書き込み void WriteNLG_CMD(int cmd) @@ -329,6 +370,23 @@ fputc(data, nlg_file); } + +#endif + +// ファイルを閉じる +void CloseNLG(void) +{ + if (!nlg_file) + return; + + fclose(nlg_file); +#if defined(__MICROLIB) && defined(__ARMCC_VERSION) // with microlib and ARM compiler + free(nlg_file); +#endif + + nlg_file = NULL; +} + // データの読み出し int ReadNLG(void) { @@ -423,11 +481,10 @@ int irq_count; int irq_loop; long loop_address; + int irq_counter; int irq_counter2; - int song_no; - } NLG_R; @@ -460,6 +517,7 @@ np->irq_count = 0; np->irq_loop = GetLoopPtrNLG(); np->loop_address = -1; + np->irq_counter = 0; np->irq_counter2 = 0; @@ -492,9 +550,12 @@ // fflush(stdout); char buf[16]; - sprintf(buf, "%d.%02d:%02d",np->song_no, np->total_sec / 60, np->total_sec % 60); + sprintf(buf, "%02d:%02d", + np->total_sec / 60, + np->total_sec % 60); - lcd_printStrY(1, buf); + lcd_setCursor(3,1); + lcd_printStr(buf); } /* NLGの再生 */ @@ -508,6 +569,7 @@ int total_us = 0; int us_tick = np->base_clk / 1000000; + printf("start play\n"); Timer t; t.start(); @@ -632,7 +694,7 @@ NLG_R n; -int nlg_play(const char *nlg_file,int song_no) +int nlg_play(const char *nlg_file) { printf("nlg_play:%s\n",nlg_file); @@ -645,12 +707,11 @@ printf("Failed to init.\n"); return -1; } - - n.song_no = song_no; + + printf("Play..\n"); /* 再生する */ PlayNLG(&n, 360); - printf("\n"); boardMute(); @@ -734,8 +795,15 @@ if (disp_mode) { char buf[16]; + + ioShiftOutTest(( 0x08 << 8) | (ACTLOW)); + // ioShiftOutTest(( 0xff << 8) | (ACTLOW)); + // ioShiftOutTest(( 0xaa << 8) | (ACTLOW)); + // ioShiftOutTest(( 0x22 << 8) | (ACTLOW)); + + printf("DATE:%s\nTIME:%s", __DATE__, __TIME__); - lcd_printStr2("NBCTRL", "Ver 1.04"); + lcd_printStr2("NBCTRL", "Ver 1.06"); wait(3); sprintf(buf, "%8s", __DATE__); lcd_printStrYscr(1, buf); @@ -759,16 +827,22 @@ int idx = 0; while(files > 0) { + char buf[16]; + get_nlg_file(file, idx); sprintf(path, "/sd/%s", file); printf("path=%s\n",path); + lcd_cls(); lcd_printStrY(0, file); - nlg_play(path, idx); + sprintf(buf, "%2d ", idx); + lcd_printStrY(1, buf); + + nlg_play(path); - // wait for chattering + // wait for chattering wait(0.25); // wait release while(!sw_play || !sw_next); @@ -777,13 +851,20 @@ if (g_stop) { - lcd_printStrY(1, "STOP "); + lcd_printStrY(1, " STOP "); // wait push while(sw_play && sw_next); - if (!sw_play) + if (!sw_play) { + lcd_printStrY(1, " PREV "); prev_flag = true; + } + else + { + lcd_printStrY(1, " NEXT "); + prev_flag = false; + } // wait release while(!sw_play || !sw_next);