Key and trackball driver implementation code based on Dragon Board 410c development board

Foreword:

In the previous blog, "Dynamic Driver Based on the Dragon Board 410c Development Board," I have described the process of writing the touch screen driver and its architecture. I will tell you about the button and trackball driver in this blog.

First, the button and trackball drive

The MSM has the functions of buttons and trackballs. The corresponding driver is in the file arch/arm/mach-msm/board-mahimahi-keypad.c. The implementation process of this file is introduced.

(1) The global definition code in the file board-mahimahi-keypad.c is as follows:

staTIc struct gpio_event_info *mahimahi_input_info [] = {
&mahimahi_keypad_matrix_info.info, // keyboard matrix
&mahimahi_keypad_key_info.info, // keyboard information
&jogball_x_axis.info.info, // Trackball X direction information
&jogball_y_axis.info.info, // Trackball Y direction information
};
staTIc struct gpio_event_platform_data mahimahi_input_data = {
.names = {
"mahimahi-keypad", // button device
"mahimahi-nav", // trackball equipment
NULL,
},
.info = mahimahi_input_info,
.info_count = ARRAY_SIZE(mahimahi_input_info),
.power = jogball_power,
};


staTIc struct platform_device mahimahi_input_device = {
.name = GPIO_EVENT_DEV_NAME,
.id = 0,
.dev = {
.platform_data = &mahimahi_input_data,
},
};

The buttons and trackball are implemented by the GPIO system, so an array of type gpio_event_info is defined.

"mahimahi-keypad" and "mahimahi-nav" are the names of the two devices.

The gpio_event_info pointer array mahimahi_input_info contains mahimahi_keypad_matrix_info.info, mahimahi_keypad_key_info.info, jogball_x_axis.info.info and jogball_y_axis.info.info.

The button driver is a driver that utilizes the GPIO matrix. It is defined by the gpio_event_matrix_info matrix. The definition also needs to contain information about the GPIO matrix of the button and the input device. The contents are as follows:

staTIc unsigned int mahimahi_col_gpios[] = { 33, 32, 31 };

Static unsigned int mahimahi_row_gpios[] = { 42, 41, 40 };

#define KEYMAP_INDEX(col, row) ((col)*ARRAY_
SIZE(mahimahi_row_gpios) + (row))
#define KEYMAP_SIZE (ARRAY_SIZE(mahimahi_col_gpios) * \
ARRAY_SIZE(mahimahi_row_gpios))
Static const unsigned short mahimahi_keymap
[KEYMAP_SIZE] = { // button mapping
[KEYMAP_INDEX(0, 0)] = KEY_VOLUMEUP, /* 115 */
[KEYMAP_INDEX(0, 1)] = KEY_VOLUMEDOWN, /* 114 */
[KEYMAP_INDEX(1, 1)] = MATRIX_KEY(1, BTN_MOUSE),
};
Static struct gpio_event_matrix_info mahimahi
_keypad_matrix_info = {
.info.func = gpio_event_matrix_func,
// key function implementation
.keymap = mahimahi_keymap,
.output_gpios = mahimahi_col_gpios,
.input_gpios = mahimahi_row_gpios,
.noutputs = ARRAY_SIZE(mahimahi_col_gpios),
.ninputs = ARRAY_SIZE(mahimahi_row_gpios),
.settle_time.tv.nsec = 40 * NSEC_PER_USEC,
.poll_time.tv.nsec = 20 * NSEC_PER_MSEC,
.flags = (GPIOKPF_LEVEL_TRIGGERED_IRQ |
GPIOKPF_REMOVE_PHANTOM_KEYS |
GPIOKPF_PRINT_UNMAPPED_KEYS),
};
Static struct gpio_event_direct_entry mahimahi_
Keypad_key_map[] = { // Power button
{
.gpio = MAHIMAHI_GPIO_POWER_KEY,
.code = KEY_POWER,
},
};
Static struct gpio_event_input_info mahimahi_
Keypad_key_info = {
.info.func = gpio_event_input_func,
// key function implementation
.info.no_suspend = true,
.flags = 0,
.type = EV_KEY,
.keymap = mahimahi_keypad_key_map,
.keymap_size = ARRAY_SIZE(mahimahi_keypad_key_map)
};

Keypad_key_matrix _info and keypad _info are structures of type gpio_event_matrix_info, which are responsible for the processing of two and one button respectively.

In fact, the MSM platform basically has only three buttons: Power, volume up button and volume down button. The scan codes for volume increase and volume decrease are KEY_VOLUMEUP (=115) and KEY_VOLUMEDOWN (=114), respectively.

Tip: The two buttons of the volume control are defined in the qwerty.kl of the full keyboard, and are compatible with the Linux input device and the Android button standard.

The trackball part is also implemented by GPIO, which consists of two parts: X direction and Y direction. The contents are as follows:

Static uint32_t jogball_x_gpios[] = {
MAHIMAHI_GPIO_BALL_LEFT, MAHIMAHI_GPIO_BALL_RIGHT,
};
Static uint32_t jogball_y_gpios[] = {
MAHIMAHI_GPIO_BALL_UP, MAHIMAHI_GPIO_BALL_DOWN,
};
Static struct jog_axis_info jogball_x_axis = {
// X-axis content
.info = {
.info.func = gpio_event_axis_func,
// key function implementation
.count = ARRAY_SIZE(jogball_x_gpios),
.dev = 1,
.type = EV_REL,
.code = REL_X,
.decoded_size = 1U << ARRAY_SIZE(jogball_x_gpios),
.map = jogball_axis_map,
.gpio = jogball_x_gpios,
.flags = GPIOEAF_PRINT_UNKNOWN_DIRECTION,
}
};
Static struct jog_axis_info jogball_y_axis = {
// content of the y-axis
.info = {
.info.func = gpio_event_axis_func,
// key function implementation
.count = ARRAY_SIZE(jogball_y_gpios)
.dev = 1,
.type = EV_REL,
.code = REL_Y,
.decoded_size = 1U << ARRAY_SIZE(jogball_y_gpios),
.map = jogball_axis_map,
.gpio = jogball_y_gpios,
.flags = GPIOEAF_PRINT_UNKNOWN_DIRECTION,
}
};

In the above code, the trackball here is defined by a structure of type jog_axis_info, and the type of this device is relative to the device EV_REL.

Note: In addition to the default AVRCP.kl and qwerty.kl, the file h2w_headset.kl file has been added to the MSM8916 platform.

Vrla Batteries

Vrla Solar Battery,100Ah Vrla Battery,Vrla Gel Deep Cycle Battery,Agm Vrla Battery

Shaoxing Honyo International Trading Co., Ltd , https://www.honyopower.com

Posted on