diff --git a/dumpstate/DumpstateDevice.cpp b/dumpstate/DumpstateDevice.cpp index 069f8b2..e4643e0 100755 --- a/dumpstate/DumpstateDevice.cpp +++ b/dumpstate/DumpstateDevice.cpp @@ -411,39 +411,6 @@ static void DumpUFS(int fd) { } } -static void DumpVibrator(int fd) { - const std::string dir = "/sys/class/leds/vibrator/device/"; - const std::vector files { - "asp_enable", - "comp_enable", - "cp_dig_scale", - "cp_trigger_duration", - "cp_trigger_index", - "cp_trigger_q_sub", - "cp_trigger_queue", - "dig_scale", - "exc_enable", - "f0_stored", - "fw_rev", - "heartbeat", - "hw_reset", - "leds/vibrator/activate", - "leds/vibrator/duration", - "leds/vibrator/state", - "num_waves", - "q_stored", - "redc_comp_enable", - "redc_stored", - "standby_timeout", - "vbatt_max", - "vbatt_min", - }; - - for (const auto &file : files) { - DumpFileToFd(fd, "Vibrator", dir+file); - } -} - // Methods from ::android::hardware::dumpstate::V1_0::IDumpstateDevice follow. Return DumpstateDevice::dumpstateBoard(const hidl_handle& handle) { // Ignore return value, just return an empty status. @@ -573,8 +540,6 @@ Return DumpstateDevice::dumpstateBoard_1_1(const hidl_handle& h RunCommandToFd(fd, "Citadel STATS", {"/vendor/bin/hw/citadel_updater", "--stats"}); RunCommandToFd(fd, "Citadel BOARDID", {"/vendor/bin/hw/citadel_updater", "--board_id"}); - DumpVibrator(fd); - // Dump various events in WiFi data path DumpFileToFd(fd, "WLAN DP Trace", "/d/wlan/dpt_stats/dump_set_dpt_logs"); diff --git a/vibrator/drv2624/Android.bp b/vibrator/drv2624/Android.bp index cf75650..420c228 100644 --- a/vibrator/drv2624/Android.bp +++ b/vibrator/drv2624/Android.bp @@ -1,5 +1,5 @@ // -// Copyright (C) 2017 The Android Open Source Project +// Copyright (C) 2019 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/vibrator/drv2624/Hardware.h b/vibrator/drv2624/Hardware.h index d43fa6d..d3d760e 100644 --- a/vibrator/drv2624/Hardware.h +++ b/vibrator/drv2624/Hardware.h @@ -95,6 +95,7 @@ class HwCal : public Vibrator::HwCal, private HwCalBase { static constexpr char LRA_PERIOD_CONFIG[] = "lra_period"; static constexpr char EFFECT_COEFF_CONFIG[] = "haptic_coefficient"; static constexpr char STEADY_AMP_MAX_CONFIG[] = "vibration_amp_max"; + static constexpr char STEADY_COEFF_CONFIG[] = "vibration_coefficient"; static constexpr uint32_t WAVEFORM_CLICK_EFFECT_MS = 6; static constexpr uint32_t WAVEFORM_TICK_EFFECT_MS = 2; @@ -104,6 +105,7 @@ class HwCal : public Vibrator::HwCal, private HwCalBase { static constexpr uint32_t DEFAULT_LRA_PERIOD = 262; static constexpr uint32_t DEFAULT_FREQUENCY_SHIFT = 10; static constexpr uint32_t DEFAULT_VOLTAGE_MAX = 107; // 2.15V; + static constexpr uint32_t DEFAULT_LP_TRIGGER_SUPPORT = 1; public: HwCal() {} @@ -128,6 +130,12 @@ class HwCal : public Vibrator::HwCal, private HwCalBase { } return false; } + bool getSteadyCoeffs(std::array *value) override { + if (getPersist(STEADY_COEFF_CONFIG, value)) { + return true; + } + return false; + } bool getCloseLoopThreshold(uint32_t *value) override { return getProperty("closeloop.threshold", value, UINT32_MAX); return true; @@ -163,6 +171,9 @@ class HwCal : public Vibrator::HwCal, private HwCalBase { bool getSteadyShape(uint32_t *value) override { return getProperty("steady.shape", value, UINT32_MAX); } + bool getTriggerEffectSupport(uint32_t *value) override { + return getProperty("lptrigger", value, DEFAULT_LP_TRIGGER_SUPPORT); + } void debug(int fd) override { HwCalBase::debug(fd); } }; diff --git a/vibrator/drv2624/Vibrator.cpp b/vibrator/drv2624/Vibrator.cpp index 02d786f..1811c9f 100644 --- a/vibrator/drv2624/Vibrator.cpp +++ b/vibrator/drv2624/Vibrator.cpp @@ -175,10 +175,11 @@ using EffectStrength = ::android::hardware::vibrator::V1_0::EffectStrength; Vibrator::Vibrator(std::unique_ptr hwapi, std::unique_ptr hwcal) : mHwApi(std::move(hwapi)), mHwCal(std::move(hwcal)) { std::string autocal; - uint32_t lraPeriod = 0; + uint32_t lraPeriod = 0, lpTrigSupport = 0; bool dynamicConfig = false; - bool hasEffectCoeffs = false; + bool hasEffectCoeffs = false, hasSteadyCoeffs = false; std::array effectCoeffs = {0}; + std::array steadyCoeffs = {0}; if (!mHwApi->setState(true)) { ALOGE("Failed to set state (%d): %s", errno, strerror(errno)); @@ -224,7 +225,7 @@ Vibrator::Vibrator(std::unique_ptr hwapi, std::unique_ptr hwcal) } // Add a boundary protection for level 5 only, since // some devices might not be able to reach the maximum target G - if ((mEffectTargetOdClamp[4] <= 0) || (mEffectTargetOdClamp[4] > 161)) { + if ((mEffectTargetOdClamp[4] <= 0) || (mEffectTargetOdClamp[4] > shortVoltageMax)) { mEffectTargetOdClamp[4] = shortVoltageMax; } @@ -235,13 +236,26 @@ Vibrator::Vibrator(std::unique_ptr hwapi, std::unique_ptr hwcal) .olLraPeriod = lraPeriod, })); - mSteadyTargetOdClamp = mHwCal->getSteadyAmpMax(&tempAmpMax) - ? round((STEADY_TARGET_G[0] / tempAmpMax) * longVoltageMax) - : longVoltageMax; + hasSteadyCoeffs = mHwCal->getSteadyCoeffs(&steadyCoeffs); + if (hasSteadyCoeffs) { + for (i = 0; i < 3; i++) { + // Use cubic approach to get the target voltage levels + tempVolLevel = targetGToVlevelsUnderCubicEquation(steadyCoeffs, STEADY_TARGET_G[i]); + mSteadyTargetOdClamp[i] = convertLevelsToOdClamp(tempVolLevel, lraPeriod); + if ((mSteadyTargetOdClamp[i] <= 0) || (mSteadyTargetOdClamp[i] > longVoltageMax)) { + mSteadyTargetOdClamp[i] = longVoltageMax; + } + } + } else { + mSteadyTargetOdClamp[0] = + mHwCal->getSteadyAmpMax(&tempAmpMax) + ? round((STEADY_TARGET_G[0] / tempAmpMax) * longVoltageMax) + : longVoltageMax; + } mHwCal->getSteadyShape(&shape); mSteadyConfig.reset(new VibrationConfig({ .shape = (shape == UINT32_MAX) ? WaveShape::SQUARE : static_cast(shape), - .odClamp = &mSteadyTargetOdClamp, + .odClamp = &mSteadyTargetOdClamp[0], // 1. Change long lra period to frequency // 2. Get frequency': subtract the frequency shift from the frequency // 3. Get final long lra period after put the frequency' to formula @@ -258,7 +272,10 @@ Vibrator::Vibrator(std::unique_ptr hwapi, std::unique_ptr hwcal) // This enables effect #1 from the waveform library to be triggered by SLPI // while the AP is in suspend mode - if (!mHwApi->setLpTriggerEffect(1)) { + // For default setting, we will enable this feature if that project did not + // set the lptrigger config + mHwCal->getTriggerEffectSupport(&lpTrigSupport); + if (!mHwApi->setLpTriggerEffect(lpTrigSupport)) { ALOGW("Failed to set LP trigger mode (%d): %s", errno, strerror(errno)); } } @@ -361,7 +378,8 @@ Return Vibrator::debug(const hidl_handle &handle, dprintf(fd, " Close Loop Thresh: %" PRIu32 "\n", mCloseLoopThreshold); if (mSteadyConfig) { dprintf(fd, " Steady Shape: %" PRIu32 "\n", mSteadyConfig->shape); - dprintf(fd, " Steady OD Clamp: %" PRIu32 "\n", mSteadyConfig->odClamp[0]); + dprintf(fd, " Steady OD Clamp: %" PRIu32 " %" PRIu32 " %" PRIu32 "\n", + mSteadyConfig->odClamp[0], mSteadyConfig->odClamp[1], mSteadyConfig->odClamp[2]); dprintf(fd, " Steady OL LRA Period: %" PRIu32 "\n", mSteadyConfig->olLraPeriod); } if (mEffectConfig) { diff --git a/vibrator/drv2624/Vibrator.h b/vibrator/drv2624/Vibrator.h index 16cd8e8..9069664 100644 --- a/vibrator/drv2624/Vibrator.h +++ b/vibrator/drv2624/Vibrator.h @@ -97,6 +97,8 @@ class Vibrator : public IVibrator { virtual bool getEffectCoeffs(std::array *value) = 0; // Obtain the max steady G value virtual bool getSteadyAmpMax(float *value) = 0; + // Obtains the steady coeffs to calculate the target voltage + virtual bool getSteadyCoeffs(std::array *value) = 0; // Obtains threshold in ms, above which close-loop should be used. virtual bool getCloseLoopThreshold(uint32_t *value) = 0; // Obtains dynamic/static configuration choice. @@ -119,6 +121,8 @@ class Vibrator : public IVibrator { virtual bool getEffectShape(uint32_t *value) = 0; // Obtains the wave shape for steady vibration virtual bool getSteadyShape(uint32_t *value) = 0; + // Obtains the trigger effect support + virtual bool getTriggerEffectSupport(uint32_t *value) = 0; // Emit diagnostic information to the given file. virtual void debug(int fd) = 0; }; @@ -189,7 +193,7 @@ class Vibrator : public IVibrator { uint32_t mDoubleClickDuration; uint32_t mHeavyClickDuration; std::array mEffectTargetOdClamp; - uint32_t mSteadyTargetOdClamp; + std::array mSteadyTargetOdClamp; }; } // namespace implementation diff --git a/vibrator/drv2624/drv2624.bin b/vibrator/drv2624/drv2624.bin index e6f896d..7736404 100644 Binary files a/vibrator/drv2624/drv2624.bin and b/vibrator/drv2624/drv2624.bin differ diff --git a/vibrator/drv2624/tests/mocks.h b/vibrator/drv2624/tests/mocks.h index d4867df..07a8c21 100644 --- a/vibrator/drv2624/tests/mocks.h +++ b/vibrator/drv2624/tests/mocks.h @@ -47,6 +47,7 @@ class MockCal : public ::android::hardware::vibrator::V1_3::implementation::Vibr MOCK_METHOD1(getLraPeriod, bool(uint32_t *value)); MOCK_METHOD1(getEffectCoeffs, bool(std::array *value)); MOCK_METHOD1(getSteadyAmpMax, bool(float *value)); + MOCK_METHOD1(getSteadyCoeffs, bool(std::array *value)); MOCK_METHOD1(getCloseLoopThreshold, bool(uint32_t *value)); MOCK_METHOD1(getDynamicConfig, bool(bool *value)); MOCK_METHOD1(getLongFrequencyShift, bool(uint32_t *value)); @@ -58,6 +59,7 @@ class MockCal : public ::android::hardware::vibrator::V1_3::implementation::Vibr MOCK_METHOD1(getHeavyClickDuration, bool(uint32_t *value)); MOCK_METHOD1(getEffectShape, bool(uint32_t *value)); MOCK_METHOD1(getSteadyShape, bool(uint32_t *value)); + MOCK_METHOD1(getTriggerEffectSupport, bool(uint32_t *value)); MOCK_METHOD1(debug, void(int fd)); ~MockCal() override { destructor(); };