FreeCalypso > hg > fc-tourmaline
annotate src/cs/drivers/drv_app/buzzer/pwt.c @ 294:e17bdedfbf2b
VIBR SWE initial implementation
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 27 Mar 2022 08:46:10 +0000 |
parents | a72feaed133a |
children |
rev | line source |
---|---|
290
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This C module is a FreeCalypso addition: it implements hw driver functions |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * for Calypso buzzer output in PWT mode. |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include "main/sys_types.h" |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include "pwt.h" |
291
a72feaed133a
PWT buzzer driver: conditionalize on TARGET_HAS_BUZZER
Mychaela Falconia <falcon@freecalypso.org>
parents:
290
diff
changeset
|
8 #include "fc-target.h" |
290
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #define ASIC_CONF_REG (*(volatile SYS_UWORD16 *) 0xFFFEF008) |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #define PWT_MODE_MASK 0x0020 |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #define PWT_FRC_REG (*(volatile SYS_UWORD8 *) 0xFFFE8800) |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #define PWT_VCR_REG (*(volatile SYS_UWORD8 *) 0xFFFE8801) |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #define PWT_GCR_REG (*(volatile SYS_UWORD8 *) 0xFFFE8802) |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 /* flag tells L1 to suppress deep sleep */ |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 SYS_BOOL PWT_tone_is_on; |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 void PWT_block_on(void) |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 { |
291
a72feaed133a
PWT buzzer driver: conditionalize on TARGET_HAS_BUZZER
Mychaela Falconia <falcon@freecalypso.org>
parents:
290
diff
changeset
|
22 #ifdef TARGET_HAS_BUZZER |
290
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 ASIC_CONF_REG |= PWT_MODE_MASK; |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 PWT_GCR_REG = 0x01; |
291
a72feaed133a
PWT buzzer driver: conditionalize on TARGET_HAS_BUZZER
Mychaela Falconia <falcon@freecalypso.org>
parents:
290
diff
changeset
|
25 #endif |
290
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 } |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 void PWT_block_off(void) |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 { |
291
a72feaed133a
PWT buzzer driver: conditionalize on TARGET_HAS_BUZZER
Mychaela Falconia <falcon@freecalypso.org>
parents:
290
diff
changeset
|
30 #ifdef TARGET_HAS_BUZZER |
290
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 ASIC_CONF_REG &= ~PWT_MODE_MASK; |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 PWT_GCR_REG = 0; |
291
a72feaed133a
PWT buzzer driver: conditionalize on TARGET_HAS_BUZZER
Mychaela Falconia <falcon@freecalypso.org>
parents:
290
diff
changeset
|
33 #endif |
290
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 void PWT_play_tone(SYS_UWORD8 note, SYS_UWORD8 volume) |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 { |
291
a72feaed133a
PWT buzzer driver: conditionalize on TARGET_HAS_BUZZER
Mychaela Falconia <falcon@freecalypso.org>
parents:
290
diff
changeset
|
38 #ifdef TARGET_HAS_BUZZER |
290
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 PWT_FRC_REG = note; |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 PWT_VCR_REG = (volume << 1) | 1; |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 PWT_tone_is_on = 1; |
291
a72feaed133a
PWT buzzer driver: conditionalize on TARGET_HAS_BUZZER
Mychaela Falconia <falcon@freecalypso.org>
parents:
290
diff
changeset
|
42 #endif |
290
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 } |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 void PWT_stop_tone(void) |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 { |
291
a72feaed133a
PWT buzzer driver: conditionalize on TARGET_HAS_BUZZER
Mychaela Falconia <falcon@freecalypso.org>
parents:
290
diff
changeset
|
47 #ifdef TARGET_HAS_BUZZER |
290
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 PWT_VCR_REG = 0; |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 PWT_tone_is_on = 0; |
291
a72feaed133a
PWT buzzer driver: conditionalize on TARGET_HAS_BUZZER
Mychaela Falconia <falcon@freecalypso.org>
parents:
290
diff
changeset
|
50 #endif |
290
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 } |