[PATCH 1/1] Input: rotary-encoder - fix direction for quarter-period

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The direction detection logic in quarter-period mode was inconsistent
 with half-period and full-period modes when using GRAY encoding.

According to the GRAY encoding state sequence for positive(clockwise)
rotation - 3->2->1->0 - in function get_state, the quarter-period mode
current interprets this as negative direction, while counter-clockwise
becomes positive. This leads to revesed interpretation compared to the
other 2 modes.

This patch corrects the quarter-period direction logic, maintaining
consistency across all encoding modes.

Tested on encoder with 2000 PPR, confirmed correct direction detection
after this patch.

Signed-off-by: Wang Peng <wangpeng@xxxxxxxxxxxx>
---
 drivers/input/misc/rotary_encoder.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c
index f706e1997..9be84380b 100644
--- a/drivers/input/misc/rotary_encoder.c
+++ b/drivers/input/misc/rotary_encoder.c
@@ -163,10 +163,10 @@ static irqreturn_t rotary_encoder_quarter_period_irq(int irq, void *dev_id)
 	state = rotary_encoder_get_state(encoder);
 
 	if ((encoder->last_stable + 1) % 4 == state) {
-		encoder->dir = 1;
+		encoder->dir = -1;
 		rotary_encoder_report_event(encoder);
 	} else if (encoder->last_stable == (state + 1) % 4) {
-		encoder->dir = -1;
+		encoder->dir = 1;
 		rotary_encoder_report_event(encoder);
 	}
 
-- 
2.50.0





[Index of Archives]     [Linux Media Devel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Linux Wireless Networking]     [Linux Omap]

  Powered by Linux