|
Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
|
Interfaces for haptic drivers. More...
Topics | |
| Device-specific Haptics API extensions | |
| Haptics Driver Backend API | |
Files | |
| file | haptics.h |
| Main header file for haptics driver API. | |
Data Structures | |
| union | haptics_config |
| Haptics source configuration. More... | |
Typedefs | |
| typedef 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. | |
Enumerations | |
| enum | haptics_error_type { HAPTICS_ERROR_OVERCURRENT = BIT(0) , HAPTICS_ERROR_OVERTEMPERATURE = BIT(1) , HAPTICS_ERROR_UNDERVOLTAGE = BIT(2) , HAPTICS_ERROR_OVERVOLTAGE = BIT(3) , HAPTICS_ERROR_DC = BIT(4) } |
| Haptics error types. More... | |
| enum | haptics_monitor { HAPTICS_MONITOR_BEMF , HAPTICS_MONITOR_CURRENT , HAPTICS_MONITOR_F0 , HAPTICS_MONITOR_RE , HAPTICS_MONITOR_AMBIENT_TEMP , HAPTICS_MONITOR_DIE_TEMP , HAPTICS_MONITOR_VBAT , HAPTICS_MONITOR_VBST , HAPTICS_MONITOR_VOUT , HAPTICS_MONITOR_ALL } |
| Integrated sensing features. More... | |
| enum | haptics_monitor_type { HAPTICS_MONITOR_TYPE_MIN , HAPTICS_MONITOR_TYPE_MAX , HAPTICS_MONITOR_TYPE_MEAN , HAPTICS_MONITOR_TYPE_SINGLE } |
| Qualifiers for integrated sensor readings. More... | |
| enum | haptics_source { HAPTICS_SOURCE_ROM , HAPTICS_SOURCE_RAM , HAPTICS_SOURCE_DAI , HAPTICS_SOURCE_ANALOG , HAPTICS_SOURCE_PWM , HAPTICS_SOURCE_CONTROL_PORT , HAPTICS_SOURCE_ALL } |
| Haptics playback sources. More... | |
Functions | |
| int | haptics_calibrate (const struct device *dev, const uint32_t routine) |
| Calibrate the haptic driver for an external actuator. | |
| 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. | |
| 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. | |
| 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. | |
| 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_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_start_output (const struct device *dev) |
| Start playback for a haptic effect. | |
| int | haptics_stop_output (const struct device *dev) |
| Stop an ongoing haptic effect and cancel any queued effects, if applicable. | |
| 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. | |
Interfaces for haptic drivers.
| typedef void(* haptics_error_callback_t) (const struct device *dev, const uint32_t errors, void *const user_data) |
#include <zephyr/drivers/haptics.h>
Function type of callback invoked when an error occurs.
| [in] | dev | Pointer to the device structure for the haptic device instance |
| [in] | errors | Device errors (bitmask of haptics_error_type values) |
| [in] | user_data | User data provided when the error callback was registered |
| enum haptics_error_type |
#include <zephyr/drivers/haptics.h>
Haptics error types.
Most haptic drivers provide protection features to prevent damage during operation. Applications can register a callback function (see haptics_register_error_callback()) to handle or recover from error states. The following error types are used to construct a bitmask provided to the application layer at run-time (see haptics_error_callback_t).
| enum haptics_monitor |
#include <zephyr/drivers/haptics.h>
Integrated sensing features.
Some haptic drivers include integrated sensors for monitoring electrical and physical characteristics (e.g., voltage, current, resistance, etc.) related to power or an external actuator. Use any of the following monitor options with haptics_monitor_get() or haptics_monitor_set() to retrieve sensor readings or enable measurements, respectively.
| enum haptics_monitor_type |
#include <zephyr/drivers/haptics.h>
Qualifiers for integrated sensor readings.
There is no uniform implementation for integrated sensors in haptic drivers. Some only provide the most recent sensor reading, and others aggregate readings over time into minimums, maximums, and averages. Refer to device drivers for implementation details.
| enum haptics_source |
#include <zephyr/drivers/haptics.h>
Haptics playback sources.
Haptic effects are typically pre-programmed in non-volatile memory, programmed at run-time into volatile memory, or streamed to the haptic driver over a control port or using a well-defined digital interface (e.g., I2S) or analog signal. Provide any of the following playback sources to haptics_select_source() to configure the device before calling haptics_start_output().
#include <zephyr/drivers/haptics.h>
Calibrate the haptic driver for an external actuator.
Most haptic drivers provide calibration features that tune the hardware for an external actuator's particular physical and electrical characteristics, e.g., coil resistance and resonant frequency. Not all haptic drivers require discrete calibration routines. Refer to device drivers for implementation details.
| [in] | dev | Pointer to the device structure for the haptic device instance |
| [in] | routine | Device-specific calibration routine, refer to the device's header file |
| 0 | if successful |
| -ENOSYS | if not implemented |
| <0 | if failed |
| int haptics_monitor_get | ( | const struct device * | dev, |
| const enum haptics_monitor | monitor, | ||
| const enum haptics_monitor_type | type, | ||
| struct sensor_value *const | val ) |
#include <zephyr/drivers/haptics.h>
Retrieve an integrated sensor reading from the haptic driver.
Some haptic drivers may require enabling an integrated sensor using haptics_monitor_set() before values can be read from the device. Refer to device drivers for implementation details.
Note: Requesting readings from all sensors simultaneously (e.g., setting monitor to HAPTICS_MONITOR_ALL) is invalid.
| [in] | dev | Pointer to the device structure for the haptic device instance |
| [in] | monitor | Sensing option (of type haptics_monitor) |
| [in] | type | Type of sensor reading (of type haptics_monitor_type) |
| [out] | val | Sensor reading (of type sensor_value) |
| 0 | if successful |
| -ENOSYS | if not implemented |
| <0 | if failed |
| int haptics_monitor_set | ( | const struct device * | dev, |
| const enum haptics_monitor | monitor, | ||
| const bool | enable ) |
#include <zephyr/drivers/haptics.h>
Enable or disable integrated sensing for the haptic driver.
Some haptic drivers may allow disabling integrated sensor measurements to reduce power consumption. Refer to device drivers for implementation details.
| [in] | dev | Pointer to the device structure for the haptic device instance |
| [in] | monitor | Sensing option (of type haptics_monitor) |
| [in] | enable | True if enabling integrated sensing, false if disabling |
| 0 | if successful |
| -ENOSYS | if not implemented |
| <0 | if failed |
|
inlinestatic |
#include <zephyr/drivers/haptics.h>
Register a callback function for haptics errors.
| [in] | dev | Pointer to the device structure for the haptic device instance |
| [in] | cb | Callback function (of type haptics_error_callback_t) |
| [in] | user_data | User data to be provided back to the application via the callback |
| 0 | if successful |
| -ENOSYS | if not implemented |
| <0 | if failed |
| int haptics_select_source | ( | const struct device * | dev, |
| const enum haptics_source | src, | ||
| const union haptics_config *const | cfg ) |
#include <zephyr/drivers/haptics.h>
Specify a playback source and related configuration details.
Typically, an application should call this function before calling haptics_start_output(). If unused, there is no uniform default playback source across haptic drivers, so behavior is up to the particular device driver. Refer to device drivers for implementation details.
Note: Some playback sources do not require any additional configuration details, in which case cfg should be set to NULL.
| [in] | dev | Pointer to the device structure for the haptic device instance |
| [in] | src | Playback source (of type haptics_source) |
| [in] | cfg | Source configuration (of type haptics_config) or NULL |
| 0 | if successful |
| <0 | if failed |
| int haptics_set_level | ( | const struct device * | dev, |
| const enum haptics_source | src, | ||
| const union haptics_config *const | cfg, | ||
| const uint32_t | level ) |
#include <zephyr/drivers/haptics.h>
Set level controls for haptic effects.
Most haptic drivers support configuring output level on a global, source-, or even waveform-specific basis. For example, to set global level for a haptic driver, an application might set src to HAPTICS_SOURCE_ALL and cfg to NULL, while level configuration for a pre-programmed waveform might set src to HAPTICS_SOURCE_ROM and cfg to the desired 'idx' value. Refer to device drivers for implementation details.
| [in] | dev | Pointer to the device structure for the haptic device instance |
| [in] | src | Playback source (of type haptics_source) |
| [in] | cfg | Source configuration (of type haptics_config) or NULL |
| [in] | level | Device-specific output level value, rfer to the device driver for details |
| 0 | if successful |
| -ENOSYS | if not implemented |
| <0 | if failed |
| int haptics_start_output | ( | const struct device * | dev | ) |
#include <zephyr/drivers/haptics.h>
Start playback for a haptic effect.
Start playback for a haptic effect specified using haptics_select_source(). If no source is specified, behavior is driver-specific. Refer to device drivers for implementation details.
| [in] | dev | Pointer to the device structure for the haptic device instance |
| 0 | if successful |
| <0 | if failed |
| int haptics_stop_output | ( | const struct device * | dev | ) |
#include <zephyr/drivers/haptics.h>
Stop an ongoing haptic effect and cancel any queued effects, if applicable.
If desired, any queued effects must be re-queued using haptics_start_output().
| [in] | dev | Pointer to the device structure for the haptic device instance |
| 0 | if successful |
| <0 | if failed |
| int haptics_stream_samples | ( | const struct device * | dev, |
| const uint8_t *const | samples, | ||
| const size_t | len ) |
#include <zephyr/drivers/haptics.h>
Stream 8-bit samples over the control port for haptic effects.
Most haptic drivers play samples streamed over a control port at a fixed sample rate. Refer to device drivers for implementation details.
Note: HAPTICS_SOURCE_CONTROL_PORT should be provided to haptics_select_source() before calling this function.
| [in] | dev | Pointer to the device structure for the haptic device instance |
| [in] | samples | Pointer to an array of 8-bit samples |
| [in] | len | Number of samples to write |
| 0 | if successful |
| -ENOSYS | if not implemented |
| <0 | if failed |