Android jogball Driver Analysis)

Source: Internet
Author: User

Original article: http://cyher.net/gnulinux/android/android-driver-jogball

 

1 Overview
Jogball is the first Android phone-The trackball pulley attached to HTC Dream. Through jogball, users can easily perform webpage flip and map flip operations, this method of adding a trackball on a mobile phone can cancel the traditional 4-dimensional navigation key. jogball is not the first such function of HTC. It was implemented as early as HTC 3300 (Dopod P800, the trackball operation can be easily controlled like a computer's mouse. Now jogball is basically the standard configuration for Android phones.

2 diagram & architecture

2.1 gpio_event Subsystem
The jogball driver is implemented by the gpio_event subsystem in Linux code.
Consists of the following files:
Driver/input/MISC/gpio_event.c
Driver/input/MISC/gpio_input.c
Driver/input/MISC/gpio_output.c
Driver/input/MISC/gpio_matrix.c
Driver/input/MISC/gpio_axis.c
The gpio_event subsystem is a common code for gpio input devices. It can contain keyboard arrays and coordinate input required by General embedded devices.

2.2 jogball Architecture
Jogball is classified in gpio_axis.c and is a relative coordinate system. It is used to determine the height of an electrical signal to add or subtract a certain value to the coordinate. For details, see gpio_axis.c.
The struct initialization in gpio_axis.c is in the xxx-borad.c, the basic architecture is like this, the details are described below.

3 Hardware Description

3.1 jogball Mechanical Properties
Jogball is an input device based on ball rolling, so its mechanical characteristics are also very important. Knowing its mechanical characteristics makes it easier for us to understand the drive.
Jogball is similar to the previous tumble mouse. The scroll wheel is used to rotate the surrounding cylinder. Each cylinder end has a magnet. From the perspective of the cross section, the magnet iron is composed of N-pole slice and S-pole slice to form a circumference. In this way, when the magnet rotates, the N pole and the S pole switch make the hall IC generate a high level.
Note: when the ball is rotated, the two relative directions can be rotated in only one direction, which is a mechanical feature written in the software for reduction.

3.2 Electrical Characteristics of jogball
Jogball's most important electrical feature is this hall IC,
Working principle of Hall elements: the so-called Hall effect refers to the physical phenomenon in which the transverse potential difference occurs when the magnetic field acts on the carrier in the conducting metal conductor and semiconductor. The Hall effect of metals was discovered by the American physicist Hall in 1879. When the current passes through the metal foil, if the magnetic field is applied in the direction perpendicular to the current, the lateral potential difference will occur on both sides of the metal foil. The Hall effect in semiconductors is more explicit than that in metal foil, while the ferromagnetic metal will present a strong Hall effect below the Curie temperature.
Therefore, jogball produces high voltage due to the magnetic field changes caused by the rotating magnetic axis. Therefore, it is difficult to understand jogball's digital input process based on mechanical characteristics.

3.3 schematic diagram of jogball
In fact, jogball is only a mechanical structure, and the schematic diagram is Hall IC. If you are interested, download it here.

4. Data Structure
Struct hero_axis_info {
Struct gpio_event_axis_info Info;/* gpio_event_axis structure information */
Uint16_t in_state;/* records the input high and low level signals */
Uint16_t out_state;/* records the output level signal */
Uint16_t temp_state;/* temporary storage level */
Uint16_t threshold;/* threshold value, which exceeds this value and is reported to the input subsystem */
};

Struct gpio_event_axis_info {
/* Initialize to gpio_event_axis_func */
Struct gpio_event_info Info;/* gpio_event information */
Uint8_t count;/* Number of gpio */
Uint8_t type;/* ev_rel or ev_abs */
Uint16_t code;/* type of the Input key value */
Uint16_t decoded_size;/* size of the gpio array */
Uint16_t (* map) (struct gpio_event_axis_info * info, uint16_t in);/* parse callback function */
Uint32_t * gpio;/* gpio port array */
Uint32_t flags;/* debug tag value */
Uint32_t enable_emc_protect_delay;/* Protection interval */
Uint16_t emc_gpio_state;/* gpio_state */
Atomic_t emc_disable_irqnum;/* blocked interrupt number used in latency */
};

Struct gpio_event_info {
INT (* func) (struct input_dev * input_dev,
Struct gpio_event_info * info,
Void ** data, int func );
/* Implement the callback function registered to the kernel in the gpio_event subsystem */
INT (* event) (struct input_dev * input_dev,
Struct gpio_event_info * info,
Void ** data, unsigned int type,
Unsigned int code, int value);/* out events */
};

Struct gpio_event_platform_data {
Const char * Name;/* name */
Struct gpio_event_info ** Info;/* structure pointer of gpio_event */
Size_t info_count;/* Number of info struct registered to axis */
INT (* power) (const struct gpio_event_platform_data * pdata, bool on);/* power management callback function */
};

5. Code Analysis

5.1 General Code
Driver/input/MISC/gpio_event.c
/* Basic gpio_event Data Structure */
Struct gpio_event {
Struct input_dev * input_dev;
Const struct gpio_event_platform_data * Info;
Struct early_suspend;
Void * State [0];
};

/* Callback function registered to input */
Static int gpio_input_event (struct input_dev * Dev, unsigned int type, unsigned int code, int value)

/* Call the callback function provided by the lower layer to implement specific registration */
Static int gpio_event_call_all_func (struct gpio_event * IP, int func)
/* Power management */
# Ifdef config_has_earlysuspend
Void gpio_event_suspend (struct early_suspend * H)

Void gpio_event_resume (struct early_suspend * H)
# Endif
/* Register */
Static int _ init gpio_event_probe (struct platform_device * pdev)
/* Cancel */
Static int gpio_event_remove (struct platform_device * pdev)

Static struct platform_driver gpio_event_driver
Static int _ devinit gpio_event_init (void)

Static void _ exit gpio_event_exit (void)
Gpio_event.c: mainly the framework of the gpio_event Subsystem

5.2 SOC code
Driver/input/MISC/gpio_axis.c
Struct gpio_axis_state {
Struct input_dev * input_dev;/* input device structure */
Struct gpio_event_axis_info * Info;/* Coordinate System Data Structure */
Uint32_t Pos;/* location */
Struct hrtimer emc_hrtimer_delay;/* Delay Time */
Atomic_t atomic_emc_hrtimer_is_run;/* Delayed atomic variable */
};
/* Report input data */
Static void gpio_event_update_axis (struct gpio_axis_state * as, int Report)
/* Time processing function */
Static Enum hrtimer_restart emc_progress_hrtimer_handler_func (struct hrtimer * timer)
/* Interrupt processing function */
Static irqreturn_t gpio_axis_irq_handler (int irq, void * dev_id)
/* Register the callback function for the upper layer */
Int gpio_event_axis_func (struct input_dev * input_dev, struct gpio_event_info * info, void ** data, int func)

5.3 platform code
Example:/ARCH/ARM/match-MSM/board-72 × 7. c
Uint16_t hero_axis_map (struct gpio_event_axis_info * info, uint16_t in)
{
Struct hero_axis_info * Ai = container_of (Info, struct hero_axis_info, Info );
Uint16_t out = ai-> out_state;
 
If (nav_just_on ){
If (jiffies = nav_on_jiffies | jiffies = nav_on_jiffies + 1)
Goto ignore;
Nav_just_on = 0;
}
 
If (AI-> in_state ^ In) & amp; 1)/* check for any numerical changes in the direction of 1 */
Out --;
If (AI-> n_state ^ In) & amp; 2)/* checks whether there is a numerical change in the relative direction of 1 */
Out ++;
Ai->; out_state = out;
Ignore:
Ai-> in_state = in;
If (AI-> out_state-ai-> temp_state = ai-> threshold ){
Ai-> temp_state ++;
Ai-> out_state = ai-> temp_state;
} Else if (AI-> temp_state-ai-out_state = ai-> threshold ){
Ai-> temp_state --;
Ai-> out_state = ai-> temp_state;
} Else if (ABS (AI-> out_state-ai->; temp_state)> Ai-> threshold)
Ai-> temp_state = ai-> out_state;
 
