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_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_END, 61 }; 62 63 struct VibratorI2cCfg { 64 DevHandle handle; 65 uint16_t busNum; 66 uint16_t devAddr; // Address of the I2C device 67 uint16_t regWidth; // length of the register address 68 }; 69 70 struct VibratorAttr { 71 uint16_t chipIdReg; 72 uint16_t chipIdValue; 73 uint16_t defaultIntensity; 74 uint16_t defaultFrequency; 75 }; 76 77 struct VibratorBus { 78 uint8_t busType; // enum VibratorBusType 79 union { 80 struct VibratorI2cCfg i2cCfg; 81 uint32_t GpioNum; 82 }; 83 }; 84 85 struct VibratorInfo { 86 bool isSupportIntensity; /**< setting intensity capability */ 87 bool isSupportFrequency; /**< setting frequency capability */ 88 uint16_t intensityMaxValue; /**< Max intensity */ 89 uint16_t intensityMinValue; /**< Min intensity */ 90 int16_t frequencyMaxValue; /**< Max frequency */ 91 int16_t frequencyMinValue; /**< Min frequency */ 92 }; 93 94 95 struct VibratorCfgData { 96 struct VibratorBus vibratorBus; 97 struct VibratorInfo vibratorInfo; 98 struct VibratorAttr vibratorAttr; 99 }; 100 101 #endif /* VIBRATOR_DRIVER_TYPE_H */ 102