Skip to content

Commit db3512d

Browse files
kartbencfriedt
authored andcommitted
include: drivers: haptics: add Doxygen docs for drv2605
Aim for full coverage for the drv2605 device-specific haptics API. Signed-off-by: Benjamin Cabé <[email protected]>
1 parent 9791165 commit db3512d

File tree

2 files changed

+142
-29
lines changed

2 files changed

+142
-29
lines changed

include/zephyr/drivers/haptics.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
* @defgroup haptics_interface Haptics Interface
1313
* @ingroup io_interfaces
1414
* @{
15+
*
16+
* @defgroup haptics_interface_ext Device-specific Haptics API extensions
17+
*
18+
* @{
19+
* @}
1520
*/
1621

1722
#include <zephyr/device.h>

include/zephyr/drivers/haptics/drv2605.h

Lines changed: 137 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
/**
7+
* @file
8+
* @brief Header file providing the API for the DRV2605 haptic driver
9+
* @ingroup drv2605_interface
10+
*/
11+
612
#ifndef ZEPHYR_INCLUDE_DRIVERS_HAPTICS_DRV2605_H_
713
#define ZEPHYR_INCLUDE_DRIVERS_HAPTICS_DRV2605_H_
814

@@ -13,63 +19,162 @@
1319
extern "C" {
1420
#endif
1521

22+
/**
23+
* @defgroup drv2605_interface DRV2605
24+
* @ingroup haptics_interface_ext
25+
* @brief DRV2605 Haptic Driver for ERM and LRA
26+
* @{
27+
*/
28+
29+
/** Maximum number of waveforms that can be stored in the sequencer */
1630
#define DRV2605_WAVEFORM_SEQUENCER_MAX 8
1731

32+
/**
33+
* @brief Effect libraries
34+
*
35+
* This enumeration defines the different effect libraries that can be used with the DRV2605 when
36+
* using ROM source. TouchSense 2220 libraries are for open-loop ERM motors,
37+
* @ref DRV2605_LIBRARY_LRA is to be used for closed-loop LRA motors.
38+
*/
1839
enum drv2605_library {
19-
DRV2605_LIBRARY_EMPTY = 0,
20-
DRV2605_LIBRARY_TS2200_A,
21-
DRV2605_LIBRARY_TS2200_B,
22-
DRV2605_LIBRARY_TS2200_C,
23-
DRV2605_LIBRARY_TS2200_D,
24-
DRV2605_LIBRARY_TS2200_E,
25-
DRV2605_LIBRARY_LRA,
40+
DRV2605_LIBRARY_EMPTY = 0, /**< Empty library */
41+
DRV2605_LIBRARY_TS2200_A, /**< TouchSense 2220 A library */
42+
DRV2605_LIBRARY_TS2200_B, /**< TouchSense 2220 B library */
43+
DRV2605_LIBRARY_TS2200_C, /**< TouchSense 2220 C library */
44+
DRV2605_LIBRARY_TS2200_D, /**< TouchSense 2220 D library */
45+
DRV2605_LIBRARY_TS2200_E, /**< TouchSense 2220 E library */
46+
DRV2605_LIBRARY_LRA, /**< Linear Resonance Actuator (LRA) library */
2647
};
2748

49+
/**
50+
* @brief Modes of operation
51+
*
52+
* @details This enumeration defines the different modes of operation supported by the DRV2605.
53+
*
54+
* See Table 5 of the DRV2605 datasheet for more information on the various operation modes.
55+
*/
2856
enum drv2605_mode {
29-
DRV2605_MODE_INTERNAL_TRIGGER = 0,
30-
DRV2605_MODE_EXTERNAL_EDGE_TRIGGER,
31-
DRV2605_MODE_EXTERNAL_LEVEL_TRIGGER,
32-
DRV2605_MODE_PWM_ANALOG_INPUT,
33-
DRV2605_MODE_AUDIO_TO_VIBE,
34-
DRV2605_MODE_RTP,
35-
DRV2605_MODE_DIAGNOSTICS,
36-
DRV2605_MODE_AUTO_CAL,
57+
DRV2605_MODE_INTERNAL_TRIGGER = 0, /**< Internal trigger mode */
58+
DRV2605_MODE_EXTERNAL_EDGE_TRIGGER, /**< External trigger mode (edge) */
59+
DRV2605_MODE_EXTERNAL_LEVEL_TRIGGER, /**< External trigger mode (level) */
60+
DRV2605_MODE_PWM_ANALOG_INPUT, /**< PWM or Analog input mode */
61+
DRV2605_MODE_AUDIO_TO_VIBE, /**< Audio-to-vibe mode */
62+
DRV2605_MODE_RTP, /**< RTP mode */
63+
DRV2605_MODE_DIAGNOSTICS, /**< Diagnostics mode */
64+
DRV2605_MODE_AUTO_CAL, /**< Auto-calibration mode */
3765
};
3866

3967
/**
40-
* @brief DRV2605 haptic driver signal sources
68+
* @brief Types of haptic signal sources.
69+
*
70+
* @details This enumeration defines the different types of haptic signal sources supported by the
71+
* DRV2605.
4172
*/
4273
enum drv2605_haptics_source {
43-
/** The playback source is device ROM */
44-
DRV2605_HAPTICS_SOURCE_ROM,
45-
/** The playback source is the RTP buffer */
46-
DRV2605_HAPTICS_SOURCE_RTP,
47-
/** The playback source is audio */
48-
DRV2605_HAPTICS_SOURCE_AUDIO,
49-
/** The playback source is a PWM signal */
50-
DRV2605_HAPTICS_SOURCE_PWM,
51-
/** The playback source is an analog signal */
52-
DRV2605_HAPTICS_SOURCE_ANALOG,
74+
DRV2605_HAPTICS_SOURCE_ROM, /**< Playback from the pre-programmed ROM library. */
75+
DRV2605_HAPTICS_SOURCE_RTP, /**< Playback from Real-Time Playback (RTP) data stream. */
76+
DRV2605_HAPTICS_SOURCE_AUDIO, /**< Playback is generated from an audio signal. */
77+
DRV2605_HAPTICS_SOURCE_PWM, /**< Playback is driven by an external PWM signal. */
78+
DRV2605_HAPTICS_SOURCE_ANALOG, /**< Playback is driven by an external analog signal. */
5379
};
5480

81+
/**
82+
* @brief ROM data configuration
83+
*
84+
* @details This structure contains configuration data for when the DRV2605 is using the internal
85+
* ROM as the haptic source (@ref DRV2605_HAPTICS_SOURCE_ROM).
86+
*/
5587
struct drv2605_rom_data {
88+
/** Mode of operation for triggering the ROM effects. */
5689
enum drv2605_mode trigger;
90+
/** Effect library to use for playback. */
5791
enum drv2605_library library;
92+
/**
93+
* @brief Waveform sequencer contents.
94+
*
95+
* This array contains the register values for the sequencer registers (0x04 to 0x0B).
96+
* Each byte can describe either:
97+
* - A waveform identifier (1 to 123) from the selected library to be played.
98+
* - A wait time, if the MSB is set. The lower 7 bits are a multiple of 10 ms.
99+
* Playback stops at the first zero entry.
100+
*
101+
* See Table 8 of the DRV2605 datasheet.
102+
*/
58103
uint8_t seq_regs[DRV2605_WAVEFORM_SEQUENCER_MAX];
104+
/**
105+
* @brief Overdrive time offset.
106+
*
107+
* A signed 8-bit value that adds a time offset to the overdrive portion of the waveform.
108+
* The offset is `overdrive_time * 5 ms`.
109+
*
110+
* See Table 10 of the DRV2605 datasheet.
111+
*/
59112
uint8_t overdrive_time;
113+
/**
114+
* @brief Sustain positive time offset.
115+
*
116+
* A signed 8-bit value that adds a time offset to the positive sustain portion of the
117+
* waveform. The offset is `sustain_pos_time * 5 ms`.
118+
*
119+
* See Table 11 of the DRV2605 datasheet.
120+
*/
60121
uint8_t sustain_pos_time;
122+
/**
123+
* @brief Sustain negative time offset.
124+
*
125+
* A signed 8-bit value that adds a time offset to the negative sustain portion of the
126+
* waveform. The offset is `sustain_neg_time * 5 ms`.
127+
*
128+
* See Table 12 of the DRV2605 datasheet.
129+
*/
61130
uint8_t sustain_neg_time;
131+
/**
132+
* @brief Brake time offset.
133+
*
134+
* A signed 8-bit value that adds a time offset to the braking portion of the waveform.
135+
* The offset is `brake_time * 5 ms`.
136+
*
137+
* See Table 13 of the DRV2605 datasheet.
138+
*/
62139
uint8_t brake_time;
63140
};
64141

142+
/**
143+
* @brief Real-Time Playback (RTP) data configuration.
144+
*
145+
* @details This structure contains configuration data for when the DRV2605 is in RTP mode
146+
* (@ref DRV2605_HAPTICS_SOURCE_RTP). It allows for streaming custom haptic waveforms.
147+
*/
65148
struct drv2605_rtp_data {
149+
/** The number of entries in the @ref rtp_hold_us and @ref rtp_input arrays. */
66150
size_t size;
151+
/**
152+
* @brief Pointer to an array of hold times.
153+
*
154+
* Each value specifies the duration in microseconds to hold the corresponding
155+
* amplitude from the `rtp_input` array.
156+
*/
67157
uint32_t *rtp_hold_us;
158+
/**
159+
* @brief Pointer to an array of RTP amplitude values.
160+
*
161+
* Each value is an 8-bit amplitude that will be written to the RTP input register (0x02).
162+
* These values can be signed or unsigned depending on device configuration.
163+
*/
68164
uint8_t *rtp_input;
69165
};
70166

167+
/**
168+
* @brief Configuration data union.
169+
*
170+
* @details This union holds a pointer to the specific configuration data struct required
171+
* for the selected haptic source. The correct member must be populated before calling
172+
* drv2605_haptic_config().
173+
*/
71174
union drv2605_config_data {
175+
/** Pointer to ROM configuration data. Use when source is @ref DRV2605_HAPTICS_SOURCE_ROM */
72176
struct drv2605_rom_data *rom_data;
177+
/** Pointer to RTP configuration data. Use when source is @ref DRV2605_HAPTICS_SOURCE_RTP */
73178
struct drv2605_rtp_data *rtp_data;
74179
};
75180

@@ -80,13 +185,16 @@ union drv2605_config_data {
80185
* @param source The type of haptic signal source desired
81186
* @param config_data Pointer to the configuration data union for the source
82187
*
83-
* @retval 0 if successful
84-
* @retval -ENOTSUP if the signal source is not supported
85-
* @retval <0 if failed
188+
* @retval 0 success
189+
* @retval -ENOTSUP signal source not supported
190+
* @retval -errno another negative error code on failure
86191
*/
87192
int drv2605_haptic_config(const struct device *dev, enum drv2605_haptics_source source,
88193
const union drv2605_config_data *config_data);
89194

195+
196+
/** @} */
197+
90198
#ifdef __cplusplus
91199
}
92200
#endif /* __cplusplus */

0 commit comments

Comments
 (0)