29 static TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
30 static TIM_OCInitTypeDef TIM_OCInitStructure;
40 extern RCC_ClocksTypeDef RCC_ClockFreq;
55 void BUZZER_SetFrequency( u16 freq )
60 CCR_Val = ( RCC_ClockFreq.PCLK1_Frequency / freq );
62 TIM_TimeBaseStructure.TIM_Period = CCR_Val * 2;
63 TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
64 TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
65 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
67 TIM_TimeBaseInit( TIM3, &TIM_TimeBaseStructure );
70 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
72 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
73 TIM_OCInitStructure.TIM_Pulse = CCR_Val;
75 TIM_OC3Init( TIM3, &TIM_OCInitStructure );
76 TIM_OC3PreloadConfig( TIM3, TIM_OCPreload_Enable );
79 AUDIO_BUZZER_SetToneFrequency( freq );
98 NODEBUG2
void BUZZER_Init(
void )
101 GPIO_InitTypeDef GPIO_InitStructure;
104 RCC_PERIPH_GPIO_CLOCK_CMD( RCC_APB2Periph_GPIOB, ENABLE );
107 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
108 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
109 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
111 GPIO_Init( GPIOB, &GPIO_InitStructure );
118 RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3, ENABLE );
120 TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
121 TIM_OCStructInit( &TIM_OCInitStructure );
124 TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
125 TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
126 TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
127 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
129 TIM_TimeBaseInit( TIM3, &TIM_TimeBaseStructure );
132 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
134 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
135 TIM_OCInitStructure.TIM_Pulse = CCR_Val;
137 TIM_OC3Init( TIM3, &TIM_OCInitStructure );
138 TIM_OC3PreloadConfig( TIM3, TIM_OCPreload_Disable );
140 BUZZER_SetFrequency( 440 );
174 if (( AUDIO_Playback_status !=
NO_SOUND )
175 || ( AUDIO_Recording_status !=
NO_RECORD )
176 || ( AUDIO_BuzzerOn == 0 ) )
189 AUDIO_BUZZER_OnOff(
ON );
198 AUDIO_BUZZER_OnOff(
ON );
200 TIM_Cmd( TIM3, ENABLE );
207 AUDIO_BUZZER_OnOff(
OFF );
209 TIM_Cmd( TIM3, DISABLE );