summaryrefslogtreecommitdiffstats
path: root/app/buzzer.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/buzzer.c')
-rw-r--r--app/buzzer.c205
1 files changed, 106 insertions, 99 deletions
diff --git a/app/buzzer.c b/app/buzzer.c
index 4c45630..d6f1eb2 100644
--- a/app/buzzer.c
+++ b/app/buzzer.c
@@ -8,116 +8,125 @@ int ringing;
#define C6 1047
#define E6 1319
-void buzzer_on(void)
+void
+buzzer_on (void)
{
- gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
- GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
- GPIO_TIM1_CH1);
- gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
- GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
- GPIO_TIM1_CH1N);
+ gpio_set_mode (GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
+ GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_TIM1_CH1);
+ gpio_set_mode (GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
+ GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_TIM1_CH1N);
- timer_reset(TIM1);
+ timer_reset (TIM1);
- timer_set_mode(TIM1, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_CENTER_1, TIM_CR1_DIR_UP);
- timer_set_oc_mode(TIM1, TIM_OC1, TIM_OCM_PWM2);
- timer_enable_oc_output(TIM1, TIM_OC1);
- timer_enable_oc_output(TIM1, TIM_OC1N);
- timer_enable_break_main_output(TIM1);
+ timer_set_mode (TIM1, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_CENTER_1,
+ TIM_CR1_DIR_UP);
+ timer_set_oc_mode (TIM1, TIM_OC1, TIM_OCM_PWM2);
+ timer_enable_oc_output (TIM1, TIM_OC1);
+ timer_enable_oc_output (TIM1, TIM_OC1N);
+ timer_enable_break_main_output (TIM1);
- timer_set_oc_value(TIM1, TIM_OC1, period/2);
- timer_set_period(TIM1, period);
+ timer_set_oc_value (TIM1, TIM_OC1, period / 2);
+ timer_set_period (TIM1, period);
- timer_enable_counter(TIM1);
+ timer_enable_counter (TIM1);
}
-void buzzer_off(void)
+
+void
+buzzer_off (void)
{
gpio_set_mode (GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO8);
- gpio_clear(GPIOA,GPIO8);
+ gpio_clear (GPIOA, GPIO8);
gpio_set_mode (GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO13);
- gpio_clear(GPIOB,GPIO13);
- timer_disable_counter(TIM1);
+ gpio_clear (GPIOB, GPIO13);
+ timer_disable_counter (TIM1);
}
-void buzzer_set_freq(int hz)
+void
+buzzer_set_freq (int hz)
{
- period=(48000000/4)/hz;
- timer_set_oc_value(TIM1, TIM_OC1, period/2);
- timer_set_period(TIM1, period);
+ period = (48000000 / 4) / hz;
+ timer_set_oc_value (TIM1, TIM_OC1, period / 2);
+ timer_set_period (TIM1, period);
}
-void buzzer_init(void)
+void
+buzzer_init (void)
{
- /*buzzer*/
- buzzer_off();
- buzzer_set_freq(440);
+ /*buzzer */
+ buzzer_off ();
+ buzzer_set_freq (440);
}
-void ring_tick(void)
+void
+ring_tick (void)
{
-static int t;
-
-if (!ringing) return;
-ringing--;
-
-if (!ringing) {
- place=0;
- buzzer_off();
- return;
-}
-
-
-
-t++;
-if (t<50) return;
-t=0;
-
-
-switch(place){
-case 1:
-case 3:
-case 5:
-case 7:
-
-case 13:
-case 15:
-case 17:
-case 19:
- place++;
- buzzer_set_freq(C6);
- break;
-
-case 0:
-case 12:
- place++;
- buzzer_set_freq(E6);
- buzzer_on();
- break;
-case 2:
-case 4:
-case 6:
-case 14:
-case 16:
-case 18:
- place++;
- buzzer_set_freq(E6);
- break;
-
-case 8:
-case 20:
- place++;
- buzzer_off();
- break;
-
-default:
- place++;
- break;
-case 59:
- place=0;
-}
+ static int t;
+
+ if (!ringing)
+ return;
+ ringing--;
+
+ if (!ringing)
+ {
+ place = 0;
+ buzzer_off ();
+ return;
+ }
+
+
+
+ t++;
+ if (t < 50)
+ return;
+ t = 0;
+
+
+ switch (place)
+ {
+ case 1:
+ case 3:
+ case 5:
+ case 7:
+
+ case 13:
+ case 15:
+ case 17:
+ case 19:
+ place++;
+ buzzer_set_freq (C6);
+ break;
+
+ case 0:
+ case 12:
+ place++;
+ buzzer_set_freq (E6);
+ buzzer_on ();
+ break;
+ case 2:
+ case 4:
+ case 6:
+ case 14:
+ case 16:
+ case 18:
+ place++;
+ buzzer_set_freq (E6);
+ break;
+
+ case 8:
+ case 20:
+ place++;
+ buzzer_off ();
+ break;
+
+ default:
+ place++;
+ break;
+ case 59:
+ place = 0;
+ }
@@ -125,19 +134,17 @@ case 59:
}
-void ring_off(void)
+void
+ring_off (void)
{
-place=0;
-ringing=0;
-buzzer_off();
+ place = 0;
+ ringing = 0;
+ buzzer_off ();
}
-void ring(int l)
+void
+ring (int l)
{
//mb();
-ringing=l;
+ ringing = l;
}
-
-
-
-