Blame view

RIOT/boards/chronos/drivers/buzzer.c 1.05 KB
fb11e647   vrobic   reseau statique a...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  /*
   * Copyright (C) 2014 INRIA
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @ingroup chronos
   * @{
   */
  
  /**
   * @file
   * @brief       eZ430-chronos beeper
   *
   * @author      Oliver Hahm <oliver.hahm@inria.fr>
   * @author      Ludwig KnΓΌpfer <ludwig.knuepfer@fu-berlin.de>
   * @author      mikoff
   *
   */
  
  #include <stdint.h>
  #include <stdint.h>
  #include <cc430f6137.h>
  
  #include "buzzer.h"
  #include "xtimer.h"
  
  void buzzer_beep(uint8_t pitch, uint32_t duration)
  {
      // Reset TA1R, set up mode, TA1 runs from 32768Hz ACLK
      TA1CTL = TACLR | MC_1 | TASSEL__ACLK;
  
      // Set PWM frequency
      TA1CCR0 = pitch;
  
      // Enable IRQ, set output mode "toggle"
      TA1CCTL0 = OUTMOD_4;
  
      // Allow buzzer PWM output on P2.7
      P2SEL |= BIT7;
  
      xtimer_usleep(duration);
  
      // Stop PWM timer
      TA1CTL &= ~(BIT4 | BIT5);
  
      // Reset and disable buzzer PWM output
      P2OUT &= ~BIT7;
      P2SEL &= ~BIT7;
      TA1CCTL0 &= ~CCIE;
  }