From patchwork Wed May 12 13:04:49 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jelle Martijn Kok X-Patchwork-Id: 99004 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4CD9stk004406 for ; Wed, 12 May 2010 13:09:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751554Ab0ELNJx (ORCPT ); Wed, 12 May 2010 09:09:53 -0400 Received: from lime.solrad.nl ([213.193.238.107]:49554 "EHLO lime.solrad.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751075Ab0ELNJw (ORCPT ); Wed, 12 May 2010 09:09:52 -0400 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 12 May 2010 13:09:54 +0000 (UTC) X-Greylist: delayed 301 seconds by postgrey-1.27 at vger.kernel.org; Wed, 12 May 2010 09:09:52 EDT Received: from green.youcom.nl (green.youcom.nl [::ffff:195.64.93.233]) (TLS: TLSv1/SSLv3,256bits,AES256-SHA) by lime.solrad.nl with esmtp; Wed, 12 May 2010 15:04:50 +0200 id 000EAFEE.4BEAA772.000029E1 Received: from [192.168.5.122] ([::ffff:192.168.5.122]) (AUTH: LOGIN jmkok) by green.youcom.nl with esmtp; Wed, 12 May 2010 15:04:49 +0200 id 0000000001F28543.000000004BEAA771.00007DB4 Message-ID: <4BEAA771.5010006@youcom.nl> Date: Wed, 12 May 2010 15:04:49 +0200 From: Jelle Martijn Kok Organization: You/Com Audiocommunicatie BV User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100423 Thunderbird/3.0.4 MIME-Version: 1.0 To: linux-input@vger.kernel.org Subject: [PATCH 1/3] rotary_encoder: increase/decrease on both rest states Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c index 1f8e010..24621b8 100644 --- a/drivers/input/misc/rotary_encoder.c +++ b/drivers/input/misc/rotary_encoder.c @@ -36,8 +36,7 @@ struct rotary_encoder { unsigned int irq_a; unsigned int irq_b; - bool armed; - unsigned char dir; /* 0 - clockwise, 1 - CCW */ + int last_state; }; static irqreturn_t rotary_encoder_irq(int irq, void *dev_id) @@ -52,51 +51,47 @@ static irqreturn_t rotary_encoder_irq(int irq, void *dev_id) b ^= pdata->inverted_b; state = (a << 1) | b; - switch (state) { - - case 0x0: - if (!encoder->armed) - break; - - if (pdata->relative_axis) { - input_report_rel(encoder->input, pdata->axis, - encoder->dir ? -1 : 1); - } else { - unsigned int pos = encoder->pos; + if (((state == 0x0) || (state == 0x3)) && ((encoder->last_state == 0x01) || (encoder->last_state == 0x02))) { + int state_exor = state ^ encoder->last_state; + int dir = 0; + if (state_exor == 0x01) { + dir = +1; + } + else { + dir = -1; + } - if (encoder->dir) { - /* turning counter-clockwise */ - if (pdata->rollover) - pos += pdata->steps; - if (pos) - pos--; + if (dir) { + if (pdata->relative_axis) { + input_report_rel(encoder->input, pdata->axis, + dir); } else { - /* turning clockwise */ - if (pdata->rollover || pos < pdata->steps) - pos++; + unsigned int pos = encoder->pos; + + if (dir == -1) { + /* turning counter-clockwise */ + if (pdata->rollover) + pos += pdata->steps; + if (pos) + pos--; + } else { + /* turning clockwise */ + if (pdata->rollover || pos < pdata->steps) + pos++; + } + if (pdata->rollover) + pos %= pdata->steps; + encoder->pos = pos; + input_report_abs(encoder->input, pdata->axis, + encoder->pos); } - if (pdata->rollover) - pos %= pdata->steps; - encoder->pos = pos; - input_report_abs(encoder->input, pdata->axis, - encoder->pos); + input_sync(encoder->input); } - input_sync(encoder->input); - - encoder->armed = false; - break; - - case 0x1: - case 0x2: - if (encoder->armed) - encoder->dir = state - 1; - break; - - case 0x3: - encoder->armed = true; - break; } + /* always store the state - even on 00 or 11 */ + encoder->last_state = state; + return IRQ_HANDLED;