Changeset d46c6ecd in mainline
- Timestamp:
- 2006-08-09T16:09:05Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8b4be29
- Parents:
- 287920f
- Location:
- kernel/genarch
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/Makefile.inc
r287920f rd46c6ecd 69 69 GENARCH_SOURCES += \ 70 70 genarch/src/kbd/i8042.c \ 71 genarch/src/kbd/key.c \ 71 72 genarch/src/kbd/scanc_pc.c 72 73 endif … … 76 77 GENARCH_SOURCES += \ 77 78 genarch/src/kbd/z8530.c \ 79 genarch/src/kbd/key.c \ 78 80 genarch/src/kbd/scanc_sun.c 79 81 endif -
kernel/genarch/src/kbd/i8042.c
r287920f rd46c6ecd 38 38 39 39 #include <genarch/kbd/i8042.h> 40 #include <genarch/kbd/key.h> 40 41 #include <genarch/kbd/scanc.h> 41 42 #include <genarch/kbd/scanc_pc.h> … … 45 46 #include <arch/asm.h> 46 47 #include <arch.h> 47 #include <synch/spinlock.h>48 48 #include <typedefs.h> 49 49 #include <console/chardev.h> 50 50 #include <console/console.h> 51 #include <macros.h>52 51 #include <interrupt.h> 53 52 … … 79 78 #define i8042_MOUSE_DATA 0x20 80 79 81 #define KEY_RELEASE 0x8082 83 static void key_released(uint8_t sc);84 static void key_pressed(uint8_t sc);85 static char key_read(chardev_t *d);86 87 #define PRESSED_SHIFT (1<<0)88 #define PRESSED_CAPSLOCK (1<<1)89 #define LOCKED_CAPSLOCK (1<<0)90 91 #define ACTIVE_READ_BUFF_SIZE 16 /* Must be power of 2 */92 93 static uint8_t active_read_buff[ACTIVE_READ_BUFF_SIZE];94 95 SPINLOCK_INITIALIZE(keylock); /**< keylock protects keyflags and lockflags. */96 static volatile int keyflags; /**< Tracking of multiple keypresses. */97 static volatile int lockflags; /**< Tracking of multiple keys lockings. */98 99 80 static void i8042_suspend(chardev_t *); 100 81 static void i8042_resume(chardev_t *); 101 82 102 staticchardev_t kbrd;83 chardev_t kbrd; 103 84 static chardev_operations_t ops = { 104 85 .suspend = i8042_suspend, … … 183 164 } 184 165 185 /** Process release of key.186 *187 * @param sc Scancode of the key being released.188 */189 void key_released(uint8_t sc)190 {191 spinlock_lock(&keylock);192 switch (sc) {193 case SC_LSHIFT:194 case SC_RSHIFT:195 keyflags &= ~PRESSED_SHIFT;196 break;197 case SC_CAPSLOCK:198 keyflags &= ~PRESSED_CAPSLOCK;199 if (lockflags & LOCKED_CAPSLOCK)200 lockflags &= ~LOCKED_CAPSLOCK;201 else202 lockflags |= LOCKED_CAPSLOCK;203 break;204 default:205 break;206 }207 spinlock_unlock(&keylock);208 }209 210 /** Process keypress.211 *212 * @param sc Scancode of the key being pressed.213 */214 void key_pressed(uint8_t sc)215 {216 char *map = sc_primary_map;217 char ascii = sc_primary_map[sc];218 bool shift, capslock;219 bool letter = false;220 221 spinlock_lock(&keylock);222 switch (sc) {223 case SC_LSHIFT:224 case SC_RSHIFT:225 keyflags |= PRESSED_SHIFT;226 break;227 case SC_CAPSLOCK:228 keyflags |= PRESSED_CAPSLOCK;229 break;230 case SC_SPEC_ESCAPE:231 break;232 case SC_LEFTARR:233 chardev_push_character(&kbrd, 0x1b);234 chardev_push_character(&kbrd, 0x5b);235 chardev_push_character(&kbrd, 0x44);236 break;237 case SC_RIGHTARR:238 chardev_push_character(&kbrd, 0x1b);239 chardev_push_character(&kbrd, 0x5b);240 chardev_push_character(&kbrd, 0x43);241 break;242 case SC_UPARR:243 chardev_push_character(&kbrd, 0x1b);244 chardev_push_character(&kbrd, 0x5b);245 chardev_push_character(&kbrd, 0x41);246 break;247 case SC_DOWNARR:248 chardev_push_character(&kbrd, 0x1b);249 chardev_push_character(&kbrd, 0x5b);250 chardev_push_character(&kbrd, 0x42);251 break;252 case SC_HOME:253 chardev_push_character(&kbrd, 0x1b);254 chardev_push_character(&kbrd, 0x4f);255 chardev_push_character(&kbrd, 0x48);256 break;257 case SC_END:258 chardev_push_character(&kbrd, 0x1b);259 chardev_push_character(&kbrd, 0x4f);260 chardev_push_character(&kbrd, 0x46);261 break;262 case SC_DELETE:263 chardev_push_character(&kbrd, 0x1b);264 chardev_push_character(&kbrd, 0x5b);265 chardev_push_character(&kbrd, 0x33);266 chardev_push_character(&kbrd, 0x7e);267 break;268 default:269 letter = is_lower(ascii);270 capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);271 shift = keyflags & PRESSED_SHIFT;272 if (letter && capslock)273 shift = !shift;274 if (shift)275 map = sc_secondary_map;276 chardev_push_character(&kbrd, map[sc]);277 break;278 }279 spinlock_unlock(&keylock);280 }281 282 166 /* Called from getc(). */ 283 167 void i8042_resume(chardev_t *d) … … 290 174 } 291 175 292 static uint8_t active_read_buff_read(void) 293 { 294 static int i=0; 295 i &= (ACTIVE_READ_BUFF_SIZE-1); 296 if(!active_read_buff[i]) { 297 return 0; 298 } 299 return active_read_buff[i++]; 300 } 301 302 static void active_read_buff_write(uint8_t ch) 303 { 304 static int i=0; 305 active_read_buff[i] = ch; 306 i++; 307 i &= (ACTIVE_READ_BUFF_SIZE-1); 308 active_read_buff[i]=0; 309 } 310 311 312 static void active_read_key_pressed(uint8_t sc) 313 { 314 char *map = sc_primary_map; 315 char ascii = sc_primary_map[sc]; 316 bool shift, capslock; 317 bool letter = false; 318 319 /*spinlock_lock(&keylock);*/ 320 switch (sc) { 321 case SC_LSHIFT: 322 case SC_RSHIFT: 323 keyflags |= PRESSED_SHIFT; 324 break; 325 case SC_CAPSLOCK: 326 keyflags |= PRESSED_CAPSLOCK; 327 break; 328 case SC_SPEC_ESCAPE: 329 break; 330 case SC_LEFTARR: 331 active_read_buff_write(0x1b); 332 active_read_buff_write(0x5b); 333 active_read_buff_write(0x44); 334 break; 335 case SC_RIGHTARR: 336 active_read_buff_write(0x1b); 337 active_read_buff_write(0x5b); 338 active_read_buff_write(0x43); 339 break; 340 case SC_UPARR: 341 active_read_buff_write(0x1b); 342 active_read_buff_write(0x5b); 343 active_read_buff_write(0x41); 344 break; 345 case SC_DOWNARR: 346 active_read_buff_write(0x1b); 347 active_read_buff_write(0x5b); 348 active_read_buff_write(0x42); 349 break; 350 case SC_HOME: 351 active_read_buff_write(0x1b); 352 active_read_buff_write(0x4f); 353 active_read_buff_write(0x48); 354 break; 355 case SC_END: 356 active_read_buff_write(0x1b); 357 active_read_buff_write(0x4f); 358 active_read_buff_write(0x46); 359 break; 360 case SC_DELETE: 361 active_read_buff_write(0x1b); 362 active_read_buff_write(0x5b); 363 active_read_buff_write(0x33); 364 active_read_buff_write(0x7e); 365 break; 366 default: 367 letter = is_lower(ascii); 368 capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK); 369 shift = keyflags & PRESSED_SHIFT; 370 if (letter && capslock) 371 shift = !shift; 372 if (shift) 373 map = sc_secondary_map; 374 active_read_buff_write(map[sc]); 375 break; 376 } 377 /*spinlock_unlock(&keylock);*/ 378 379 } 380 381 static char key_read(chardev_t *d) 176 char key_read(chardev_t *d) 382 177 { 383 178 char ch; -
kernel/genarch/src/kbd/z8530.c
r287920f rd46c6ecd 43 43 44 44 #include <genarch/kbd/z8530.h> 45 #include <genarch/kbd/key.h> 45 46 #include <genarch/kbd/scanc.h> 46 47 #include <genarch/kbd/scanc_sun.h> … … 50 51 #include <arch/asm.h> 51 52 #include <arch.h> 52 #include <synch/spinlock.h>53 53 #include <typedefs.h> 54 54 #include <console/chardev.h> 55 55 #include <console/console.h> 56 #include <macros.h>57 56 #include <interrupt.h> 58 57 … … 84 83 #define z8530_MOUSE_DATA 0x20 85 84 86 #define KEY_RELEASE 0x8087 88 85 /* 89 86 * These codes read from z8530 data register are silently ignored. … … 91 88 #define IGNORE_CODE 0x7f /* all keys up */ 92 89 93 static void key_released(uint8_t sc);94 static void key_pressed(uint8_t sc);95 static char key_read(chardev_t *d);96 97 #define PRESSED_SHIFT (1<<0)98 #define PRESSED_CAPSLOCK (1<<1)99 #define LOCKED_CAPSLOCK (1<<0)100 101 #define ACTIVE_READ_BUFF_SIZE 16 /* Must be power of 2 */102 103 static uint8_t active_read_buff[ACTIVE_READ_BUFF_SIZE];104 105 SPINLOCK_INITIALIZE(keylock); /**< keylock protects keyflags and lockflags. */106 static volatile int keyflags; /**< Tracking of multiple keypresses. */107 static volatile int lockflags; /**< Tracking of multiple keys lockings. */108 109 90 static void z8530_suspend(chardev_t *); 110 91 static void z8530_resume(chardev_t *); 111 92 112 staticchardev_t kbrd;93 chardev_t kbrd; 113 94 static chardev_operations_t ops = { 114 95 .suspend = z8530_suspend, … … 193 174 } 194 175 195 /** Process release of key.196 *197 * @param sc Scancode of the key being released.198 */199 void key_released(uint8_t sc)200 {201 spinlock_lock(&keylock);202 switch (sc) {203 case SC_LSHIFT:204 case SC_RSHIFT:205 keyflags &= ~PRESSED_SHIFT;206 break;207 case SC_CAPSLOCK:208 keyflags &= ~PRESSED_CAPSLOCK;209 if (lockflags & LOCKED_CAPSLOCK)210 lockflags &= ~LOCKED_CAPSLOCK;211 else212 lockflags |= LOCKED_CAPSLOCK;213 break;214 default:215 break;216 }217 spinlock_unlock(&keylock);218 }219 220 /** Process keypress.221 *222 * @param sc Scancode of the key being pressed.223 */224 void key_pressed(uint8_t sc)225 {226 char *map = sc_primary_map;227 char ascii = sc_primary_map[sc];228 bool shift, capslock;229 bool letter = false;230 231 spinlock_lock(&keylock);232 switch (sc) {233 case SC_LSHIFT:234 case SC_RSHIFT:235 keyflags |= PRESSED_SHIFT;236 break;237 case SC_CAPSLOCK:238 keyflags |= PRESSED_CAPSLOCK;239 break;240 case SC_SPEC_ESCAPE:241 break;242 case SC_LEFTARR:243 chardev_push_character(&kbrd, 0x1b);244 chardev_push_character(&kbrd, 0x5b);245 chardev_push_character(&kbrd, 0x44);246 break;247 case SC_RIGHTARR:248 chardev_push_character(&kbrd, 0x1b);249 chardev_push_character(&kbrd, 0x5b);250 chardev_push_character(&kbrd, 0x43);251 break;252 case SC_UPARR:253 chardev_push_character(&kbrd, 0x1b);254 chardev_push_character(&kbrd, 0x5b);255 chardev_push_character(&kbrd, 0x41);256 break;257 case SC_DOWNARR:258 chardev_push_character(&kbrd, 0x1b);259 chardev_push_character(&kbrd, 0x5b);260 chardev_push_character(&kbrd, 0x42);261 break;262 case SC_HOME:263 chardev_push_character(&kbrd, 0x1b);264 chardev_push_character(&kbrd, 0x4f);265 chardev_push_character(&kbrd, 0x48);266 break;267 case SC_END:268 chardev_push_character(&kbrd, 0x1b);269 chardev_push_character(&kbrd, 0x4f);270 chardev_push_character(&kbrd, 0x46);271 break;272 case SC_DELETE:273 chardev_push_character(&kbrd, 0x1b);274 chardev_push_character(&kbrd, 0x5b);275 chardev_push_character(&kbrd, 0x33);276 chardev_push_character(&kbrd, 0x7e);277 break;278 default:279 letter = is_lower(ascii);280 capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);281 shift = keyflags & PRESSED_SHIFT;282 if (letter && capslock)283 shift = !shift;284 if (shift)285 map = sc_secondary_map;286 chardev_push_character(&kbrd, map[sc]);287 break;288 }289 spinlock_unlock(&keylock);290 }291 292 176 /* Called from getc(). */ 293 177 void z8530_resume(chardev_t *d) … … 300 184 } 301 185 302 static uint8_t active_read_buff_read(void) 303 { 304 static int i=0; 305 i &= (ACTIVE_READ_BUFF_SIZE-1); 306 if(!active_read_buff[i]) { 307 return 0; 308 } 309 return active_read_buff[i++]; 310 } 311 312 static void active_read_buff_write(uint8_t ch) 313 { 314 static int i=0; 315 active_read_buff[i] = ch; 316 i++; 317 i &= (ACTIVE_READ_BUFF_SIZE-1); 318 active_read_buff[i]=0; 319 } 320 321 322 static void active_read_key_pressed(uint8_t sc) 323 { 324 char *map = sc_primary_map; 325 char ascii = sc_primary_map[sc]; 326 bool shift, capslock; 327 bool letter = false; 328 329 /*spinlock_lock(&keylock);*/ 330 switch (sc) { 331 case SC_LSHIFT: 332 case SC_RSHIFT: 333 keyflags |= PRESSED_SHIFT; 334 break; 335 case SC_CAPSLOCK: 336 keyflags |= PRESSED_CAPSLOCK; 337 break; 338 case SC_SPEC_ESCAPE: 339 break; 340 case SC_LEFTARR: 341 active_read_buff_write(0x1b); 342 active_read_buff_write(0x5b); 343 active_read_buff_write(0x44); 344 break; 345 case SC_RIGHTARR: 346 active_read_buff_write(0x1b); 347 active_read_buff_write(0x5b); 348 active_read_buff_write(0x43); 349 break; 350 case SC_UPARR: 351 active_read_buff_write(0x1b); 352 active_read_buff_write(0x5b); 353 active_read_buff_write(0x41); 354 break; 355 case SC_DOWNARR: 356 active_read_buff_write(0x1b); 357 active_read_buff_write(0x5b); 358 active_read_buff_write(0x42); 359 break; 360 case SC_HOME: 361 active_read_buff_write(0x1b); 362 active_read_buff_write(0x4f); 363 active_read_buff_write(0x48); 364 break; 365 case SC_END: 366 active_read_buff_write(0x1b); 367 active_read_buff_write(0x4f); 368 active_read_buff_write(0x46); 369 break; 370 case SC_DELETE: 371 active_read_buff_write(0x1b); 372 active_read_buff_write(0x5b); 373 active_read_buff_write(0x33); 374 active_read_buff_write(0x7e); 375 break; 376 default: 377 letter = is_lower(ascii); 378 capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK); 379 shift = keyflags & PRESSED_SHIFT; 380 if (letter && capslock) 381 shift = !shift; 382 if (shift) 383 map = sc_secondary_map; 384 active_read_buff_write(map[sc]); 385 break; 386 } 387 /*spinlock_unlock(&keylock);*/ 388 389 } 390 391 static char key_read(chardev_t *d) 186 char key_read(chardev_t *d) 392 187 { 393 188 char ch;
Note:
See TracChangeset
for help on using the changeset viewer.