vibrator: Sync factory fixed to mainline

Bug: 149666621
Bug: 149274114
Test: manual check logs
Change-Id: Ib360f31008c5619d64a1c5c2a9b24baed53140f7
Signed-off-by: chasewu <chasewu@google.com>
This commit is contained in:
chasewu 2020-02-19 19:33:36 +08:00 committed by Cyan_Hsieh
parent a56cf80f80
commit 4057c6cb8d
7 changed files with 46 additions and 46 deletions

View File

@ -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<std::string> 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<void> DumpstateDevice::dumpstateBoard(const hidl_handle& handle) {
// Ignore return value, just return an empty status.
@ -573,8 +540,6 @@ Return<DumpstateStatus> 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");

View File

@ -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.

View File

@ -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<float, 4> *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); }
};

View File

@ -175,10 +175,11 @@ using EffectStrength = ::android::hardware::vibrator::V1_0::EffectStrength;
Vibrator::Vibrator(std::unique_ptr<HwApi> hwapi, std::unique_ptr<HwCal> 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<float, 4> effectCoeffs = {0};
std::array<float, 4> 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> hwapi, std::unique_ptr<HwCal> 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> hwapi, std::unique_ptr<HwCal> hwcal)
.olLraPeriod = lraPeriod,
}));
mSteadyTargetOdClamp = mHwCal->getSteadyAmpMax(&tempAmpMax)
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<WaveShape>(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> hwapi, std::unique_ptr<HwCal> 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<void> 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) {

View File

@ -97,6 +97,8 @@ class Vibrator : public IVibrator {
virtual bool getEffectCoeffs(std::array<float, 4> *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<float, 4> *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<uint32_t, 5> mEffectTargetOdClamp;
uint32_t mSteadyTargetOdClamp;
std::array<uint32_t, 3> mSteadyTargetOdClamp;
};
} // namespace implementation

Binary file not shown.

View File

@ -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<float, 4> *value));
MOCK_METHOD1(getSteadyAmpMax, bool(float *value));
MOCK_METHOD1(getSteadyCoeffs, bool(std::array<float, 4> *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(); };