Changeset 5d1ff11 in mainline
- Timestamp:
- 2021-06-29T19:25:50Z (4 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 61bf9dd9
- Parents:
- e87415e6
- Location:
- uspace
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/i8042/i8042.h
re87415e6 r5d1ff11 1 1 /* 2 * Copyright (c) 2021 Jiri Svoboda 2 3 * Copyright (c) 2006 Josef Cejka 3 4 * Copyright (c) 2011 Jan Vesely 4 * Copyright (c) 2017 Jiri Svoboda5 5 * All rights reserved. 6 6 * … … 48 48 #define NAME "i8042" 49 49 50 #define BUFFER_SIZE 12 50 /** Buffer needs to be large enough for rate at which keyboard or mouse 51 * produces data (mouse produces data at faster rate). 52 */ 53 #define BUFFER_SIZE 64 51 54 52 55 /** i8042 HW I/O interface */ -
uspace/srv/hid/console/console.c
re87415e6 r5d1ff11 63 63 typedef struct { 64 64 atomic_flag refcnt; /**< Connection reference count */ 65 prodcons_t input_pc; /**< Incoming keyboardevents */65 prodcons_t input_pc; /**< Incoming console events */ 66 66 67 67 /** … … 99 99 static sysarg_t cols; 100 100 static sysarg_t rows; 101 102 /** Mouse pointer X coordinate */ 103 static int pointer_x; 104 /** Mouse pointer Y coordinate */ 105 static int pointer_y; 106 /** Character under mouse cursor */ 107 static charfield_t pointer_bg; 108 109 static int mouse_scale_x = 4; 110 static int mouse_scale_y = 8; 101 111 102 112 /** Array of data for virtual consoles */ … … 166 176 }; 167 177 178 static void pointer_draw(void); 179 static void pointer_undraw(void); 180 168 181 static console_t *srv_to_console(con_srv_t *srv) 169 182 { … … 231 244 232 245 fibril_mutex_lock(&switch_mtx); 246 pointer_undraw(); 233 247 234 248 if (cons == active_console) { … … 239 253 active_console = cons; 240 254 255 pointer_draw(); 241 256 fibril_mutex_unlock(&switch_mtx); 242 257 243 258 cons_damage(cons); 259 } 260 261 /** Draw mouse pointer. */ 262 static void pointer_draw(void) 263 { 264 charfield_t *ch; 265 int col, row; 266 267 /* Downscale coordinates to text resolution */ 268 col = pointer_x / mouse_scale_x; 269 row = pointer_y / mouse_scale_y; 270 271 /* Make sure they are in range */ 272 if (col < 0 || row < 0 || col >= (int)cols || row >= (int)rows) 273 return; 274 275 ch = chargrid_charfield_at(active_console->frontbuf, col, row); 276 277 /* 278 * Store background attributes for undrawing the pointer. 279 * This is necessary as styles cannot be inverted with 280 * round trip (unlike RGB or INDEX) 281 */ 282 pointer_bg = *ch; 283 284 /* In general the color should be a one's complement of the background */ 285 if (ch->attrs.type == CHAR_ATTR_INDEX) { 286 ch->attrs.val.index.bgcolor ^= 0xf; 287 ch->attrs.val.index.fgcolor ^= 0xf; 288 } else if (ch->attrs.type == CHAR_ATTR_RGB) { 289 ch->attrs.val.rgb.fgcolor ^= 0xffffff; 290 ch->attrs.val.rgb.bgcolor ^= 0xffffff; 291 } else if (ch->attrs.type == CHAR_ATTR_STYLE) { 292 /* Don't have a proper inverse for each style */ 293 if (ch->attrs.val.style == STYLE_INVERTED) 294 ch->attrs.val.style = STYLE_NORMAL; 295 else 296 ch->attrs.val.style = STYLE_INVERTED; 297 } 298 299 /* Make sure the cell gets updated */ 300 ch->flags |= CHAR_FLAG_DIRTY; 301 } 302 303 /** Undraw mouse pointer. */ 304 static void pointer_undraw(void) 305 { 306 charfield_t *ch; 307 int col, row; 308 309 col = pointer_x / mouse_scale_x; 310 row = pointer_y / mouse_scale_y; 311 if (col < 0 || row < 0 || col >= (int)cols || row >= (int)rows) 312 return; 313 314 ch = chargrid_charfield_at(active_console->frontbuf, col, row); 315 *ch = pointer_bg; 316 ch->flags |= CHAR_FLAG_DIRTY; 317 } 318 319 /** Queue console event. 320 * 321 * @param cons Console 322 * @param ev Console event 323 */ 324 static void console_queue_cons_event(console_t *cons, cons_event_t *ev) 325 { 326 /* Got key press/release event */ 327 cons_event_t *event = 328 (cons_event_t *) malloc(sizeof(cons_event_t)); 329 if (event == NULL) 330 return; 331 332 *event = *ev; 333 link_initialize(&event->link); 334 335 prodcons_produce(&cons->input_pc, &event->link); 244 336 } 245 337 … … 264 356 keymod_t mods, char32_t c) 265 357 { 358 cons_event_t event; 359 266 360 if ((key >= KC_F1) && (key <= KC_F1 + CONSOLE_COUNT) && 267 361 ((mods & KM_CTRL) == 0)) { … … 269 363 } else { 270 364 /* Got key press/release event */ 271 kbd_event_t *event = 272 (kbd_event_t *) malloc(sizeof(kbd_event_t)); 273 if (event == NULL) { 274 return ENOMEM; 275 } 276 277 link_initialize(&event->link); 278 event->type = type; 279 event->key = key; 280 event->mods = mods; 281 event->c = c; 282 283 prodcons_produce(&active_console->input_pc, 284 &event->link); 285 } 286 287 return EOK; 365 event.type = CEV_KEY; 366 367 event.ev.key.type = type; 368 event.ev.key.key = key; 369 event.ev.key.mods = mods; 370 event.ev.key.c = c; 371 372 console_queue_cons_event(active_console, &event); 373 } 374 375 return EOK; 376 } 377 378 /** Update pointer position. 379 * 380 * @param new_x New X coordinate (in pixels) 381 * @param new_y New Y coordinate (in pixels) 382 */ 383 static void pointer_update(int new_x, int new_y) 384 { 385 bool upd_pointer; 386 387 /* Make sure coordinates are in range */ 388 389 if (new_x < 0) 390 new_x = 0; 391 if (new_x >= (int)cols * mouse_scale_x) 392 new_x = cols * mouse_scale_x - 1; 393 if (new_y < 0) 394 new_y = 0; 395 if (new_y >= (int)rows * mouse_scale_y) 396 new_y = rows * mouse_scale_y - 1; 397 398 /* Determine if pointer moved to a different character cell */ 399 upd_pointer = (new_x / mouse_scale_x != pointer_x / mouse_scale_x) || 400 (new_y / mouse_scale_y != pointer_y / mouse_scale_y); 401 402 if (upd_pointer) 403 pointer_undraw(); 404 405 /* Store new pointer position */ 406 pointer_x = new_x; 407 pointer_y = new_y; 408 409 if (upd_pointer) { 410 pointer_draw(); 411 cons_update(active_console); 412 } 288 413 } 289 414 290 415 static errno_t input_ev_move(input_t *input, int dx, int dy) 291 416 { 417 pointer_update(pointer_x + dx, pointer_y + dy); 292 418 return EOK; 293 419 } … … 296 422 unsigned max_x, unsigned max_y) 297 423 { 424 pointer_update(mouse_scale_x * cols * x / max_x, mouse_scale_y * rows * y / max_y); 298 425 return EOK; 299 426 } … … 301 428 static errno_t input_ev_button(input_t *input, int bnum, int bpress) 302 429 { 430 cons_event_t event; 431 432 event.type = CEV_POS; 433 event.ev.pos.type = bpress ? POS_PRESS : POS_RELEASE; 434 event.ev.pos.btn_num = bnum; 435 event.ev.pos.hpos = pointer_x / mouse_scale_x; 436 event.ev.pos.vpos = pointer_y / mouse_scale_y; 437 438 console_queue_cons_event(active_console, &event); 303 439 return EOK; 304 440 } … … 310 446 311 447 fibril_mutex_lock(&cons->mtx); 448 pointer_undraw(); 312 449 313 450 switch (ch) { … … 327 464 } 328 465 466 pointer_draw(); 329 467 fibril_mutex_unlock(&cons->mtx); 330 468 … … 336 474 { 337 475 fibril_mutex_lock(&cons->mtx); 476 pointer_undraw(); 338 477 chargrid_set_cursor_visibility(cons->frontbuf, visible); 478 pointer_draw(); 339 479 fibril_mutex_unlock(&cons->mtx); 340 480 … … 379 519 if (pos < size) { 380 520 link_t *link = prodcons_consume(&cons->input_pc); 381 kbd_event_t *event = list_get_instance(link, kbd_event_t, link); 521 cons_event_t *event = list_get_instance(link, 522 cons_event_t, link); 382 523 383 524 /* Accept key presses of printable chars only. */ 384 if ((event->type == KEY_PRESS) && (event->c != 0)) { 385 char32_t tmp[2] = { event->c, 0 }; 525 if (event->type == CEV_KEY && event->ev.key.type == KEY_PRESS && 526 (event->ev.key.c != 0)) { 527 char32_t tmp[2] = { event->ev.key.c, 0 }; 386 528 wstr_to_str(cons->char_remains, UTF8_CHAR_BUFFER_SIZE, tmp); 387 529 cons->char_remains_len = str_size(cons->char_remains); … … 420 562 421 563 fibril_mutex_lock(&cons->mtx); 564 pointer_undraw(); 422 565 chargrid_clear(cons->frontbuf); 566 pointer_draw(); 423 567 fibril_mutex_unlock(&cons->mtx); 424 568 … … 431 575 432 576 fibril_mutex_lock(&cons->mtx); 577 pointer_undraw(); 433 578 chargrid_set_cursor(cons->frontbuf, col, row); 579 pointer_draw(); 434 580 fibril_mutex_unlock(&cons->mtx); 435 581 … … 511 657 console_t *cons = srv_to_console(srv); 512 658 link_t *link = prodcons_consume(&cons->input_pc); 513 kbd_event_t *kevent = list_get_instance(link, kbd_event_t, link); 514 515 event->type = CEV_KEY; 516 event->ev.key = *kevent; 517 518 free(kevent); 659 cons_event_t *cevent = list_get_instance(link, cons_event_t, link); 660 661 *event = *cevent; 662 free(cevent); 519 663 return EOK; 520 664 } … … 621 765 /* Update front buffer from user buffer */ 622 766 767 pointer_undraw(); 768 623 769 for (row = r0; row < r1; row++) { 624 770 for (col = c0; col < c1; col++) { … … 628 774 } 629 775 776 pointer_draw(); 630 777 fibril_mutex_unlock(&cons->mtx); 631 778
Note:
See TracChangeset
for help on using the changeset viewer.