comparison src/cs/drivers/drv_app/buzzer/buzzer.c @ 0:4e78acac3d88

src/{condat,cs,gpf,nucleus}: import from Selenite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:23:26 +0000
parents
children 4f839e1991e8
comparison
equal deleted inserted replaced
-1:000000000000 0:4e78acac3d88
1 /*
2 * BUZZER.C
3 *
4 * Buzzer driver
5 *
6 * Target : ARM
7 *
8 * Copyright (c) Texas Instruments 2000
9 *
10 */
11
12
13 #include "main/sys_types.h"
14 #include "memif/mem.h"
15 #include "armio/armio.h"
16 #include "buzzer.h"
17 #include "timer/timer.h"
18
19 #include "board.cfg"
20
21 /*
22 * Initialize buzzer
23 *
24 */
25 void BZ_Init(void)
26 {
27 }
28
29 /*
30 * BZ_Enable / BZ_Disable
31 *
32 * Enable / disable buzzer
33 *
34 * The buzzer uses timer 1
35 */
36 void BZ_Enable(void)
37 {
38 *((volatile SYS_UWORD16 *) ARMIO_PWM_CNTL) |= BZ_ON;
39 }
40
41 void BZ_Disable(void)
42 {
43 *((volatile SYS_UWORD16 *) ARMIO_PWM_CNTL) &= ~BZ_ON;
44 }
45
46 /*
47 * BZ_Tone
48 *
49 * Changes the timer count to set the tone frequency in Hz
50 *
51 * 58 ticks= 1 ms, which give a frequency of 500 Hz
52 *
53 *
54 */
55 void BZ_Tone(int f)
56 {
57 if (f > 255)
58 {
59 f = 255;
60 }
61 *((volatile SYS_UWORD16 *) ARMIO_LOAD_TIM) = f;
62 }
63
64 /*
65 * BZ_Volume
66 *
67 * Changes the buzzer volume
68 *
69 */
70 void BZ_Volume(int v)
71 {
72 // the level range is 0 up to 63
73 if (v > 63)
74 {
75 v = 63;
76 }
77 *((volatile SYS_UWORD16 *) BZ_LEVEL) = v;
78 }
79
80 /*
81 * BZ_KeyBeep_ON
82 *
83 * Audio feedback to user after keybeep
84 *
85 */
86 void BZ_KeyBeep_ON(void)
87 {
88 volatile int i;
89
90 BZ_Init ();
91 BZ_Volume (255);
92 BZ_Enable ();
93 BZ_Tone (50);
94
95 for (i = 0; i < 17000; i++)
96 ;
97
98 BZ_Disable ();
99 }
100
101
102
103 /*
104 * BZ_KeyBeep_OFF
105 *
106 * Audio feedback to user after keybeep
107 *
108 */
109 void BZ_KeyBeep_OFF(void)
110 {
111 volatile int i;
112
113 BZ_Init ();
114 BZ_Volume (255);
115 BZ_Enable ();
116 BZ_Tone (100);
117
118 for (i = 0; i < 17000; i++)
119 ;
120
121 BZ_Disable ();
122 }
123
124
125
126 /*
127 * LT_Enable / LT_Disable
128 *
129 * Enable / disable LCD lighting
130 *
131 */
132 void LT_Enable(void)
133 {
134 #if (BOARD == 7 || BOARD == 8 || BOARD == 9)
135 *((volatile SYS_UWORD16 *) ARMIO_PWM_CNTL) |= LT_ON;
136 #endif
137 }
138 void LT_Disable(void)
139 {
140 #if (BOARD == 7 || BOARD == 8 || BOARD == 9)
141 *((volatile SYS_UWORD16 *) ARMIO_PWM_CNTL) &= ~LT_ON;
142 #endif
143 }
144
145
146 /*
147 * LT_Level
148 *
149 * Set LCD display level
150 */
151 void LT_Level(SYS_WORD8 level)
152 {
153 if (level > 63) level=63;
154
155 // the level range is 0 up to 63
156 *((volatile SYS_UWORD16 *) LT_LEVEL) = level;
157 }
158
159
160 /*
161 * LT_Status
162 *
163 * Return lighting status for sleep manager
164 *
165 */
166 SYS_BOOL LT_Status(void)
167 {
168 #if (BOARD == 7 || BOARD == 8 || BOARD == 9)
169 if (*((volatile SYS_UWORD16 *) ARMIO_PWM_CNTL) & LT_ON)
170 return(1); // the light is on
171 else
172 return(0);
173 #endif
174
175 return(0);
176
177 }