From fe7aebb0fa469c98f4ac3bc52874738f84edb515 Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Wed, 17 Dec 2025 22:06:02 +0800
Subject: [PATCH] Add buzzer test source code
---
bsp/drivers/test-apps/buzzer.c | 76 ++++++++++++++++++++++++++++++++++++++
1 files changed, 76 insertions(+), 0 deletions(-)
diff --git a/bsp/drivers/test-apps/buzzer.c b/bsp/drivers/test-apps/buzzer.c
new file mode 100644
index 0000000..f9c247f
--- /dev/null
+++ b/bsp/drivers/test-apps/buzzer.c
@@ -0,0 +1,76 @@
+/*********************************************************************************
+ * Copyright: (C) 2025 LingYun IoT System Studio
+ * All rights reserved.
+ *
+ * Filename: buzzer.c
+ * Description: This file is linux kernel pwm-beeper driver test code.
+ *
+ * Version: 1.0.0(12/17/2025)
+ * Author: Guo Wenxue <guowenxue@gmail.com>
+ * ChangeLog: 1, Release initial version on "12/17/2025 09:44:08 PM"
+ *
+ ********************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <linux/input.h>
+#include <sys/time.h>
+
+int main(int argc, char *argv[]) {
+ int fd;
+ struct input_event ev;
+ int frequency = 10000; // Default: 10kHz
+ float duration = 0.5; // Default: 0.5 seconds
+
+ // Parse command line arguments
+ if (argc >= 2) {
+ frequency = atoi(argv[1]);
+ }
+ if (argc >= 3) {
+ duration = atof(argv[2]);
+ }
+
+ // Open buzzer device
+ fd = open("/dev/input/event0", O_WRONLY);
+ if (fd < 0) {
+ perror("Failed to open /dev/input/event0");
+ return 1;
+ }
+
+ printf("=== PWM Buzzer Control ===\n");
+ printf("Device: /dev/input/event0\n");
+ printf("Frequency: %d Hz\n", frequency);
+ printf("Duration: %.2f seconds\n", duration);
+
+ // Clear event structure
+ memset(&ev, 0, sizeof(ev));
+ ev.type = EV_SND; // 0x12 = Sound event
+ ev.code = SND_TONE; // 0x02 = Tone control
+ ev.value = frequency; // Frequency in Hz
+
+ printf("\nStarting beep...\n");
+ if (write(fd, &ev, sizeof(ev)) != sizeof(ev)) {
+ perror("Failed to write start event");
+ close(fd);
+ return 1;
+ }
+
+ // Wait for specified duration
+ usleep(duration * 1000000);
+
+ // Stop beeping
+ ev.value = 0; // 0 Hz = stop
+ printf("Stopping beep...\n");
+ if (write(fd, &ev, sizeof(ev)) != sizeof(ev)) {
+ perror("Failed to write stop event");
+ }
+
+ // Close device
+ close(fd);
+ printf("\nTest completed!\n");
+
+ return 0;
+}
--
Gitblit v1.9.1