1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef VIBRATOR_HAPTIC_H 10 #define VIBRATOR_HAPTIC_H 11 12 #include "hdf_device_desc.h" 13 #include "hdf_dlist.h" 14 #include "osal_mutex.h" 15 #include "osal_timer.h" 16 #include "vibrator_driver_type.h" 17 18 #define VIBRATOR_MAX_HAPTIC_SEQ 1024 19 #define VIBRATOR_MIN_WAIT_TIME 50 // unit:ms 20 21 enum VibratorEffectType { 22 VIBRATOR_TYPE_EFFECT = 0, // Preset effect in device 23 VIBRATOR_TYPE_TIME = 1, // Preset effect by time 24 }; 25 26 enum VibratorTimeSeqIndex { 27 VIBRATOR_TIME_DELAY_INDEX = 0, 28 VIBRATOR_TIME_DURATION_INDEX = 1, 29 VIBRATOR_TIME_INDEX_BUTT, 30 }; 31 32 struct VibratorEffectNode { 33 const char *effect; 34 int32_t num; 35 uint32_t type; // preset type 36 uint32_t *seq; 37 struct DListHead node; 38 }; 39 40 struct VibratorEffectCfg { 41 enum VibratorConfigMode cfgMode; // References enum VibratorConfigMode 42 uint32_t duration; 43 const char *effect; 44 }; 45 46 struct VibratorHapticData { 47 bool supportHaptic; 48 struct DListHead effectSeqHead; 49 struct OsalMutex mutex; 50 OsalTimer timer; 51 uint32_t duration[VIBRATOR_TIME_INDEX_BUTT]; 52 int32_t effectType; 53 int32_t seqCount; 54 uint32_t *currentEffectSeq; 55 int32_t currentSeqIndex; 56 }; 57 58 int32_t CreateVibratorHaptic(struct HdfDeviceObject *device); 59 int32_t StartHaptic(struct VibratorEffectCfg *effectCfg); 60 int32_t StopHaptic(void); 61 int32_t DestroyVibratorHaptic(void); 62 63 #endif /* VIBRATOR_HAPTIC_H */ 64