vibrator: Adopt Common Implementation
Adopt the common vibrator HAL implementation for the DRV2624 controller.
Test: Manual, PTS, VTS
Change-Id: I38e54f146c32ef47a5607c3acec347185c0f53fb
Signed-off-by: Harpreet "Eli" Sangha <eliptus@google.com>
diff --git a/CleanSpec.mk b/CleanSpec.mk
index 6d71bc6..271657d 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -177,3 +177,7 @@
# Remove obsolete android.hardware.boot@1.0-impl-wrapper.recovery.so
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/recovery/root/system/lib64/hw/android.hardware.boot@1.0-impl-wrapper.recovery.so)
+
+# Vibrator HAL 1.2 renamed from 'bonito' to 'drv2624'
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/etc/init/android.hardware.vibrator@1.2-service.bonito.rc)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/bin/hw/android.hardware.vibrator@1.2-service.bonito)
diff --git a/device-bonito.mk b/device-bonito.mk
index f98bd39..f5a1f94 100644
--- a/device-bonito.mk
+++ b/device-bonito.mk
@@ -25,6 +25,7 @@
# Vibrator HAL
PRODUCT_PRODUCT_PROPERTIES +=\
+ ro.vibrator.hal.config.dynamic=1 \
ro.vibrator.hal.click.duration=8 \
ro.vibrator.hal.tick.duration=5 \
ro.vibrator.hal.heavyclick.duration=12 \
diff --git a/device-sargo.mk b/device-sargo.mk
index 8362fd2..5e1c8c4 100644
--- a/device-sargo.mk
+++ b/device-sargo.mk
@@ -27,6 +27,7 @@
# Vibrator HAL
PRODUCT_PRODUCT_PROPERTIES +=\
+ ro.vibrator.hal.config.dynamic=1 \
ro.vibrator.hal.click.duration=8 \
ro.vibrator.hal.tick.duration=5 \
ro.vibrator.hal.heavyclick.duration=12 \
diff --git a/device.mk b/device.mk
index bddb38e..1642210 100644
--- a/device.mk
+++ b/device.mk
@@ -478,7 +478,7 @@
# Vibrator HAL
PRODUCT_PACKAGES += \
- android.hardware.vibrator@1.2-service.bonito \
+ android.hardware.vibrator@1.2-service.drv2624
# Thermal HAL
PRODUCT_PACKAGES += \
diff --git a/manifest.xml b/manifest.xml
index 67de3c7..5e26e8a 100644
--- a/manifest.xml
+++ b/manifest.xml
@@ -368,15 +368,6 @@
</interface>
</hal>
<hal format="hidl">
- <name>android.hardware.vibrator</name>
- <transport>hwbinder</transport>
- <version>1.2</version>
- <interface>
- <name>IVibrator</name>
- <instance>default</instance>
- </interface>
- </hal>
- <hal format="hidl">
<name>android.hardware.weaver</name>
<transport>hwbinder</transport>
<version>1.0</version>
diff --git a/vibrator/Android.bp b/vibrator/Android.bp
deleted file mode 100644
index 2462082..0000000
--- a/vibrator/Android.bp
+++ /dev/null
@@ -1,34 +0,0 @@
-//
-// Copyright (C) 2017 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.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-cc_binary {
- name: "android.hardware.vibrator@1.2-service.bonito",
- relative_install_path: "hw",
- init_rc: ["android.hardware.vibrator@1.2-service.bonito.rc"],
- srcs: ["service.cpp", "Vibrator.cpp"],
- cflags: ["-Wall", "-Werror"],
- shared_libs: [
- "libhidlbase",
- "libcutils",
- "libhidltransport",
- "liblog",
- "libhwbinder",
- "libutils",
- "libhardware",
- "android.hardware.vibrator@1.0",
- "android.hardware.vibrator@1.1",
- "android.hardware.vibrator@1.2"
- ],
- proprietary: true,
-}
diff --git a/vibrator/OWNERS b/vibrator/OWNERS
deleted file mode 100644
index 2ce9955..0000000
--- a/vibrator/OWNERS
+++ /dev/null
@@ -1,3 +0,0 @@
-eliptus@google.com
-michaelwr@google.com
-chasewu@google.com
diff --git a/vibrator/Vibrator.cpp b/vibrator/Vibrator.cpp
deleted file mode 100644
index 509d739..0000000
--- a/vibrator/Vibrator.cpp
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "VibratorService"
-
-#include <log/log.h>
-
-#include <cutils/properties.h>
-#include <hardware/hardware.h>
-#include <hardware/vibrator.h>
-
-#include "Vibrator.h"
-
-#include <cinttypes>
-#include <cmath>
-#include <fstream>
-#include <iostream>
-
-namespace android {
-namespace hardware {
-namespace vibrator {
-namespace V1_2 {
-namespace implementation {
-
-static constexpr int8_t MAX_RTP_INPUT = 127;
-static constexpr int8_t MIN_RTP_INPUT = 0;
-
-static constexpr char RTP_MODE[] = "rtp";
-static constexpr char WAVEFORM_MODE[] = "waveform";
-
-static constexpr uint32_t LOOP_MODE_OPEN = 1;
-static constexpr uint32_t SINE_WAVE = 1;
-static constexpr uint32_t SQUARE_WAVE = 0;
-
-// Default max voltage 2.15V
-static constexpr uint32_t VOLTAGE_MAX = 107;
-
-// Use effect #1 in the waveform library for CLICK effect
-static constexpr char WAVEFORM_CLICK_EFFECT_SEQ[] = "1 0";
-static constexpr int32_t WAVEFORM_CLICK_EFFECT_MS = 6;
-
-// Use effect #2 in the waveform library for TICK effect
-static constexpr char WAVEFORM_TICK_EFFECT_SEQ[] = "2 0";
-static constexpr int32_t WAVEFORM_TICK_EFFECT_MS = 2;
-
-// Use effect #3 in the waveform library for DOUBLE_CLICK effect
-static constexpr char WAVEFORM_DOUBLE_CLICK_EFFECT_SEQ[] = "3 0";
-static constexpr uint32_t WAVEFORM_DOUBLE_CLICK_EFFECT_MS = 182;
-
-// Use effect #4 in the waveform library for HEAVY_CLICK effect
-static constexpr char WAVEFORM_HEAVY_CLICK_EFFECT_SEQ[] = "4 0";
-static constexpr uint32_t WAVEFORM_HEAVY_CLICK_EFFECT_MS = 8;
-
-using Status = ::android::hardware::vibrator::V1_0::Status;
-using EffectStrength = ::android::hardware::vibrator::V1_0::EffectStrength;
-
-Vibrator::Vibrator(HwApi &&hwapi, std::uint32_t short_lra_period, std::uint32_t long_lra_period)
- : mHwApi(std::move(hwapi)), mShortLraPeriod(short_lra_period), mLongLraPeriod(long_lra_period) {
- mClickDuration = property_get_int32("ro.vibrator.hal.click.duration", WAVEFORM_CLICK_EFFECT_MS);
- mTickDuration = property_get_int32("ro.vibrator.hal.tick.duration", WAVEFORM_TICK_EFFECT_MS);
- mHeavyClickDuration =
- property_get_int32("ro.vibrator.hal.heavyclick.duration", WAVEFORM_HEAVY_CLICK_EFFECT_MS);
- mShortVoltageMax = property_get_int32("ro.vibrator.hal.short.voltage", VOLTAGE_MAX);
- mLongVoltageMax = property_get_int32("ro.vibrator.hal.long.voltage", VOLTAGE_MAX);
-
- // This enables effect #1 from the waveform library to be triggered by SLPI
- // while the AP is in suspend mode
- mHwApi.lpTriggerEffect << 1 << std::endl;
- if (!mHwApi.lpTriggerEffect) {
- ALOGW("Failed to set LP trigger mode (%d): %s", errno, strerror(errno));
- }
-}
-
-Return<Status> Vibrator::on(uint32_t timeoutMs, bool isWaveform) {
- // Bonito / Sargo only support open-loop mode
- mHwApi.ctrlLoop << LOOP_MODE_OPEN << std::endl;
- mHwApi.duration << timeoutMs << std::endl;
- if (!mHwApi.duration) {
- ALOGE("Failed to set duration (%d): %s", errno, strerror(errno));
- return Status::UNKNOWN_ERROR;
- }
-
- if (isWaveform) {
- mHwApi.mode << WAVEFORM_MODE << std::endl;
- mHwApi.lraWaveShape << SINE_WAVE << std::endl;
- mHwApi.odClamp << mShortVoltageMax << std::endl;
- mHwApi.olLraPeriod << mShortLraPeriod << std::endl;
- } else {
- mHwApi.mode << RTP_MODE << std::endl;
- mHwApi.lraWaveShape << SQUARE_WAVE << std::endl;
- mHwApi.odClamp << mLongVoltageMax << std::endl;
- mHwApi.olLraPeriod << mLongLraPeriod << std::endl;
- }
-
- mHwApi.activate << 1 << std::endl;
- if (!mHwApi.activate) {
- ALOGE("Failed to activate (%d): %s", errno, strerror(errno));
- return Status::UNKNOWN_ERROR;
- }
-
- return Status::OK;
-}
-
-// Methods from ::android::hardware::vibrator::V1_2::IVibrator follow.
-Return<Status> Vibrator::on(uint32_t timeoutMs) {
- return on(timeoutMs, false /* isWaveform */);
-}
-
-Return<Status> Vibrator::off() {
- mHwApi.activate << 0 << std::endl;
- if (!mHwApi.activate) {
- ALOGE("Failed to turn vibrator off (%d): %s", errno, strerror(errno));
- return Status::UNKNOWN_ERROR;
- }
- return Status::OK;
-}
-
-Return<bool> Vibrator::supportsAmplitudeControl() {
- return (mHwApi.rtpInput ? true : false);
-}
-
-Return<Status> Vibrator::setAmplitude(uint8_t amplitude) {
- if (amplitude == 0) {
- return Status::BAD_VALUE;
- }
-
- int32_t rtp_input =
- std::round((amplitude - 1) / 254.0 * (MAX_RTP_INPUT - MIN_RTP_INPUT) + MIN_RTP_INPUT);
-
- mHwApi.rtpInput << rtp_input << std::endl;
- if (!mHwApi.rtpInput) {
- ALOGE("Failed to set amplitude (%d): %s", errno, strerror(errno));
- return Status::UNKNOWN_ERROR;
- }
-
- return Status::OK;
-}
-
-static uint8_t convertEffectStrength(EffectStrength strength) {
- uint8_t scale;
-
- switch (strength) {
- case EffectStrength::LIGHT:
- scale = 2; // 50%
- break;
- case EffectStrength::MEDIUM:
- case EffectStrength::STRONG:
- scale = 0; // 100%
- break;
- }
-
- return scale;
-}
-
-Return<void> Vibrator::perform(V1_0::Effect effect, EffectStrength strength, perform_cb _hidl_cb) {
- return performWrapper(effect, strength, _hidl_cb);
-}
-
-Return<void> Vibrator::perform_1_1(V1_1::Effect_1_1 effect, EffectStrength strength,
- perform_cb _hidl_cb) {
- return performWrapper(effect, strength, _hidl_cb);
-}
-
-Return<void> Vibrator::perform_1_2(Effect effect, EffectStrength strength, perform_cb _hidl_cb) {
- return performWrapper(effect, strength, _hidl_cb);
-}
-
-template <typename T>
-Return<void> Vibrator::performWrapper(T effect, EffectStrength strength, perform_cb _hidl_cb) {
- auto validEffectRange = hidl_enum_range<T>();
- if (effect < *validEffectRange.begin() || effect > *std::prev(validEffectRange.end())) {
- _hidl_cb(Status::UNSUPPORTED_OPERATION, 0);
- return Void();
- }
- auto validStrengthRange = hidl_enum_range<EffectStrength>();
- if (strength < *validStrengthRange.begin() || strength > *std::prev(validStrengthRange.end())) {
- _hidl_cb(Status::UNSUPPORTED_OPERATION, 0);
- return Void();
- }
- return performEffect(static_cast<Effect>(effect), strength, _hidl_cb);
-}
-
-Return<void> Vibrator::performEffect(Effect effect, EffectStrength strength, perform_cb _hidl_cb) {
- Status status = Status::OK;
- uint32_t timeMS;
-
- switch (effect) {
- case Effect::CLICK:
- mHwApi.sequencer << WAVEFORM_CLICK_EFFECT_SEQ << std::endl;
- timeMS = mClickDuration;
- break;
- case Effect::DOUBLE_CLICK:
- mHwApi.sequencer << WAVEFORM_DOUBLE_CLICK_EFFECT_SEQ << std::endl;
- timeMS = WAVEFORM_DOUBLE_CLICK_EFFECT_MS;
- break;
- case Effect::TICK:
- mHwApi.sequencer << WAVEFORM_TICK_EFFECT_SEQ << std::endl;
- timeMS = mTickDuration;
- break;
- case Effect::HEAVY_CLICK:
- mHwApi.sequencer << WAVEFORM_HEAVY_CLICK_EFFECT_SEQ << std::endl;
- timeMS = mHeavyClickDuration;
- break;
- default:
- _hidl_cb(Status::UNSUPPORTED_OPERATION, 0);
- return Void();
- }
- mHwApi.scale << convertEffectStrength(strength) << std::endl;
- on(timeMS, true /* isWaveform */);
- _hidl_cb(status, timeMS);
- return Void();
-}
-
-} // namespace implementation
-} // namespace V1_2
-} // namespace vibrator
-} // namespace hardware
-} // namespace android
diff --git a/vibrator/Vibrator.h b/vibrator/Vibrator.h
deleted file mode 100644
index 08635cf..0000000
--- a/vibrator/Vibrator.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef ANDROID_HARDWARE_VIBRATOR_V1_2_VIBRATOR_H
-#define ANDROID_HARDWARE_VIBRATOR_V1_2_VIBRATOR_H
-
-#include <android/hardware/vibrator/1.2/IVibrator.h>
-#include <hidl/Status.h>
-
-#include <fstream>
-
-namespace android {
-namespace hardware {
-namespace vibrator {
-namespace V1_2 {
-namespace implementation {
-
-class Vibrator : public IVibrator {
- public:
- typedef struct {
- std::ofstream activate;
- std::ofstream ctrlLoop;
- std::ofstream duration;
- std::ofstream lpTriggerEffect;
- std::ofstream lraWaveShape;
- std::ofstream mode;
- std::ofstream odClamp;
- std::ofstream olLraPeriod;
- std::ofstream rtpInput;
- std::ofstream scale;
- std::ofstream sequencer;
- std::ofstream state;
- } HwApi;
-
- public:
- Vibrator(HwApi &&hwapi, std::uint32_t short_lra_period, std::uint32_t long_lra_period);
-
- // Methods from ::android::hardware::vibrator::V1_0::IVibrator follow.
- using Status = ::android::hardware::vibrator::V1_0::Status;
- Return<Status> on(uint32_t timeoutMs) override;
- Return<Status> off() override;
- Return<bool> supportsAmplitudeControl() override;
- Return<Status> setAmplitude(uint8_t amplitude) override;
-
- using EffectStrength = ::android::hardware::vibrator::V1_0::EffectStrength;
- Return<void> perform(V1_0::Effect effect, EffectStrength strength,
- perform_cb _hidl_cb) override;
- Return<void> perform_1_1(V1_1::Effect_1_1 effect, EffectStrength strength,
- perform_cb _hidl_cb) override;
- Return<void> perform_1_2(Effect effect, EffectStrength strength, perform_cb _hidl_cb) override;
-
- private:
- Return<Status> on(uint32_t timeoutMs, bool isWaveform);
- template <typename T>
- Return<void> performWrapper(T effect, EffectStrength strength, perform_cb _hidl_cb);
- Return<void> performEffect(Effect effect, EffectStrength strength, perform_cb _hidl_cb);
- HwApi mHwApi;
- std::uint32_t mShortLraPeriod;
- std::uint32_t mLongLraPeriod;
- int32_t mClickDuration;
- int32_t mTickDuration;
- int32_t mHeavyClickDuration;
- int32_t mShortVoltageMax;
- int32_t mLongVoltageMax;
-};
-} // namespace implementation
-} // namespace V1_2
-} // namespace vibrator
-} // namespace hardware
-} // namespace android
-
-#endif // ANDROID_HARDWARE_VIBRATOR_V1_2_VIBRATOR_H
diff --git a/vibrator/android.hardware.vibrator@1.2-service.bonito.rc b/vibrator/android.hardware.vibrator@1.2-service.bonito.rc
deleted file mode 100644
index b47bee8..0000000
--- a/vibrator/android.hardware.vibrator@1.2-service.bonito.rc
+++ /dev/null
@@ -1,4 +0,0 @@
-service vendor.vibrator-1-2 /vendor/bin/hw/android.hardware.vibrator@1.2-service.bonito
- class hal
- user system
- group system
diff --git a/vibrator/service.cpp b/vibrator/service.cpp
deleted file mode 100644
index b090420..0000000
--- a/vibrator/service.cpp
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#define LOG_TAG "android.hardware.vibrator@1.2-service.bonito"
-
-#include <android/hardware/vibrator/1.2/IVibrator.h>
-#include <cutils/properties.h>
-#include <hidl/HidlSupport.h>
-#include <hidl/HidlTransportSupport.h>
-#include <utils/Errors.h>
-#include <utils/StrongPointer.h>
-
-#include "Vibrator.h"
-
-using android::hardware::configureRpcThreadpool;
-using android::hardware::joinRpcThreadpool;
-using android::hardware::vibrator::V1_2::IVibrator;
-using android::hardware::vibrator::V1_2::implementation::Vibrator;
-using namespace android;
-
-// Refer to Documentation/ABI/testing/sysfs-class-led-driver-drv2624
-// kernel documentation on the detail usages for ABIs below
-static constexpr char ACTIVATE_PATH[] = "/sys/class/leds/vibrator/activate";
-static constexpr char DURATION_PATH[] = "/sys/class/leds/vibrator/duration";
-static constexpr char STATE_PATH[] = "/sys/class/leds/vibrator/state";
-static constexpr char RTP_INPUT_PATH[] = "/sys/class/leds/vibrator/device/rtp_input";
-static constexpr char MODE_PATH[] = "/sys/class/leds/vibrator/device/mode";
-static constexpr char SEQUENCER_PATH[] = "/sys/class/leds/vibrator/device/set_sequencer";
-static constexpr char SCALE_PATH[] = "/sys/class/leds/vibrator/device/scale";
-static constexpr char CTRL_LOOP_PATH[] = "/sys/class/leds/vibrator/device/ctrl_loop";
-static constexpr char LP_TRIGGER_PATH[] = "/sys/class/leds/vibrator/device/lp_trigger_effect";
-static constexpr char LRA_WAVE_SHAPE_PATH[] = "/sys/class/leds/vibrator/device/lra_wave_shape";
-static constexpr char OD_CLAMP_PATH[] = "/sys/class/leds/vibrator/device/od_clamp";
-
-// File path to the calibration file
-static constexpr char CALIBRATION_FILEPATH[] = "/persist/haptics/drv2624.cal";
-
-// Kernel ABIs for updating the calibration data
-static constexpr char AUTOCAL_CONFIG[] = "autocal";
-static constexpr char LRA_PERIOD_CONFIG[] = "lra_period";
-static constexpr char AUTOCAL_FILEPATH[] = "/sys/class/leds/vibrator/device/autocal";
-static constexpr char OL_LRA_PERIOD_FILEPATH[] = "/sys/class/leds/vibrator/device/ol_lra_period";
-
-// Set a default lra period in case there is no calibration file
-static constexpr uint32_t DEFAULT_LRA_PERIOD = 262;
-static constexpr uint32_t DEFAULT_FREQUENCY_SHIFT = 10;
-
-static std::uint32_t freqPeriodFormula(std::uint32_t in) {
- return 1000000000 / (24615 * in);
-}
-
-static std::string trim(const std::string &str, const std::string &whitespace = " \t") {
- const auto str_begin = str.find_first_not_of(whitespace);
- if (str_begin == std::string::npos) {
- return "";
- }
-
- const auto str_end = str.find_last_not_of(whitespace);
- const auto str_range = str_end - str_begin + 1;
-
- return str.substr(str_begin, str_range);
-}
-
-static bool loadCalibrationData(std::uint32_t &short_lra_period, std::uint32_t &long_lra_period) {
- std::map<std::string, std::string> config_data;
-
- std::ofstream autocal{AUTOCAL_FILEPATH};
- if (!autocal) {
- int error = errno;
- ALOGE("Failed to open %s (%d): %s", AUTOCAL_FILEPATH, error, strerror(error));
- return false;
- }
-
- std::ofstream ol_lra_period{OL_LRA_PERIOD_FILEPATH};
- if (!ol_lra_period) {
- int error = errno;
- ALOGE("Failed to open %s (%d): %s", OL_LRA_PERIOD_FILEPATH, error, strerror(error));
- return false;
- }
-
- std::ifstream cal_data{CALIBRATION_FILEPATH};
- if (!cal_data) {
- int error = errno;
- ALOGE("Failed to open %s (%d): %s", CALIBRATION_FILEPATH, error, strerror(error));
- return false;
- }
-
- std::string line;
-
- while (std::getline(cal_data, line)) {
- if (line.empty() || line[0] == '#') {
- continue;
- }
- std::istringstream is_line(line);
- std::string key;
- if (std::getline(is_line, key, ':')) {
- std::string value;
-
- if (std::getline(is_line, value)) {
- config_data[trim(key)] = trim(value);
- }
- }
- }
-
- if (config_data.find(AUTOCAL_CONFIG) != config_data.end()) {
- autocal << config_data[AUTOCAL_CONFIG] << std::endl;
- }
-
- if (config_data.find(LRA_PERIOD_CONFIG) != config_data.end()) {
- uint32_t thisFrequency;
- uint32_t thisPeriod;
- ol_lra_period << config_data[LRA_PERIOD_CONFIG] << std::endl;
- thisPeriod = std::stoul(config_data[LRA_PERIOD_CONFIG]);
- short_lra_period = thisPeriod;
- // 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
- thisFrequency =
- freqPeriodFormula(thisPeriod) -
- property_get_int32("ro.vibrator.hal.long.frequency.shift", DEFAULT_FREQUENCY_SHIFT);
- long_lra_period = freqPeriodFormula(thisFrequency);
- }
-
- return true;
-}
-
-status_t registerVibratorService() {
- // Calibration data: lra period 262(i.e. 155Hz)
- std::uint32_t short_lra_period(DEFAULT_LRA_PERIOD);
- std::uint32_t long_lra_period(DEFAULT_LRA_PERIOD);
- Vibrator::HwApi hwapi;
-
- // ostreams below are required
- hwapi.activate.open(ACTIVATE_PATH);
- if (!hwapi.activate) {
- int error = errno;
- ALOGE("Failed to open %s (%d): %s", ACTIVATE_PATH, error, strerror(error));
- return -error;
- }
-
- hwapi.duration.open(DURATION_PATH);
- if (!hwapi.duration) {
- int error = errno;
- ALOGE("Failed to open %s (%d): %s", DURATION_PATH, error, strerror(error));
- return -error;
- }
-
- hwapi.state.open(STATE_PATH);
- if (!hwapi.state) {
- int error = errno;
- ALOGE("Failed to open %s (%d): %s", STATE_PATH, error, strerror(error));
- return -error;
- }
-
- hwapi.state << 1 << std::endl;
- if (!hwapi.state) {
- int error = errno;
- ALOGE("Failed to set state (%d): %s", errno, strerror(errno));
- return -error;
- }
-
- // ostreams below are optional
- hwapi.rtpInput.open(RTP_INPUT_PATH);
- if (!hwapi.rtpInput) {
- int error = errno;
- ALOGW("Failed to open %s (%d): %s", RTP_INPUT_PATH, error, strerror(error));
- }
-
- hwapi.mode.open(MODE_PATH);
- if (!hwapi.mode) {
- int error = errno;
- ALOGW("Failed to open %s (%d): %s", MODE_PATH, error, strerror(error));
- }
-
- hwapi.sequencer.open(SEQUENCER_PATH);
- if (!hwapi.sequencer) {
- int error = errno;
- ALOGW("Failed to open %s (%d): %s", SEQUENCER_PATH, error, strerror(error));
- }
-
- hwapi.scale.open(SCALE_PATH);
- if (!hwapi.scale) {
- int error = errno;
- ALOGW("Failed to open %s (%d): %s", SCALE_PATH, error, strerror(error));
- }
-
- hwapi.ctrlLoop.open(CTRL_LOOP_PATH);
- if (!hwapi.ctrlLoop) {
- int error = errno;
- ALOGW("Failed to open %s (%d): %s", CTRL_LOOP_PATH, error, strerror(error));
- }
-
- hwapi.lpTriggerEffect.open(LP_TRIGGER_PATH);
- if (!hwapi.lpTriggerEffect) {
- int error = errno;
- ALOGW("Failed to open %s (%d): %s", LP_TRIGGER_PATH, error, strerror(error));
- }
-
- hwapi.lraWaveShape.open(LRA_WAVE_SHAPE_PATH);
- if (!hwapi.lraWaveShape) {
- int error = errno;
- ALOGW("Failed to open %s (%d): %s", LRA_WAVE_SHAPE_PATH, error, strerror(error));
- }
-
- hwapi.odClamp.open(OD_CLAMP_PATH);
- if (!hwapi.odClamp) {
- int error = errno;
- ALOGW("Failed to open %s (%d): %s", OD_CLAMP_PATH, error, strerror(error));
- }
-
- hwapi.olLraPeriod.open(OL_LRA_PERIOD_FILEPATH);
- if (!hwapi.olLraPeriod) {
- int error = errno;
- ALOGW("Failed to open %s (%d): %s", OL_LRA_PERIOD_FILEPATH, error, strerror(error));
- }
-
- if (!loadCalibrationData(short_lra_period, long_lra_period)) {
- ALOGW("Failed load calibration data");
- }
-
- sp<IVibrator> vibrator = new Vibrator(std::move(hwapi), short_lra_period, long_lra_period);
-
- return vibrator->registerAsService();
-}
-
-int main() {
- configureRpcThreadpool(1, true);
- status_t status = registerVibratorService();
-
- if (status != OK) {
- return status;
- }
-
- joinRpcThreadpool();
-}