16bit resolution PWM wave player with SD card, super lite version.

Dependencies:   mbed DirectSPI FastPWM

Supported boards (confirmed):
Nucleo-F030R8
Nucleo-L152RE
Nucleo-F401RE
Nucleo-F411RE

Only compilation is OK (unchecked, but may work):
Nucleo-L073RZ
Nucleo-F334R8
Nucleo-F303RE
Nucleo-F429ZI
Nucleo-F446RE
Nucleo-F446ZE
Nucleo-L476RG

Supported SD card:
SDSC/SDHC card,
FAT16 and FAT32.
(1) At first, format SD card using SD Card Formatter
https://www.sdcard.org/downloads/formatter_4/index.html
(2) Copy PCM wav files to the SD card.
Supported file:
PCM wave file that have file extension ".wav" on root directory.
16bit/8bit, fs(sampling rate)=32kHz,44.1kHz,48kHz.
Stereo/Mono.

Hardware setting:
Refer to the file port_setting.txt
PWM output port:
Left upper(Hi) PWM 8bit out: PB_5 (TM3_CH2)
Right upper(Hi) PWM 8bit out: PB4 (TM3_CH1)
Left lower(Low) PWM 8bit out: PC_9 (TM3_CH4)
Right lower(Low) PWM 8bit out: PC_8 (TM3_CH3)
http://mpu.up.seesaa.net/image/16bit-wave-player-output-schema.png
USER_BUTTON: PC_13(default button)
Next song: One click in Play mode.
Pause : Push long time .
Play : One click from Pause.

