3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
6
+ /**
7
+ * @file
8
+ * @brief Header file providing the API for the DRV2605 haptic driver
9
+ * @ingroup drv2605_interface
10
+ */
11
+
6
12
#ifndef ZEPHYR_INCLUDE_DRIVERS_HAPTICS_DRV2605_H_
7
13
#define ZEPHYR_INCLUDE_DRIVERS_HAPTICS_DRV2605_H_
8
14
13
19
extern "C" {
14
20
#endif
15
21
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 */
16
30
#define DRV2605_WAVEFORM_SEQUENCER_MAX 8
17
31
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
+ */
18
39
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 */
26
47
};
27
48
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
+ */
28
56
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 */
37
65
};
38
66
39
67
/**
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.
41
72
*/
42
73
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. */
53
79
};
54
80
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
+ */
55
87
struct drv2605_rom_data {
88
+ /** Mode of operation for triggering the ROM effects. */
56
89
enum drv2605_mode trigger ;
90
+ /** Effect library to use for playback. */
57
91
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
+ */
58
103
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
+ */
59
112
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
+ */
60
121
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
+ */
61
130
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
+ */
62
139
uint8_t brake_time ;
63
140
};
64
141
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
+ */
65
148
struct drv2605_rtp_data {
149
+ /** The number of entries in the @ref rtp_hold_us and @ref rtp_input arrays. */
66
150
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
+ */
67
157
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
+ */
68
164
uint8_t * rtp_input ;
69
165
};
70
166
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
+ */
71
174
union drv2605_config_data {
175
+ /** Pointer to ROM configuration data. Use when source is @ref DRV2605_HAPTICS_SOURCE_ROM */
72
176
struct drv2605_rom_data * rom_data ;
177
+ /** Pointer to RTP configuration data. Use when source is @ref DRV2605_HAPTICS_SOURCE_RTP */
73
178
struct drv2605_rtp_data * rtp_data ;
74
179
};
75
180
@@ -80,13 +185,16 @@ union drv2605_config_data {
80
185
* @param source The type of haptic signal source desired
81
186
* @param config_data Pointer to the configuration data union for the source
82
187
*
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
86
191
*/
87
192
int drv2605_haptic_config (const struct device * dev , enum drv2605_haptics_source source ,
88
193
const union drv2605_config_data * config_data );
89
194
195
+
196
+ /** @} */
197
+
90
198
#ifdef __cplusplus
91
199
}
92
200
#endif /* __cplusplus */
0 commit comments