• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 *seq; // The first element of seq is preset type referring to enum VibratorEffectType
36     struct DListHead node;
37 };
38 
39 struct VibratorEffectCfg {
40     enum VibratorConfigMode cfgMode; // References enum VibratorConfigMode
41     uint32_t duration;
42     const char *effect;
43 };
44 
45 struct VibratorHapticData {
46     bool supportHaptic;
47     struct DListHead effectSeqHead;
48     struct OsalMutex mutex;
49     OsalTimer timer;
50     uint32_t duration[VIBRATOR_TIME_INDEX_BUTT];
51     int32_t effectType;
52     int32_t seqCount;
53     uint32_t *currentEffectSeq;
54     int32_t currentSeqIndex;
55 };
56 
57 int32_t CreateVibratorHaptic(struct HdfDeviceObject *device);
58 int32_t StartHaptic(struct VibratorEffectCfg *effectCfg);
59 int32_t StopHaptic(void);
60 int32_t DestroyVibratorHaptic(void);
61 
62 #endif /* VIBRATOR_HAPTIC_H */
63