1 /* 2 * Copyright (c) 2021-2023 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_DRIVER_TYPE_H 10 #define VIBRATOR_DRIVER_TYPE_H 11 12 #include "hdf_core_log.h" 13 #include "i2c_if.h" 14 15 #define CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(ptr, ret) do { \ 16 if ((ptr) == NULL) { \ 17 HDF_LOGE("%s:line %d pointer is null and return errno", __func__, __LINE__); \ 18 return (ret); \ 19 } \ 20 } while (0) 21 22 #define CHECK_VIBRATOR_PARSER_RESULT_RETURN_VALUE(ret, str) do { \ 23 if ((ret) != HDF_SUCCESS) { \ 24 HDF_LOGE("%s:line %d %s fail, ret = %d!", __func__, __LINE__, str, ret); \ 25 return HDF_FAILURE; \ 26 } \ 27 } while (0) 28 29 #define CHECK_VIBRATOR_NULL_PTR_RETURN(ptr) do { \ 30 if ((ptr) == NULL) { \ 31 HDF_LOGE("%s:line %d pointer is null and return", __func__, __LINE__); \ 32 return; \ 33 } \ 34 } while (0) 35 36 enum VibratorBusType { 37 VIBRATOR_BUS_I2C = 0, 38 VIBRATOR_BUS_GPIO = 1, 39 }; 40 41 enum VibratorState { 42 VIBRATOR_STATE_IDLE = 0, 43 VIBRATOR_STATE_START_TIMER = 1, 44 VIBRATOR_STATE_STOP = 2, 45 VIBRATOR_STATE_SET_EFFECT = 3, 46 }; 47 48 enum VibratorConfigMode { 49 VIBRATOR_MODE_ONCE = 0, // The mode of a one-shot vibration effect. 50 VIBRATOR_MODE_PRESET = 1, // The mode of a preset vibration effect. 51 VIBRATOR_MODE_BUTT = 0XFF, 52 }; 53 54 enum VibratorDrvIoCmd { 55 VIBRATOR_DRV_IO_START_ONCE = 0, 56 VIBRATOR_DRV_IO_START_PRESET = 1, 57 VIBRATOR_DRV_IO_STOP = 2, 58 VIBRATOR_DRV_IO_GET_INFO = 3, 59 VIBRATOR_DRV_IO_ENABLE_MODULATION_PARAMETER = 4, 60 VIBRATOR_DRV_IO_IS_VIBRATOR_RUNNING = 5, 61 VIBRATOR_DRV_IO_END, 62 }; 63 64 struct VibratorI2cCfg { 65 DevHandle handle; 66 uint16_t busNum; 67 uint16_t devAddr; // Address of the I2C device 68 uint16_t regWidth; // length of the register address 69 }; 70 71 struct VibratorAttr { 72 uint16_t chipIdReg; 73 uint16_t chipIdValue; 74 uint16_t defaultIntensity; 75 uint16_t defaultFrequency; 76 }; 77 78 struct VibratorBus { 79 uint8_t busType; // enum VibratorBusType 80 union { 81 struct VibratorI2cCfg i2cCfg; 82 uint32_t GpioNum; 83 }; 84 }; 85 86 struct VibratorInfo { 87 bool isSupportIntensity; /**< setting intensity capability */ 88 bool isSupportFrequency; /**< setting frequency capability */ 89 uint16_t intensityMaxValue; /**< Max intensity */ 90 uint16_t intensityMinValue; /**< Min intensity */ 91 int16_t frequencyMaxValue; /**< Max frequency */ 92 int16_t frequencyMinValue; /**< Min frequency */ 93 }; 94 95 96 struct VibratorCfgData { 97 struct VibratorBus vibratorBus; 98 struct VibratorInfo vibratorInfo; 99 struct VibratorAttr vibratorAttr; 100 }; 101 102 #endif /* VIBRATOR_DRIVER_TYPE_H */ 103