Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
buzzer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 Carlo Caione <ccaione@baylibre.com>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12
13#ifndef ZEPHYR_INCLUDE_DRIVERS_BUZZER_H_
14#define ZEPHYR_INCLUDE_DRIVERS_BUZZER_H_
15
32
33#include <errno.h>
34#include <stdint.h>
35
36#include <zephyr/device.h>
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
43#define BUZZER_FREQ_REST 0U
44
46#define BUZZER_VOLUME_MAX 100U
47
55#define BUZZER_DURATION_FOREVER UINT32_MAX
56
61
67typedef int (*buzzer_tone_t)(const struct device *dev, uint32_t freq_hz,
68 uint32_t duration_ms);
69
75typedef int (*buzzer_set_volume_t)(const struct device *dev, uint8_t percent);
76
82typedef int (*buzzer_beep_t)(const struct device *dev, uint32_t duration_ms);
83
89typedef int (*buzzer_stop_t)(const struct device *dev);
90
104
106
131static inline int buzzer_tone(const struct device *dev, uint32_t freq_hz,
132 uint32_t duration_ms)
133{
134 return DEVICE_API_GET(buzzer, dev)->tone(dev, freq_hz, duration_ms);
135}
136
156static inline int buzzer_set_volume(const struct device *dev, uint8_t percent)
157{
158 return DEVICE_API_GET(buzzer, dev)->set_volume(dev, percent);
159}
160
179static inline int buzzer_beep(const struct device *dev, uint32_t duration_ms)
180{
181 return DEVICE_API_GET(buzzer, dev)->beep(dev, duration_ms);
182}
183
194static inline int buzzer_stop(const struct device *dev)
195{
196 return DEVICE_API_GET(buzzer, dev)->stop(dev);
197}
198
199#ifdef __cplusplus
200}
201#endif
202
204
205#endif /* ZEPHYR_INCLUDE_DRIVERS_BUZZER_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1425
System error numbers.
int(* buzzer_set_volume_t)(const struct device *dev, uint8_t percent)
Set the buzzer volume.
Definition buzzer.h:75
int(* buzzer_tone_t)(const struct device *dev, uint32_t freq_hz, uint32_t duration_ms)
Play a single tone for a given duration.
Definition buzzer.h:67
int(* buzzer_stop_t)(const struct device *dev)
Stop any tone currently being played.
Definition buzzer.h:89
int(* buzzer_beep_t)(const struct device *dev, uint32_t duration_ms)
Play the buzzer's default tone.
Definition buzzer.h:82
static int buzzer_tone(const struct device *dev, uint32_t freq_hz, uint32_t duration_ms)
Play a single tone at freq_hz for duration_ms.
Definition buzzer.h:131
static int buzzer_set_volume(const struct device *dev, uint8_t percent)
Set the buzzer volume.
Definition buzzer.h:156
static int buzzer_stop(const struct device *dev)
Stop any tone currently being played.
Definition buzzer.h:194
static int buzzer_beep(const struct device *dev, uint32_t duration_ms)
Play the buzzer's default tone for duration_ms.
Definition buzzer.h:179
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
<span class="mlabel">Driver Operations</span> Buzzer driver operations
Definition buzzer.h:94
buzzer_stop_t stop
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition buzzer.h:102
buzzer_beep_t beep
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition buzzer.h:100
buzzer_set_volume_t set_volume
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition buzzer.h:98
buzzer_tone_t tone
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition buzzer.h:96
Runtime device structure (in ROM) per driver instance.
Definition device.h:513