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
53
54 /* Device-specific error codes can follow, refer to the device’s header file */
56 HAPTICS_ERROR_PRIV_START = BIT(5),
58};
59
85
98
99 /* Device-specific monitor sample types, refer to the device's header file */
101 HAPTICS_MONITOR_TYPE_PRIV_START,
103};
104
121
122 /* Device-specific playback sources, refer to the device’s header file */
124 HAPTICS_SOURCE_PRIV_START,
126};
127
144
152typedef void (*haptics_error_callback_t)(const struct device *dev, const uint32_t errors,
153 void *const user_data);
154
159
164typedef int (*haptics_calibrate_t)(const struct device *dev, const uint32_t routine);
165
170typedef int (*haptics_monitor_get_t)(const struct device *dev, const enum haptics_monitor monitor,
171 const enum haptics_monitor_type type,
172 struct sensor_value *const val);
173
178typedef int (*haptics_monitor_set_t)(const struct device *dev, const enum haptics_monitor monitor,
179 const bool enable);
180
185typedef int (*haptics_register_error_callback_t)(const struct device *dev,
187 void *const user_data);
188
193typedef int (*haptics_select_source_t)(const struct device *dev, const enum haptics_source src,
194 const union haptics_config *const cfg);
195
200typedef int (*haptics_set_level_t)(const struct device *dev, const enum haptics_source src,
201 const union haptics_config *const cfg, const uint32_t level);
202
207typedef int (*haptics_start_output_t)(const struct device *dev);
208
213typedef int (*haptics_stop_output_t)(const struct device *dev);
214
219typedef int (*haptics_stream_samples_t)(const struct device *dev, const uint8_t *const samples,
220 const size_t len);
221
263
267
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
312__syscall int haptics_monitor_get(const struct device *dev, const enum haptics_monitor monitor,
313 const enum haptics_monitor_type type,
314 struct sensor_value *const val);
315
316static inline int z_impl_haptics_monitor_get(const struct device *dev,
317 const enum haptics_monitor monitor,
318 const enum haptics_monitor_type type,
319 struct sensor_value *const val)
320{
321 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
322
323 if (api->monitor_get == NULL) {
324 return -ENOSYS;
325 }
326
327 __ASSERT_NO_MSG(monitor != HAPTICS_MONITOR_ALL);
328 __ASSERT_NO_MSG(val != NULL);
329
330 return api->monitor_get(dev, monitor, type, val);
331}
332
346__syscall int haptics_monitor_set(const struct device *dev, const enum haptics_monitor monitor,
347 const bool enable);
348
349static inline int z_impl_haptics_monitor_set(const struct device *dev,
350 const enum haptics_monitor monitor, const bool enable)
351{
352 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
353
354 if (api->monitor_set == NULL) {
355 return -ENOSYS;
356 }
357
358 return api->monitor_set(dev, monitor, enable);
359}
360
371static inline int haptics_register_error_callback(const struct device *dev,
373 void *const user_data)
374{
375 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
376
377 if (api->register_error_callback == NULL) {
378 return -ENOSYS;
379 }
380
381 __ASSERT_NO_MSG(cb != NULL);
382
383 return api->register_error_callback(dev, cb, user_data);
384}
385
402__syscall int haptics_select_source(const struct device *dev, const enum haptics_source src,
403 const union haptics_config *const cfg);
404
405static inline int z_impl_haptics_select_source(const struct device *dev,
406 const enum haptics_source src,
407 const union haptics_config *const cfg)
408{
409 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
410
411 __ASSERT_NO_MSG(api->select_source != NULL);
412
413 return api->select_source(dev, src, cfg);
414}
415
433__syscall int haptics_set_level(const struct device *dev, const enum haptics_source src,
434 const union haptics_config *const cfg, const uint32_t level);
435
436static inline int z_impl_haptics_set_level(const struct device *dev, const enum haptics_source src,
437 const union haptics_config *const cfg,
438 const uint32_t level)
439{
440 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
441
442 if (api->set_level == NULL) {
443 return -ENOSYS;
444 }
445
446 return api->set_level(dev, src, cfg, level);
447}
448
459__syscall int haptics_start_output(const struct device *dev);
460
461static inline int z_impl_haptics_start_output(const struct device *dev)
462{
463 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
464
465 __ASSERT_NO_MSG(api->start_output != NULL);
466
467 return api->start_output(dev);
468}
469
479__syscall int haptics_stop_output(const struct device *dev);
480
481static inline int z_impl_haptics_stop_output(const struct device *dev)
482{
483 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
484
485 __ASSERT_NO_MSG(api->stop_output != NULL);
486
487 return api->stop_output(dev);
488}
489
506__syscall int haptics_stream_samples(const struct device *dev, const uint8_t *const samples,
507 const size_t len);
508
509static inline int z_impl_haptics_stream_samples(const struct device *dev,
510 const uint8_t *const samples, const size_t len)
511{
512 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
513
514 if (api->stream_samples == NULL) {
515 return -ENOSYS;
516 }
517
518 __ASSERT_NO_MSG(samples != NULL);
519
520 return api->stream_samples(dev, samples, len);
521}
522
526
527#ifdef __cplusplus
528}
529#endif /* __cplusplus */
530
531#include <zephyr/syscalls/haptics.h>
532
533#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:1461
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:185
haptics_monitor
Integrated sensing features.
Definition haptics.h:68
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:170
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:178
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:193
int(* haptics_calibrate_t)(const struct device *dev, const uint32_t routine)
@def_driverbackendgroup{Haptics,haptics_interface}
Definition haptics.h:164
haptics_source
Haptics playback sources.
Definition haptics.h:113
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:207
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:47
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:152
int(* haptics_stop_output_t)(const struct device *dev)
Stop an ongoing haptic effect and cancel any queued effects, if applicable.
Definition haptics.h:213
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:200
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:371
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:219
haptics_monitor_type
Qualifiers for integrated sensor readings.
Definition haptics.h:93
@ HAPTICS_MONITOR_CURRENT
Amperage.
Definition haptics.h:70
@ HAPTICS_MONITOR_BEMF
Back EMF.
Definition haptics.h:69
@ HAPTICS_MONITOR_VBAT
Supply voltage.
Definition haptics.h:75
@ HAPTICS_MONITOR_VOUT
Amplifier output voltage.
Definition haptics.h:77
@ HAPTICS_MONITOR_F0
Resonant frequency.
Definition haptics.h:71
@ HAPTICS_MONITOR_DIE_TEMP
Die temperature.
Definition haptics.h:74
@ HAPTICS_MONITOR_VBST
Boost supply voltage.
Definition haptics.h:76
@ HAPTICS_MONITOR_RE
Coil resistance.
Definition haptics.h:72
@ HAPTICS_MONITOR_ALL
All integrated sensors.
Definition haptics.h:78
@ HAPTICS_MONITOR_AMBIENT_TEMP
Ambient temperature.
Definition haptics.h:73
@ HAPTICS_SOURCE_PWM
Effect streamed from a PWM source.
Definition haptics.h:118
@ HAPTICS_SOURCE_RAM
Effect loaded at runtime into volatile memory.
Definition haptics.h:115
@ HAPTICS_SOURCE_CONTROL_PORT
Effect streamed via the control port (e.g., I2C or SPI).
Definition haptics.h:119
@ HAPTICS_SOURCE_ANALOG
Effect streamed from an analog source.
Definition haptics.h:117
@ HAPTICS_SOURCE_ALL
All playback sources.
Definition haptics.h:120
@ HAPTICS_SOURCE_ROM
Effect from a pre-programmed wavetable.
Definition haptics.h:114
@ HAPTICS_SOURCE_DAI
Effect streamed from a digital audio source (e.g., I2S).
Definition haptics.h:116
@ HAPTICS_ERROR_OVERVOLTAGE
Power source overvoltage error.
Definition haptics.h:51
@ HAPTICS_ERROR_DC
Output direct-current error.
Definition haptics.h:52
@ HAPTICS_ERROR_OVERCURRENT
Output overcurrent error.
Definition haptics.h:48
@ HAPTICS_ERROR_UNDERVOLTAGE
Power source undervoltage error.
Definition haptics.h:50
@ HAPTICS_ERROR_OVERTEMPERATURE
Device overtemperature error.
Definition haptics.h:49
@ HAPTICS_MONITOR_TYPE_MEAN
Mean sensor reading.
Definition haptics.h:96
@ HAPTICS_MONITOR_TYPE_MAX
Maximum sensor reading.
Definition haptics.h:95
@ HAPTICS_MONITOR_TYPE_SINGLE
Most recent or single-shot sensor reading.
Definition haptics.h:97
@ HAPTICS_MONITOR_TYPE_MIN
Minimum sensor reading.
Definition haptics.h:94
#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:525
@driver_ops{Haptics}
Definition haptics.h:225
haptics_select_source_t select_source
@driver_ops_mandatory Specify a playback source and related configuration details.
Definition haptics.h:245
haptics_stream_samples_t stream_samples
@driver_ops_optional Stream 8-bit samples over the control port for haptic effects.
Definition haptics.h:261
haptics_monitor_get_t monitor_get
@driver_ops_optional Retrieve an integrated sensor reading from the haptic driver.
Definition haptics.h:233
haptics_register_error_callback_t register_error_callback
@driver_ops_optional Register a callback function for haptics errors.
Definition haptics.h:241
haptics_set_level_t set_level
@driver_ops_optional Set level controls for haptic effects.
Definition haptics.h:249
haptics_start_output_t start_output
@driver_ops_mandatory Start playback for a haptic effect.
Definition haptics.h:253
haptics_monitor_set_t monitor_set
@driver_ops_optional Enable or disable integrated sensing for the haptic driver.
Definition haptics.h:237
haptics_calibrate_t calibrate
@driver_ops_optional Calibrate the haptic driver for an external actuator.
Definition haptics.h:229
haptics_stop_output_t stop_output
@driver_ops_mandatory Stop an ongoing haptic effect and cancel any queued effects,...
Definition haptics.h:257
Representation of a sensor readout value.
Definition sensor.h:56
Digital Audio Interface Configuration.
Definition codec.h:153
Haptics source configuration.
Definition haptics.h:137
uint32_t idx
Used to specify an effect from a list of waveforms stored in memory.
Definition haptics.h:138
audio_dai_type_t type
Digital audio interface type, e.g., I2S.
Definition haptics.h:140
audio_dai_cfg_t cfg
Digital audio interface configuration details.
Definition haptics.h:141
struct haptics_config::@005371130076236225132356133002326124042216105076 dai
Digital audio interface configuration for "audio to haptics" features.