FreeCalypso > hg > fc-tourmaline
annotate src/cs/drivers/drv_app/buzzer/pwt.c @ 290:0e5ccb343284
implement PWT buzzer driver
The piece implemented here is the low-level driver component; there will
also be a higher-level buzzer melody player service, to be implemented
in RiViera land, that will be the sole caller of PWT API functions
provided by the present driver.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 26 Mar 2022 18:23:50 +0000 |
parents | |
children | a72feaed133a |
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" |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #define ASIC_CONF_REG (*(volatile SYS_UWORD16 *) 0xFFFEF008) |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #define PWT_MODE_MASK 0x0020 |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #define PWT_FRC_REG (*(volatile SYS_UWORD8 *) 0xFFFE8800) |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #define PWT_VCR_REG (*(volatile SYS_UWORD8 *) 0xFFFE8801) |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #define PWT_GCR_REG (*(volatile SYS_UWORD8 *) 0xFFFE8802) |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 /* flag tells L1 to suppress deep sleep */ |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 SYS_BOOL PWT_tone_is_on; |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 void PWT_block_on(void) |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 { |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 ASIC_CONF_REG |= PWT_MODE_MASK; |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 PWT_GCR_REG = 0x01; |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 } |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 void PWT_block_off(void) |
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 ASIC_CONF_REG &= ~PWT_MODE_MASK; |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 PWT_GCR_REG = 0; |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 void PWT_play_tone(SYS_UWORD8 note, SYS_UWORD8 volume) |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 { |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 PWT_FRC_REG = note; |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 PWT_VCR_REG = (volume << 1) | 1; |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 PWT_tone_is_on = 1; |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 void PWT_stop_tone(void) |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 { |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 PWT_VCR_REG = 0; |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 PWT_tone_is_on = 0; |
0e5ccb343284
implement PWT buzzer driver
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |