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 03 10:28:22 2019 +0900
Revision:
11:8dc9fa1e1bdc
Parent:
8:e35c1f3add8c
Child:
13:544349ffb861
Simplified: PWM LED indicator and etc.

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 0:9a5c2fb0d96f 117 }
mimi3 0:9a5c2fb0d96f 118 #if TEST_PORT_ENABLE
mimi3 0:9a5c2fb0d96f 119 test_port =0;
mimi3 0:9a5c2fb0d96f 120 #endif
mimi3 5:4aa4cc29d5ef 121
mimi3 8:e35c1f3add8c 122 TIM_PWM->SR &= (~TIM_SR_UIF);
mimi3 0:9a5c2fb0d96f 123 }
mimi3 0:9a5c2fb0d96f 124 }
mimi3 0:9a5c2fb0d96f 125
mimi3 0:9a5c2fb0d96f 126 /******************
mimi3 0:9a5c2fb0d96f 127 wave_player_main
mimi3 0:9a5c2fb0d96f 128 *******************/
mimi3 0:9a5c2fb0d96f 129 void wave_player_main(){
mimi3 0:9a5c2fb0d96f 130 bVolumeUpFactor = calcPcmValidBits() - 8;
mimi3 0:9a5c2fb0d96f 131 word wBtnLowCount = 0;
mimi3 11:8dc9fa1e1bdc 132 #if HAVE_LED_IND_BLINK
mimi3 0:9a5c2fb0d96f 133 byte bTimeout_led = 0;
mimi3 0:9a5c2fb0d96f 134 #endif
mimi3 0:9a5c2fb0d96f 135 sbit btn_bit_prev = true, btn_short_on = false;
mimi3 0:9a5c2fb0d96f 136 sbit btn_long_on = false;
mimi3 0:9a5c2fb0d96f 137 #if HAVE_POWER_OFF_MODE
mimi3 0:9a5c2fb0d96f 138 btn_long_on2 = false;
mimi3 0:9a5c2fb0d96f 139 #endif
mimi3 11:8dc9fa1e1bdc 140
mimi3 0:9a5c2fb0d96f 141 sbit btn_pause_prev = false;
mimi3 11:8dc9fa1e1bdc 142 #define fbtn_next_song_on btn_short_on
mimi3 0:9a5c2fb0d96f 143 #define btn_pause_on btn_long_on
mimi3 0:9a5c2fb0d96f 144 #define btn_power_off_on btn_long_on2
mimi3 0:9a5c2fb0d96f 145
mimi3 11:8dc9fa1e1bdc 146 #if HAVE_LED_IND_PWM // pseudo PWM setting
mimi3 11:8dc9fa1e1bdc 147 const int8_t IND_PERIOD = 125;
mimi3 11:8dc9fa1e1bdc 148 const int8_t IND_DUTY_LOW_SPEED = 1;
mimi3 11:8dc9fa1e1bdc 149 const int8_t IND_DUTY_HI_SPEED = 3;
mimi3 11:8dc9fa1e1bdc 150 int8_t sbIndDuty = 0;
mimi3 11:8dc9fa1e1bdc 151 int8_t sbIndCurrPos = 0;
mimi3 11:8dc9fa1e1bdc 152 int8_t sbIndSpeed = IND_DUTY_LOW_SPEED;
mimi3 11:8dc9fa1e1bdc 153 int8_t sbIndDelta = sbIndSpeed;
mimi3 0:9a5c2fb0d96f 154 #endif
mimi3 0:9a5c2fb0d96f 155
mimi3 0:9a5c2fb0d96f 156 init_tickTimer();
mimi3 0:9a5c2fb0d96f 157
mimi3 0:9a5c2fb0d96f 158 while(1){
mimi3 0:9a5c2fb0d96f 159 //; wait 10msec Ticker flag
mimi3 0:9a5c2fb0d96f 160 while ( !isTickTimer_IF() ) {
mimi3 0:9a5c2fb0d96f 161 if( ldwSongFileSectors == 0 ){ //; found end of file
mimi3 0:9a5c2fb0d96f 162 break; //promptly exit and prepare next song
mimi3 0:9a5c2fb0d96f 163 }
mimi3 11:8dc9fa1e1bdc 164 #if HAVE_LED_IND_PWM
mimi3 11:8dc9fa1e1bdc 165 /*# ---------------------
mimi3 11:8dc9fa1e1bdc 166 # pseudo PWM for LED
mimi3 11:8dc9fa1e1bdc 167 # ---------------------*/
mimi3 11:8dc9fa1e1bdc 168 if(sbIndCurrPos < sbIndDuty) { ind_on();}
mimi3 11:8dc9fa1e1bdc 169 else{ ind_off();}
mimi3 11:8dc9fa1e1bdc 170 sbIndCurrPos++;
mimi3 11:8dc9fa1e1bdc 171 if(sbIndCurrPos == IND_PERIOD){ sbIndCurrPos = 0; }
mimi3 0:9a5c2fb0d96f 172 #endif
mimi3 0:9a5c2fb0d96f 173 } //; end. wait 10msec Ticker flag
mimi3 0:9a5c2fb0d96f 174
mimi3 0:9a5c2fb0d96f 175 //-------------------
mimi3 0:9a5c2fb0d96f 176 tickTimer_IF_clear();
mimi3 0:9a5c2fb0d96f 177 //-------------------
mimi3 0:9a5c2fb0d96f 178
mimi3 0:9a5c2fb0d96f 179 /*-------------------
mimi3 0:9a5c2fb0d96f 180 Next song and start
mimi3 0:9a5c2fb0d96f 181 -------------------*/
mimi3 11:8dc9fa1e1bdc 182 if ( ( ldwSongFileSectors == 0 ) | fbtn_next_song_on ){
mimi3 11:8dc9fa1e1bdc 183 pwm_period_timer_music_stop();
mimi3 11:8dc9fa1e1bdc 184 fbtn_next_song_on = false;
mimi3 11:8dc9fa1e1bdc 185 sd_stop_read();
mimi3 11:8dc9fa1e1bdc 186
mimi3 11:8dc9fa1e1bdc 187 /*# ------------------
mimi3 11:8dc9fa1e1bdc 188 # Search next song
mimi3 11:8dc9fa1e1bdc 189 # ------------------*/
mimi3 0:9a5c2fb0d96f 190 searchNextFile();
mimi3 0:9a5c2fb0d96f 191 //## Seek to Target file sector
mimi3 0:9a5c2fb0d96f 192 sd_start_read( gdwTargetFileSector );
mimi3 0:9a5c2fb0d96f 193
mimi3 11:8dc9fa1e1bdc 194 //; delete about last 30Kbyte to cut tag data in *.wav file
mimi3 11:8dc9fa1e1bdc 195 ldwSongFileSectors = ( (gdwBPB_FileSize - CUT_LAST_TAG_NOISE) )>>9 ; //512 , change to sector
mimi3 11:8dc9fa1e1bdc 196
mimi3 11:8dc9fa1e1bdc 197 /*# ------------------
mimi3 11:8dc9fa1e1bdc 198 # Get wav header info
mimi3 11:8dc9fa1e1bdc 199 # ------------------*/
mimi3 11:8dc9fa1e1bdc 200 sd_read_pulse_byte(22); // pos(22) ## Skip part of WAV header
mimi3 11:8dc9fa1e1bdc 201 lbCh_mode = sd_data_byte();// pos(23)
mimi3 11:8dc9fa1e1bdc 202 sd_data_byte(); // pos(24) # dummy read
mimi3 0:9a5c2fb0d96f 203 ldwSample_freq = sd_data_byte() + (sd_data_byte() << 8) +
mimi3 0:9a5c2fb0d96f 204 (sd_data_byte() << 16) +
mimi3 11:8dc9fa1e1bdc 205 (sd_data_byte() << 24); // pos(28)
mimi3 11:8dc9fa1e1bdc 206 sd_read_pulse_byte(6); // pos(34) ## Skip some headers
mimi3 11:8dc9fa1e1bdc 207 lbSample_bits = sd_data_byte(); // pos(35)
mimi3 11:8dc9fa1e1bdc 208 sd_read_pulse_byte(9) ; // pos(44) ## Skip to last position of header
mimi3 0:9a5c2fb0d96f 209
mimi3 11:8dc9fa1e1bdc 210 /*# ------------------
mimi3 11:8dc9fa1e1bdc 211 # Set sampling frequency
mimi3 11:8dc9fa1e1bdc 212 # ------------------*/
mimi3 11:8dc9fa1e1bdc 213 setPwmPeriod(ldwSample_freq);
mimi3 0:9a5c2fb0d96f 214
mimi3 11:8dc9fa1e1bdc 215 /*# ------------------
mimi3 11:8dc9fa1e1bdc 216 # Music start
mimi3 11:8dc9fa1e1bdc 217 # ------------------*/
mimi3 11:8dc9fa1e1bdc 218 lwReadCount = wREAD_COUNT - bHEADER_COUNT;
mimi3 11:8dc9fa1e1bdc 219 pwm_period_timer_music_start();
mimi3 0:9a5c2fb0d96f 220 }
mimi3 0:9a5c2fb0d96f 221
mimi3 0:9a5c2fb0d96f 222 /*-------------------
mimi3 0:9a5c2fb0d96f 223 LED indicator 1 --- pseudo PWM
mimi3 0:9a5c2fb0d96f 224 -------------------*/
mimi3 11:8dc9fa1e1bdc 225 #if HAVE_LED_IND_PWM
mimi3 11:8dc9fa1e1bdc 226 sbIndDuty += sbIndDelta;
mimi3 11:8dc9fa1e1bdc 227 if(sbIndDuty > IND_PERIOD){ sbIndDelta = -1 * sbIndSpeed;}
mimi3 11:8dc9fa1e1bdc 228 if(sbIndDuty == 0){ sbIndDelta = sbIndSpeed;}
mimi3 11:8dc9fa1e1bdc 229 if(fPlaying){ sbIndSpeed = IND_DUTY_LOW_SPEED;}
mimi3 11:8dc9fa1e1bdc 230 else{ sbIndSpeed = IND_DUTY_HI_SPEED;}
mimi3 0:9a5c2fb0d96f 231 #endif
mimi3 0:9a5c2fb0d96f 232
mimi3 0:9a5c2fb0d96f 233 /*-------------------
mimi3 0:9a5c2fb0d96f 234 LED indicator 2 --- simple ON/OFF
mimi3 0:9a5c2fb0d96f 235 -------------------*/
mimi3 11:8dc9fa1e1bdc 236 #if HAVE_LED_IND_BLINK
mimi3 0:9a5c2fb0d96f 237 if (bTimeout_led == 0){
mimi3 0:9a5c2fb0d96f 238 if( fPlaying ){
mimi3 0:9a5c2fb0d96f 239 bTimeout_led = LED_PERIOD_PLAYNG ;// during Playing, on/off
mimi3 0:9a5c2fb0d96f 240 led = !led;
mimi3 0:9a5c2fb0d96f 241 }else{
mimi3 0:9a5c2fb0d96f 242 #if HAVE_LED_PAUSE_INDICATOR
mimi3 0:9a5c2fb0d96f 243 bTimeout_led = LED_PERIOD_PAUSING ;// during Pause, on/off
mimi3 0:9a5c2fb0d96f 244 led = !led;
mimi3 0:9a5c2fb0d96f 245 #else
mimi3 0:9a5c2fb0d96f 246 bTimeout_led = 1;
mimi3 0:9a5c2fb0d96f 247 led = 0;
mimi3 0:9a5c2fb0d96f 248 #endif
mimi3 0:9a5c2fb0d96f 249 }
mimi3 0:9a5c2fb0d96f 250 }
mimi3 0:9a5c2fb0d96f 251 bTimeout_led = bTimeout_led - 1;
mimi3 0:9a5c2fb0d96f 252 #endif
mimi3 0:9a5c2fb0d96f 253
mimi3 0:9a5c2fb0d96f 254 /*-------------------
mimi3 0:9a5c2fb0d96f 255 button sw input
mimi3 0:9a5c2fb0d96f 256 -------------------*/
mimi3 0:9a5c2fb0d96f 257 #if HAVE_BUTTON_SW
mimi3 0:9a5c2fb0d96f 258 if( btn_bit_prev ^ btn_bit_now) {
mimi3 0:9a5c2fb0d96f 259 if (btn_bit_now){ // ; 0 --> 1: btn released
mimi3 0:9a5c2fb0d96f 260 if( (wBtnLowCount > 10) && (wBtnLowCount < 130)){// ; 100msec < x < 1.3sec
mimi3 0:9a5c2fb0d96f 261 btn_short_on = true;
mimi3 0:9a5c2fb0d96f 262 }
mimi3 0:9a5c2fb0d96f 263 wBtnLowCount = 0;
mimi3 0:9a5c2fb0d96f 264 }
mimi3 0:9a5c2fb0d96f 265 }
mimi3 0:9a5c2fb0d96f 266 btn_bit_prev = btn_bit_now;
mimi3 0:9a5c2fb0d96f 267 if (btn_bit_now == false){
mimi3 0:9a5c2fb0d96f 268 wBtnLowCount = wBtnLowCount + 1;
mimi3 0:9a5c2fb0d96f 269 }
mimi3 0:9a5c2fb0d96f 270 //; recognized pause on
mimi3 0:9a5c2fb0d96f 271 if (wBtnLowCount > 120) { // ; 1.2sec >
mimi3 0:9a5c2fb0d96f 272 btn_long_on = true;
mimi3 0:9a5c2fb0d96f 273 }
mimi3 0:9a5c2fb0d96f 274 #if HAVE_POWER_OFF_MODE
mimi3 0:9a5c2fb0d96f 275 if (wBtnLowCount > 400){ //; 4sec >
mimi3 0:9a5c2fb0d96f 276 //; "long on2" is meaning go to sleep mode
mimi3 0:9a5c2fb0d96f 277 btn_long_on2 = true;
mimi3 0:9a5c2fb0d96f 278 }
mimi3 0:9a5c2fb0d96f 279 #endif
mimi3 11:8dc9fa1e1bdc 280
mimi3 11:8dc9fa1e1bdc 281 /*-------------------
mimi3 11:8dc9fa1e1bdc 282 Pause release
mimi3 11:8dc9fa1e1bdc 283 -------------------*/
mimi3 11:8dc9fa1e1bdc 284 if( fbtn_next_song_on){
mimi3 11:8dc9fa1e1bdc 285 if( !fPlaying){ // ; if during pause
mimi3 11:8dc9fa1e1bdc 286 fPlaying = true ; //release pause
mimi3 11:8dc9fa1e1bdc 287 fbtn_next_song_on = false;
mimi3 11:8dc9fa1e1bdc 288 btn_pause_on = false;
mimi3 11:8dc9fa1e1bdc 289 pwm_period_timer_music_start();
mimi3 11:8dc9fa1e1bdc 290 }
mimi3 11:8dc9fa1e1bdc 291 }
mimi3 11:8dc9fa1e1bdc 292
mimi3 11:8dc9fa1e1bdc 293 /*-------------------
mimi3 11:8dc9fa1e1bdc 294 Pause enter
mimi3 11:8dc9fa1e1bdc 295 -------------------*/
mimi3 11:8dc9fa1e1bdc 296 if( btn_pause_prev ^ btn_pause_on ){
mimi3 11:8dc9fa1e1bdc 297 if( btn_pause_on ){
mimi3 11:8dc9fa1e1bdc 298 fPlaying = false;
mimi3 11:8dc9fa1e1bdc 299 pwm_period_timer_music_stop();
mimi3 11:8dc9fa1e1bdc 300 }
mimi3 11:8dc9fa1e1bdc 301 }
mimi3 11:8dc9fa1e1bdc 302 btn_pause_prev = btn_pause_on;
mimi3 0:9a5c2fb0d96f 303 #endif
mimi3 0:9a5c2fb0d96f 304 } //; [forever loop end]
mimi3 0:9a5c2fb0d96f 305 }
mimi3 0:9a5c2fb0d96f 306
mimi3 0:9a5c2fb0d96f 307