1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - WM - demos - wep-1
3   File:     key.c
4 
5   Copyright 2006-2008 Nintendo.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Date:: 2008-09-18#$
14   $Rev: 8573 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 #ifdef SDK_TWL
19 #include <twl.h>
20 #else
21 #include <nitro.h>
22 #endif
23 #include "key.h"
24 
25 static KeyInfo sKeyInfo;
26 
keyRead(KeyInfo * pKey)27 static void keyRead(KeyInfo * pKey)
28 {
29     static u16 repeat_count[12];
30     int     i;
31     u16     r;
32 
33     r = PAD_Read();
34     pKey->trg = 0x0000;
35     pKey->up = 0x0000;
36     pKey->rep = 0x0000;
37 
38     for (i = 0; i < 12; i++)
39     {
40         if (r & (0x0001 << i))
41         {
42             if (!(pKey->cnt & (0x0001 << i)))
43             {
44                 pKey->trg |= (0x0001 << i);
45                 repeat_count[i] = 1;
46 
47             }
48             else
49             {
50                 if (repeat_count[i] > KEY_REPEAT_START)
51                 {
52                     pKey->rep |= (0x0001 << i);
53                     repeat_count[i] = KEY_REPEAT_START - KEY_REPEAT_SPAN;
54                 }
55                 else
56                 {
57                     repeat_count[i]++;
58                 }
59             }
60         }
61         else
62         {
63             if (pKey->cnt & (0x0001 << i))
64             {
65                 pKey->up |= (0x0001 << i);
66             }
67         }
68     }
69 
70     pKey->cnt = r;
71 }
72 
updateKeys(void)73 void updateKeys(void)
74 {
75     keyRead(&sKeyInfo);
76 }
77 
getKeyInfo(void)78 KeyInfo *getKeyInfo(void)
79 {
80     return &sKeyInfo;
81 }
82