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 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 #define DRV2605_WAVEFORM_SEQUENCER_MAX 8 17 18 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, 26 }; 27 28 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, 37 }; 38 39 /** 40 * @brief DRV2605 haptic driver signal sources 41 */ 42 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, 53 }; 54 55 struct drv2605_rom_data { 56 enum drv2605_mode trigger; 57 enum drv2605_library library; 58 uint8_t seq_regs[DRV2605_WAVEFORM_SEQUENCER_MAX]; 59 uint8_t overdrive_time; 60 uint8_t sustain_pos_time; 61 uint8_t sustain_neg_time; 62 uint8_t brake_time; 63 }; 64 65 struct drv2605_rtp_data { 66 size_t size; 67 uint32_t *rtp_hold_us; 68 uint8_t *rtp_input; 69 }; 70 71 union drv2605_config_data { 72 struct drv2605_rom_data *rom_data; 73 struct drv2605_rtp_data *rtp_data; 74 }; 75 76 /** 77 * @brief Configure the DRV2605 device for a particular signal source 78 * 79 * @param dev Pointer to the device structure for haptic device instance 80 * @param source The type of haptic signal source desired 81 * @param config_data Pointer to the configuration data union for the source 82 * 83 * @retval 0 if successful 84 * @retval -ENOTSUP if the signal source is not supported 85 * @retval <0 if failed 86 */ 87 int drv2605_haptic_config(const struct device *dev, enum drv2605_haptics_source source, 88 const union drv2605_config_data *config_data); 89 90 #ifdef __cplusplus 91 } 92 #endif /* __cplusplus */ 93 94 #endif 95