These programs are based on the tq2440 platform and mainly implement the operation of keyboard keys. For convenience, only four buttons are enabled. The hardware structure is shown below;
The hardware diagram shows that the eint1, eint2, eint4, and eint0 interrupt pins are connected by pressing the buttons. In WindowsCE, we only need to handle these four interruptions, as detailed below;
From this figure, we can see that eint0 ~ 4. gpf0 ~ 4 control, so before the driver needs to configure these four gpio ports, so that the drop delay trigger, the following code;
V_piopregs-> gpfcon & = ~ (0x3 <0);/* Set eint0 (gpf0) as eint0 */
V_piopregs-> gpfcon | = (0x2 <0 );
V_piopregs-> extint0 & = ~ (0x7 <0);/* configure eint0 as falling edge mode */
V_piopregs-> extint0 | = (0x2 <0 );
V_piopregs-> gpfcon & = ~ (0x3 <2);/* Set eint1 (gpf0) as eint1 */
V_piopregs-> gpfcon | = (0x2 <2 );
V_piopregs-> extint0 & = ~ (0x7 <4);/* configure eint1 as falling edge mode */
V_piopregs-> extint0 | = (0x2 <4 );
V_piopregs-> gpfcon & = ~ (0x3 <4);/* Set eint2 (gpf2) as Eint */
V_piopregs-> gpfcon | = (0x2 <4 );
V_piopregs-> extint0 & = ~ (0x7 <8);/* configure eint2 as falling edge mode */
V_piopregs-> extint0 | = (0x2 <8 );
V_piopregs-> gpfcon & = ~ (0x3 <8);/* Set eint0 (gpf4) as eint4 */
V_piopregs-> gpfcon | = (0x2 <8 );
V_piopregs-> extint0 & = ~ (0x7 <16);/* configure eint4 as falling edge mod */
V_piopregs-> extint0 | = (0x2 <16 );
After the configuration is complete, run the following code to interrupt the processing thread;
Intevent = createevent (null, false, false, null );
If (! Intevent)
{
Retailmsg (1, (text ("error: keybd: failed to create event./R/N ")));
Return false;
}
IRQ = 1; // irq_eint1;
If (! Kerneliocontrol (ioctl_hal_request_sysintr, & IRQ, sizeof (uint32), & g_keysysintr [0], sizeof (uint32), null ))
{
Retailmsg (1, (text ("error: keybd: failed to request sysintr value./R/N ")));
Return false;
}
IRQ = 32; // irq_eint4;
If (! Kerneliocontrol (ioctl_hal_request_sysintr, & IRQ, sizeof (uint32), & g_keysysintr [1], sizeof (uint32), null ))
{
Retailmsg (1, (text ("error: keybd: failed to request sysintr value./R/N ")));
Return false;
}
IRQ = 2; // irq_eint2;
If (! Kerneliocontrol (ioctl_hal_request_sysintr, & IRQ, sizeof (uint32), & g_keysysintr [2], sizeof (uint32), null ))
{
Retailmsg (1, (text ("error: keybd: failed to request sysintr value./R/N ")));
Return false;
}
IRQ = 0; // irq_eint0;
If (! Kerneliocontrol (ioctl_hal_request_sysintr, & IRQ, sizeof (uint32), & g_keysysintr [3], sizeof (uint32), null ))
{
Retailmsg (1, (text ("error: keybd: failed to request sysintr value./R/N ")));
Return false;
}
If (! Interruptinitialize (g_keysysintr [0], intevent, null, 0 ))
{
Retailmsg (1, (text ("fail to initialize userkey interrupt event/R/N ")));
Return false;
}
If (! Interruptinitialize (g_keysysintr [1], intevent, null, 0 ))
{
Retailmsg (1, (text ("fail to initialize userkey interrupt event/R/N ")));
Return false;
}
If (! Interruptinitialize (g_keysysintr [2], intevent, null, 0 ))
{
Retailmsg (1, (text ("fail to initialize userkey interrupt event/R/N ")));
Return false;
}
If (! Interruptinitialize (g_keysysintr [3], intevent, null, 0 ))
{
Retailmsg (1, (text ("fail to initialize userkey interrupt event/R/N ")));
Return false;
}
While (1)
{
Waitforsingleobject (intevent, infinite );
Retailmsg (0, (L "intmask = % x, eintmask = % x, gpgcon = % x/R/N", v_pintrregs-> intmsk, v_piopregs-> eintmask, v_piopregs-> gpfcon ));
// Eint1-K1-vk_up-0x26
If (v_pintrregs-> intmsk & (1 <{
Retailmsg (1, (text ("[key1-Up]/R/N ")));
Keybd_event (vk_up, 0x26, 0, 0 );
Sleep (30 );
Keybd_event (vk_up, 0x26, keyeventf_keyup, 0 );
Interruptdone (g_keysysintr [0]);
}
// Eint4-K2-vk_down-0x28
If (v_piopregs-> eintmask & (1 <{
Retailmsg (1, (text ("[key2-Down]/R/N ")));
Keybd_event (vk_down, 0x28, 0, 0 );
Sleep (30 );
Keybd_event (vk_down, 0x28, keyeventf_keyup, 0 );
Interruptdone (g_keysysintr [1]);
}
// Eint2-K3-vk_left-0x25
If (v_pintrregs-> intmsk & (1 <{
Retailmsg (1, (text ("[K3-Left]/R/N ")));
Keybd_event (vk_left, 0x25, 0, 0 );
Sleep (30 );
Keybd_event (vk_left, 0x25, keyeventf_keyup, 0 );
Interruptdone (g_keysysintr [2]);
}
// Eint0-K4-vk_right-0x27
If (v_pintrregs-> intmsk & (1 <{
Retailmsg (1, (text ("[K4-right]/R/N ")));
Keybd_event (vk_right, 0x27, 0, 0 );
Sleep (30 );
Keybd_event (vk_right, 0x27, keyeventf_keyup, 0 );
Interruptdone (g_keysysintr [3]);
}
}