Changeset d972534 in mainline for uspace/drv/usbhid/main.c
- Timestamp:
- 2011-02-24T23:32:04Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 54e682f
- Parents:
- f2ba5d9f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/main.c
rf2ba5d9f rd972534 59 59 60 60 #define BUFFER_SIZE 8 61 #define BUFFER_OUT_SIZE 1 61 62 #define NAME "usbhid" 62 63 … … 122 123 123 124 static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length) 124 { 125 {uint8_t buffer[BUFFER_SIZE]; 125 126 printf("%s\n", msg); 126 127 … … 161 162 static int active_layout = 0; 162 163 163 static void kbd_push_ev(int type, unsigned int key) 164 static void usbkbd_req_set_report(usb_hid_dev_kbd_t *kbd_dev, uint8_t *buffer, 165 size_t buf_size) 166 { 167 int rc, sess_rc; 168 169 sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe); 170 if (sess_rc != EOK) { 171 usb_log_warning("Failed to start a session: %s.\n", 172 str_error(sess_rc)); 173 return; 174 } 175 176 usb_log_debug("Sending Set_Report request to the device.\n"); 177 // TODO: determine what interface to use!! (now set to 1) 178 rc = usb_control_request_set(&kbd_dev->ctrl_pipe, 179 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 180 USB_HIDREQ_SET_REPORT, USB_HID_REPORT_TYPE_OUTPUT, 181 1, buffer, buf_size); 182 183 sess_rc = usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe); 184 185 if (rc != EOK) { 186 usb_log_warning("Error sending output report to the keyboard: " 187 "%s.\n", str_error(rc)); 188 return; 189 } 190 191 if (sess_rc != EOK) { 192 usb_log_warning("Error closing session: %s.\n", 193 str_error(sess_rc)); 194 return; 195 } 196 } 197 198 static void usbkbd_set_led(unsigned mods, usb_hid_dev_kbd_t *kbd_dev) 199 { 200 uint8_t buffer[BUFFER_SIZE]; 201 int rc= 0; 202 203 uint8_t leds = 0; 204 205 if (mods & KM_NUM_LOCK) { 206 leds |= USB_HID_LED_NUM_LOCK; 207 } 208 209 if (mods & KM_CAPS_LOCK) { 210 leds |= USB_HID_LED_CAPS_LOCK; 211 } 212 213 if (mods & KM_SCROLL_LOCK) { 214 leds |= USB_HID_LED_SCROLL_LOCK; 215 } 216 217 // TODO: COMPOSE and KANA 218 219 usb_log_debug("Creating output report.\n"); 220 if ((rc = usb_hid_boot_keyboard_output_report( 221 leds, buffer, BUFFER_SIZE)) != EOK) { 222 usb_log_warning("Error composing output report to the keyboard:" 223 "%s.\n", str_error(rc)); 224 return; 225 } 226 227 usbkbd_req_set_report(kbd_dev, buffer, BUFFER_SIZE); 228 } 229 230 static void kbd_push_ev(int type, unsigned int key, usb_hid_dev_kbd_t *kbd_dev) 164 231 { 165 232 console_event_t ev; … … 185 252 186 253 switch (key) { 187 case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break;188 case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break;189 case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break;254 case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; usb_log_debug("\n\nPushing CAPS LOCK! (mask: %u)\n\n", mod_mask); break; 255 case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; usb_log_debug("\n\nPushing NUM LOCK! (mask: %u)\n\n", mod_mask); break; 256 case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; usb_log_debug("\n\nPushing SCROLL LOCK! (mask: %u)\n\n", mod_mask); break; 190 257 default: mod_mask = 0; break; 191 258 } 192 259 193 260 if (mod_mask != 0) { 261 usb_log_debug("\n\nChanging mods and lock keys\n\n"); 262 usb_log_debug("\n\nmods before: 0x%x\n\n", mods); 263 usb_log_debug("\n\nLock keys before:0x%x\n\n", lock_keys); 264 194 265 if (type == KEY_PRESS) { 195 266 /* … … 202 273 203 274 /* Update keyboard lock indicator lights. */ 204 // TODO 205 //kbd_ctl_set_ind(mods); 275 usbkbd_set_led(mods, kbd_dev); 206 276 } else { 207 277 lock_keys = lock_keys & ~mod_mask; … … 213 283 usb_log_debug2("keycode: %u\n", key); 214 284 */ 285 usb_log_debug("\n\nmods after: 0x%x\n\n", mods); 286 usb_log_debug("\n\nLock keys after: 0x%x\n\n", lock_keys); 215 287 216 288 if (type == KEY_PRESS && (mods & KM_LCTRL) && … … 238 310 ev.key = key; 239 311 ev.mods = mods; 312 313 if (ev.mods & KM_NUM_LOCK) { 314 usb_log_debug("\n\nNum Lock turned on.\n\n"); 315 } 240 316 241 317 ev.c = layout[active_layout]->parse_ev(&ev); … … 288 364 if (usb_hid_modifiers_keycodes[i] != 0) { 289 365 kbd_push_ev(KEY_PRESS, 290 usb_hid_modifiers_keycodes[i] );366 usb_hid_modifiers_keycodes[i], kbd_dev); 291 367 } 292 368 } else if (!(modifiers & usb_hid_modifiers_consts[i]) && … … 295 371 if (usb_hid_modifiers_keycodes[i] != 0) { 296 372 kbd_push_ev(KEY_RELEASE, 297 usb_hid_modifiers_keycodes[i] );373 usb_hid_modifiers_keycodes[i], kbd_dev); 298 374 } 299 375 } // no change … … 323 399 // not found, i.e. the key was released 324 400 key = usbkbd_parse_scancode(kbd_dev->keycodes[j]); 325 kbd_push_ev(KEY_RELEASE, key );401 kbd_push_ev(KEY_RELEASE, key, kbd_dev); 326 402 } else { 327 403 // found, nothing happens … … 343 419 // not found, i.e. new key pressed 344 420 key = usbkbd_parse_scancode(key_codes[i]); 345 kbd_push_ev(KEY_PRESS, key );421 kbd_push_ev(KEY_PRESS, key, kbd_dev); 346 422 } else { 347 423 // found, nothing happens … … 621 697 622 698 while (true) { 623 async_usleep(1000 * 10 );699 async_usleep(1000 * 1000); 624 700 625 701 sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->poll_pipe);
Note:
See TracChangeset
for help on using the changeset viewer.