![](/media/cache/profiles/94bd3f4d79c60af8831740e58a68dd6e.jpg.50x50_q85.jpg)
use VS1033(MP3 decoder) and UL024TF(TFTLCD)
Dependencies: TFTLCDwithFastIO FastIO SDFileSystem TouchPanel VS1033 mbed
Diff: main.cpp
- Revision:
- 10:93267d24ad1a
- Parent:
- 9:96b053c0865e
--- a/main.cpp Thu Jul 30 06:54:23 2015 +0000 +++ b/main.cpp Mon Aug 10 15:52:47 2015 +0000 @@ -10,19 +10,20 @@ #include "TouchPanel.h" #include "mbed.h" -// prepare the data bus for writing commands and pixel data -// create the lcd instance //(PinName CS, PinName RESET, PinName RS, PinName WR, BusOut *DATA_PORT, PinName BL=NC, PinName RD=NC, backlight_t blType=Constant, float defaultBackLightLevel=1.0) +//LCDのバスピンはTFTLCDライブラリ内のili9328.cpp内に記述する改変をしている ILI9328_LCD lcd( P0_12, P0_11, P0_13, P0_14, NULL, NC, P1_9 ); // control pins and data bus SDFileSystem sd(/*MOSI*/ P0_9, /*MISO*/ P0_8, /*SCK*/ P1_29, /*CS*/ P0_2, /*Mountpoint*/ "sd", NC, SDFileSystem::SWITCH_NONE, 20000000); + VS1053 mp3(/*MOSI*/ P1_22 , /*MISO*/ P1_21, /*SCK*/ P1_20, /*CS*/ P1_23, /*BSYNC*/ P2_17, /*DREQ*/ P2_16, /*RST*/ P2_18, /*SPI freq.*/ 5000000); -Ticker Int100ms; +Ticker Int10ms; Serial pc(P0_19,P0_18); #define SD_READ_BLOCK_SIZE (256) +//操作用ボタンの配置座標 #define BOTTON_PREV_XPOS (15) #define BOTTON_PREV_YPOS (180) #define BOTTON_PLAY_XPOS (91) @@ -31,11 +32,8 @@ #define BOTTON_STOP_YPOS (180) #define BOTTON_NEXT_XPOS (245) #define BOTTON_NEXT_YPOS (180) -#define BOTTON_VOLUP_XPOS (245) -#define BOTTON_VOLUP_YPOS (10) -#define BOTTON_VOLDOWN_XPOS (245) -#define BOTTON_VOLDOWN_YPOS (80) +//prevボタンのタッチ判定関数 bool checkTouchBotton_prev(int32_t xpos,int32_t ypos) { bool result = 0; @@ -47,6 +45,7 @@ return result; } +//playボタンのタッチ判定関数 bool checkTouchBotton_play(int32_t xpos,int32_t ypos) { bool result = 0; @@ -58,6 +57,7 @@ return result; } +//stopボタンのタッチ判定関数 bool checkTouchBotton_stop(int32_t xpos,int32_t ypos) { bool result = 0; @@ -69,6 +69,7 @@ return result; } +//nextボタンのタッチ判定関数 bool checkTouchBotton_next(int32_t xpos,int32_t ypos) { bool result = 0; @@ -80,28 +81,7 @@ return result; } -bool checkTouchBotton_volup(int32_t xpos,int32_t ypos) -{ - bool result = 0; - if( ( (xpos >= BOTTON_VOLUP_XPOS+5) && (xpos <= BOTTON_VOLUP_XPOS+55) ) && - ( (ypos >= BOTTON_VOLUP_YPOS+5) && (ypos <= BOTTON_VOLUP_YPOS+55) ) ) - { - result = 1; - } - return result; -} - -bool checkTouchBotton_voldown(int32_t xpos,int32_t ypos) -{ - bool result = 0; - if( ( (xpos >= BOTTON_VOLDOWN_XPOS+5) && (xpos <= BOTTON_VOLDOWN_XPOS+55) ) && - ( (ypos >= BOTTON_VOLDOWN_YPOS+5) && (ypos <= BOTTON_VOLDOWN_YPOS+55) ) ) - { - result = 1; - } - return result; -} - +//どのボタンが押されたかの定義 #define TOUCHPANEL_BOTTON_TOUCH_STOP (0) #define TOUCHPANEL_BOTTON_TOUCH_PLAY (1) #define TOUCHPANEL_BOTTON_TOUCH_NEXT (2) @@ -111,6 +91,7 @@ #define TOUCHPANEL_BOTTON_NOT_TOUCH (-1) #define TOUCHPANEL_OTHER_TOUCH (-2) +//タッチ検出用関数 int8_t detectTouchBotton(int32_t xpos,int32_t ypos) { int8_t result = 0; @@ -131,14 +112,6 @@ { result = TOUCHPANEL_BOTTON_TOUCH_NEXT; } - else if( checkTouchBotton_volup(xpos,ypos) ) - { - result = TOUCHPANEL_BOTTON_TOUCH_VOLUP; - } - else if( checkTouchBotton_voldown(xpos,ypos) ) - { - result = TOUCHPANEL_BOTTON_TOUCH_VOLDOWN; - } else if( (xpos == -1) || (ypos == -1) ) { result = TOUCHPANEL_BOTTON_NOT_TOUCH; @@ -156,7 +129,7 @@ bool gf_mp3Playwe_VolmeUpdate = 0; bool gf_TimerInt = 0; -void Int100msFunc() +void Int10msFunc() { gf_TimerInt = 1; } @@ -188,16 +161,12 @@ const bitmap_t img_button_prev = { RGB16, 60, 60, &bmp_button_prev }; const bitmap_t img_button_pause = { RGB16, 60, 60, &bmp_button_pause }; -// const bitmap_t img_button_volup = { RGB16, 60, 60, &bmp_button_volup }; -// const bitmap_t img_button_voldown = { RGB16, 60, 60, &bmp_button_voldown }; - - pc.baud(921600); printf("Power ON\r\n"); - Int100ms.attach_us(&Int100msFunc, 10000); + Int10ms.attach_us(&Int10msFunc, 10000); - //SD Init.(本来ならいらないけど、SDカードによっちゃもう1回リセットしないとダメポ + //SD Init.(本来ならいらないけど、SDカードによっちゃもう1回リセットしないとアクセスできない場合あり sd.disk_initialize(); printf("SDCard inited.\r\n"); @@ -217,8 +186,10 @@ printf("VS1033 inited.\r\n"); printf("init CMPL.\r\n"); + //バックスクリーン色を青色に指定し、画面全体をバックスクリーン色で塗りつぶし lcd.SetBackground(COLOR_BLUE); lcd.FillScreen(-1); + //フォント指定 lcd.SetFont( &TerminusBigFont ); //for Caliblation @@ -233,15 +204,13 @@ wait_ms(500); } + //MP3プレイヤー操作用ボタンを配置 //Xpos, Ypos, ImageData(type:bitmap_t), Scale lcd.DrawBitmap( BOTTON_PREV_XPOS, BOTTON_PREV_YPOS, (const bitmap_t*)&img_button_prev, 1 ); lcd.DrawBitmap( BOTTON_PLAY_XPOS, BOTTON_PLAY_YPOS, (const bitmap_t*)&img_button_play, 1 ); lcd.DrawBitmap( BOTTON_STOP_XPOS, BOTTON_STOP_YPOS, (const bitmap_t*)&img_button_stop, 1 ); lcd.DrawBitmap( BOTTON_NEXT_XPOS, BOTTON_STOP_YPOS, (const bitmap_t*)&img_button_next, 1 ); -// lcd.DrawBitmap( BOTTON_VOLUP_XPOS, BOTTON_VOLUP_YPOS, (const bitmap_t*)&img_button_volup, 1 ); -// lcd.DrawBitmap( BOTTON_VOLDOWN_XPOS, BOTTON_VOLDOWN_YPOS, (const bitmap_t*)&img_button_voldown, 1 ); - //////////////////////////////////////////////////////////// /* SDCard GetFileList Section */ //////////////////////////////////////////////////////////// @@ -260,7 +229,7 @@ d = opendir("/sd"); if ( d != NULL ) { - while ( (p = readdir(d)) != NULL ) + while ( (p = readdir(d)) != NULL ) //SDカード内のファイル一覧を取得 { char *ret; ret = strstr(p->d_name,"System"); //System Vol..フォルダは除外 @@ -276,7 +245,8 @@ } closedir(d); -//g_mp3Player_Stateに対して↓ +//MP3プレイヤーの状態遷移定義 +//g_mp3Player_State変数にて使用 #define MP3_STATE_STOPPING (0) #define MP3_STATE_STOPREQ (1) #define MP3_STATE_PLAYREQ (2) @@ -296,6 +266,7 @@ g_mp3Player_State = MP3_STATE_FILECHANGE; f_mp3Playwe_Playing = 0; lcd.Print("STOP ",15,145); + //プログレスバーの描画 lcd.DrawRect(135,155,310,165,COLOR_WHITE); lcd.FillRect(136,156,309,164,COLOR_BLUE); @@ -305,7 +276,7 @@ ////////////////////////////////////////////////////////////// /* TouchPanel GetStatas Section */ ////////////////////////////////////////////////////////////// - if(gf_TimerInt == 1) + if(gf_TimerInt == 1) //10msタイマのフラグが立っていたらタッチパネル読み込みを行う { gf_TimerInt = 0; @@ -319,7 +290,7 @@ aveXReadPos = 0; aveYReadPos = 0; } - #define TOUCHPANEL_AVERAGE_COUNT (5) + #define TOUCHPANEL_AVERAGE_COUNT (5) //5回読んだタッチパネル座標の平均値を取得 else if(c_TouchPanelAve <= TOUCHPANEL_AVERAGE_COUNT) { printf("X:%d Y:%d\r\n",XReadPos,YReadPos); @@ -334,7 +305,7 @@ c_TouchPanelAve = (TOUCHPANEL_AVERAGE_COUNT+1); printf("Xave:%d Yave:%d\r\n",aveXReadPos,aveYReadPos); } - if(c_TouchPanelAve == (TOUCHPANEL_AVERAGE_COUNT+1) ) + if(c_TouchPanelAve == (TOUCHPANEL_AVERAGE_COUNT+1) ) //平均値を元にどのボタンが押されたか判定 { switch( detectTouchBotton(aveXReadPos,aveYReadPos) ) {