summaryrefslogtreecommitdiff
path: root/firmware/target/arm/s5l8702/ipod6g/piezo-6g.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/s5l8702/ipod6g/piezo-6g.c')
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/piezo-6g.c125
1 files changed, 125 insertions, 0 deletions
diff --git a/firmware/target/arm/s5l8702/ipod6g/piezo-6g.c b/firmware/target/arm/s5l8702/ipod6g/piezo-6g.c
new file mode 100644
index 0000000000..06735673be
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/piezo-6g.c
@@ -0,0 +1,125 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006-2007 Robert Keevil
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "system.h"
23#include "kernel.h"
24#include "piezo.h"
25
26static unsigned int duration;
27static bool beeping;
28
29void INT_TIMERA(void)
30{
31 /* clear interrupt */
32 TACON = TACON;
33 if (!(--duration))
34 piezo_stop();
35}
36
37static void piezo_start(unsigned short cycles, unsigned short periods)
38{
39#ifndef SIMULATOR
40 duration = periods;
41 beeping = 1;
42 /* select TA_OUT function on GPIO ports */
43 PCON0 = (PCON0 & 0x00ffffff) | 0x53000000;
44 /* configure timer for 100 kHz (12 MHz / 4 / 30) */
45 TACMD = (1 << 1); /* TA_CLR */
46 TAPRE = 30 - 1; /* prescaler */
47 TACON = (1 << 13) | /* TA_INT1_EN */
48 (0 << 12) | /* TA_INT0_EN */
49 (0 << 11) | /* TA_START */
50 (1 << 8) | /* TA_CS = ECLK / 4 */
51 (1 << 6) | /* select ECLK (12 MHz) */
52 (1 << 4); /* TA_MODE_SEL = PWM mode */
53 TADATA0 = cycles; /* set interval period */
54 TADATA1 = cycles << 1; /* set interval period */
55 TACMD = (1 << 0); /* TA_EN */
56#endif
57}
58
59void piezo_stop(void)
60{
61#ifndef SIMULATOR
62 beeping = 0;
63 TACMD = (1 << 1); /* TA_CLR */
64 /* configure GPIO for the lowest power consumption */
65 PCON0 = (PCON0 & 0x00ffffff) | 0xee000000;
66#endif
67}
68
69void piezo_clear(void)
70{
71 piezo_stop();
72}
73
74bool piezo_busy(void)
75{
76 return beeping;
77}
78
79void piezo_init(void)
80{
81 piezo_stop();
82}
83
84void piezo_button_beep(bool beep, bool force)
85{
86 if (force)
87 while (beeping)
88 yield();
89
90 if (!beeping)
91 {
92 if (beep)
93 piezo_start(22, 457);
94 else
95 piezo_start(40, 4);
96 }
97}
98
99#ifdef BOOTLOADER
100void piezo_tone(uint32_t period /*uS*/, int32_t duration /*ms*/)
101{
102 int32_t stop = USEC_TIMER + duration*1000;
103 uint32_t level = 0;
104
105 while ((int32_t)USEC_TIMER - stop < 0)
106 {
107 level ^= 1;
108 GPIOCMD = 0x0060e | level;
109 udelay(period >> 1);
110 }
111
112 GPIOCMD = 0x0060e;
113}
114
115void piezo_seq(uint16_t *seq)
116{
117 uint16_t period;
118
119 while ((period = *seq++) != 0)
120 {
121 piezo_tone(period, *seq++);
122 udelay(*seq++ * 1000);
123 }
124}
125#endif