00001 00006 /* 00007 * The contents of this file are subject to the Mozilla Public License 00008 * Version 1.0 (the "License"); you may not use this file except in 00009 * compliance with the License. You may obtain a copy of the License at 00010 * http://www.mozilla.org/MPL/ 00011 * 00012 * Software distributed under the License is distributed on an "AS IS" 00013 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 00014 * License for the specific language governing rights and limitations 00015 * under the License. 00016 * 00017 * The Original Code is legOS code, released October 17, 1999. 00018 * 00019 * The Initial Developer of the Original Code is Markus L. Noga. 00020 * Portions created by Markus L. Noga are Copyright (C) 1999 00021 * Markus L. Noga. All Rights Reserved. 00022 * 00023 * Contributor(s): Markus L. Noga <markus@noga.de> 00024 */ 00025 00026 #include <dkey.h> 00027 00028 #ifdef CONF_DKEY 00029 00030 #include <unistd.h> 00031 #include <sys/tm.h> 00032 00033 #ifdef CONF_AUTOSHUTOFF 00034 #include <sys/timeout.h> 00035 #endif 00036 00038 // 00039 // Global Variables 00040 // 00042 00043 volatile unsigned char dkey_multi; 00044 volatile unsigned char dkey; 00045 00047 // 00048 // Internal Variables 00049 // 00051 00052 char dkey_timer __attribute__ ((unused)); 00053 00055 // 00056 // Functions 00057 // 00059 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00060 __asm__("\n\ 00061 .text\n\ 00062 .align 1\n\ 00063 .global _dkey_handler\n\ 00064 _dkey_handler:\n\ 00065 mov.b @_dkey_timer,r6l ; check debouncing timer==0\n\ 00066 beq dkey_check\n\ 00067 \n\ 00068 dec r6l\n\ 00069 mov.b r6l,@_dkey_timer\n\ 00070 rts\n\ 00071 \n\ 00072 dkey_check:\n\ 00073 sub.b r6l,r6l ; generate button codes\n\ 00074 ; from PORT4/PORT7 in r6l\n\ 00075 mov.b @_PORT4,r6h\n\ 00076 bld #1,r6h\n\ 00077 bist #0,r6l\n\ 00078 bld #2,r6h\n\ 00079 bist #1,r6l\n\ 00080 \n\ 00081 mov.b @_PORT7,r6h\n\ 00082 bld #6,r6h\n\ 00083 bist #2,r6l\n\ 00084 bld #7,r6h\n\ 00085 bist #3,r6l\n\ 00086 \n\ 00087 mov.b @_dkey_multi,r6h\n\ 00088 xor.b r6l,r6h ; create mask of changed positions in r6h\n\ 00089 beq dkey_same\n\ 00090 \n\ 00091 mov.b r6l,@_dkey_multi\n\ 00092 \n\ 00093 and.b r6h,r6l ; mask out unchanged positions\n\ 00094 mov.b r6l,@_dkey\n\ 00095 \n\ 00096 mov.b #100,r6l ; set debouncing timer\n\ 00097 mov.b r6l,@_dkey_timer\n\ 00098 \n\ 00099 dkey_same:\n\ 00100 rts\n\ 00101 "); 00102 #endif // DOXYGEN_SHOULD_SKIP_THIS 00103 00105 // 00106 wakeup_t dkey_pressed(wakeup_t data) { 00107 #ifdef CONF_AUTOSHUTOFF 00108 if (idle_powerdown) { // if idle too long, say the OFF key was pressed 00109 dkey = KEY_ONOFF; 00110 return KEY_ONOFF; 00111 } 00112 #endif 00113 return (dkey & (unsigned char)data); 00114 } 00115 00117 // 00118 wakeup_t dkey_released(wakeup_t data) { 00119 return ! (dkey & (unsigned char)data); 00120 } 00121 00123 // 00124 int getchar(void) { 00125 wait_event(dkey_released,KEY_ANY); 00126 #ifdef CONF_AUTOSHUTOFF 00127 shutoff_restart(); 00128 #endif 00129 wait_event(dkey_pressed ,KEY_ANY); 00130 return dkey; 00131 } 00132 00134 00136 int dbutton(void) 00137 { 00138 int rv; 00139 __asm__ __volatile__("\n\ 00140 mov.b @_PORT4,%0l\n\ 00141 mov.b @_PORT7,%0h\n\ 00142 " :"=r"(rv) // output 00143 : // input 00144 :"cc" // clobbered 00145 ); 00146 return rv; 00147 } 00148 00149 #endif // CONF_DKEY
brickOS is released under the
Mozilla Public License.
Original code copyright 1998-2002 by the authors. |