source: rtems/c/src/lib/libbsp/arm/nds/libnds/source/arm9/keys.c @ 0d34641c

4.104.115
Last change on this file since 0d34641c was 0d34641c, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/30/09 at 04:14:38

Remove CVS-'s.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*------------------------------------------------------------------------------
2        $Id$
3
4        key input code -- provides slightly higher level input forming
5
6        Copyright (C) 2005
7                        Christian Auby (DesktopMan)
8                        Dave Murphy (WinterMute)
9
10        This software is provided 'as-is', without any express or implied
11        warranty.  In no event will the authors be held liable for any
12        damages arising from the use of this software.
13
14        Permission is granted to anyone to use this software for any
15        purpose, including commercial applications, and to alter it and
16        redistribute it freely, subject to the following restrictions:
17
18        1.      The origin of this software must not be misrepresented; you
19                must not claim that you wrote the original software. If you use
20                this software in a product, an acknowledgment in the product
21                documentation would be appreciated but is not required.
22        2.      Altered source versions must be plainly marked as such, and
23                must not be misrepresented as being the original software.
24        3.      This notice may not be removed or altered from any source
25                distribution.
26
27------------------------------------------------------------------------------*/
28
29#include <stdlib.h>
30
31#include <nds/ipc.h>
32#include <nds/system.h>
33#include <nds/arm9/input.h>
34
35//------------------------------------------------------------------------------
36
37#define KEYS_CUR (( ((~REG_KEYINPUT)&0x3ff) | (((~IPC->buttons)&3)<<10) | (((~IPC->buttons)<<6) & (KEY_TOUCH|KEY_LID) ))^KEY_LID)
38
39static uint16 keys = 0;
40static uint16 keysold = 0;
41static uint16 keysrepeat = 0;
42
43static u8 delay = 60, repeat = 30, count = 60;
44
45//------------------------------------------------------------------------------
46void scanKeys(void) {
47//------------------------------------------------------------------------------
48        keysold = keys;
49        keys = KEYS_CUR;
50
51    if ( delay != 0 ) {
52        if ( keys != keysold ) {
53            count = delay ;
54            keysrepeat = keysDown() ;
55        }
56        count--;
57        if ( count == 0 ) {
58            count = repeat;
59            keysrepeat = keys;
60        }
61    }
62}
63
64//------------------------------------------------------------------------------
65uint32 keysHeld(void) {
66//------------------------------------------------------------------------------
67        return keys;
68}
69
70//------------------------------------------------------------------------------
71uint32 keysDown(void) {
72//------------------------------------------------------------------------------
73        return (keys ^ keysold) & keys;
74}
75
76//------------------------------------------------------------------------------
77uint32 keysDownRepeat(void) {
78//------------------------------------------------------------------------------
79        uint32 tmp = keysrepeat;
80
81    keysrepeat = 0;
82
83    return tmp;
84}
85
86//------------------------------------------------------------------------------
87void keysSetRepeat( u8 setDelay, u8 setRepeat ) {
88//------------------------------------------------------------------------------
89    delay = setDelay ;
90    repeat = setRepeat ;
91    count = delay ;
92    keysrepeat = 0 ;
93}
94
95//------------------------------------------------------------------------------
96uint32 keysUp(void) {
97//------------------------------------------------------------------------------
98        return (keys ^ keysold) & (~keys);
99}
Note: See TracBrowser for help on using the repository browser.