changeset 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 4d203ef0eb4b
children a72feaed133a
files components/buzzer src/cs/drivers/drv_app/buzzer/pwt.c src/cs/drivers/drv_app/buzzer/pwt.h
diffstat 3 files changed, 52 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/components/buzzer	Sat Mar 26 17:03:36 2022 +0000
+++ b/components/buzzer	Sat Mar 26 18:23:50 2022 +0000
@@ -36,4 +36,5 @@
 SRCDIR=$SRC/cs/drivers/drv_app/buzzer
 
 cfile_plain $SRCDIR/buzzer.c
+cfile_plain $SRCDIR/pwt.c
 cfile_plain $SRCDIR/vibrator.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cs/drivers/drv_app/buzzer/pwt.c	Sat Mar 26 18:23:50 2022 +0000
@@ -0,0 +1,42 @@
+/*
+ * This C module is a FreeCalypso addition: it implements hw driver functions
+ * for Calypso buzzer output in PWT mode.
+ */
+
+#include "main/sys_types.h"
+#include "pwt.h"
+
+#define	ASIC_CONF_REG	(*(volatile SYS_UWORD16 *) 0xFFFEF008)
+#define	PWT_MODE_MASK	0x0020
+
+#define	PWT_FRC_REG	(*(volatile SYS_UWORD8 *) 0xFFFE8800)
+#define	PWT_VCR_REG	(*(volatile SYS_UWORD8 *) 0xFFFE8801)
+#define	PWT_GCR_REG	(*(volatile SYS_UWORD8 *) 0xFFFE8802)
+
+/* flag tells L1 to suppress deep sleep */
+SYS_BOOL PWT_tone_is_on;
+
+void PWT_block_on(void)
+{
+	ASIC_CONF_REG |= PWT_MODE_MASK;
+	PWT_GCR_REG = 0x01;
+}
+
+void PWT_block_off(void)
+{
+	ASIC_CONF_REG &= ~PWT_MODE_MASK;
+	PWT_GCR_REG = 0;
+}
+
+void PWT_play_tone(SYS_UWORD8 note, SYS_UWORD8 volume)
+{
+	PWT_FRC_REG = note;
+	PWT_VCR_REG = (volume << 1) | 1;
+	PWT_tone_is_on = 1;
+}
+
+void PWT_stop_tone(void)
+{
+	PWT_VCR_REG = 0;
+	PWT_tone_is_on = 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cs/drivers/drv_app/buzzer/pwt.h	Sat Mar 26 18:23:50 2022 +0000
@@ -0,0 +1,9 @@
+/*
+ * This header file is a FreeCalypso addition: it defines the functional
+ * interface to the PWT buzzer driver.
+ */
+
+void PWT_block_on(void);
+void PWT_block_off(void);
+void PWT_play_tone(SYS_UWORD8 note, SYS_UWORD8 volume);
+void PWT_stop_tone(void);