nlgplay for mbed
Dependencies: SDFileSystemEx mbed
Diff: main.cpp
- Revision:
- 8:88c89fd324bd
- Parent:
- 7:7e183b33c3f9
- Child:
- 9:834e9eed0d72
diff -r 7e183b33c3f9 -r 88c89fd324bd main.cpp --- a/main.cpp Mon Aug 18 22:32:46 2014 +0000 +++ b/main.cpp Wed Aug 20 00:31:00 2014 +0000 @@ -1,17 +1,14 @@ +// +// NLGPLAY : NLG file player for mbed +// + #include "mbed.h" #include "SDFileSystem.h" #include "lcd.h" -// #define USE_NBV3 +#define USE_NBV3 +#define USE_FASTIO -// (pinname, initial value) -DigitalOut io01(dp13, 0); -DigitalOut io02(dp26, 0); -DigitalOut io03(dp17, 0); -DigitalOut io04(dp4, 0); - -DigitalOut io05(dp18, 0); -DigitalOut io06(dp11, 0); // (pinname, mode) DigitalIn sw_play(dp24, PullUp); @@ -52,6 +49,11 @@ int nlg_ctc0; int nlg_ctc3; +#define _WAIT for(int wcnt=0; wcnt < 2; wcnt++) + +#ifndef USE_FASTIO +// 通常IO + #define RCK io04 #define SCK io03 #define DBS io01 @@ -60,11 +62,21 @@ #define IO_A0 io05 #define IO_WR io06 +// (pinname, initial value) +DigitalOut io01(dp13, 0); // P1_4 +DigitalOut io02(dp26, 0); // P0_3 +DigitalOut io03(dp17, 0); // P1_8 +DigitalOut io04(dp4, 0); // P0_11 -#define _WAIT for(int wcnt=0; wcnt < 2; wcnt++) +DigitalOut io05(dp18, 0); // P1_9 +DigitalOut io06(dp11, 0); // P1_1 + +void ioInit() +{ +} // 16bit output -inline void ioShiftOut(unsigned int data) +void ioShiftOut(unsigned int data) { int i; @@ -94,6 +106,68 @@ RCK = 0; // _WAIT; } +#else + +// 高速IO + +#define RCK IO_04 +#define SCK IO_03 +#define DBS IO_01 +#define CTS IO_02 + + +#define IO_A0 io05 +#define IO_WR io06 + +DigitalOut io05(dp18, 0); // P1_9 +DigitalOut io06(dp11, 0); // P1_1 + + +#define IO_01 (1<<4) // P1_4 +#define IO_02 (1<<3) // P0_3 +#define IO_03 (1<<8) // P1_8 +#define IO_04 (1<<11) // P0_11 + + +void ioInit() +{ + // 出力 + LPC_GPIO0->DIR |= (IO_02 | IO_04); + LPC_GPIO1->DIR |= (IO_01 | IO_03); +} + +// 16bit output +void ioShiftOut(unsigned int data) +{ + int i; + + for(i = 0; i < 8; i++) + { + /* 2ビット分のデータをそれぞれ出力 */ + if (data & 0x80) + LPC_GPIO0->DATA |= CTS; + else + LPC_GPIO0->DATA &= ~CTS; + + if (data & 0x8000) + LPC_GPIO1->DATA |= DBS; + else + LPC_GPIO1->DATA &= DBS; + + data <<= 1; + + LPC_GPIO1->DATA |= SCK; + LPC_GPIO1->DATA &= SCK; + } + + LPC_GPIO0->DATA |= RCK; + LPC_GPIO0->DATA &= ~RCK; + +} + + +#endif + /* 制御信号定義 */ @@ -224,22 +298,6 @@ typedef unsigned long dword; -// 変数書き出し(WORD) -void WriteWORD(byte *p,word val) -{ - p[0] = (val & 0xff); - p[1] = ((val>>8) & 0xff); -} - -// 変数書き出し(DWORD) -void WriteDWORD(byte *p,dword val) -{ - p[0] = (val & 0xff); - p[1] = ((val>>8) & 0xff); - p[2] = ((val>>16) & 0xff); - p[3] = ((val>>24) & 0xff); -} - // 変数読み出し(WORD) word ReadWORD(byte *p) { @@ -300,6 +358,23 @@ #if 0 + +// 変数書き出し(WORD) +inline void WriteWORD(byte *p,word val) +{ + p[0] = (val & 0xff); + p[1] = ((val>>8) & 0xff); +} + +// 変数書き出し(DWORD) +inline void WriteDWORD(byte *p,dword val) +{ + p[0] = (val & 0xff); + p[1] = ((val>>8) & 0xff); + p[2] = ((val>>16) & 0xff); + p[3] = ((val>>24) & 0xff); +} + // 書き込み用NLGファイルを開く int CreateNLG(const char *file) { @@ -369,6 +444,7 @@ return; fclose(nlg_file); + #if defined(__MICROLIB) && defined(__ARMCC_VERSION) // with microlib and ARM compiler free(nlg_file); #endif @@ -377,31 +453,31 @@ } // データの読み出し -int ReadNLG(void) +inline int ReadNLG(void) { return fgetc(nlg_file); } // ファイルポインタの位置を取得 -long TellNLG(void) +inline long TellNLG(void) { return ftell(nlg_file); } // ファイルポインタの位置を設定 -void SeekNLG(long pos) +inline void SeekNLG(long pos) { fseek(nlg_file, pos, SEEK_SET); } // タイトルの取得 -char *GetTitleNLG(void) +inline char *GetTitleNLG(void) { return nlg_title; } // ティックの取得 -int GetTickNLG(void) +inline int GetTickNLG(void) { return nlg_tick; } @@ -810,6 +886,8 @@ led1 = 0; led2 = 0; + ioInit(); + wait_ms(20); // reset SHIFT REGISTER @@ -844,18 +922,13 @@ t.stop(); printf("result_us=%dus\n", result_us); - printf("DATE:%s\nTIME:%s\n", __DATE__, __TIME__); - + sprintf(buf, "R:%dus", result_us); + lcd_printStrY(1, buf); + wait(3); + sprintf(buf, "%8s", __DATE__); lcd_printStrYscr(1, buf); wait(3); - sprintf(buf, "%8s", __TIME__); - lcd_printStrY(1, buf); - wait(3); - - sprintf(buf, "R:%dus", result_us); - lcd_printStrY(1, buf); - wait(3); if (files < 0) lcd_printStrY(1, "NO FILES");