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>
32#include <zephyr/drivers/gpio.h>
34#include <zephyr/sys/__assert.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
54
55 /* Device-specific error codes can follow, refer to the device’s header file */
57 HAPTICS_ERROR_PRIV_START = BIT(5),
59};
60
86
99
100 /* Device-specific monitor sample types, refer to the device's header file */
102 HAPTICS_MONITOR_TYPE_PRIV_START,
104};
105
122
123 /* Device-specific playback sources, refer to the device’s header file */
125 HAPTICS_SOURCE_PRIV_START,
127};
128
145
153typedef void (*haptics_error_callback_t)(const struct device *dev, const uint32_t errors,
154 void *const user_data);
155
160
165typedef int (*haptics_calibrate_t)(const struct device *dev, const uint32_t routine);
166
171typedef int (*haptics_monitor_get_t)(const struct device *dev, const enum haptics_monitor monitor,
172 const enum haptics_monitor_type type,
173 struct sensor_value *const val);
174
179typedef int (*haptics_monitor_set_t)(const struct device *dev, const enum haptics_monitor monitor,
180 const bool enable);
181
186typedef int (*haptics_register_error_callback_t)(const struct device *dev,
188 void *const user_data);
189
194typedef int (*haptics_select_source_t)(const struct device *dev, const enum haptics_source src,
195 const union haptics_config *const cfg);
196
201typedef int (*haptics_set_level_t)(const struct device *dev, const enum haptics_source src,
202 const union haptics_config *const cfg, const uint32_t level);
203
208typedef int (*haptics_start_output_t)(const struct device *dev);
209
214typedef int (*haptics_stop_output_t)(const struct device *dev);
215
220typedef int (*haptics_stream_samples_t)(const struct device *dev, const uint8_t *const samples,
221 const size_t len);
222
264
268
284__syscall int haptics_calibrate(const struct device *dev, const uint32_t routine);
285
286static inline int z_impl_haptics_calibrate(const struct device *dev, const uint32_t routine)
287{
288 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
289
290 if (api->calibrate == NULL) {
291 return -ENOSYS;
292 }
293
294 return api->calibrate(dev, routine);
295}
296
315__syscall int haptics_monitor_get(const struct device *dev, const enum haptics_monitor monitor,
316 const enum haptics_monitor_type type,
317 struct sensor_value *const val);
318
319static inline int z_impl_haptics_monitor_get(const struct device *dev,
320 const enum haptics_monitor monitor,
321 const enum haptics_monitor_type type,
322 struct sensor_value *const val)
323{
324 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
325
326 if (api->monitor_get == NULL) {
327 return -ENOSYS;
328 }
329
330 __ASSERT_NO_MSG(monitor != HAPTICS_MONITOR_ALL);
331 __ASSERT_NO_MSG(val != NULL);
332
333 return api->monitor_get(dev, monitor, type, val);
334}
335
350__syscall int haptics_monitor_set(const struct device *dev, const enum haptics_monitor monitor,
351 const bool enable);
352
353static inline int z_impl_haptics_monitor_set(const struct device *dev,
354 const enum haptics_monitor monitor, const bool enable)
355{
356 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
357
358 if (api->monitor_set == NULL) {
359 return -ENOSYS;
360 }
361
362 return api->monitor_set(dev, monitor, enable);
363}
364
376static inline int haptics_register_error_callback(const struct device *dev,
378 void *const user_data)
379{
380 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
381
382 if (api->register_error_callback == NULL) {
383 return -ENOSYS;
384 }
385
386 __ASSERT_NO_MSG(cb != NULL);
387
388 return api->register_error_callback(dev, cb, user_data);
389}
390
408__syscall int haptics_select_source(const struct device *dev, const enum haptics_source src,
409 const union haptics_config *const cfg);
410
411static inline int z_impl_haptics_select_source(const struct device *dev,
412 const enum haptics_source src,
413 const union haptics_config *const cfg)
414{
415 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
416
417 __ASSERT_NO_MSG(api->select_source != NULL);
418
419 return api->select_source(dev, src, cfg);
420}
421
440__syscall int haptics_set_level(const struct device *dev, const enum haptics_source src,
441 const union haptics_config *const cfg, const uint32_t level);
442
443static inline int z_impl_haptics_set_level(const struct device *dev, const enum haptics_source src,
444 const union haptics_config *const cfg,
445 const uint32_t level)
446{
447 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
448
449 if (api->set_level == NULL) {
450 return -ENOSYS;
451 }
452
453 return api->set_level(dev, src, cfg, level);
454}
455
467__syscall int haptics_start_output(const struct device *dev);
468
469static inline int z_impl_haptics_start_output(const struct device *dev)
470{
471 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
472
473 __ASSERT_NO_MSG(api->start_output != NULL);
474
475 return api->start_output(dev);
476}
477
488__syscall int haptics_stop_output(const struct device *dev);
489
490static inline int z_impl_haptics_stop_output(const struct device *dev)
491{
492 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
493
494 __ASSERT_NO_MSG(api->stop_output != NULL);
495
496 return api->stop_output(dev);
497}
498
516__syscall int haptics_stream_samples(const struct device *dev, const uint8_t *const samples,
517 const size_t len);
518
519static inline int z_impl_haptics_stream_samples(const struct device *dev,
520 const uint8_t *const samples, const size_t len)
521{
522 const struct haptics_driver_api *api = DEVICE_API_GET(haptics, dev);
523
524 if (api->stream_samples == NULL) {
525 return -ENOSYS;
526 }
527
528 __ASSERT_NO_MSG(samples != NULL);
529
530 return api->stream_samples(dev, samples, len);
531}
532
536
537#ifdef __cplusplus
538}
539#endif /* __cplusplus */
540
541#include <zephyr/syscalls/haptics.h>
542
543#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:1449
Main header file for GPIO driver API.
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:186
haptics_monitor
Integrated sensing features.
Definition haptics.h:69
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:171
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:179
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:194
int(* haptics_calibrate_t)(const struct device *dev, const uint32_t routine)
@def_driverbackendgroup{Haptics,haptics_interface}
Definition haptics.h:165
haptics_source
Haptics playback sources.
Definition haptics.h:114
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:208
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:48
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:153
int(* haptics_stop_output_t)(const struct device *dev)
Stop an ongoing haptic effect and cancel any queued effects, if applicable.
Definition haptics.h:214
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:201
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:376
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:220
haptics_monitor_type
Qualifiers for integrated sensor readings.
Definition haptics.h:94
@ HAPTICS_MONITOR_CURRENT
Amperage.
Definition haptics.h:71
@ HAPTICS_MONITOR_BEMF
Back EMF.
Definition haptics.h:70
@ HAPTICS_MONITOR_VBAT
Supply voltage.
Definition haptics.h:76
@ HAPTICS_MONITOR_VOUT
Amplifier output voltage.
Definition haptics.h:78
@ HAPTICS_MONITOR_F0
Resonant frequency.
Definition haptics.h:72
@ HAPTICS_MONITOR_DIE_TEMP
Die temperature.
Definition haptics.h:75
@ HAPTICS_MONITOR_VBST
Boost supply voltage.
Definition haptics.h:77
@ HAPTICS_MONITOR_RE
Coil resistance.
Definition haptics.h:73
@ HAPTICS_MONITOR_ALL
All integrated sensors.
Definition haptics.h:79
@ HAPTICS_MONITOR_AMBIENT_TEMP
Ambient temperature.
Definition haptics.h:74
@ HAPTICS_SOURCE_PWM
Effect streamed from a PWM source.
Definition haptics.h:119
@ HAPTICS_SOURCE_RAM
Effect loaded at runtime into volatile memory.
Definition haptics.h:116
@ HAPTICS_SOURCE_CONTROL_PORT
Effect streamed via the control port (e.g., I2C or SPI).
Definition haptics.h:120
@ HAPTICS_SOURCE_ANALOG
Effect streamed from an analog source.
Definition haptics.h:118
@ HAPTICS_SOURCE_ALL
All playback sources.
Definition haptics.h:121
@ HAPTICS_SOURCE_ROM
Effect from a pre-programmed wavetable.
Definition haptics.h:115
@ HAPTICS_SOURCE_DAI
Effect streamed from a digital audio source (e.g., I2S).
Definition haptics.h:117
@ HAPTICS_ERROR_OVERVOLTAGE
Power source overvoltage error.
Definition haptics.h:52
@ HAPTICS_ERROR_DC
Output direct-current error.
Definition haptics.h:53
@ HAPTICS_ERROR_OVERCURRENT
Output overcurrent error.
Definition haptics.h:49
@ HAPTICS_ERROR_UNDERVOLTAGE
Power source undervoltage error.
Definition haptics.h:51
@ HAPTICS_ERROR_OVERTEMPERATURE
Device overtemperature error.
Definition haptics.h:50
@ HAPTICS_MONITOR_TYPE_MEAN
Mean sensor reading.
Definition haptics.h:97
@ HAPTICS_MONITOR_TYPE_MAX
Maximum sensor reading.
Definition haptics.h:96
@ HAPTICS_MONITOR_TYPE_SINGLE
Most recent or single-shot sensor reading.
Definition haptics.h:98
@ HAPTICS_MONITOR_TYPE_MIN
Minimum sensor reading.
Definition haptics.h:95
#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:513
@driver_ops{Haptics}
Definition haptics.h:226
haptics_select_source_t select_source
@driver_ops_mandatory Specify a playback source and related configuration details.
Definition haptics.h:246
haptics_stream_samples_t stream_samples
@driver_ops_optional Stream 8-bit samples over the control port for haptic effects.
Definition haptics.h:262
haptics_monitor_get_t monitor_get
@driver_ops_optional Retrieve an integrated sensor reading from the haptic driver.
Definition haptics.h:234
haptics_register_error_callback_t register_error_callback
@driver_ops_optional Register a callback function for haptics errors.
Definition haptics.h:242
haptics_set_level_t set_level
@driver_ops_optional Set level controls for haptic effects.
Definition haptics.h:250
haptics_start_output_t start_output
@driver_ops_mandatory Start playback for a haptic effect.
Definition haptics.h:254
haptics_monitor_set_t monitor_set
@driver_ops_optional Enable or disable integrated sensing for the haptic driver.
Definition haptics.h:238
haptics_calibrate_t calibrate
@driver_ops_optional Calibrate the haptic driver for an external actuator.
Definition haptics.h:230
haptics_stop_output_t stop_output
@driver_ops_mandatory Stop an ongoing haptic effect and cancel any queued effects,...
Definition haptics.h:258
Representation of a sensor readout value.
Definition sensor.h:56
Digital Audio Interface Configuration.
Definition codec.h:153
Haptics source configuration.
Definition haptics.h:138
uint32_t idx
Used to specify an effect from a list of waveforms stored in memory.
Definition haptics.h:139
audio_dai_type_t type
Digital audio interface type, e.g., I2S.
Definition haptics.h:141
audio_dai_cfg_t cfg
Digital audio interface configuration details.
Definition haptics.h:142
struct haptics_config::@005371130076236225132356133002326124042216105076 dai
Digital audio interface configuration for "audio to haptics" features.