6410 add keyboard control for eboot

Source: Internet
Author: User

During the upgrade, you need a prompt to add a keyboard to control the magic horse.

Therefore, we need to add this keyboard to eboot.

Because this interrupt cannot be used in eboot, you can only use scan keys.

The buttons are:

Row: gpk8 ~ Gpk13

Column: gpl0 ~ Gpl4 (you only need to use one column here. Use gpl0, so there will be six buttons)

Refer to the keyboard-driven keypad, Which is simplified here. It is divided into three parts: initialization, cyclic scanning, and key recognition.

First, initialize the keyboard:

Call

Ret = initkey ();

After the initialization is successful, it is called in the loop

Kscan_proc ();

Check and press the button, and then pass

KeyValue = getkeydown ();

Obtain the pressed buttons and perform identification.

The six buttons are defined as follows: (key. h)

#defineKEY_ENTER(0x1)#defineKEY_SCAN(0x2)#defineKEY_CANCEL(0x4)#defineKEY_DELETE(0x8)#defineKEY_BACKSPACE(0x10)#defineKEY_UP(0x20)

The implementation of key. C is as follows:

// *** you add ***// for 6410 key.// use row0 & col0~col5#include "Key.h"#include <windows.h>#include "Winbase.h"#include <oal.h>#include <s3c6410.h>//#ifdef _KEY_H_//#define _KEY_H_// define#defineSIZE_COLS1#defineKEYIF_Row_Read(pKeyPadReg->KEYIFROW)// KEYIFCON#defineFC_EN_DIS            (0<<3)#defineFC_EN_EN             (1<<3)#defineDF_EN_DIS            (0<<2)#defineDF_EN_EN             (1<<2)#defineINT_R_ENABLE         (0<<1)#defineINT_R_DISABLE        (1<<1)#defineINT_F_ENABLE         (0<<0)#defineINT_F_DISABLE        (1<<0)// KEYIFFC#defineFC_DIV_VAL(n)        (((n)&0x3ff)<<0)#defineKEY_POWER_ON   (1<<11)                      // PCLKCON#ifndef FIN#define FIN        12000000#endif#defineFT_CLK_DIV     (FIN/32000 - 1)// KEYIFSTSCLR#defineCLEAR_P_INT            (0xFF<<0)#defineCLEAR_R_INT            (0xFF<<8)// global variablevolatile S3C6410_GPIO_REG *pGPIOReg2 = NULL;volatile S3C6410_KEYPAD_REG *pKeyPadReg = NULL;volatile S3C6410_SYSCON_REG *pSysConReg = NULL;DWORD KeyState[SIZE_COLS];// functionBOOL InitKey();void KScan_Proc();DWORD GetKeyDown();void ClearKey();BOOL InitKey(){    // GPIO Virtual alloc    pGPIOReg2 = (S3C6410_GPIO_REG *)OALPAtoVA(S3C6410_BASE_REG_PA_GPIO, FALSE);if(pGPIOReg2 == NULL)return FALSE;    // Keypad Virtual alloc    pKeyPadReg = (S3C6410_KEYPAD_REG *)OALPAtoVA(S3C6410_BASE_REG_PA_KEYPAD, FALSE);if(pKeyPadReg == NULL)return FALSE;    // Syscon Virtual alloc    pSysConReg = (S3C6410_SYSCON_REG *)OALPAtoVA(S3C6410_BASE_REG_PA_SYSCON, FALSE);if(pSysConReg == NULL)return FALSE;// enable the Keypad Clock (PCLK)pSysConReg->PCLK_GATE |= KEY_POWER_ON;pKeyPadReg->KEYIFCON = INT_F_DISABLE|INT_R_DISABLE|DF_EN_EN|FC_EN_DIS;//Keypad interfae debouncing filter clock division registerpKeyPadReg->KEYIFFC = FC_DIV_VAL(FT_CLK_DIV);pKeyPadReg->KEYIFCOL = (0x00<<8);// select all column - Set Keypad column GPIO to output(low)//pGPIOReg2->GPLCON0=(pGPIOReg2->GPLCON0 & ~(0xfffff<<0)) | (0x33333<<0);    //KBC_0(GPL0)~ KBC_4(GPL4)pGPIOReg2->GPLCON0=(pGPIOReg2->GPLCON0 & ~(0xf<<0)) | (0x3<<0);//KBC_0(GPL0)pKeyPadReg->KEYIFCOL = (0x0 & 0xff);// configure - Set Keypad row GPIO to [Key PAD ROW]pGPIOReg2->GPKCON1=(pGPIOReg2->GPKCON1 & ~(0xffffff<<0)) | (0x333333<<0);    //KBR_0(GPK8)~ KBR_5(GPK13)// unmask the key interruptpKeyPadReg->KEYIFSTSCLR = CLEAR_P_INT|CLEAR_R_INT;    // Clear Pressed/Released Interruptreturn TRUE;}void KScan_Proc(){int i=0;volatile int m=0;// Read the Matrix// KBC_0 ~ KBC_7for(i = 0 ; i < SIZE_COLS; i++){pKeyPadReg->KEYIFCOL = (0x0 & 0xff);// select a columnpKeyPadReg->KEYIFCOL = pKeyPadReg->KEYIFCOL | (0xff & ~(0x1 << i));for(m=0; m<2000; m++);KeyState[i] = (~KEYIF_Row_Read) & 0xff;for(m=0; m<2000; m++);}pKeyPadReg->KEYIFCOL = (0x0 & 0xff);}DWORD GetKeyDown(){DWORD key = 0x0;int i=0;for(i = 0 ; i < SIZE_COLS; i++){if(KeyState[i] & KEY_ENTER)key |= KEY_ENTER;if(KeyState[i] & KEY_SCAN)key |= KEY_SCAN;if(KeyState[i] & KEY_CANCEL)key |= KEY_CANCEL;if(KeyState[i] & KEY_DELETE)key |= KEY_DELETE;if(KeyState[i] & KEY_BACKSPACE)key |= KEY_BACKSPACE;if(KeyState[i] & KEY_UP)key |= KEY_UP;}return key;}void ClearKey(){memset(KeyState, 0, sizeof(KeyState)/sizeof(DWORD));}//#endif

Record it here.

It is for reference only. Do not imitate it ~~

If an error exists, please note that

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.