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/audio/codec.h>
29#include <zephyr/device.h>
30#include <zephyr/drivers/gpio.h>
32#include <zephyr/sys/__assert.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
52
53 /* Device-specific error codes can follow, refer to the device’s header file */
55 HAPTICS_ERROR_PRIV_START = BIT(5),
57};
58
84
97
98 /* Device-specific monitor sample types, refer to the device's header file */
100 HAPTICS_MONITOR_TYPE_PRIV_START,
102};
103
120
121 /* Device-specific playback sources, refer to the device’s header file */
123 HAPTICS_SOURCE_PRIV_START,
125};
126
143
151typedef void (*haptics_error_callback_t)(const struct device *dev, const uint32_t errors,
152 void *const user_data);
153
158
163typedef int (*haptics_calibrate_t)(const struct device *dev, const uint32_t routine);
164
169typedef int (*haptics_monitor_get_t)(const struct device *dev, const enum haptics_monitor monitor,
170 const enum haptics_monitor_type type,
171 struct sensor_value *const val);
172
177typedef int (*haptics_monitor_set_t)(const struct device *dev, const enum haptics_monitor monitor,
178 const bool enable);
179
184typedef int (*haptics_register_error_callback_t)(const struct device *dev,
186 void *const user_data);
187
192typedef int (*haptics_select_source_t)(const struct device *dev, const enum haptics_source src,
193 const union haptics_config *const cfg);
194
199typedef int (*haptics_set_level_t)(const struct device *dev, const enum haptics_source src,
200 const union haptics_config *const cfg, const uint32_t level);
201
206typedef int (*haptics_start_output_t)(const struct device *dev);
207
212typedef int (*haptics_stop_output_t)(const struct device *dev);
213
218typedef int (*haptics_stream_samples_t)(const struct device *dev, const uint8_t *const samples,
219 const size_t len);
220
262
266
282__syscall int haptics_calibrate(const struct device *dev, const uint32_t routine);
283
284static inline int z_impl_haptics_calibrate(const struct device *dev, const uint32_t routine)
285{
286 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
287
288 if (api->calibrate == NULL) {
289 return -ENOSYS;
290 }
291
292 return api->calibrate(dev, routine);
293}
294
313__syscall int haptics_monitor_get(const struct device *dev, const enum haptics_monitor monitor,
314 const enum haptics_monitor_type type,
315 struct sensor_value *const val);
316
317static inline int z_impl_haptics_monitor_get(const struct device *dev,
318 const enum haptics_monitor monitor,
319 const enum haptics_monitor_type type,
320 struct sensor_value *const val)
321{
322 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
323
324 if (api->monitor_get == NULL) {
325 return -ENOSYS;
326 }
327
328 __ASSERT_NO_MSG(monitor != HAPTICS_MONITOR_ALL);
329 __ASSERT_NO_MSG(val != NULL);
330
331 return api->monitor_get(dev, monitor, type, val);
332}
333
348__syscall int haptics_monitor_set(const struct device *dev, const enum haptics_monitor monitor,
349 const bool enable);
350
351static inline int z_impl_haptics_monitor_set(const struct device *dev,
352 const enum haptics_monitor monitor, const bool enable)
353{
354 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
355
356 if (api->monitor_set == NULL) {
357 return -ENOSYS;
358 }
359
360 return api->monitor_set(dev, monitor, enable);
361}
362
374static inline int haptics_register_error_callback(const struct device *dev,
376 void *const user_data)
377{
378 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
379
380 if (api->register_error_callback == NULL) {
381 return -ENOSYS;
382 }
383
384 __ASSERT_NO_MSG(cb != NULL);
385
386 return api->register_error_callback(dev, cb, user_data);
387}
388
406__syscall int haptics_select_source(const struct device *dev, const enum haptics_source src,
407 const union haptics_config *const cfg);
408
409static inline int z_impl_haptics_select_source(const struct device *dev,
410 const enum haptics_source src,
411 const union haptics_config *const cfg)
412{
413 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
414
415 __ASSERT_NO_MSG(api->select_source != NULL);
416
417 return api->select_source(dev, src, cfg);
418}
419
438__syscall int haptics_set_level(const struct device *dev, const enum haptics_source src,
439 const union haptics_config *const cfg, const uint32_t level);
440
441static inline int z_impl_haptics_set_level(const struct device *dev, const enum haptics_source src,
442 const union haptics_config *const cfg,
443 const uint32_t level)
444{
445 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
446
447 if (api->set_level == NULL) {
448 return -ENOSYS;
449 }
450
451 return api->set_level(dev, src, cfg, level);
452}
453
465__syscall int haptics_start_output(const struct device *dev);
466
467static inline int z_impl_haptics_start_output(const struct device *dev)
468{
469 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
470
471 __ASSERT_NO_MSG(api->start_output != NULL);
472
473 return api->start_output(dev);
474}
475
486__syscall int haptics_stop_output(const struct device *dev);
487
488static inline int z_impl_haptics_stop_output(const struct device *dev)
489{
490 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
491
492 __ASSERT_NO_MSG(api->stop_output != NULL);
493
494 return api->stop_output(dev);
495}
496
514__syscall int haptics_stream_samples(const struct device *dev, const uint8_t *const samples,
515 const size_t len);
516
517static inline int z_impl_haptics_stream_samples(const struct device *dev,
518 const uint8_t *const samples, const size_t len)
519{
520 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
521
522 if (api->stream_samples == NULL) {
523 return -ENOSYS;
524 }
525
526 __ASSERT_NO_MSG(samples != NULL);
527
528 return api->stream_samples(dev, samples, len);
529}
530
534
535#ifdef __cplusplus
536}
537#endif /* __cplusplus */
538
539#include <syscalls/haptics.h>
540
541#endif /* ZEPHYR_INCLUDE_DRIVERS_HAPTICS_H_ */
Public API header file for Audio Codec.
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1425
Main header file for GPIO driver API.
audio_dai_type_t
Digital Audio Interface (DAI) type.
Definition codec.h:63
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:184
int(* haptics_monitor_get_t)(const struct device *dev, const enum haptics_monitor monitor, const enum haptics_monitor_type type, struct sensor_value *const val)
Retrieve an integrated sensor reading from the haptic driver.
Definition haptics.h:169
int(* haptics_monitor_set_t)(const struct device *dev, const enum haptics_monitor monitor, const bool enable)
Enable or disable integrated sensing for the haptic driver.
Definition haptics.h:177
int(* haptics_select_source_t)(const struct device *dev, const enum haptics_source src, const union haptics_config *const cfg)
Specify a playback source for haptics_start_output().
Definition haptics.h:192
int(* haptics_calibrate_t)(const struct device *dev, const uint32_t routine)
Calibrate the haptic driver for an external actuator.
Definition haptics.h:163
int(* haptics_start_output_t)(const struct device *dev)
Start playback for a haptic effect.
Definition haptics.h:206
int(* haptics_stop_output_t)(const struct device *dev)
Stop an ongoing haptic effect and cancel any queued effects, if applicable.
Definition haptics.h:212
int(* haptics_set_level_t)(const struct device *dev, const enum haptics_source src, const union haptics_config *const cfg, const uint32_t level)
Set level controls for haptic effects.
Definition haptics.h:199
int(* haptics_stream_samples_t)(const struct device *dev, const uint8_t *const samples, const size_t len)
Stream 8-bit samples over the control port for haptic effects.
Definition haptics.h:218
haptics_monitor
Integrated sensing features.
Definition haptics.h:67
int haptics_stop_output(const struct device *dev)
Stop an ongoing haptic effect and cancel any queued effects, if applicable.
haptics_source
Haptics playback sources.
Definition haptics.h:112
int haptics_select_source(const struct device *dev, const enum haptics_source src, const union haptics_config *const cfg)
Specify a playback source and related configuration details.
int haptics_stream_samples(const struct device *dev, const uint8_t *const samples, const size_t len)
Stream 8-bit samples over the control port for haptic effects.
int haptics_start_output(const struct device *dev)
Start playback for a haptic effect.
int haptics_calibrate(const struct device *dev, const uint32_t routine)
Calibrate the haptic driver for an external actuator.
int haptics_set_level(const struct device *dev, const enum haptics_source src, const union haptics_config *const cfg, const uint32_t level)
Set level controls for haptic effects.
int haptics_monitor_get(const struct device *dev, const enum haptics_monitor monitor, const enum haptics_monitor_type type, struct sensor_value *const val)
Retrieve an integrated sensor reading from the haptic driver.
haptics_error_type
Haptics error types.
Definition haptics.h:46
int haptics_monitor_set(const struct device *dev, const enum haptics_monitor monitor, const bool enable)
Enable or disable integrated sensing for the haptic driver.
void(* haptics_error_callback_t)(const struct device *dev, const uint32_t errors, void *const user_data)
Function type of callback invoked when an error occurs.
Definition haptics.h:151
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:374
haptics_monitor_type
Qualifiers for integrated sensor readings.
Definition haptics.h:92
@ HAPTICS_MONITOR_CURRENT
Amperage.
Definition haptics.h:69
@ HAPTICS_MONITOR_BEMF
Back EMF.
Definition haptics.h:68
@ HAPTICS_MONITOR_VBAT
Supply voltage.
Definition haptics.h:74
@ HAPTICS_MONITOR_VOUT
Amplifier output voltage.
Definition haptics.h:76
@ HAPTICS_MONITOR_F0
Resonant frequency.
Definition haptics.h:70
@ HAPTICS_MONITOR_DIE_TEMP
Die temperature.
Definition haptics.h:73
@ HAPTICS_MONITOR_VBST
Boost supply voltage.
Definition haptics.h:75
@ HAPTICS_MONITOR_RE
Coil resistance.
Definition haptics.h:71
@ HAPTICS_MONITOR_ALL
All integrated sensors.
Definition haptics.h:77
@ HAPTICS_MONITOR_AMBIENT_TEMP
Ambient temperature.
Definition haptics.h:72
@ HAPTICS_SOURCE_PWM
Effect streamed from a PWM source.
Definition haptics.h:117
@ HAPTICS_SOURCE_RAM
Effect loaded at runtime into volatile memory.
Definition haptics.h:114
@ HAPTICS_SOURCE_CONTROL_PORT
Effect streamed via the control port (e.g., I2C or SPI).
Definition haptics.h:118
@ HAPTICS_SOURCE_ANALOG
Effect streamed from an analog source.
Definition haptics.h:116
@ HAPTICS_SOURCE_ALL
All playback sources.
Definition haptics.h:119
@ HAPTICS_SOURCE_ROM
Effect from a pre-programmed wavetable.
Definition haptics.h:113
@ HAPTICS_SOURCE_DAI
Effect streamed from a digital audio source (e.g., I2S).
Definition haptics.h:115
@ HAPTICS_ERROR_OVERVOLTAGE
Power source overvoltage error.
Definition haptics.h:50
@ HAPTICS_ERROR_DC
Output direct-current error.
Definition haptics.h:51
@ HAPTICS_ERROR_OVERCURRENT
Output overcurrent error.
Definition haptics.h:47
@ HAPTICS_ERROR_UNDERVOLTAGE
Power source undervoltage error.
Definition haptics.h:49
@ HAPTICS_ERROR_OVERTEMPERATURE
Device overtemperature error.
Definition haptics.h:48
@ HAPTICS_MONITOR_TYPE_MEAN
Mean sensor reading.
Definition haptics.h:95
@ HAPTICS_MONITOR_TYPE_MAX
Maximum sensor reading.
Definition haptics.h:94
@ HAPTICS_MONITOR_TYPE_SINGLE
Most recent or single-shot sensor reading.
Definition haptics.h:96
@ HAPTICS_MONITOR_TYPE_MIN
Minimum sensor reading.
Definition haptics.h:93
#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
Main header file for sensor driver API.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
<span class="mlabel">Driver Operations</span> Haptics driver operations
Definition haptics.h:224
haptics_select_source_t select_source
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition haptics.h:244
haptics_stream_samples_t stream_samples
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition haptics.h:260
haptics_monitor_get_t monitor_get
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition haptics.h:232
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:240
haptics_set_level_t set_level
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition haptics.h:248
haptics_start_output_t start_output
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition haptics.h:252
haptics_monitor_set_t monitor_set
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition haptics.h:236
haptics_calibrate_t calibrate
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition haptics.h:228
haptics_stop_output_t stop_output
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition haptics.h:256
Representation of a sensor readout value.
Definition sensor.h:55
Digital Audio Interface Configuration.
Definition codec.h:151
Haptics source configuration.
Definition haptics.h:136
uint32_t idx
Used to specify an effect from a list of waveforms stored in memory.
Definition haptics.h:137
audio_dai_type_t type
Digital audio interface type, e.g., I2S.
Definition haptics.h:139
struct haptics_config::@252171155116075075015152322253304273144057276332 dai
Digital audio interface configuration for "audio to haptics" features.
audio_dai_cfg_t cfg
Digital audio interface configuration details.
Definition haptics.h:140