Committer:
mimi3
Date:
Sun Feb 17 10:27:26 2019 +0900
Revision:
13:544349ffb861
Parent:
11:8dc9fa1e1bdc
Child:
18:082bce602af9
change: Checking end of song

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mimi3 0:9a5c2fb0d96f 1 #include "sys.h"
mimi3 0:9a5c2fb0d96f 2 #include "sd_card.h"
mimi3 0:9a5c2fb0d96f 3 #include "fat_lib.h"
mimi3 0:9a5c2fb0d96f 4 #include "pwm_lib.h"
mimi3 0:9a5c2fb0d96f 5 #include "timers.h"
mimi3 0:9a5c2fb0d96f 6
mimi3 0:9a5c2fb0d96f 7 #define CH_STEREO 2 // 2:STEREO, 1:MONO
mimi3 0:9a5c2fb0d96f 8 #define wREAD_COUNT 512
mimi3 0:9a5c2fb0d96f 9 #define bHEADER_COUNT 44
mimi3 0:9a5c2fb0d96f 10 #define send_ff() spi_read()
mimi3 0:9a5c2fb0d96f 11 #define send_ff16() spi_read16()
mimi3 0:9a5c2fb0d96f 12 #define CUT_LAST_TAG_NOISE (30*1000)
mimi3 11:8dc9fa1e1bdc 13 #if (HAVE_LED_IND_PWM==1) || (HAVE_LED_IND_BLINK==1)
mimi3 0:9a5c2fb0d96f 14 DigitalOut led(IND_LED);
mimi3 0:9a5c2fb0d96f 15 #endif
mimi3 11:8dc9fa1e1bdc 16 #define ind_on() (led = 1)
mimi3 11:8dc9fa1e1bdc 17 #define ind_off() (led = 0)
mimi3 11:8dc9fa1e1bdc 18
mimi3 11:8dc9fa1e1bdc 19 #define pwm_period_timer_music_start() ( pwm_period_timer_start(),fPlaying = true)
mimi3 11:8dc9fa1e1bdc 20 #define pwm_period_timer_music_stop() ( pwm_period_timer_stop(), fPlaying = false)
mimi3 0:9a5c2fb0d96f 21
mimi3 0:9a5c2fb0d96f 22 /******************
mimi3 0:9a5c2fb0d96f 23 varialble definitions
mimi3 0:9a5c2fb0d96f 24 *******************/
mimi3 0:9a5c2fb0d96f 25 #define LED_PERIOD_PLAYNG 75 //[ * 10 msec]
mimi3 0:9a5c2fb0d96f 26 #define LED_PERIOD_PAUSING 10 //[ * 10 msec]
mimi3 0:9a5c2fb0d96f 27 dword ldwSongFileSectors;
mimi3 0:9a5c2fb0d96f 28 dword ldwSample_freq;
mimi3 0:9a5c2fb0d96f 29 word lwReadCount;
mimi3 0:9a5c2fb0d96f 30 byte lbSample_bits = 16;
mimi3 0:9a5c2fb0d96f 31 byte lbCh_mode = CH_STEREO;
mimi3 0:9a5c2fb0d96f 32 byte bVolumeUpFactor;
mimi3 11:8dc9fa1e1bdc 33 bool fPlaying = false;
mimi3 0:9a5c2fb0d96f 34
mimi3 0:9a5c2fb0d96f 35 DigitalIn btn_bit_now(USER_BUTTON,PullUp);
mimi3 0:9a5c2fb0d96f 36
mimi3 0:9a5c2fb0d96f 37 #if TEST_PORT_ENABLE
mimi3 0:9a5c2fb0d96f 38 DigitalOut test_port(TEST_PORT);
mimi3 0:9a5c2fb0d96f 39 #endif
mimi3 0:9a5c2fb0d96f 40
mimi3 0:9a5c2fb0d96f 41 /**********************
mimi3 0:9a5c2fb0d96f 42 Period Timer Interrupt
mimi3 0:9a5c2fb0d96f 43 **********************/
mimi3 0:9a5c2fb0d96f 44 /* HAL callback for PWM Timer Intrrupt * */
mimi3 6:d9ea630e1ba5 45 void OPT_SPEED pwmPeriodIntr( void ){
mimi3 8:e35c1f3add8c 46 if(TIM_PWM->SR & TIM_SR_UIF){
mimi3 0:9a5c2fb0d96f 47 #if TEST_PORT_ENABLE
mimi3 0:9a5c2fb0d96f 48 test_port =1;
mimi3 0:9a5c2fb0d96f 49 #endif
mimi3 0:9a5c2fb0d96f 50 #if PWM16BIT
mimi3 0:9a5c2fb0d96f 51 word wL_low,wL_hi,wR_low,wR_hi;
mimi3 0:9a5c2fb0d96f 52 dword dw;
mimi3 0:9a5c2fb0d96f 53 if( lbSample_bits == 16 ) {
mimi3 0:9a5c2fb0d96f 54 dw = ((word)(send_ff() + (send_ff()<<8) + 0x8000)) << bVolumeUpFactor;
mimi3 0:9a5c2fb0d96f 55 wL_low = wR_low = (dw & 0xff); // get lower 8bit
mimi3 0:9a5c2fb0d96f 56 wL_hi = wR_hi = (dw >>8); // get upper 10bit
mimi3 0:9a5c2fb0d96f 57 lwReadCount -= 2;
mimi3 0:9a5c2fb0d96f 58 if( lbCh_mode == CH_STEREO ) {
mimi3 0:9a5c2fb0d96f 59 dw = ((word)(send_ff() + (send_ff()<<8) + 0x8000)) << bVolumeUpFactor;
mimi3 0:9a5c2fb0d96f 60 wR_low = (dw & 0xff);
mimi3 0:9a5c2fb0d96f 61 wR_hi = (dw >> 8);
mimi3 0:9a5c2fb0d96f 62 lwReadCount -= 2;
mimi3 0:9a5c2fb0d96f 63 }
mimi3 0:9a5c2fb0d96f 64 }
mimi3 0:9a5c2fb0d96f 65 #if DATA_8BIT_SUPPORT
mimi3 0:9a5c2fb0d96f 66 else { /* 8bit data */
mimi3 0:9a5c2fb0d96f 67 wL_hi = wR_hi = send_ff() << bVolumeUpFactor; // volume up to 10bit (x4) from 8bit
mimi3 0:9a5c2fb0d96f 68 wL_low = 0;
mimi3 0:9a5c2fb0d96f 69 wR_low = 0;
mimi3 0:9a5c2fb0d96f 70 lwReadCount -= 1;
mimi3 0:9a5c2fb0d96f 71 if( lbCh_mode == CH_STEREO ) { /* for stereo */
mimi3 0:9a5c2fb0d96f 72 wR_hi = send_ff() << 2;
mimi3 0:9a5c2fb0d96f 73 wR_low = 0;
mimi3 0:9a5c2fb0d96f 74 lwReadCount -= 1;
mimi3 0:9a5c2fb0d96f 75 }
mimi3 0:9a5c2fb0d96f 76 }
mimi3 0:9a5c2fb0d96f 77 #endif
mimi3 0:9a5c2fb0d96f 78 //# change pwm duties
mimi3 0:9a5c2fb0d96f 79 pwm_dutyL_hi( wL_hi ) ;
mimi3 0:9a5c2fb0d96f 80 pwm_dutyL_low( wL_low ) ;
mimi3 0:9a5c2fb0d96f 81 pwm_dutyR_hi( wR_hi ) ;
mimi3 0:9a5c2fb0d96f 82 pwm_dutyR_low( wR_low ) ;
mimi3 0:9a5c2fb0d96f 83
mimi3 0:9a5c2fb0d96f 84 #else // not PWM16BIT
mimi3 0:9a5c2fb0d96f 85 word wL =0,wR = 0;
mimi3 0:9a5c2fb0d96f 86 if( lbSample_bits == 16 ) {
mimi3 0:9a5c2fb0d96f 87 wL = wR = ((word)(send_ff() + (send_ff()<<8) + 0x8000))>>gPcmShifNum;
mimi3 0:9a5c2fb0d96f 88 lwReadCount -= 2;
mimi3 0:9a5c2fb0d96f 89 if( lbCh_mode == CH_STEREO ) {
mimi3 0:9a5c2fb0d96f 90 wR = (word)(send_ff() + (send_ff()<<8) + 0x8000)>>gPcmShifNum;
mimi3 0:9a5c2fb0d96f 91 lwReadCount -= 2;
mimi3 0:9a5c2fb0d96f 92 }
mimi3 0:9a5c2fb0d96f 93 }
mimi3 0:9a5c2fb0d96f 94 #if DATA_8BIT_SUPPORT
mimi3 0:9a5c2fb0d96f 95 else { /* 8bit data */
mimi3 0:9a5c2fb0d96f 96 wL = wR = send_ff() << bVolumeUpFactor; // volume up to 10bit (x4) from 8bit
mimi3 0:9a5c2fb0d96f 97 lwReadCount -= 1;
mimi3 0:9a5c2fb0d96f 98 if( lbCh_mode == CH_STEREO ) { /* for stereo */
mimi3 0:9a5c2fb0d96f 99 wR = send_ff() << bVolumeUpFactor;
mimi3 0:9a5c2fb0d96f 100 lwReadCount -= 1;
mimi3 0:9a5c2fb0d96f 101 }
mimi3 0:9a5c2fb0d96f 102 }
mimi3 0:9a5c2fb0d96f 103 #endif
mimi3 0:9a5c2fb0d96f 104 //# change pwm duties
mimi3 0:9a5c2fb0d96f 105 pwm_dutyL_hi( wL ) ;
mimi3 0:9a5c2fb0d96f 106 pwm_dutyR_hi( wR ) ;
mimi3 0:9a5c2fb0d96f 107 #endif
mimi3 0:9a5c2fb0d96f 108
mimi3 0:9a5c2fb0d96f 109 //; check 512byte sector boundery
mimi3 0:9a5c2fb0d96f 110 if( lwReadCount == 0){
mimi3 0:9a5c2fb0d96f 111 //; end 1 sector
mimi3 0:9a5c2fb0d96f 112 send_ff() ;// dummy read 1st. discard CRC
mimi3 0:9a5c2fb0d96f 113 send_ff() ;// 2nd.
mimi3 0:9a5c2fb0d96f 114 while( send_ff() != 0xFE) {}
mimi3 0:9a5c2fb0d96f 115 lwReadCount = wREAD_COUNT;
mimi3 0:9a5c2fb0d96f 116 ldwSongFileSectors -= 1;
mimi3 13:544349ffb861 117 if(ldwSongFileSectors == 0){
mimi3 13:544349ffb861 118 pwm_period_timer_music_stop();
mimi3 13:544349ffb861 119 }
mimi3 0:9a5c2fb0d96f 120 }
mimi3 0:9a5c2fb0d96f 121 #if TEST_PORT_ENABLE
mimi3 0:9a5c2fb0d96f 122 test_port =0;
mimi3 0:9a5c2fb0d96f 123 #endif
mimi3 5:4aa4cc29d5ef 124
mimi3 8:e35c1f3add8c 125 TIM_PWM->SR &= (~TIM_SR_UIF);
mimi3 0:9a5c2fb0d96f 126 }
mimi3 0:9a5c2fb0d96f 127 }
mimi3 0:9a5c2fb0d96f 128
mimi3 0:9a5c2fb0d96f 129 /******************
mimi3 0:9a5c2fb0d96f 130 wave_player_main
mimi3 0:9a5c2fb0d96f 131 *******************/
mimi3 0:9a5c2fb0d96f 132 void wave_player_main(){
mimi3 0:9a5c2fb0d96f 133 bVolumeUpFactor = calcPcmValidBits() - 8;
mimi3 0:9a5c2fb0d96f 134 word wBtnLowCount = 0;
mimi3 11:8dc9fa1e1bdc 135 #if HAVE_LED_IND_BLINK
mimi3 0:9a5c2fb0d96f 136 byte bTimeout_led = 0;
mimi3 0:9a5c2fb0d96f 137 #endif
mimi3 0:9a5c2fb0d96f 138 sbit btn_bit_prev = true, btn_short_on = false;
mimi3 0:9a5c2fb0d96f 139 sbit btn_long_on = false;
mimi3 0:9a5c2fb0d96f 140 #if HAVE_POWER_OFF_MODE
mimi3 0:9a5c2fb0d96f 141 btn_long_on2 = false;
mimi3 0:9a5c2fb0d96f 142 #endif
mimi3 11:8dc9fa1e1bdc 143
mimi3 0:9a5c2fb0d96f 144 sbit btn_pause_prev = false;
mimi3 11:8dc9fa1e1bdc 145 #define fbtn_next_song_on btn_short_on
mimi3 0:9a5c2fb0d96f 146 #define btn_pause_on btn_long_on
mimi3 0:9a5c2fb0d96f 147 #define btn_power_off_on btn_long_on2
mimi3 0:9a5c2fb0d96f 148
mimi3 11:8dc9fa1e1bdc 149 #if HAVE_LED_IND_PWM // pseudo PWM setting
mimi3 11:8dc9fa1e1bdc 150 const int8_t IND_PERIOD = 125;
mimi3 11:8dc9fa1e1bdc 151 const int8_t IND_DUTY_LOW_SPEED = 1;
mimi3 11:8dc9fa1e1bdc 152 const int8_t IND_DUTY_HI_SPEED = 3;
mimi3 11:8dc9fa1e1bdc 153 int8_t sbIndDuty = 0;
mimi3 11:8dc9fa1e1bdc 154 int8_t sbIndCurrPos = 0;
mimi3 11:8dc9fa1e1bdc 155 int8_t sbIndSpeed = IND_DUTY_LOW_SPEED;
mimi3 11:8dc9fa1e1bdc 156 int8_t sbIndDelta = sbIndSpeed;
mimi3 0:9a5c2fb0d96f 157 #endif
mimi3 0:9a5c2fb0d96f 158
mimi3 0:9a5c2fb0d96f 159 init_tickTimer();
mimi3 0:9a5c2fb0d96f 160
mimi3 0:9a5c2fb0d96f 161 while(1){
mimi3 0:9a5c2fb0d96f 162 //; wait 10msec Ticker flag
mimi3 0:9a5c2fb0d96f 163 while ( !isTickTimer_IF() ) {
mimi3 0:9a5c2fb0d96f 164 if( ldwSongFileSectors == 0 ){ //; found end of file
mimi3 0:9a5c2fb0d96f 165 break; //promptly exit and prepare next song
mimi3 0:9a5c2fb0d96f 166 }
mimi3 11:8dc9fa1e1bdc 167 #if HAVE_LED_IND_PWM
mimi3 11:8dc9fa1e1bdc 168 /*# ---------------------
mimi3 11:8dc9fa1e1bdc 169 # pseudo PWM for LED
mimi3 11:8dc9fa1e1bdc 170 # ---------------------*/
mimi3 11:8dc9fa1e1bdc 171 if(sbIndCurrPos < sbIndDuty) { ind_on();}
mimi3 11:8dc9fa1e1bdc 172 else{ ind_off();}
mimi3 11:8dc9fa1e1bdc 173 sbIndCurrPos++;
mimi3 11:8dc9fa1e1bdc 174 if(sbIndCurrPos == IND_PERIOD){ sbIndCurrPos = 0; }
mimi3 0:9a5c2fb0d96f 175 #endif
mimi3 0:9a5c2fb0d96f 176 } //; end. wait 10msec Ticker flag
mimi3 0:9a5c2fb0d96f 177
mimi3 0:9a5c2fb0d96f 178 //-------------------
mimi3 0:9a5c2fb0d96f 179 tickTimer_IF_clear();
mimi3 0:9a5c2fb0d96f 180 //-------------------
mimi3 0:9a5c2fb0d96f 181
mimi3 0:9a5c2fb0d96f 182 /*-------------------
mimi3 0:9a5c2fb0d96f 183 Next song and start
mimi3 0:9a5c2fb0d96f 184 -------------------*/
mimi3 11:8dc9fa1e1bdc 185 if ( ( ldwSongFileSectors == 0 ) | fbtn_next_song_on ){
mimi3 11:8dc9fa1e1bdc 186 pwm_period_timer_music_stop();
mimi3 11:8dc9fa1e1bdc 187 fbtn_next_song_on = false;
mimi3 11:8dc9fa1e1bdc 188 sd_stop_read();
mimi3 11:8dc9fa1e1bdc 189
mimi3 11:8dc9fa1e1bdc 190 /*# ------------------
mimi3 11:8dc9fa1e1bdc 191 # Search next song
mimi3 11:8dc9fa1e1bdc 192 # ------------------*/
mimi3 0:9a5c2fb0d96f 193 searchNextFile();
mimi3 0:9a5c2fb0d96f 194 //## Seek to Target file sector
mimi3 0:9a5c2fb0d96f 195 sd_start_read( gdwTargetFileSector );
mimi3 0:9a5c2fb0d96f 196
mimi3 11:8dc9fa1e1bdc 197 //; delete about last 30Kbyte to cut tag data in *.wav file
mimi3 11:8dc9fa1e1bdc 198 ldwSongFileSectors = ( (gdwBPB_FileSize - CUT_LAST_TAG_NOISE) )>>9 ; //512 , change to sector
mimi3 11:8dc9fa1e1bdc 199
mimi3 11:8dc9fa1e1bdc 200 /*# ------------------
mimi3 11:8dc9fa1e1bdc 201 # Get wav header info
mimi3 11:8dc9fa1e1bdc 202 # ------------------*/
mimi3 11:8dc9fa1e1bdc 203 sd_read_pulse_byte(22); // pos(22) ## Skip part of WAV header
mimi3 11:8dc9fa1e1bdc 204 lbCh_mode = sd_data_byte();// pos(23)
mimi3 11:8dc9fa1e1bdc 205 sd_data_byte(); // pos(24) # dummy read
mimi3 0:9a5c2fb0d96f 206 ldwSample_freq = sd_data_byte() + (sd_data_byte() << 8) +
mimi3 0:9a5c2fb0d96f 207 (sd_data_byte() << 16) +
mimi3 11:8dc9fa1e1bdc 208 (sd_data_byte() << 24); // pos(28)
mimi3 11:8dc9fa1e1bdc 209 sd_read_pulse_byte(6); // pos(34) ## Skip some headers
mimi3 11:8dc9fa1e1bdc 210 lbSample_bits = sd_data_byte(); // pos(35)
mimi3 11:8dc9fa1e1bdc 211 sd_read_pulse_byte(9) ; // pos(44) ## Skip to last position of header
mimi3 0:9a5c2fb0d96f 212
mimi3 11:8dc9fa1e1bdc 213 /*# ------------------
mimi3 11:8dc9fa1e1bdc 214 # Set sampling frequency
mimi3 11:8dc9fa1e1bdc 215 # ------------------*/
mimi3 11:8dc9fa1e1bdc 216 setPwmPeriod(ldwSample_freq);
mimi3 0:9a5c2fb0d96f 217
mimi3 11:8dc9fa1e1bdc 218 /*# ------------------
mimi3 11:8dc9fa1e1bdc 219 # Music start
mimi3 11:8dc9fa1e1bdc 220 # ------------------*/
mimi3 11:8dc9fa1e1bdc 221 lwReadCount = wREAD_COUNT - bHEADER_COUNT;
mimi3 11:8dc9fa1e1bdc 222 pwm_period_timer_music_start();
mimi3 0:9a5c2fb0d96f 223 }
mimi3 0:9a5c2fb0d96f 224
mimi3 0:9a5c2fb0d96f 225 /*-------------------
mimi3 0:9a5c2fb0d96f 226 LED indicator 1 --- pseudo PWM
mimi3 0:9a5c2fb0d96f 227 -------------------*/
mimi3 11:8dc9fa1e1bdc 228 #if HAVE_LED_IND_PWM
mimi3 11:8dc9fa1e1bdc 229 sbIndDuty += sbIndDelta;
mimi3 11:8dc9fa1e1bdc 230 if(sbIndDuty > IND_PERIOD){ sbIndDelta = -1 * sbIndSpeed;}
mimi3 11:8dc9fa1e1bdc 231 if(sbIndDuty == 0){ sbIndDelta = sbIndSpeed;}
mimi3 11:8dc9fa1e1bdc 232 if(fPlaying){ sbIndSpeed = IND_DUTY_LOW_SPEED;}
mimi3 11:8dc9fa1e1bdc 233 else{ sbIndSpeed = IND_DUTY_HI_SPEED;}
mimi3 0:9a5c2fb0d96f 234 #endif
mimi3 0:9a5c2fb0d96f 235
mimi3 0:9a5c2fb0d96f 236 /*-------------------
mimi3 0:9a5c2fb0d96f 237 LED indicator 2 --- simple ON/OFF
mimi3 0:9a5c2fb0d96f 238 -------------------*/
mimi3 11:8dc9fa1e1bdc 239 #if HAVE_LED_IND_BLINK
mimi3 0:9a5c2fb0d96f 240 if (bTimeout_led == 0){
mimi3 0:9a5c2fb0d96f 241 if( fPlaying ){
mimi3 0:9a5c2fb0d96f 242 bTimeout_led = LED_PERIOD_PLAYNG ;// during Playing, on/off
mimi3 0:9a5c2fb0d96f 243 led = !led;
mimi3 0:9a5c2fb0d96f 244 }else{
mimi3 0:9a5c2fb0d96f 245 #if HAVE_LED_PAUSE_INDICATOR
mimi3 0:9a5c2fb0d96f 246 bTimeout_led = LED_PERIOD_PAUSING ;// during Pause, on/off
mimi3 0:9a5c2fb0d96f 247 led = !led;
mimi3 0:9a5c2fb0d96f 248 #else
mimi3 0:9a5c2fb0d96f 249 bTimeout_led = 1;
mimi3 0:9a5c2fb0d96f 250 led = 0;
mimi3 0:9a5c2fb0d96f 251 #endif
mimi3 0:9a5c2fb0d96f 252 }
mimi3 0:9a5c2fb0d96f 253 }
mimi3 0:9a5c2fb0d96f 254 bTimeout_led = bTimeout_led - 1;
mimi3 0:9a5c2fb0d96f 255 #endif
mimi3 0:9a5c2fb0d96f 256
mimi3 0:9a5c2fb0d96f 257 /*-------------------
mimi3 0:9a5c2fb0d96f 258 button sw input
mimi3 0:9a5c2fb0d96f 259 -------------------*/
mimi3 0:9a5c2fb0d96f 260 #if HAVE_BUTTON_SW
mimi3 0:9a5c2fb0d96f 261 if( btn_bit_prev ^ btn_bit_now) {
mimi3 0:9a5c2fb0d96f 262 if (btn_bit_now){ // ; 0 --> 1: btn released
mimi3 0:9a5c2fb0d96f 263 if( (wBtnLowCount > 10) && (wBtnLowCount < 130)){// ; 100msec < x < 1.3sec
mimi3 0:9a5c2fb0d96f 264 btn_short_on = true;
mimi3 0:9a5c2fb0d96f 265 }
mimi3 0:9a5c2fb0d96f 266 wBtnLowCount = 0;
mimi3 0:9a5c2fb0d96f 267 }
mimi3 0:9a5c2fb0d96f 268 }
mimi3 0:9a5c2fb0d96f 269 btn_bit_prev = btn_bit_now;
mimi3 0:9a5c2fb0d96f 270 if (btn_bit_now == false){
mimi3 0:9a5c2fb0d96f 271 wBtnLowCount = wBtnLowCount + 1;
mimi3 0:9a5c2fb0d96f 272 }
mimi3 0:9a5c2fb0d96f 273 //; recognized pause on
mimi3 0:9a5c2fb0d96f 274 if (wBtnLowCount > 120) { // ; 1.2sec >
mimi3 0:9a5c2fb0d96f 275 btn_long_on = true;
mimi3 0:9a5c2fb0d96f 276 }
mimi3 0:9a5c2fb0d96f 277 #if HAVE_POWER_OFF_MODE
mimi3 0:9a5c2fb0d96f 278 if (wBtnLowCount > 400){ //; 4sec >
mimi3 0:9a5c2fb0d96f 279 //; "long on2" is meaning go to sleep mode
mimi3 0:9a5c2fb0d96f 280 btn_long_on2 = true;
mimi3 0:9a5c2fb0d96f 281 }
mimi3 0:9a5c2fb0d96f 282 #endif
mimi3 11:8dc9fa1e1bdc 283
mimi3 11:8dc9fa1e1bdc 284 /*-------------------
mimi3 11:8dc9fa1e1bdc 285 Pause release
mimi3 11:8dc9fa1e1bdc 286 -------------------*/
mimi3 11:8dc9fa1e1bdc 287 if( fbtn_next_song_on){
mimi3 11:8dc9fa1e1bdc 288 if( !fPlaying){ // ; if during pause
mimi3 11:8dc9fa1e1bdc 289 fPlaying = true ; //release pause
mimi3 11:8dc9fa1e1bdc 290 fbtn_next_song_on = false;
mimi3 11:8dc9fa1e1bdc 291 btn_pause_on = false;
mimi3 11:8dc9fa1e1bdc 292 pwm_period_timer_music_start();
mimi3 11:8dc9fa1e1bdc 293 }
mimi3 11:8dc9fa1e1bdc 294 }
mimi3 11:8dc9fa1e1bdc 295
mimi3 11:8dc9fa1e1bdc 296 /*-------------------
mimi3 11:8dc9fa1e1bdc 297 Pause enter
mimi3 11:8dc9fa1e1bdc 298 -------------------*/
mimi3 11:8dc9fa1e1bdc 299 if( btn_pause_prev ^ btn_pause_on ){
mimi3 11:8dc9fa1e1bdc 300 if( btn_pause_on ){
mimi3 11:8dc9fa1e1bdc 301 fPlaying = false;
mimi3 11:8dc9fa1e1bdc 302 pwm_period_timer_music_stop();
mimi3 11:8dc9fa1e1bdc 303 }
mimi3 11:8dc9fa1e1bdc 304 }
mimi3 11:8dc9fa1e1bdc 305 btn_pause_prev = btn_pause_on;
mimi3 0:9a5c2fb0d96f 306 #endif
mimi3 0:9a5c2fb0d96f 307 } //; [forever loop end]
mimi3 0:9a5c2fb0d96f 308 }
mimi3 0:9a5c2fb0d96f 309
mimi3 0:9a5c2fb0d96f 310