Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: ff-memless - add notion of direction to for rumble effects

This adds simple direction calculation when combining effects. It's useful
to decide motor direction for rumble (vibrator).

Signed-off-by: Jari Vanhala <ext-jari.vanhala@nokia.com>
Acked-by: Anssi Hannula <anssi.hannula@iki.fi>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

authored by

Jari Vanhala and committed by
Dmitry Torokhov
94ec26c8 1b11c88d

+36
+36
drivers/input/ff-memless.c
··· 221 221 } 222 222 223 223 /* 224 + * Only left/right direction should be used (under/over 0x8000) for 225 + * forward/reverse motor direction (to keep calculation fast & simple). 226 + */ 227 + static u16 ml_calculate_direction(u16 direction, u16 force, 228 + u16 new_direction, u16 new_force) 229 + { 230 + if (!force) 231 + return new_direction; 232 + if (!new_force) 233 + return direction; 234 + return (((u32)(direction >> 1) * force + 235 + (new_direction >> 1) * new_force) / 236 + (force + new_force)) << 1; 237 + } 238 + 239 + /* 224 240 * Combine two effects and apply gain. 225 241 */ 226 242 static void ml_combine_effects(struct ff_effect *effect, ··· 270 254 case FF_RUMBLE: 271 255 strong = (u32)new->u.rumble.strong_magnitude * gain / 0xffff; 272 256 weak = (u32)new->u.rumble.weak_magnitude * gain / 0xffff; 257 + 258 + if (effect->u.rumble.strong_magnitude + strong) 259 + effect->direction = ml_calculate_direction( 260 + effect->direction, 261 + effect->u.rumble.strong_magnitude, 262 + new->direction, strong); 263 + else if (effect->u.rumble.weak_magnitude + weak) 264 + effect->direction = ml_calculate_direction( 265 + effect->direction, 266 + effect->u.rumble.weak_magnitude, 267 + new->direction, weak); 268 + else 269 + effect->direction = 0; 273 270 effect->u.rumble.strong_magnitude = 274 271 min(strong + effect->u.rumble.strong_magnitude, 275 272 0xffffU); ··· 297 268 /* here we also scale it 0x7fff => 0xffff */ 298 269 i = i * gain / 0x7fff; 299 270 271 + if (effect->u.rumble.strong_magnitude + i) 272 + effect->direction = ml_calculate_direction( 273 + effect->direction, 274 + effect->u.rumble.strong_magnitude, 275 + new->direction, i); 276 + else 277 + effect->direction = 0; 300 278 effect->u.rumble.strong_magnitude = 301 279 min(i + effect->u.rumble.strong_magnitude, 0xffffU); 302 280 effect->u.rumble.weak_magnitude =