From 0b3cc7ea7b3eb80e24b184b2c3ec6a633f70de3d Mon Sep 17 00:00:00 2001 From: Tai Kuo Date: Mon, 21 Oct 2024 11:40:03 +0800 Subject: [PATCH 1/3] cs40l26: organize dump() AIDL section Bug: 356823441 Test: dumpsys android.hardware.vibrator.IVibrator/default Flag: EXEMPT refactor Change-Id: Ie14e60482c3e6763921dc22f804155cd6f3b9fcd --- vibrator/cs40l26/Vibrator.cpp | 49 ++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/vibrator/cs40l26/Vibrator.cpp b/vibrator/cs40l26/Vibrator.cpp index e091571..89bd146 100644 --- a/vibrator/cs40l26/Vibrator.cpp +++ b/vibrator/cs40l26/Vibrator.cpp @@ -1482,40 +1482,31 @@ binder_status_t Vibrator::dump(int fd, const char **args, uint32_t numArgs) { dprintf(fd, " Redc: %.02f\n", mRedc); dprintf(fd, " Voltage Levels:\n"); - dprintf(fd, " Tick Effect Min: %" PRIu32 " Max: %" PRIu32 "\n", mTickEffectVol[0], + dprintf(fd, " Tick Effect Min: %" PRIu32 " Max: %" PRIu32 "\n", mTickEffectVol[0], mTickEffectVol[1]); - dprintf(fd, " Click Effect Min: %" PRIu32 " Max: %" PRIu32 "\n", mClickEffectVol[0], + dprintf(fd, " Click Effect Min: %" PRIu32 " Max: %" PRIu32 "\n", mClickEffectVol[0], mClickEffectVol[1]); - dprintf(fd, " Long Effect Min: %" PRIu32 " Max: %" PRIu32 "\n", mLongEffectVol[0], + dprintf(fd, " Long Effect Min: %" PRIu32 " Max: %" PRIu32 "\n", mLongEffectVol[0], mLongEffectVol[1]); - dprintf(fd, " FF effect:\n"); - dprintf(fd, " Physical waveform:\n"); - dprintf(fd, "==== Base ====\n\tId\tIndex\tt ->\tt'\tBrake\ttrigger button\n"); uint8_t effectId; + dprintf(fd, " Scales\n"); + dprintf(fd, "\tId\tMinScale\tMaxScale\n"); + for (effectId = 0; effectId < WAVEFORM_MAX_PHYSICAL_INDEX; effectId++) { + dprintf(fd, "\t%d\t%d\t\t%d\n", effectId, mPrimitiveMinScale[effectId], + mPrimitiveMaxScale[effectId]); + } + + dprintf(fd, " Base FF effect:\n"); + dprintf(fd, " Physical waveform:\n"); + dprintf(fd, "\tId\tIndex\tt ->\tt'\tBrake\ttrigger button\n"); for (effectId = 0; effectId < WAVEFORM_MAX_PHYSICAL_INDEX; effectId++) { dprintf(fd, "\t%d\t%d\t%d\t%d\t%d\t%X\n", mFfEffects[effectId].id, mFfEffects[effectId].u.periodic.custom_data[1], mEffectDurations[effectId], mFfEffects[effectId].replay.length, mEffectBrakingDurations[effectId], mFfEffects[effectId].trigger.button); } - if (mIsDual) { - dprintf(fd, "==== Flip ====\n\tId\tIndex\tt ->\tt'\tBrake\ttrigger button\n"); - for (effectId = 0; effectId < WAVEFORM_MAX_PHYSICAL_INDEX; effectId++) { - dprintf(fd, "\t%d\t%d\t%d\t%d\t%d\t%X\n", mFfEffectsDual[effectId].id, - mFfEffectsDual[effectId].u.periodic.custom_data[1], mEffectDurations[effectId], - mFfEffectsDual[effectId].replay.length, mEffectBrakingDurations[effectId], - mFfEffectsDual[effectId].trigger.button); - } - } - - dprintf(fd, "==== Scales ====\n\tId\tMinScale\tMaxScale\n"); - for (effectId = 0; effectId < WAVEFORM_MAX_PHYSICAL_INDEX; effectId++) { - dprintf(fd, "\t%d\t%d\t\t%d\n", effectId, mPrimitiveMinScale[effectId], - mPrimitiveMaxScale[effectId]); - } - - dprintf(fd, "\nBase: OWT waveform:\n"); + dprintf(fd, " OWT waveform:\n"); dprintf(fd, "\tId\tBytes\tData\tt\ttrigger button\n"); for (effectId = WAVEFORM_MAX_PHYSICAL_INDEX; effectId < WAVEFORM_MAX_INDEX; effectId++) { uint32_t numBytes = mFfEffects[effectId].u.periodic.custom_len * 2; @@ -1531,8 +1522,18 @@ binder_status_t Vibrator::dump(int fd, const char **args, uint32_t numArgs) { dprintf(fd, "\t%d\t%d\t{%s}\t%u\t%X\n", mFfEffects[effectId].id, numBytes, ss.str().c_str(), mFfEffectsDual[effectId].replay.length, mFfEffects[effectId].trigger.button); } + if (mIsDual) { - dprintf(fd, "Flip: OWT waveform:\n"); + dprintf(fd, " Flip FF effect:\n"); + dprintf(fd, " Physical waveform:\n"); + dprintf(fd, "\tId\tIndex\tt ->\tt'\tBrake\ttrigger button\n"); + for (effectId = 0; effectId < WAVEFORM_MAX_PHYSICAL_INDEX; effectId++) { + dprintf(fd, "\t%d\t%d\t%d\t%d\t%d\t%X\n", mFfEffectsDual[effectId].id, + mFfEffectsDual[effectId].u.periodic.custom_data[1], mEffectDurations[effectId], + mFfEffectsDual[effectId].replay.length, mEffectBrakingDurations[effectId], + mFfEffectsDual[effectId].trigger.button); + } + dprintf(fd, " OWT waveform:\n"); dprintf(fd, "\tId\tBytes\tData\tt\ttrigger button\n"); for (effectId = WAVEFORM_MAX_PHYSICAL_INDEX; effectId < WAVEFORM_MAX_INDEX; effectId++) { uint32_t numBytes = mFfEffectsDual[effectId].u.periodic.custom_len * 2; From 46065a44625e1d9535918a8f29ada33679219e4a Mon Sep 17 00:00:00 2001 From: Tai Kuo Date: Thu, 1 Feb 2024 15:22:37 +0800 Subject: [PATCH 2/3] vibrator/cs40l26: update default scales of click, tick and long vib Flow: 1. If the calibration file exist, use the value. 2. If no property, use the default setting {5,95}. Bug: 356823441 Bug: 322937989 Test: Check dumpsys records for the scaling results. case1: no calibration file and properties. case2: valid property range case3: float property (invalid) Flag: EXEMPT bugfix Change-Id: Ia3e89f34189e9725ab01d85d931925129745608c (cherry picked from commit 4063493a64fcd0f20b49a492106f58b0e3349c5c) --- vibrator/common/utils.h | 13 +++++++++++++ vibrator/cs40l26/Hardware.h | 15 ++++++--------- vibrator/cs40l26/tests/test-hwcal.cpp | 6 +++--- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/vibrator/common/utils.h b/vibrator/common/utils.h index 86dd37e..b5005a6 100644 --- a/vibrator/common/utils.h +++ b/vibrator/common/utils.h @@ -103,6 +103,19 @@ inline Enable_If_Unsigned getProperty(const std::string &key, const T def) return ::android::base::GetUintProperty(key, def); } +template +inline std::array getProperty(const std::string &key, const std::array &def) { + std::string value = ::android::base::GetProperty(key, ""); + if (!value.empty()) { + std::array result{0}; + std::stringstream stream{value}; + utils::unpack(stream, &result); + if (stream && stream.eof()) + return result; + } + return def; +} + template <> inline bool getProperty(const std::string &key, const bool def) { return ::android::base::GetBoolProperty(key, def); diff --git a/vibrator/cs40l26/Hardware.h b/vibrator/cs40l26/Hardware.h index e2c2d36..e4dd344 100644 --- a/vibrator/cs40l26/Hardware.h +++ b/vibrator/cs40l26/Hardware.h @@ -318,9 +318,9 @@ class HwCal : public Vibrator::HwCal, private HwCalBase { static constexpr uint32_t VERSION_DEFAULT = 2; static constexpr int32_t DEFAULT_FREQUENCY_SHIFT = 0; - static constexpr std::array V_TICK_DEFAULT = {1, 100}; - static constexpr std::array V_CLICK_DEFAULT = {1, 100}; - static constexpr std::array V_LONG_DEFAULT = {1, 100}; + static constexpr std::array V_TICK_DEFAULT = {5, 95}; + static constexpr std::array V_CLICK_DEFAULT = {5, 95}; + static constexpr std::array V_LONG_DEFAULT = {5, 95}; public: HwCal() {} @@ -370,22 +370,19 @@ class HwCal : public Vibrator::HwCal, private HwCalBase { if (getPersist(TICK_VOLTAGES_CONFIG, value)) { return true; } - *value = V_TICK_DEFAULT; - return true; + return getProperty(TICK_VOLTAGES_CONFIG, value, V_TICK_DEFAULT); } bool getClickVolLevels(std::array *value) override { if (getPersist(CLICK_VOLTAGES_CONFIG, value)) { return true; } - *value = V_CLICK_DEFAULT; - return true; + return getProperty(CLICK_VOLTAGES_CONFIG, value, V_CLICK_DEFAULT); } bool getLongVolLevels(std::array *value) override { if (getPersist(LONG_VOLTAGES_CONFIG, value)) { return true; } - *value = V_LONG_DEFAULT; - return true; + return getProperty(LONG_VOLTAGES_CONFIG, value, V_LONG_DEFAULT); } bool isChirpEnabled() override { return utils::getProperty("persist.vendor.vibrator.hal.chirp.enabled", false); diff --git a/vibrator/cs40l26/tests/test-hwcal.cpp b/vibrator/cs40l26/tests/test-hwcal.cpp index e482b6c..5223c85 100644 --- a/vibrator/cs40l26/tests/test-hwcal.cpp +++ b/vibrator/cs40l26/tests/test-hwcal.cpp @@ -30,9 +30,9 @@ using ::testing::Test; class HwCalTest : public Test { protected: - static constexpr std::array V_TICK_DEFAULT = {1, 100}; - static constexpr std::array V_CLICK_DEFAULT = {1, 100}; - static constexpr std::array V_LONG_DEFAULT = {1, 100}; + static constexpr std::array V_TICK_DEFAULT = {5, 95}; + static constexpr std::array V_CLICK_DEFAULT = {5, 95}; + static constexpr std::array V_LONG_DEFAULT = {5, 95}; public: void SetUp() override { setenv("CALIBRATION_FILEPATH", mCalFile.path, true); } From f669a1ea526da4a6d674019431bbeed67ced50d2 Mon Sep 17 00:00:00 2001 From: Tai Kuo Date: Mon, 21 Oct 2024 11:44:38 +0800 Subject: [PATCH 3/3] cs40l26: add DBC bin info and reduce duplicates Bug: 356823441 Test: dumpsys android.hardware.vibrator.IVibrator/default Flag: EXEMPT bugfix Change-Id: Id3d9fac99b204de581269818e69722932e4911fc (cherry picked from commit 6e4e8d2052e352a56eeab2e452addaf484d79d9f) --- vibrator/cs40l26/Vibrator.cpp | 83 ++++++++++++++--------------------- 1 file changed, 34 insertions(+), 49 deletions(-) diff --git a/vibrator/cs40l26/Vibrator.cpp b/vibrator/cs40l26/Vibrator.cpp index 89bd146..6c3c84b 100644 --- a/vibrator/cs40l26/Vibrator.cpp +++ b/vibrator/cs40l26/Vibrator.cpp @@ -1554,70 +1554,55 @@ binder_status_t Vibrator::dump(int fd, const char **args, uint32_t numArgs) { dprintf(fd, "\n"); dprintf(fd, "Versions:\n"); + const std::vector> moduleFolderNames = { + {"cs40l26_core", "Haptics"}, {"cl_dsp_core", "DSP"}}; + const std::string firmwareFolder = "/vendor/firmware/"; + const std::string waveformName = "cs40l26.bin"; + const std::array firmwareFileNames = {"cs40l26.wmfw", "cs40l26-calib.wmfw"}; + const std::array tuningFileNames = {"cs40l26-svc.bin", "cs40l26-calib.bin", + "cs40l26-dvl.bin", "cs40l26-dbc.bin"}; std::ifstream verFile; const auto verBinFileMode = std::ifstream::in | std::ifstream::binary; std::string ver; - verFile.open("/sys/module/cs40l26_core/version"); - if (verFile.is_open()) { - getline(verFile, ver); - dprintf(fd, " Haptics Driver: %s\n", ver.c_str()); - verFile.close(); + for (const auto &[folder, logTag] : moduleFolderNames) { + verFile.open("/sys/module/" + folder + "/version"); + if (verFile.is_open()) { + getline(verFile, ver); + dprintf(fd, " %s Driver: %s\n", logTag.c_str(), ver.c_str()); + verFile.close(); + } } - verFile.open("/sys/module/cl_dsp_core/version"); - if (verFile.is_open()) { - getline(verFile, ver); - dprintf(fd, " DSP Driver: %s\n", ver.c_str()); - verFile.close(); + for (auto &name : firmwareFileNames) { + verFile.open(firmwareFolder + name, verBinFileMode); + if (verFile.is_open()) { + verFile.seekg(113); + dprintf(fd, " %s: %d.%d.%d\n", name.c_str(), verFile.get(), verFile.get(), + verFile.get()); + verFile.close(); + } } - verFile.open("/vendor/firmware/cs40l26.wmfw", verBinFileMode); - if (verFile.is_open()) { - verFile.seekg(113); - dprintf(fd, " cs40l26.wmfw: %d.%d.%d\n", verFile.get(), verFile.get(), verFile.get()); - verFile.close(); - } - verFile.open("/vendor/firmware/cs40l26-calib.wmfw", verBinFileMode); - if (verFile.is_open()) { - verFile.seekg(113); - dprintf(fd, " cs40l26-calib.wmfw: %d.%d.%d\n", verFile.get(), verFile.get(), - verFile.get()); - verFile.close(); - } - verFile.open("/vendor/firmware/cs40l26.bin", verBinFileMode); + verFile.open(firmwareFolder + waveformName, verBinFileMode); if (verFile.is_open()) { while (getline(verFile, ver)) { auto pos = ver.find("Date: "); if (pos != std::string::npos) { ver = ver.substr(pos + 6, pos + 15); - dprintf(fd, " cs40l26.bin: %s\n", ver.c_str()); + dprintf(fd, " %s: %s\n", waveformName.c_str(), ver.c_str()); break; } } verFile.close(); } - verFile.open("/vendor/firmware/cs40l26-svc.bin", verBinFileMode); - if (verFile.is_open()) { - verFile.seekg(36); - getline(verFile, ver); - ver = ver.substr(ver.rfind('\\') + 1); - dprintf(fd, " cs40l26-svc.bin: %s\n", ver.c_str()); - verFile.close(); - } - verFile.open("/vendor/firmware/cs40l26-calib.bin", verBinFileMode); - if (verFile.is_open()) { - verFile.seekg(36); - getline(verFile, ver); - ver = ver.substr(ver.rfind('\\') + 1); - dprintf(fd, " cs40l26-calib.bin: %s\n", ver.c_str()); - verFile.close(); - } - verFile.open("/vendor/firmware/cs40l26-dvl.bin", verBinFileMode); - if (verFile.is_open()) { - verFile.seekg(36); - getline(verFile, ver); - ver = ver.substr(0, ver.find('\0') + 1); - ver = ver.substr(ver.rfind('\\') + 1); - dprintf(fd, " cs40l26-dvl.bin: %s\n", ver.c_str()); - verFile.close(); + for (auto &name : tuningFileNames) { + verFile.open(firmwareFolder + name, verBinFileMode); + if (verFile.is_open()) { + verFile.seekg(36); + getline(verFile, ver); + ver = ver.substr(0, ver.find(".bin") + 4); + ver = ver.substr(ver.rfind('\\') + 1); + dprintf(fd, " %s: %s\n", name.c_str(), ver.c_str()); + verFile.close(); + } } dprintf(fd, "\n");