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.

Revision:
18:082bce602af9
Parent:
13:544349ffb861
Child:
19:54aed6200a35
--- a/wave_player_main.cpp	Sun Feb 17 15:10:58 2019 +0900
+++ b/wave_player_main.cpp	Sat Feb 23 21:12:14 2019 +0900
@@ -48,38 +48,35 @@
             test_port =1;
         #endif
         #if PWM16BIT
-            word wL_low,wL_hi,wR_low,wR_hi;
-            dword dw;
+            byte bL_low,bL_hi,bR_low,bR_hi;
             if( lbSample_bits == 16 ) {
-                dw = ((word)(send_ff() + (send_ff()<<8) + 0x8000)) << bVolumeUpFactor;
-                wL_low = wR_low = (dw & 0xff); // get lower 8bit
-                wL_hi  = wR_hi = (dw >>8);     // get upper 10bit
+                bL_low = bR_low = send_ff();
+                bL_hi  = bR_hi = send_ff() + 0x80;
                 lwReadCount -= 2;
                 if( lbCh_mode == CH_STEREO ) {
-                    dw = ((word)(send_ff() + (send_ff()<<8) + 0x8000)) << bVolumeUpFactor;
-                    wR_low = (dw & 0xff);
-                    wR_hi  = (dw >> 8);
+                    bR_low = send_ff();
+                    bR_hi  = send_ff() + 0x80;
                     lwReadCount -= 2;
                 }
             }
             #if DATA_8BIT_SUPPORT
                 else {                                            /* 8bit data */
-                    wL_hi  = wR_hi = send_ff() << bVolumeUpFactor; // volume up to 10bit (x4) from 8bit
-                    wL_low = 0;
-                    wR_low = 0;
+                    bL_hi  = bR_hi = send_ff();
+                    bL_low = 0;
+                    bR_low = 0;
                     lwReadCount -= 1;
                     if( lbCh_mode == CH_STEREO ) {                /* for stereo */
-                        wR_hi  = send_ff() << 2;
-                        wR_low = 0;
+                        bR_hi  = send_ff();
+                        bR_low = 0;
                         lwReadCount -= 1;
                     }
                 }
             #endif
             //# change  pwm duties
-            pwm_dutyL_hi(  wL_hi ) ;
-            pwm_dutyL_low( wL_low ) ;
-            pwm_dutyR_hi(  wR_hi ) ;
-            pwm_dutyR_low( wR_low ) ;
+            pwm_dutyL_hi(  ((word)bL_hi)  << bVolumeUpFactor );
+            pwm_dutyL_low( ((word)bL_low) << bVolumeUpFactor );
+            pwm_dutyR_hi(  ((word)bR_hi)  << bVolumeUpFactor );
+            pwm_dutyR_low( ((word)bR_low) << bVolumeUpFactor );
 
         #else // not PWM16BIT
             word wL =0,wR = 0;
@@ -93,7 +90,7 @@
             }
             #if DATA_8BIT_SUPPORT
                 else {                                            /* 8bit data */
-                    wL = wR = send_ff() << bVolumeUpFactor; // volume up to 10bit (x4) from 8bit
+                    wL = wR = send_ff() << bVolumeUpFactor;
                     lwReadCount -= 1;
                     if( lbCh_mode == CH_STEREO ) {                /* for stereo */
                         wR = send_ff() << bVolumeUpFactor;