world leader in high performance signal processing
Trace: » bfin-rotary

Blackfin Rotary/Thumbwheel Input Device Driver

Blackfin BF54x and BF52x Families of processors feature a Up/Down counter and thumbwheel interface.

A 32-bit up/down counter is provided that can sense 2-bit quadrature or binary codes as typically emitted by industrial drives or manual thumb wheels. The counter can also operate in general-purpose up/down count modes. Then, count direction is either controlled by a level sensitive input pin or by two edge detectors. A third input can provide flexible zero marker support and can alternatively be used to input the push-button signal of thumb wheels. All three pins have a programmable debouncing circuit.

Driver Selection

Device Drivers  --->
   Input device support  --->
      < >   Joystick interface
      <M>   Event interface    
      [*]   Joysticks/Gamepads  --->
      	  <*>   Blackfin Rotary support

Customization

The driver can be customized in the Platform / Board file.

Example:

  • arch/blackfin/mach-bf548/boards/ezkit.c
#if defined(CONFIG_JOYSTICK_BFIN_ROTARY) || defined(CONFIG_JOYSTICK_BFIN_ROTARY_MODULE)
#include <asm/bfin_rotary.h>
 
static struct bfin_rotary_platform_data bfin_rotary_data = {
	/*.rotary_up_key     = KEY_UP,*/
	/*.rotary_down_key   = KEY_DOWN,*/
	.rotary_rel_code   = REL_WHEEL,
	.rotary_button_key = KEY_ENTER,
	.debounce	   = 10,	/* 0..17 */
	.mode		   = ROT_QUAD_ENC | ROT_DEBE,
};
 
static struct resource bfin_rotary_resources[] = {
	{
		.start = IRQ_CNT,
		.end = IRQ_CNT,
		.flags = IORESOURCE_IRQ,
	},
};
 
static struct platform_device bfin_rotary_device = {
	.name		= "bfin-rotary",
	.id		= -1,
	.num_resources 	= ARRAY_SIZE(bfin_rotary_resources),
	.resource 	= bfin_rotary_resources,
	.dev		= {
		.platform_data = &bfin_rotary_data,
	},
};
#endif

The driver provides two options. It can either send Key (KEY) or Relative (REL) events.

Option 1 – send Key events:
Provide two KEY Codes for:

.rotary_up_key  =  KEY_PLUS
.rotary_down_key =  KEY_MINUS    

Option 2 – send REL events:
Provide one REL event type:

.rotary_rel_code =  REL_WHEEL    

In case your CZM input is connected (push-button signal of thumb wheels)
Specify the KEY event – this will enable the CZM input.

rotary_button_key = KEY_ENTER  

See include/linux/input.h for a full list of supported events

The debounce prescale value is used to select the noise filtering characteristic of the input pins.
Must be in the range of 0..17

.debounce = 10

The driver supports various Counter types

.mode =  ROT_QUAD_ENC |   ROT_DEBE  

Options are:

ROT_QUAD_ENC	        quadrature / grey code encoder mode
ROT_BIN_ENC		binary encoder mode
ROT_UD_CNT		rotary counter mode
ROT_DIR_CNT		direction counter mode

ROT_DEBE		Debounce Enable

ROT_CDGINV		CDG Pin Polarity Invert
ROT_CUDINV		CUD Pin Polarity Invert
ROT_CZMINV		CZM Pin Polarity Invert

Driver Testing

Before start testing, don't forget to confiure the following switch, otherwise rotary encode is disconnected.
bf527 ezkit: SW11 PIN 1, 2 and 3 to ON .
bf548 ezkit: SW4 PIN 1, 2 and 3 to ON.

root:/> event_test /dev/input/event1
Input driver version is 1.0.0
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "bfin-rotary"
Supported events:
  Event type 0 (Reset)
    Event code 0 (Reset)
    Event code 1 (Key)
    Event code 2 (Relative)
  Event type 1 (Key)
    Event code 28 (Enter)
  Event type 2 (Relative)
    Event code 8 (Wheel)
Testing ... (interrupt to exit)
Event: time 21755.740000, type 2 (Relative), code 8 (Wheel), value 1
Event: time 21755.740000, type 0 (Reset), code 0 (Reset), value 0
Event: time 21755.780000, type 2 (Relative), code 8 (Wheel), value 1
Event: time 21755.780000, type 0 (Reset), code 0 (Reset), value 0
Event: time 21755.808000, type 2 (Relative), code 8 (Wheel), value 1
Event: time 21755.808000, type 0 (Reset), code 0 (Reset), value 0
Event: time 21755.812000, type 2 (Relative), code 8 (Wheel), value 1
Event: time 21755.812000, type 0 (Reset), code 0 (Reset), value 0
Event: time 21756.040000, type 2 (Relative), code 8 (Wheel), value 1
Event: time 21756.040000, type 0 (Reset), code 0 (Reset), value 0
Event: time 21756.208000, type 2 (Relative), code 8 (Wheel), value -1
Event: time 21756.208000, type 0 (Reset), code 0 (Reset), value 0
Event: time 21757.152000, type 2 (Relative), code 8 (Wheel), value -1
Event: time 21757.152000, type 0 (Reset), code 0 (Reset), value 0
Event: time 21757.176000, type 2 (Relative), code 8 (Wheel), value -1
Event: time 21757.176000, type 0 (Reset), code 0 (Reset), value 0
Event: time 21757.184000, type 2 (Relative), code 8 (Wheel), value -1
Event: time 21757.184000, type 0 (Reset), code 0 (Reset), value 0
Event: time 21757.188000, type 2 (Relative), code 8 (Wheel), value -1
Event: time 21757.188000, type 0 (Reset), code 0 (Reset), value 0
Event: time 21757.380000, type 2 (Relative), code 8 (Wheel), value -1
Event: time 21757.380000, type 0 (Reset), code 0 (Reset), value 0
Event: time 21760.336000, type 1 (Key), code 28 (Enter), value 1
Event: time 21760.336000, type 0 (Reset), code 0 (Reset), value 0
Event: time 21760.336000, type 1 (Key), code 28 (Enter), value 0
Event: time 21760.336000, type 0 (Reset), code 0 (Reset), value 0