[Excerpt] MTK key scan principle and related code

Source: Internet
Author: User

I.MTKKey Scan principle:

DifferentMTKThe number of buttons provided in the platform varies, but the scanning principle is roughly the same.Mtk6253For example.

MTKProvide6*7Total42Matrix keyboard, plusPowerTotal keys43Buttons, of whichBbChip extractionSixLineRow,7Column lineCol, Such.

 

The following describes the scan principle:

In case of initialization or no buttons,RowSet to output,ColSet as input.

BbThe chip has an internal key interrupt, without any buttons, allCloLine is high,RowLine is low, once a button is pressed, suchKey10 (row1, col2)There is a press, becauseCol2Line andRow1Lines are directly connected,Col2The line is dropped as longColWhen the line is pulled down, the internal button will respond when it is interrupted. After the internal button is interrupted,BbAs soon as you know that a button is generated, you can scan the button to determine which button to press, and then proceed accordingly.

After an interruption occurs,BbSend a message to send allColLine Height, allRowLow line, scanColLine, suchKey10 (row1, col2)Click to scanCol2Pulled down; then allRowLine Height, allColLow line, scanRowLine, suchKey10 (row1, col2)Click to scanRow1Dropped down.Col2AndRow1When combined, you will know which button is pressed.

However, the scanning process is alreadyBbIt is completed quickly internally, and then the corresponding key position is saved in registers.

Each register16Each digit represents a key.53Buttons, required4Register to save. The corresponding buttons are as follows:

Each digit in the register corresponds to a key. The default value is1When a button is pressed, the corresponding position0. Then the System reads the four registers to know which key is pressed.

ReadCodeAs follows:

Kbd_map_temp_reg = (Kal_uint32) (drv_reg (kp_mid_key) <   16 )) | (Kal_uint32) (drv_reg (kp_low_key ))));

# IfDefined (drv_kbd_32keys_abve)

Kbd_map_temp_reg1=(Kal_uint32) (drv_reg (kp_hi_key ));

# ElifDefined (drv_kbd_48keys_abve)

Kbd_map_temp_reg1=(Kal_uint32) (drv_reg (kp_hi_key)< 16))|(Kal_uint32) (drv_reg (kp_mid1_key ))));

# ElifDefined (drv_kbd_64keys_abve)

Kbd_map_temp_reg1=(Kal_uint32) (drv_reg (kp_mid2_key)< 16))|(Kal_uint32) (drv_reg (kp_mid1_key ))));

Kbd_map_temp_reg2=(Kal_uint32) (drv_reg (kp_hi_key ));

# Endif

Ii. Code:

Scan the code inKbdmain. cFileKbd_task_mainFunction. Upper LayerMMIProcessing inKeybrd. cFile.

FirstKbd_initThe registration key is interrupted during initialization.

Drv_register_hisr (drv_kp_hisr_id, kbd_hisrentry );

Second, once a key is generated, a key event is sent in the interrupt handler.Kbd_task_mainIn the function, there will be an endless loop that keeps scanning the button time. If no button event occurs, exit this loop (Continue). Once a key event is detected, the system reads the value in the register and processes it.

Void Kbd_hisrentry ( Void )

{

# Ifdef key_debug

Dbg_print ("Kbd_hisrentry \ r \ n");

# Endif

# IfDefined (_ extend_qwerty_keypad __)

//Use GPT polling instead of key IRQ event trigger

Irqmask (irq_kpad_code );

# Endif //# If defined (_ extend_qwerty_keypad __)

Kbd_dbg (_ line __, kbd_gettimestamp (), ust_get_current_time (),0);

/*Lint-E (534)*/Kal_set_eg_events (KBD.Event,1, Kal_or );//Set button events

}

InKbd_task_mainChecking button events in the function

  If ( ! (Event_group &   1 ))
Continue ;

Finally, send the key timeMMILayer.

Kbd_push_onekey_to_kbdbuffer (kbd_onekey_press, kbd_press_key [count]);

Additionally, add the following parameters:

If the keyboard is full,Neotel53_09b_upls.makInKeypad_type = qwerty_keypad. If there is an extension button (that is, the land orGpioPort SimulationRowLine to expand the button)= Keypad_type = extend_qwerty_keypad

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.