Skip to content

Commit 20786c8

Browse files
BotchedRPRlog1cs
authored andcommitted
vibrator: Add device-specific configuration parameters
- use_compound_double_click_effect - seen TRUE on SM8350, where there may be not a hardware waveform for Effect::DOUBLE_CLICK - use_effect_duration_polling - seen TRUE on SM8450+, where pollVibeState accepts a timeout parameter, which has to be handled with a mutex. Change-Id: I10565306f612aaebef765a4f604fa0403f99c026
1 parent eae6a93 commit 20786c8

4 files changed

Lines changed: 62 additions & 3 deletions

File tree

aidl/vibrator/Android.bp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ cc_defaults {
3131
"liblog",
3232
"libutils",
3333
],
34+
cflags: select(soong_config_variable("SonyVibratorVars", "use_compound_double_click_effect"), {
35+
true: ["-DUSE_COMPOUND_DOUBLE_CLICK_EFFECT"],
36+
default: ["-DUSE_EFFECT_DURATION_POLLING"],
37+
}),
3438
}
3539

3640
cc_defaults {

aidl/vibrator/cs40l25/Hardware.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,15 @@ class HwApi : public Vibrator::HwApi, private HwApiBase {
7272
bool setGpioFallScale(uint32_t value) override { return set(value, &mGpioFallScale); }
7373
bool setGpioRiseIndex(uint32_t value) override { return set(value, &mGpioRiseIndex); }
7474
bool setGpioRiseScale(uint32_t value) override { return set(value, &mGpioRiseScale); }
75+
76+
#ifdef USE_EFFECT_DURATION_POLLING
7577
bool pollVibeState(uint32_t value, int32_t timeoutMs) override {
7678
return poll(value, &mVibeState, timeoutMs);
7779
}
80+
#else
81+
bool pollVibeState(bool value) override { return poll(value, &mVibeState); }
82+
#endif
83+
7884
bool setClabEnable(bool value) override { return set(value, &mClabEnable); }
7985
bool getAvailablePwleSegments(uint32_t* value) override {
8086
return get(value, &mAvailablePwleSegments);

aidl/vibrator/cs40l25/Vibrator.cpp

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ static constexpr uint32_t WAVEFORM_LOW_TICK_INDEX = 10;
6565
static constexpr uint32_t WAVEFORM_SONY_THUD_INDEX = 11;
6666
static constexpr uint32_t WAVEFORM_SONY_POP_INDEX = 12;
6767
static constexpr uint32_t WAVEFORM_SONY_HEAVY_CLICK_INDEX = 13;
68+
69+
#ifndef USE_COMPOUND_DOUBLE_CLICK_EFFECT
6870
static constexpr uint32_t WAVEFORM_SONY_DOUBLE_CLICK_INDEX = 19;
71+
#endif // USE_COMPOUND_DOUBLE_CLICK_EFFECT
6972

7073
static constexpr uint32_t WAVEFORM_UNSAVED_TRIGGER_QUEUE_INDEX = 65529;
7174
static constexpr uint32_t WAVEFORM_TRIGGER_QUEUE_INDEX = 65534;
@@ -456,11 +459,14 @@ ndk::ScopedAStatus Vibrator::compose(const std::vector<CompositeEffect>& composi
456459
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
457460
}
458461

462+
#ifdef USE_EFFECT_DURATION_POLLING
459463
// Reset the mTotalDuration
460464
{
461465
const std::scoped_lock<std::mutex> lock(mTotalDurationMutex);
462466
mTotalDuration = 0;
463467
}
468+
#endif // USE_EFFECT_DURATION_POLLING
469+
464470
for (auto& e : composite) {
465471
if (e.scale < 0.0f || e.scale > 1.0f) {
466472
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
@@ -471,10 +477,13 @@ ndk::ScopedAStatus Vibrator::compose(const std::vector<CompositeEffect>& composi
471477
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
472478
}
473479
effectBuilder << e.delayMs << ",";
480+
481+
#ifdef USE_EFFECT_DURATION_POLLING
474482
{
475483
const std::scoped_lock<std::mutex> lock(mTotalDurationMutex);
476484
mTotalDuration += e.delayMs;
477485
}
486+
#endif // USE_EFFECT_DURATION_POLLING
478487
}
479488
if (e.primitive != CompositePrimitive::NOOP) {
480489
ndk::ScopedAStatus status;
@@ -485,11 +494,13 @@ ndk::ScopedAStatus Vibrator::compose(const std::vector<CompositeEffect>& composi
485494
return status;
486495
}
487496

497+
#ifdef USE_EFFECT_DURATION_POLLING
488498
effectBuilder << effectIndex << "." << intensityToVolLevel(e.scale, effectIndex) << ",";
489499
{
490500
const std::scoped_lock<std::mutex> lock(mTotalDurationMutex);
491501
mTotalDuration += mEffectDurations[effectIndex];
492502
}
503+
#endif // USE_EFFECT_DURATION_POLLING
493504
}
494505
}
495506

@@ -520,6 +531,8 @@ ndk::ScopedAStatus Vibrator::on(uint32_t timeoutMs, uint32_t effectIndex,
520531
mHwApi->setEffectIndex(effectIndex);
521532
mHwApi->setDuration(timeoutMs);
522533
mHwApi->setActivate(1);
534+
535+
#ifdef USE_EFFECT_DURATION_POLLING
523536
usleep(10000);
524537
// Using the mToalDuration for composed effect.
525538
// For composed effect, we set the UINT32_MAX to the duration sysfs node,
@@ -528,6 +541,7 @@ ndk::ScopedAStatus Vibrator::on(uint32_t timeoutMs, uint32_t effectIndex,
528541
const std::scoped_lock<std::mutex> lock(mTotalDurationMutex);
529542
mTotalDuration = timeoutMs;
530543
}
544+
#endif // USE_EFFECT_DURATION_POLLING
531545

532546
mActiveId = effectIndex;
533547

@@ -926,10 +940,14 @@ ndk::ScopedAStatus Vibrator::composePwle(const std::vector<PrimitivePwle>& compo
926940

927941
totalDuration += MAX_COLD_START_LATENCY_MS;
928942
mHwApi->setDuration(totalDuration);
943+
944+
#ifdef USE_EFFECT_DURATION_POLLING
929945
{
930946
const std::scoped_lock<std::mutex> lock(mTotalDurationMutex);
931947
mTotalDuration = totalDuration;
932948
}
949+
#endif // USE_EFFECT_DURATION_POLLING
950+
933951
mHwApi->setActivate(1);
934952

935953
mAsyncHandle = std::async(&Vibrator::waitForComplete, this, callback);
@@ -1015,25 +1033,30 @@ ndk::ScopedAStatus Vibrator::getSimpleDetails(Effect effect, EffectStrength stre
10151033
case Effect::HEAVY_CLICK:
10161034
effectIndex = WAVEFORM_SONY_HEAVY_CLICK_INDEX;
10171035
break;
1018-
case Effect::DOUBLE_CLICK:
1019-
effectIndex = WAVEFORM_SONY_DOUBLE_CLICK_INDEX;
1020-
break;
10211036
case Effect::THUD:
10221037
effectIndex = WAVEFORM_SONY_THUD_INDEX;
10231038
break;
10241039
case Effect::POP:
10251040
effectIndex = WAVEFORM_SONY_POP_INDEX;
10261041
break;
1042+
#ifndef USE_COMPOUND_DOUBLE_CLICK_EFFECT
1043+
case Effect::DOUBLE_CLICK:
1044+
effectIndex = WAVEFORM_SONY_DOUBLE_CLICK_INDEX;
1045+
break;
1046+
#endif // USE_COMPOUND_DOUBLE_CLICK_EFFECT
10271047
default:
10281048
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
10291049
}
10301050

10311051
volLevel = intensityToVolLevel(intensity, effectIndex);
10321052
timeMs = mEffectDurations[effectIndex] + MAX_COLD_START_LATENCY_MS;
1053+
1054+
#ifdef USE_EFFECT_DURATION_POLLING
10331055
{
10341056
const std::scoped_lock<std::mutex> lock(mTotalDurationMutex);
10351057
mTotalDuration = timeMs;
10361058
}
1059+
#endif // USE_EFFECT_DURATION_POLLING
10371060

10381061
*outEffectIndex = effectIndex;
10391062
*outTimeMs = timeMs;
@@ -1078,10 +1101,13 @@ ndk::ScopedAStatus Vibrator::getCompoundDetails(Effect effect, EffectStrength st
10781101
}
10791102
effectBuilder << thisEffectIndex << "." << thisVolLevel;
10801103
timeMs += thisTimeMs;
1104+
1105+
#ifdef USE_EFFECT_DURATION_POLLING
10811106
{
10821107
const std::scoped_lock<std::mutex> lock(mTotalDurationMutex);
10831108
mTotalDuration = timeMs;
10841109
}
1110+
#endif // USE_EFFECT_DURATION_POLLING
10851111

10861112
break;
10871113
default:
@@ -1164,12 +1190,21 @@ ndk::ScopedAStatus Vibrator::performEffect(Effect effect, EffectStrength strengt
11641190
// fall-through
11651191
case Effect::THUD:
11661192
// fall-through
1193+
#ifdef USE_COMPOUND_DOUBLE_CLICK_EFFECT
1194+
case Effect::POP:
1195+
status = getSimpleDetails(effect, strength, &effectIndex, &timeMs, &volLevel);
1196+
break;
1197+
case Effect::DOUBLE_CLICK:
1198+
status = getCompoundDetails(effect, strength, &timeMs, &volLevel, &effectQueue);
1199+
break;
1200+
#else
11671201
case Effect::POP:
11681202
// fall-through
11691203
case Effect::DOUBLE_CLICK:
11701204
// fall-through
11711205
status = getSimpleDetails(effect, strength, &effectIndex, &timeMs, &volLevel);
11721206
break;
1207+
#endif // USE_COMPOUND_DOUBLE_CLICK_EFFECT
11731208
default:
11741209
status = ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
11751210
break;
@@ -1205,6 +1240,8 @@ ndk::ScopedAStatus Vibrator::performEffect(uint32_t effectIndex, uint32_t volLev
12051240

12061241
void Vibrator::waitForComplete(std::shared_ptr<IVibratorCallback>&& callback) {
12071242
ALOGD("Vibrator::waitForComplete");
1243+
1244+
#ifdef USE_EFFECT_DURATION_POLLING
12081245
uint32_t duration;
12091246
{
12101247
const std::scoped_lock<std::mutex> lock(mTotalDurationMutex);
@@ -1218,6 +1255,10 @@ void Vibrator::waitForComplete(std::shared_ptr<IVibratorCallback>&& callback) {
12181255
ALOGD("Vibrator::waitForComplete: Get STOP! Set active to 0.");
12191256
}
12201257
mHwApi->setActivate(false);
1258+
#else
1259+
mHwApi->pollVibeState(false);
1260+
mHwApi->setActivate(false);
1261+
#endif // USE_EFFECT_DURATION_POLLING
12211262

12221263
if (callback) {
12231264
auto ret = callback->onComplete();

aidl/vibrator/cs40l25/Vibrator.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,15 @@ class Vibrator : public BnVibrator {
8989
// Indicates the number of 0.125-dB steps of attenuation to apply to
9090
// waveforms triggered in response to a GPIO1 rising edge.
9191
virtual bool setGpioRiseScale(uint32_t value) = 0;
92+
#ifdef USE_EFFECT_DURATION_POLLING
9293
// Blocks until timeout or vibrator reaches desired state
9394
// (true = enabled, false = disabled).
9495
virtual bool pollVibeState(uint32_t value, int32_t timeoutMs = -1) = 0;
96+
#else
97+
// Blocks until vibrator reaches desired state
98+
// (true = enabled, false = disabled).
99+
virtual bool pollVibeState(bool value) = 0;
100+
#endif
95101
// Enables/disables closed-loop active braking.
96102
virtual bool setClabEnable(bool value) = 0;
97103
// Reports the number of available PWLE segments.
@@ -232,8 +238,10 @@ class Vibrator : public BnVibrator {
232238
bool mIsChirpEnabled;
233239
std::vector<float> mBandwidthAmplitudeMap;
234240
bool mGenerateBandwidthAmplitudeMapDone;
241+
#ifdef USE_EFFECT_DURATION_POLLING
235242
uint32_t mTotalDuration{0};
236243
std::mutex mTotalDurationMutex;
244+
#endif
237245
};
238246

239247
} // namespace vibrator

0 commit comments

Comments
 (0)