1 /*
2  * Copyright (c) 2024 Cirrus Logic, Inc.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #ifndef ZEPHYR_INCLUDE_DRIVERS_HAPTICS_DRV2605_H_
7 #define ZEPHYR_INCLUDE_DRIVERS_HAPTICS_DRV2605_H_
8 
9 #include <zephyr/drivers/haptics.h>
10 #include <zephyr/types.h>
11 
12 #define DRV2605_WAVEFORM_SEQUENCER_MAX 8
13 
14 enum drv2605_library {
15 	DRV2605_LIBRARY_EMPTY = 0,
16 	DRV2605_LIBRARY_TS2200_A,
17 	DRV2605_LIBRARY_TS2200_B,
18 	DRV2605_LIBRARY_TS2200_C,
19 	DRV2605_LIBRARY_TS2200_D,
20 	DRV2605_LIBRARY_TS2200_E,
21 	DRV2605_LIBRARY_LRA,
22 };
23 
24 enum drv2605_mode {
25 	DRV2605_MODE_INTERNAL_TRIGGER = 0,
26 	DRV2605_MODE_EXTERNAL_EDGE_TRIGGER,
27 	DRV2605_MODE_EXTERNAL_LEVEL_TRIGGER,
28 	DRV2605_MODE_PWM_ANALOG_INPUT,
29 	DRV2605_MODE_AUDIO_TO_VIBE,
30 	DRV2605_MODE_RTP,
31 	DRV2605_MODE_DIAGNOSTICS,
32 	DRV2605_MODE_AUTO_CAL,
33 };
34 
35 /**
36  * @brief DRV2605 haptic driver signal sources
37  */
38 enum drv2605_haptics_source {
39 	/** The playback source is device ROM */
40 	DRV2605_HAPTICS_SOURCE_ROM,
41 	/** The playback source is the RTP buffer */
42 	DRV2605_HAPTICS_SOURCE_RTP,
43 	/** The playback source is audio */
44 	DRV2605_HAPTICS_SOURCE_AUDIO,
45 	/** The playback source is a PWM signal */
46 	DRV2605_HAPTICS_SOURCE_PWM,
47 	/** The playback source is an analog signal */
48 	DRV2605_HAPTICS_SOURCE_ANALOG,
49 };
50 
51 struct drv2605_rom_data {
52 	enum drv2605_mode trigger;
53 	enum drv2605_library library;
54 	uint8_t seq_regs[DRV2605_WAVEFORM_SEQUENCER_MAX];
55 	uint8_t overdrive_time;
56 	uint8_t sustain_pos_time;
57 	uint8_t sustain_neg_time;
58 	uint8_t brake_time;
59 };
60 
61 struct drv2605_rtp_data {
62 	size_t size;
63 	uint32_t *rtp_hold_us;
64 	uint8_t *rtp_input;
65 };
66 
67 union drv2605_config_data {
68 	struct drv2605_rom_data *rom_data;
69 	struct drv2605_rtp_data *rtp_data;
70 };
71 
72 /**
73  * @brief Configure the DRV2605 device for a particular signal source
74  *
75  * @param dev Pointer to the device structure for haptic device instance
76  * @param source The type of haptic signal source desired
77  * @param config_data Pointer to the configuration data union for the source
78  *
79  * @retval 0 if successful
80  * @retval -ENOTSUP if the signal source is not supported
81  * @retval <0 if failed
82  */
83 int drv2605_haptic_config(const struct device *dev, enum drv2605_haptics_source source,
84 			  const union drv2605_config_data *config_data);
85 
86 #endif
87