Changeset 2f7a564 in mainline
- Timestamp:
- 2011-06-13T22:05:30Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ef15fbb
- Parents:
- a07a454
- Location:
- uspace/srv/hid/input
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/Makefile
ra07a454 r2f7a564 45 45 SOURCES = \ 46 46 generic/input.c \ 47 generic/layout.c \ 47 48 genarch/gsp.c \ 48 49 genarch/stroke.c \ -
uspace/srv/hid/input/generic/input.c
ra07a454 r2f7a564 70 70 int client_phone = -1; 71 71 72 /** Currently active modifiers. */73 static unsigned mods = KM_NUM_LOCK;74 75 /** Currently pressed lock keys. We track these to tackle autorepeat. */76 static unsigned lock_keys;77 78 72 /** List of keyboard devices */ 79 73 static link_t kbd_devs; … … 84 78 #define NUM_LAYOUTS 3 85 79 86 static layout_op _t *layout[NUM_LAYOUTS] = {87 &us_qwerty_op ,88 &us_dvorak_op ,89 &cz_op 80 static layout_ops_t *layout[NUM_LAYOUTS] = { 81 &us_qwerty_ops, 82 &us_dvorak_ops, 83 &cz_ops 90 84 }; 91 92 static int active_layout = 0;93 85 94 86 void kbd_push_scancode(kbd_dev_t *kdev, int scancode) … … 115 107 if (mod_mask != 0) { 116 108 if (type == KEY_PRESS) 117 mods =mods | mod_mask;109 kdev->mods = kdev->mods | mod_mask; 118 110 else 119 mods =mods & ~mod_mask;111 kdev->mods = kdev->mods & ~mod_mask; 120 112 } 121 113 … … 134 126 * up the lock state. 135 127 */ 136 mods = mods ^ (mod_mask & ~lock_keys);137 lock_keys =lock_keys | mod_mask;128 kdev->mods = kdev->mods ^ (mod_mask & ~kdev->lock_keys); 129 kdev->lock_keys = kdev->lock_keys | mod_mask; 138 130 139 131 /* Update keyboard lock indicator lights. */ 140 (*kdev->ctl_ops->set_ind)(kdev, mods);132 (*kdev->ctl_ops->set_ind)(kdev, kdev->mods); 141 133 } else { 142 lock_keys =lock_keys & ~mod_mask;134 kdev->lock_keys = kdev->lock_keys & ~mod_mask; 143 135 } 144 136 } … … 148 140 printf("keycode: %u\n", key); 149 141 */ 150 if (type == KEY_PRESS && ( mods & KM_LCTRL) &&142 if (type == KEY_PRESS && (kdev->mods & KM_LCTRL) && 151 143 key == KC_F1) { 152 active_layout = 0;153 layout[active_layout]->reset();144 layout_destroy(kdev->active_layout); 145 kdev->active_layout = layout_create(layout[0]); 154 146 return; 155 147 } 156 148 157 if (type == KEY_PRESS && ( mods & KM_LCTRL) &&149 if (type == KEY_PRESS && (kdev->mods & KM_LCTRL) && 158 150 key == KC_F2) { 159 active_layout = 1;160 layout[active_layout]->reset();151 layout_destroy(kdev->active_layout); 152 kdev->active_layout = layout_create(layout[1]); 161 153 return; 162 154 } 163 155 164 if (type == KEY_PRESS && ( mods & KM_LCTRL) &&156 if (type == KEY_PRESS && (kdev->mods & KM_LCTRL) && 165 157 key == KC_F3) { 166 active_layout = 2;167 layout[active_layout]->reset();158 layout_destroy(kdev->active_layout); 159 kdev->active_layout = layout_create(layout[2]); 168 160 return; 169 161 } … … 171 163 ev.type = type; 172 164 ev.key = key; 173 ev.mods = mods;174 175 ev.c = layout [active_layout]->parse_ev(&ev);165 ev.mods = kdev->mods; 166 167 ev.c = layout_parse_ev(kdev->active_layout, &ev); 176 168 177 169 async_obsolete_msg_4(client_phone, INPUT_EVENT, ev.type, ev.key, ev.mods, ev.c); … … 223 215 } 224 216 217 static kbd_dev_t *kbd_dev_new(void) 218 { 219 kbd_dev_t *kdev; 220 221 kdev = calloc(1, sizeof(kbd_dev_t)); 222 if (kdev == NULL) { 223 printf(NAME ": Allocating keyboard device. Out of memory.\n"); 224 return NULL; 225 } 226 227 link_initialize(&kdev->kbd_devs); 228 229 kdev->mods = KM_NUM_LOCK; 230 kdev->lock_keys = 0; 231 kdev->active_layout = layout_create(layout[0]); 232 233 return kdev; 234 } 235 225 236 /** Add new legacy keyboard device. */ 226 237 static void kbd_add_dev(kbd_port_ops_t *port, kbd_ctl_ops_t *ctl) … … 228 239 kbd_dev_t *kdev; 229 240 230 kdev = malloc(sizeof(kbd_dev_t)); 231 if (kdev == NULL) { 232 printf(NAME ": Failed adding keyboard device. Out of memory.\n"); 241 kdev = kbd_dev_new(); 242 if (kdev == NULL) 233 243 return; 234 } 235 236 link_initialize(&kdev->kbd_devs); 237 kdev->dev_path = NULL; 244 238 245 kdev->port_ops = port; 239 246 kdev->ctl_ops = ctl; 247 kdev->dev_path = NULL; 240 248 241 249 /* Initialize port driver. */ … … 263 271 kbd_dev_t *kdev; 264 272 265 kdev = malloc(sizeof(kbd_dev_t)); 266 if (kdev == NULL) { 267 printf(NAME ": Failed adding keyboard device. Out of memory.\n"); 273 kdev = kbd_dev_new(); 274 if (kdev == NULL) 268 275 return -1; 269 } 270 271 link_initialize(&kdev->kbd_devs); 276 272 277 kdev->dev_path = dev_path; 273 278 kdev->port_ops = NULL; … … 435 440 kbd_add_legacy_devs(); 436 441 437 /* Initialize (reset) layout. */438 layout[active_layout]->reset();439 442 440 443 /* Register driver */ -
uspace/srv/hid/input/include/kbd.h
ra07a454 r2f7a564 47 47 struct kbd_port_ops; 48 48 struct kbd_ctl_ops; 49 struct layout; 49 50 50 51 typedef struct kbd_dev { … … 63 64 /** Controller-private data */ 64 65 void *ctl_private; 66 67 /** Currently active modifiers. */ 68 unsigned mods; 69 70 /** Currently pressed lock keys. We track these to tackle autorepeat. */ 71 unsigned lock_keys; 72 73 /** Active keyboard layout */ 74 struct layout *active_layout; 65 75 } kbd_dev_t; 66 76 -
uspace/srv/hid/input/include/layout.h
ra07a454 r2f7a564 41 41 #include <io/console.h> 42 42 43 typedef struct { 44 void (*reset)(void); 45 wchar_t (*parse_ev)(kbd_event_t *);46 } layout_op_t;43 /** Layout instance state */ 44 typedef struct layout { 45 /** Ops structure */ 46 struct layout_ops *ops; 47 47 48 extern layout_op_t us_qwerty_op; 49 extern layout_op_t us_dvorak_op; 50 extern layout_op_t cz_op; 48 /* Layout-private data */ 49 void *layout_priv; 50 } layout_t; 51 52 /** Layout ops */ 53 typedef struct layout_ops { 54 int (*create)(layout_t *); 55 void (*destroy)(layout_t *); 56 wchar_t (*parse_ev)(layout_t *, kbd_event_t *); 57 } layout_ops_t; 58 59 extern layout_ops_t us_qwerty_ops; 60 extern layout_ops_t us_dvorak_ops; 61 extern layout_ops_t cz_ops; 62 63 extern layout_t *layout_create(layout_ops_t *); 64 extern void layout_destroy(layout_t *); 65 extern wchar_t layout_parse_ev(layout_t *, kbd_event_t *); 51 66 52 67 #endif -
uspace/srv/hid/input/layout/cz.c
ra07a454 r2f7a564 1 1 /* 2 * Copyright (c) 20 09Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 32 32 */ 33 33 34 #include <errno.h> 34 35 #include <kbd.h> 35 36 #include <io/console.h> … … 37 38 #include <bool.h> 38 39 #include <layout.h> 39 40 static void layout_reset(void); 41 static wchar_t layout_parse_ev(kbd_event_t *ev); 40 #include <stdlib.h> 41 42 static int cz_create(layout_t *); 43 static void cz_destroy(layout_t *); 44 static wchar_t cz_parse_ev(layout_t *, kbd_event_t *ev); 42 45 43 46 enum m_state { … … 47 50 }; 48 51 49 static enum m_state mstate; 50 51 layout_op_t cz_op = { 52 layout_reset, 53 layout_parse_ev 52 typedef struct { 53 enum m_state mstate; 54 } layout_cz_t; 55 56 layout_ops_t cz_ops = { 57 .create = cz_create, 58 .destroy = cz_destroy, 59 .parse_ev = cz_parse_ev 54 60 }; 55 61 … … 273 279 } 274 280 275 static wchar_t parse_ms_hacek( kbd_event_t *ev)281 static wchar_t parse_ms_hacek(layout_cz_t *cz_state, kbd_event_t *ev) 276 282 { 277 283 wchar_t c; 278 284 279 mstate = ms_start;285 cz_state->mstate = ms_start; 280 286 281 287 /* Produce no characters when Ctrl or Alt is pressed. */ … … 291 297 } 292 298 293 static wchar_t parse_ms_carka( kbd_event_t *ev)299 static wchar_t parse_ms_carka(layout_cz_t *cz_state, kbd_event_t *ev) 294 300 { 295 301 wchar_t c; 296 302 297 mstate = ms_start;303 cz_state->mstate = ms_start; 298 304 299 305 /* Produce no characters when Ctrl or Alt is pressed. */ … … 309 315 } 310 316 311 static wchar_t parse_ms_start( kbd_event_t *ev)317 static wchar_t parse_ms_start(layout_cz_t *cz_state, kbd_event_t *ev) 312 318 { 313 319 wchar_t c; … … 319 325 if (ev->key == KC_EQUALS) { 320 326 if ((ev->mods & KM_SHIFT) != 0) 321 mstate = ms_hacek;327 cz_state->mstate = ms_hacek; 322 328 else 323 mstate = ms_carka;329 cz_state->mstate = ms_carka; 324 330 325 331 return 0; … … 379 385 } 380 386 381 static void layout_reset(void) 382 { 383 mstate = ms_start; 384 } 385 386 static wchar_t layout_parse_ev(kbd_event_t *ev) 387 { 387 static int cz_create(layout_t *state) 388 { 389 layout_cz_t *cz_state; 390 391 cz_state = malloc(sizeof(layout_cz_t)); 392 if (cz_state == NULL) { 393 printf(NAME ": Out of memory.\n"); 394 return ENOMEM; 395 } 396 397 cz_state->mstate = ms_start; 398 state->layout_priv = (void *) cz_state; 399 400 return EOK; 401 } 402 403 static void cz_destroy(layout_t *state) 404 { 405 free(state->layout_priv); 406 } 407 408 static wchar_t cz_parse_ev(layout_t *state, kbd_event_t *ev) 409 { 410 layout_cz_t *cz_state = (layout_cz_t *) state->layout_priv; 411 388 412 if (ev->type != KEY_PRESS) 389 413 return 0; … … 392 416 return 0; 393 417 394 switch ( mstate) {418 switch (cz_state->mstate) { 395 419 case ms_start: 396 return parse_ms_start( ev);420 return parse_ms_start(cz_state, ev); 397 421 case ms_hacek: 398 return parse_ms_hacek( ev);422 return parse_ms_hacek(cz_state, ev); 399 423 case ms_carka: 400 return parse_ms_carka( ev);424 return parse_ms_carka(cz_state, ev); 401 425 } 402 426 -
uspace/srv/hid/input/layout/us_dvorak.c
ra07a454 r2f7a564 1 1 /* 2 * Copyright (c) 20 09Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 32 32 */ 33 33 34 #include <errno.h> 34 35 #include <kbd.h> 35 36 #include <io/console.h> … … 37 38 #include <layout.h> 38 39 39 static void layout_reset(void); 40 static wchar_t layout_parse_ev(kbd_event_t *ev); 41 42 layout_op_t us_dvorak_op = { 43 layout_reset, 44 layout_parse_ev 40 static int us_dvorak_create(layout_t *); 41 static void us_dvorak_destroy(layout_t *); 42 static wchar_t us_dvorak_parse_ev(layout_t *, kbd_event_t *ev); 43 44 layout_ops_t us_dvorak_ops = { 45 .create = us_dvorak_create, 46 .destroy = us_dvorak_destroy, 47 .parse_ev = us_dvorak_parse_ev 45 48 }; 46 49 … … 206 209 } 207 210 208 static void layout_reset(void) 209 { 210 } 211 212 static wchar_t layout_parse_ev(kbd_event_t *ev) 211 static int us_dvorak_create(layout_t *state) 212 { 213 return EOK; 214 } 215 216 static void us_dvorak_destroy(layout_t *state) 217 { 218 } 219 220 static wchar_t us_dvorak_parse_ev(layout_t *state, kbd_event_t *ev) 213 221 { 214 222 wchar_t c; -
uspace/srv/hid/input/layout/us_qwerty.c
ra07a454 r2f7a564 1 1 /* 2 * Copyright (c) 20 09Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 32 32 */ 33 33 34 #include <errno.h> 34 35 #include <kbd.h> 35 36 #include <io/console.h> … … 37 38 #include <layout.h> 38 39 39 static void layout_reset(void); 40 static wchar_t layout_parse_ev(kbd_event_t *ev); 41 42 layout_op_t us_qwerty_op = { 43 layout_reset, 44 layout_parse_ev 40 static int us_qwerty_create(layout_t *); 41 static void us_qwerty_destroy(layout_t *); 42 static wchar_t us_qwerty_parse_ev(layout_t *, kbd_event_t *ev); 43 44 layout_ops_t us_qwerty_ops = { 45 .create = us_qwerty_create, 46 .destroy = us_qwerty_destroy, 47 .parse_ev = us_qwerty_parse_ev 45 48 }; 46 49 … … 200 203 } 201 204 202 static void layout_reset(void) 203 { 204 } 205 206 static wchar_t layout_parse_ev(kbd_event_t *ev) 205 static int us_qwerty_create(layout_t *state) 206 { 207 return EOK; 208 } 209 210 static void us_qwerty_destroy(layout_t *state) 211 { 212 } 213 214 static wchar_t us_qwerty_parse_ev(layout_t *state, kbd_event_t *ev) 207 215 { 208 216 wchar_t c;
Note:
See TracChangeset
for help on using the changeset viewer.