1 /*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef _HARDWARE_VIBRATOR_H
18 #define _HARDWARE_VIBRATOR_H
19
20 #include <hardware/hardware.h>
21
22 __BEGIN_DECLS
23
24 #define VIBRATOR_API_VERSION HARDWARE_MODULE_API_VERSION(1,0)
25
26 /**
27 * The id of this module
28 */
29 #define VIBRATOR_HARDWARE_MODULE_ID "vibrator"
30
31 /**
32 * The id of the main vibrator device
33 */
34 #define VIBRATOR_DEVICE_ID_MAIN "main_vibrator"
35
36 struct vibrator_device;
37 typedef struct vibrator_device {
38 /**
39 * Common methods of the vibrator device. This *must* be the first member of
40 * vibrator_device as users of this structure will cast a hw_device_t to
41 * vibrator_device pointer in contexts where it's known the hw_device_t references a
42 * vibrator_device.
43 */
44 struct hw_device_t common;
45
46 /** Turn on vibrator
47 *
48 * What happens when this function is called while the the timeout of a
49 * previous call has not expired is implementation dependent.
50 *
51 * @param timeout_ms number of milliseconds to vibrate
52 *
53 * @return 0 in case of success, negative errno code else
54 */
55 int (*vibrator_on)(struct vibrator_device* vibradev, unsigned int timeout_ms);
56
57 /** Turn off vibrator
58 *
59 * It is not guaranteed that the vibrator will be immediately stopped: the
60 * behaviour is implementation dependent.
61 *
62 * @return 0 in case of success, negative errno code else
63 */
64 int (*vibrator_off)(struct vibrator_device* vibradev);
65 } vibrator_device_t;
66
vibrator_open(const struct hw_module_t * module,vibrator_device_t ** device)67 static inline int vibrator_open(const struct hw_module_t* module, vibrator_device_t** device)
68 {
69 return module->methods->open(module, VIBRATOR_DEVICE_ID_MAIN, (struct hw_device_t**)device);
70 }
71
72 __END_DECLS
73
74 #endif // _HARDWARE_VIBRATOR_H
75