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
43volatile unsigned char dkey_multi;
44volatile unsigned char dkey;
45
47//
48// Internal Variables
49//
51
52char 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\
72dkey_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\
99dkey_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//
124int getchar(void) {
126#ifdef CONF_AUTOSHUTOFF
128#endif
130 return dkey;
131}
132
133#endif // CONF_DKEY
__asm__("\n\ .text\n\ .globl _atomic_inc\n\ _atomic_inc:\n\ stc ccr, r1h ; save flags\n\ orc #0x80, ccr ; disable all but NMI\n\ mov.b @r0, r1l\n\ inc r1l\n\ mov.b r1l, @r0\n\ ldc r1h, ccr ; restore flags\n\ rts\n\ ")
Interface: debounced key driver.
wakeup_t dkey_released(wakeup_t data)
wakeup if all of the given keys are released.
#define KEY_ANY
any of the keys
Definition dkey.h:49
volatile unsigned char dkey
the current key
volatile unsigned char dkey_multi
the currently active keys
wakeup_t dkey_pressed(wakeup_t data)
wakeup if any of the given keys is pressed.
#define KEY_ONOFF
the on/off key is pressed
Definition dkey.h:44
int getchar()
wait for keypress and return key code.
Internal Interface: task management.
Internal Interface: Powerdown Timer Routines.
void shutoff_restart(void)
volatile unsigned int idle_powerdown
unsigned long wakeup_t
wakeup data area type
Definition tm.h:57
Interface: reduced UNIX standard library.
wakeup_t wait_event(wakeup_t(*wakeup)(wakeup_t), wakeup_t data)
Definition unistd.h:112

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

Generated for brickOS Kernel Developer by doxygen 1.9.8