Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
haptics.h
Go to the documentation of this file.
1/*
2 * Copyright 2024 Cirrus Logic, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12
13#ifndef ZEPHYR_INCLUDE_DRIVERS_HAPTICS_H_
14#define ZEPHYR_INCLUDE_DRIVERS_HAPTICS_H_
15
27
28#include <zephyr/device.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
43
44 /* Device-specific error codes can follow, refer to the device’s header file */
46 HAPTICS_ERROR_PRIV_START = BIT(5),
48};
49
57typedef void (*haptics_error_callback_t)(const struct device *dev, const uint32_t errors,
58 void *const user_data);
59
64
69typedef int (*haptics_stop_output_t)(const struct device *dev);
70
75typedef int (*haptics_start_output_t)(const struct device *dev);
76
81typedef int (*haptics_register_error_callback_t)(const struct device *dev,
83 void *const user_data);
84
102
106
115__syscall int haptics_start_output(const struct device *dev);
116
117static inline int z_impl_haptics_start_output(const struct device *dev)
118{
119 return DEVICE_API_GET(haptics, dev)->start_output(dev);
120}
121
130__syscall int haptics_stop_output(const struct device *dev);
131
132static inline int z_impl_haptics_stop_output(const struct device *dev)
133{
134 return DEVICE_API_GET(haptics, dev)->stop_output(dev);
135}
136
147static inline int haptics_register_error_callback(const struct device *dev,
149 void *const user_data)
150{
151 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
152
153 if (api->register_error_callback == NULL) {
154 return -ENOSYS;
155 }
156
157 return api->register_error_callback(dev, cb, user_data);
158}
159
163
164#ifdef __cplusplus
165}
166#endif /* __cplusplus */
167
168#include <syscalls/haptics.h>
169
170#endif /* ZEPHYR_INCLUDE_DRIVERS_HAPTICS_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1375
int(* haptics_register_error_callback_t)(const struct device *dev, haptics_error_callback_t cb, void *const user_data)
Register a callback function for haptics errors.
Definition haptics.h:81
int(* haptics_start_output_t)(const struct device *dev)
Set the haptic device to start output for a playback event.
Definition haptics.h:75
int(* haptics_stop_output_t)(const struct device *dev)
Set the haptic device to stop output.
Definition haptics.h:69
int haptics_stop_output(const struct device *dev)
Set the haptic device to stop output for a playback event.
int haptics_start_output(const struct device *dev)
Set the haptic device to start output for a playback event.
haptics_error_type
Haptics error types.
Definition haptics.h:37
void(* haptics_error_callback_t)(const struct device *dev, const uint32_t errors, void *const user_data)
Function type of callback invoked when a haptic device error occurs.
Definition haptics.h:57
static int haptics_register_error_callback(const struct device *dev, haptics_error_callback_t cb, void *const user_data)
Register a callback function for haptics errors.
Definition haptics.h:147
@ HAPTICS_ERROR_OVERVOLTAGE
Power source overvoltage error.
Definition haptics.h:41
@ HAPTICS_ERROR_DC
Output direct-current error.
Definition haptics.h:42
@ HAPTICS_ERROR_OVERCURRENT
Output overcurrent error.
Definition haptics.h:38
@ HAPTICS_ERROR_UNDERVOLTAGE
Power source undervoltage error.
Definition haptics.h:40
@ HAPTICS_ERROR_OVERTEMPERATURE
Device overtemperature error.
Definition haptics.h:39
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
<span class="mlabel">Driver Operations</span> Haptics driver operations
Definition haptics.h:88
haptics_register_error_callback_t register_error_callback
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition haptics.h:100
haptics_start_output_t start_output
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition haptics.h:92
haptics_stop_output_t stop_output
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition haptics.h:96