Return Ai-> temp_state;
}
The above function is the final data parsing function, that is, to convert the data read from the hardware into the actual location change function. This function mainly implements Error Control and adds
The robustness and customability of the program.

Static struct hero_axis_info hero_x_axis = {
. Threshold = 1,
. Info = {
. Info. func = gpio_event_axis_func,
. Count = array_size (hero_x_axis_gpios ),
. Type = ev_rel,
. Code = rel_x,
. Decoded_size = 1u & lt; array_size (hero_x_axis_gpios ),
. Map = hero_axis_map,
. Gpio = hero_x_axis_gpios,
. Flags = gpioeaf_print_unknown_direction/* | gpioeaf_print_raw | gpioeaf_print_event */,
. Enable_emc_protect_delay = 1 * nsec_per_msec,
}
};
Initialization of the info struct on the X axis

Static struct hero_axis_info hero_y_axis = {
. Threshold = 1,
. Info = {
. Info. func = gpio_event_axis_func,
. Count = array_size (hero_y_axis_gpios ),
. Type = ev_rel,
. Code = rel_y,
. Decoded_size = 1u & lt; array_size (hero_y_axis_gpios ),
. Map = hero_axis_map,
. Gpio = hero_y_axis_gpios,
. Flags = gpioeaf_print_unknown_direction/* | gpioeaf_print_raw | gpioeaf_print_event */,
. Enable_emc_protect_delay = 1 * nsec_per_msec,
}
};
Initialization of info struct on Y axis

6 remarks
In the code of the android framework, recognizing the jogball device as a mouse is not only the coordinates but also the buttons, but there is no axis in the driver.
There are buttons, so you need to add the key value when registering the input device. The following code:
In the gpio_event_axis_func function of drivers/input/MISC/gpio_axis.c
As-> input_dev = input_dev;
As-> info = AI;

Input_set_capability (input_dev, AI-> type, AI->; Code );
If (AI-> type = ev_abs ){
Input_set_abs_params (input_dev, AI-> code, 0,
Ai-> decoded_size-1, 0, 0 );
}
Input_set_capability (input_dev, AI-> type, bt_mouse );
The source code of this article is based on the kernel code of hero mobile phone
Kernel_hero/ARCH/ARM/Mach-MSM/board-hero.c
Http://developer.htc.com/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.