dkey.c
Go to the documentation of this file.
1 
6 /*
7  * The contents of this file are subject to the Mozilla Public License
8  * Version 1.0 (the "License"); you may not use this file except in
9  * compliance with the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS"
13  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
14  * License for the specific language governing rights and limitations
15  * under the License.
16  *
17  * The Original Code is legOS code, released October 17, 1999.
18  *
19  * The Initial Developer of the Original Code is Markus L. Noga.
20  * Portions created by Markus L. Noga are Copyright (C) 1999
21  * Markus L. Noga. All Rights Reserved.
22  *
23  * Contributor(s): Markus L. Noga <markus@noga.de>
24  */
25 
26 #include <dkey.h>
27 
28 #ifdef CONF_DKEY
29 
30 #include <unistd.h>
31 #include <sys/tm.h>
32 
33 #ifdef CONF_AUTOSHUTOFF
34 #include <sys/timeout.h>
35 #endif
36 
38 //
39 // Global Variables
40 //
42 
43 volatile unsigned char dkey_multi;
44 volatile unsigned char dkey;
45 
47 //
48 // Internal Variables
49 //
51 
52 char dkey_timer __attribute__ ((unused));
53 
55 //
56 // Functions
57 //
59 #ifndef DOXYGEN_SHOULD_SKIP_THIS
60 __asm__("\n\
61 .text\n\
62 .align 1\n\
63 .global _dkey_handler\n\
64 _dkey_handler:\n\
65  mov.b @_dkey_timer,r6l ; check debouncing timer==0\n\
66  beq dkey_check\n\
67 \n\
68  dec r6l\n\
69  mov.b r6l,@_dkey_timer\n\
70  rts\n\
71 \n\
72 dkey_check:\n\
73  sub.b r6l,r6l ; generate button codes\n\
74  ; from PORT4/PORT7 in r6l\n\
75  mov.b @_PORT4,r6h\n\
76  bld #1,r6h\n\
77  bist #0,r6l\n\
78  bld #2,r6h\n\
79  bist #1,r6l\n\
80 \n\
81  mov.b @_PORT7,r6h\n\
82  bld #6,r6h\n\
83  bist #2,r6l\n\
84  bld #7,r6h\n\
85  bist #3,r6l\n\
86 \n\
87  mov.b @_dkey_multi,r6h\n\
88  xor.b r6l,r6h ; create mask of changed positions in r6h\n\
89  beq dkey_same\n\
90 \n\
91  mov.b r6l,@_dkey_multi\n\
92 \n\
93  and.b r6h,r6l ; mask out unchanged positions\n\
94  mov.b r6l,@_dkey\n\
95 \n\
96  mov.b #100,r6l ; set debouncing timer\n\
97  mov.b r6l,@_dkey_timer\n\
98 \n\
99 dkey_same:\n\
100  rts\n\
101 ");
102 #endif // DOXYGEN_SHOULD_SKIP_THIS
103 
105 //
107 #ifdef CONF_AUTOSHUTOFF
108  if (idle_powerdown) { // if idle too long, say the OFF key was pressed
109  dkey = KEY_ONOFF;
110  return KEY_ONOFF;
111  }
112 #endif
113  return (dkey & (unsigned char)data);
114 }
115 
117 //
119  return ! (dkey & (unsigned char)data);
120 }
121 
123 //
124 int getchar(void) {
126 #ifdef CONF_AUTOSHUTOFF
127  shutoff_restart();
128 #endif
130  return dkey;
131 }
132 
133 #endif // CONF_DKEY
int getchar()
wait for keypress and return key code.
void shutoff_restart(void)
Internal Interface: Powerdown Timer Routines.
wakeup_t dkey_released(wakeup_t data)
wakeup if all of the given keys are released.
__asm__("\.text\.globl _atomic_inc\ _atomic_inc:\ stc ccr, r1h ; save flags\ orc #0x80, ccr ; disable all but NMI\ mov.b @r0, r1l\ inc r1l\ mov.b r1l, @r0\ ldc r1h, ccr ; restore flags\ rts\")
Internal Interface: task management.
volatile unsigned char dkey_multi
the currently active keys
Interface: debounced key driver.
Interface: reduced UNIX standard library.
unsigned long wakeup_t
wakeup data area type
Definition: tm.h:57
#define KEY_ONOFF
the on/off key is pressed
Definition: dkey.h:44
#define KEY_ANY
any of the keys
Definition: dkey.h:49
wakeup_t wait_event(wakeup_t(*wakeup)(wakeup_t), wakeup_t data)
volatile unsigned char dkey
the current key
wakeup_t dkey_pressed(wakeup_t data)
wakeup if any of the given keys is pressed.
volatile unsigned int idle_powerdown

brickOS is released under the Mozilla Public License.
Original code copyright 1998-2005 by the authors.

Generated for brickOS Kernel Developer by doxygen 1.8.13