Zephyr Project API 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
29
30#include <zephyr/audio/codec.h>
31#include <zephyr/device.h>
33#include <zephyr/sys/__assert.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
56
57 /* Device-specific error codes can follow, refer to the device’s header file */
59 HAPTICS_ERROR_PRIV_START = BIT(5),
61};
62
88
101
102 /* Device-specific monitor sample types, refer to the device's header file */
104 HAPTICS_MONITOR_TYPE_PRIV_START,
106};
107
124
125 /* Device-specific playback sources, refer to the device’s header file */
127 HAPTICS_SOURCE_PRIV_START,
129};
130
147
148 /* Device-specific GPIO trigger options can follow, refer to the device’s header file */
150 HAPTICS_TRIGGER_PRIV_START = BIT(4),
152};
153
170
178typedef void (*haptics_error_callback_t)(const struct device *dev, const uint32_t errors,
179 void *const user_data);
180
185
190typedef int (*haptics_calibrate_t)(const struct device *dev, const uint32_t routine);
191
196typedef int (*haptics_monitor_get_t)(const struct device *dev, const enum haptics_monitor monitor,
197 const enum haptics_monitor_type type,
198 struct sensor_value *const val);
199
204typedef int (*haptics_monitor_set_t)(const struct device *dev, const enum haptics_monitor monitor,
205 const bool enable);
206
211typedef int (*haptics_register_error_callback_t)(const struct device *dev,
213 void *const user_data);
214
219typedef int (*haptics_select_source_t)(const struct device *dev, const enum haptics_source src,
220 const union haptics_config *const cfg);
221
226typedef int (*haptics_set_level_t)(const struct device *dev, const enum haptics_source src,
227 const union haptics_config *const cfg, const uint32_t level);
228
233typedef int (*haptics_set_trigger_t)(const struct device *dev, const uint32_t trigger,
234 const uint32_t types, const enum haptics_source src,
235 const union haptics_config *const cfg, const uint32_t level);
236
241typedef int (*haptics_start_output_t)(const struct device *dev);
242
247typedef int (*haptics_stop_output_t)(const struct device *dev);
248
253typedef int (*haptics_stream_samples_t)(const struct device *dev, const uint8_t *const samples,
254 const size_t len);
255
260typedef int (*haptics_trigger_t)(const struct device *dev, const uint32_t trigger,
261 const enum haptics_trigger_type type);
262
312
316
331__syscall int haptics_calibrate(const struct device *dev, const uint32_t routine);
332
333static inline int z_impl_haptics_calibrate(const struct device *dev, const uint32_t routine)
334{
335 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
336
337 if (api->calibrate == NULL) {
338 return -ENOSYS;
339 }
340
341 return api->calibrate(dev, routine);
342}
343
361__syscall int haptics_monitor_get(const struct device *dev, const enum haptics_monitor monitor,
362 const enum haptics_monitor_type type,
363 struct sensor_value *const val);
364
365static inline int z_impl_haptics_monitor_get(const struct device *dev,
366 const enum haptics_monitor monitor,
367 const enum haptics_monitor_type type,
368 struct sensor_value *const val)
369{
370 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
371
372 if (api->monitor_get == NULL) {
373 return -ENOSYS;
374 }
375
376 __ASSERT_NO_MSG(monitor != HAPTICS_MONITOR_ALL);
377 __ASSERT_NO_MSG(val != NULL);
378
379 return api->monitor_get(dev, monitor, type, val);
380}
381
395__syscall int haptics_monitor_set(const struct device *dev, const enum haptics_monitor monitor,
396 const bool enable);
397
398static inline int z_impl_haptics_monitor_set(const struct device *dev,
399 const enum haptics_monitor monitor, const bool enable)
400{
401 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
402
403 if (api->monitor_set == NULL) {
404 return -ENOSYS;
405 }
406
407 return api->monitor_set(dev, monitor, enable);
408}
409
420static inline int haptics_register_error_callback(const struct device *dev,
422 void *const user_data)
423{
424 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
425
426 if (api->register_error_callback == NULL) {
427 return -ENOSYS;
428 }
429
430 __ASSERT_NO_MSG(cb != NULL);
431
432 return api->register_error_callback(dev, cb, user_data);
433}
434
451__syscall int haptics_select_source(const struct device *dev, const enum haptics_source src,
452 const union haptics_config *const cfg);
453
454static inline int z_impl_haptics_select_source(const struct device *dev,
455 const enum haptics_source src,
456 const union haptics_config *const cfg)
457{
458 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
459
460 __ASSERT_NO_MSG(api->select_source != NULL);
461
462 return api->select_source(dev, src, cfg);
463}
464
482__syscall int haptics_set_level(const struct device *dev, const enum haptics_source src,
483 const union haptics_config *const cfg, const uint32_t level);
484
485static inline int z_impl_haptics_set_level(const struct device *dev, const enum haptics_source src,
486 const union haptics_config *const cfg,
487 const uint32_t level)
488{
489 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
490
491 if (api->set_level == NULL) {
492 return -ENOSYS;
493 }
494
495 return api->set_level(dev, src, cfg, level);
496}
497
519__syscall int haptics_set_trigger(const struct device *dev, const uint32_t trigger,
520 const uint32_t types, const enum haptics_source src,
521 const union haptics_config *const cfg, const uint32_t level);
522
523static inline int z_impl_haptics_set_trigger(const struct device *dev, const uint32_t trigger,
524 const uint32_t types, const enum haptics_source src,
525 const union haptics_config *const cfg,
526 const uint32_t level)
527{
528 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
529
530 if (api->set_trigger == NULL) {
531 return -ENOSYS;
532 }
533
534 return api->set_trigger(dev, trigger, types, src, cfg, level);
535}
536
547__syscall int haptics_start_output(const struct device *dev);
548
549static inline int z_impl_haptics_start_output(const struct device *dev)
550{
551 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
552
553 __ASSERT_NO_MSG(api->start_output != NULL);
554
555 return api->start_output(dev);
556}
557
567__syscall int haptics_stop_output(const struct device *dev);
568
569static inline int z_impl_haptics_stop_output(const struct device *dev)
570{
571 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
572
573 __ASSERT_NO_MSG(api->stop_output != NULL);
574
575 return api->stop_output(dev);
576}
577
594__syscall int haptics_stream_samples(const struct device *dev, const uint8_t *const samples,
595 const size_t len);
596
597static inline int z_impl_haptics_stream_samples(const struct device *dev,
598 const uint8_t *const samples, const size_t len)
599{
600 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
601
602 if (api->stream_samples == NULL) {
603 return -ENOSYS;
604 }
605
606 __ASSERT_NO_MSG(samples != NULL);
607
608 return api->stream_samples(dev, samples, len);
609}
610
630__syscall int haptics_trigger(const struct device *dev, const uint32_t trigger,
631 const enum haptics_trigger_type type);
632
633static inline int z_impl_haptics_trigger(const struct device *dev, const uint32_t trigger,
634 const enum haptics_trigger_type type)
635{
636 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
637
638 if (api->trigger == NULL) {
639 return -ENOSYS;
640 }
641
642 return api->trigger(dev, trigger, type);
643}
644
648
649#ifdef __cplusplus
650}
651#endif /* __cplusplus */
652
653#include <zephyr/syscalls/haptics.h>
654
655#endif /* ZEPHYR_INCLUDE_DRIVERS_HAPTICS_H_ */
Public API header file for Audio Codec.
APIs and macros for the Zephyr device model.
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1486
audio_dai_type_t
Digital Audio Interface (DAI) type.
Definition codec.h:64
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:211
int haptics_set_trigger(const struct device *dev, const uint32_t trigger, const uint32_t types, const enum haptics_source src, const union haptics_config *const cfg, const uint32_t level)
Assign a haptic effect to a specified GPIO event or condition.
haptics_monitor
Integrated sensing features.
Definition haptics.h:71
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:196
int haptics_stop_output(const struct device *dev)
Stop an ongoing haptic effect and cancel any queued effects, if applicable.
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:204
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:219
int(* haptics_calibrate_t)(const struct device *dev, const uint32_t routine)
@def_driverbackendgroup{Haptics,haptics_interface}
Definition haptics.h:190
haptics_source
Haptics playback sources.
Definition haptics.h:116
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_start_output_t)(const struct device *dev)
Start playback for a haptic effect.
Definition haptics.h:241
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_set_trigger_t)(const struct device *dev, const uint32_t trigger, const uint32_t types, const enum haptics_source src, const union haptics_config *const cfg, const uint32_t level)
Assign a haptic effect to a specified GPIO event or condition.
Definition haptics.h:233
int(* haptics_trigger_t)(const struct device *dev, const uint32_t trigger, const enum haptics_trigger_type type)
Trigger a haptic effect.
Definition haptics.h:260
haptics_trigger_type
Options for GPIO-triggered effects.
Definition haptics.h:141
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:50
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:178
int(* haptics_stop_output_t)(const struct device *dev)
Stop an ongoing haptic effect and cancel any queued effects, if applicable.
Definition haptics.h:247
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:226
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:420
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:253
haptics_monitor_type
Qualifiers for integrated sensor readings.
Definition haptics.h:96
int haptics_trigger(const struct device *dev, const uint32_t trigger, const enum haptics_trigger_type type)
Trigger a haptic effect.
@ HAPTICS_MONITOR_CURRENT
Amperage.
Definition haptics.h:73
@ HAPTICS_MONITOR_BEMF
Back EMF.
Definition haptics.h:72
@ HAPTICS_MONITOR_VBAT
Supply voltage.
Definition haptics.h:78
@ HAPTICS_MONITOR_VOUT
Amplifier output voltage.
Definition haptics.h:80
@ HAPTICS_MONITOR_F0
Resonant frequency.
Definition haptics.h:74
@ HAPTICS_MONITOR_DIE_TEMP
Die temperature.
Definition haptics.h:77
@ HAPTICS_MONITOR_VBST
Boost supply voltage.
Definition haptics.h:79
@ HAPTICS_MONITOR_RE
Coil resistance.
Definition haptics.h:75
@ HAPTICS_MONITOR_ALL
All integrated sensors.
Definition haptics.h:81
@ HAPTICS_MONITOR_AMBIENT_TEMP
Ambient temperature.
Definition haptics.h:76
@ HAPTICS_SOURCE_PWM
Effect streamed from a PWM source.
Definition haptics.h:121
@ HAPTICS_SOURCE_RAM
Effect loaded at runtime into volatile memory.
Definition haptics.h:118
@ HAPTICS_SOURCE_CONTROL_PORT
Effect streamed via the control port (e.g., I2C or SPI).
Definition haptics.h:122
@ HAPTICS_SOURCE_ANALOG
Effect streamed from an analog source.
Definition haptics.h:120
@ HAPTICS_SOURCE_ALL
All playback sources.
Definition haptics.h:123
@ HAPTICS_SOURCE_ROM
Effect from a pre-programmed wavetable.
Definition haptics.h:117
@ HAPTICS_SOURCE_DAI
Effect streamed from a digital audio source (e.g., I2S).
Definition haptics.h:119
@ HAPTICS_TRIGGER_LOW
Level-triggered (low) GPIO condition.
Definition haptics.h:146
@ HAPTICS_TRIGGER_NONE
Disable triggered effects.
Definition haptics.h:142
@ HAPTICS_TRIGGER_HIGH
Level-triggered (high) GPIO condition.
Definition haptics.h:145
@ HAPTICS_TRIGGER_FALLING
Falling-edge (high to low) GPIO event.
Definition haptics.h:144
@ HAPTICS_TRIGGER_RISING
Rising-edge (low to high) GPIO event.
Definition haptics.h:143
@ HAPTICS_ERROR_OVERVOLTAGE
Power source overvoltage error.
Definition haptics.h:54
@ HAPTICS_ERROR_DC
Output direct-current error.
Definition haptics.h:55
@ HAPTICS_ERROR_OVERCURRENT
Output overcurrent error.
Definition haptics.h:51
@ HAPTICS_ERROR_UNDERVOLTAGE
Power source undervoltage error.
Definition haptics.h:53
@ HAPTICS_ERROR_OVERTEMPERATURE
Device overtemperature error.
Definition haptics.h:52
@ HAPTICS_MONITOR_TYPE_MEAN
Mean sensor reading.
Definition haptics.h:99
@ HAPTICS_MONITOR_TYPE_MAX
Maximum sensor reading.
Definition haptics.h:98
@ HAPTICS_MONITOR_TYPE_SINGLE
Most recent or single-shot sensor reading.
Definition haptics.h:100
@ HAPTICS_MONITOR_TYPE_MIN
Minimum sensor reading.
Definition haptics.h:97
#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:83
#define NULL
Definition iar_missing_defs.h:20
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:543
@driver_ops{Haptics}
Definition haptics.h:266
haptics_set_trigger_t set_trigger
@driver_ops_optional Assign a haptic effect to a specified GPIO event or condition.
Definition haptics.h:294
haptics_select_source_t select_source
@driver_ops_mandatory Specify a playback source and related configuration details.
Definition haptics.h:286
haptics_stream_samples_t stream_samples
@driver_ops_optional Stream 8-bit samples over the control port for haptic effects.
Definition haptics.h:306
haptics_monitor_get_t monitor_get
@driver_ops_optional Retrieve an integrated sensor reading from the haptic driver.
Definition haptics.h:274
haptics_register_error_callback_t register_error_callback
@driver_ops_optional Register a callback function for haptics errors.
Definition haptics.h:282
haptics_set_level_t set_level
@driver_ops_optional Set level controls for haptic effects.
Definition haptics.h:290
haptics_start_output_t start_output
@driver_ops_mandatory Start playback for a haptic effect.
Definition haptics.h:298
haptics_monitor_set_t monitor_set
@driver_ops_optional Enable or disable integrated sensing for the haptic driver.
Definition haptics.h:278
haptics_trigger_t trigger
@driver_ops_optional Trigger a haptic effect.
Definition haptics.h:310
haptics_calibrate_t calibrate
@driver_ops_optional Calibrate the haptic driver for an external actuator.
Definition haptics.h:270
haptics_stop_output_t stop_output
@driver_ops_mandatory Stop an ongoing haptic effect and cancel any queued effects,...
Definition haptics.h:302
Representation of a sensor readout value.
Definition sensor.h:56
Digital Audio Interface Configuration.
Definition codec.h:153
Haptics source configuration.
Definition haptics.h:163
uint32_t idx
Used to specify an effect from a list of waveforms stored in memory.
Definition haptics.h:164
audio_dai_type_t type
Digital audio interface type, e.g., I2S.
Definition haptics.h:166
audio_dai_cfg_t cfg
Digital audio interface configuration details.
Definition haptics.h:167
struct haptics_config::@005371130076236225132356133002326124042216105076 dai
Digital audio interface configuration for "audio to haptics" features.