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)
USER_BUTTON: PC_13(default button)
Next song: One click in Play mode.
Pause : Push long time .
Play : One click from Pause.
pwm_lib.h@21:dc161a192ba7, 2020-10-09 (annotated)
- Committer:
- mimi3
- Date:
- Fri Oct 09 07:47:36 2020 +0900
- Revision:
- 21:dc161a192ba7
- Parent:
- 0:9a5c2fb0d96f
trivial change
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mimi3 | 0:9a5c2fb0d96f | 1 | #ifndef __PWM_LIB_H__ |
mimi3 | 0:9a5c2fb0d96f | 2 | #define __PWM_LIB_H__ |
mimi3 | 0:9a5c2fb0d96f | 3 | |
mimi3 | 0:9a5c2fb0d96f | 4 | #include "sys.h" |
mimi3 | 0:9a5c2fb0d96f | 5 | #include "FastPWM.h" |
mimi3 | 0:9a5c2fb0d96f | 6 | |
mimi3 | 0:9a5c2fb0d96f | 7 | /* |
mimi3 | 0:9a5c2fb0d96f | 8 | * PWM Timer interrupt module |
mimi3 | 0:9a5c2fb0d96f | 9 | * */ |
mimi3 | 0:9a5c2fb0d96f | 10 | #if defined(TIM3) |
mimi3 | 0:9a5c2fb0d96f | 11 | # define TIM_PWM TIM3 |
mimi3 | 0:9a5c2fb0d96f | 12 | # define TIM_PWM_IRQ TIM3_IRQn |
mimi3 | 0:9a5c2fb0d96f | 13 | #else |
mimi3 | 0:9a5c2fb0d96f | 14 | # error Edit this file properly ! |
mimi3 | 0:9a5c2fb0d96f | 15 | #endif |
mimi3 | 0:9a5c2fb0d96f | 16 | |
mimi3 | 0:9a5c2fb0d96f | 17 | #define TPWM FastPWM |
mimi3 | 0:9a5c2fb0d96f | 18 | //#define TPWM PwmOut |
mimi3 | 0:9a5c2fb0d96f | 19 | #define PWM_TIMER_PRE_SCALE 1 |
mimi3 | 0:9a5c2fb0d96f | 20 | #define pwm_dutyL_hi(m) pwmLeftHi.pulsewidth_ticks( m ); |
mimi3 | 0:9a5c2fb0d96f | 21 | #define pwm_dutyR_hi(m) pwmRightHi.pulsewidth_ticks( m ); |
mimi3 | 0:9a5c2fb0d96f | 22 | #define pwm_dutyL_low(m) pwmLeftLow.pulsewidth_ticks( m ); |
mimi3 | 0:9a5c2fb0d96f | 23 | #define pwm_dutyR_low(m) pwmRightLow.pulsewidth_ticks( m ); |
mimi3 | 0:9a5c2fb0d96f | 24 | |
mimi3 | 0:9a5c2fb0d96f | 25 | // Use PWM3-1,PWM3-2 with TIM3 |
mimi3 | 0:9a5c2fb0d96f | 26 | #define PWM_PORT_LEFT_HI PB_5 // TIM3_CH2 |
mimi3 | 0:9a5c2fb0d96f | 27 | #define PWM_PORT_RIGHT_HI PB_4 // TIM3_CH1 |
mimi3 | 0:9a5c2fb0d96f | 28 | // Use PWM3-3,PWM3-4 with TIM3 |
mimi3 | 0:9a5c2fb0d96f | 29 | #define PWM_PORT_LEFT_LOW PC_9 // TIM3_CH4 |
mimi3 | 0:9a5c2fb0d96f | 30 | #define PWM_PORT_RIGHT_LOW PC_8 // TIM3_CH3 |
mimi3 | 0:9a5c2fb0d96f | 31 | |
mimi3 | 0:9a5c2fb0d96f | 32 | /* |
mimi3 | 0:9a5c2fb0d96f | 33 | * Timer and Interrupt definitions |
mimi3 | 0:9a5c2fb0d96f | 34 | * */ |
mimi3 | 0:9a5c2fb0d96f | 35 | #define periodTimerIntrStart() __HAL_TIM_ENABLE_IT( &TimHandle_pwm, TIM_IT_UPDATE ) |
mimi3 | 0:9a5c2fb0d96f | 36 | #define periodTimerIntrStop() __HAL_TIM_DISABLE_IT( &TimHandle_pwm, TIM_IT_UPDATE ) |
mimi3 | 0:9a5c2fb0d96f | 37 | #define periodTimerIntrClear() __HAL_TIM_CLEAR_FLAG( &TimHandle_pwm, TIM_FLAG_UPDATE) |
mimi3 | 0:9a5c2fb0d96f | 38 | #define pwmPeriodIntrEnable() NVIC_EnableIRQ( TIM_PWM_IRQ ) |
mimi3 | 0:9a5c2fb0d96f | 39 | #define pwmPeriodIntrDisable() NVIC_DisableIRQ( TIM_PWM_IRQ ) |
mimi3 | 0:9a5c2fb0d96f | 40 | |
mimi3 | 0:9a5c2fb0d96f | 41 | extern TPWM pwmLeftHi,pwmRightHi; |
mimi3 | 0:9a5c2fb0d96f | 42 | extern TPWM pwmLeftLow,pwmRightLow; |
mimi3 | 0:9a5c2fb0d96f | 43 | extern uint8_t gPcmShifNum; |
mimi3 | 0:9a5c2fb0d96f | 44 | void setPwmPeriod(int); |
mimi3 | 0:9a5c2fb0d96f | 45 | uint8_t calcPcmValidBits( void ); |
mimi3 | 0:9a5c2fb0d96f | 46 | |
mimi3 | 0:9a5c2fb0d96f | 47 | void pwm_period_timer_start(); |
mimi3 | 0:9a5c2fb0d96f | 48 | void pwm_period_timer_stop(); |
mimi3 | 0:9a5c2fb0d96f | 49 | void pwm_init() ; |
mimi3 | 0:9a5c2fb0d96f | 50 | #endif /* __PWM_LIB_H__ */ |
mimi3 | 0:9a5c2fb0d96f | 51 | |
mimi3 | 0:9a5c2fb0d96f | 52 |