Changeset d972534 in mainline
- 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
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/conv.c
rf2ba5d9f rd972534 36 36 #include <io/keycode.h> 37 37 #include <stdint.h> 38 #include <stdio.h> 39 #include <usb/debug.h> 38 40 #include "conv.h" 39 41 … … 207 209 208 210 key = map[scancode]; 211 212 if (scancode == 0x53) { 213 usb_log_debug("\n\nWe have a NUM LOCK!, sending key %u\n\n", key); 214 } 215 216 if (scancode == 0x47) { 217 usb_log_debug("\n\nWe have a SCROLL LOCK!, sending key %u\n\n", key); 218 } 219 220 if (scancode == 0x39) { 221 usb_log_debug("\n\nWe have a CAPS LOCK!, sending key %u\n\n", key); 222 } 223 209 224 // if (key != 0) 210 225 // kbd_push_ev(type, key); -
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); -
uspace/lib/usb/include/usb/classes/hid.h
rf2ba5d9f rd972534 50 50 USB_HIDREQ_SET_PROTOCOL = 11 51 51 } usb_hid_request_t; 52 53 typedef enum { 54 USB_HID_REPORT_TYPE_INPUT = 1, 55 USB_HID_REPORT_TYPE_OUTPUT = 2, 56 USB_HID_REPORT_TYPE_FEATURE = 3 57 } usb_hid_report_type_t; 52 58 53 59 /** USB/HID subclass constants. */ -
uspace/lib/usb/include/usb/classes/hidparser.h
rf2ba5d9f rd972534 83 83 } usb_hid_modifiers_t; 84 84 85 typedef enum { 86 USB_HID_LED_NUM_LOCK = 0x1, 87 USB_HID_LED_CAPS_LOCK = 0x2, 88 USB_HID_LED_SCROLL_LOCK = 0x4, 89 USB_HID_LED_COMPOSE = 0x8, 90 USB_HID_LED_KANA = 0x10, 91 USB_HID_LED_COUNT = 5 92 } usb_hid_led_t; 93 85 94 static const usb_hid_modifiers_t 86 95 usb_hid_modifiers_consts[USB_HID_MOD_COUNT] = { … … 94 103 USB_HID_MOD_RGUI 95 104 }; 105 106 //static const usb_hid_led_t usb_hid_led_consts[USB_HID_LED_COUNT] = { 107 // USB_HID_LED_NUM_LOCK, 108 // USB_HID_LED_CAPS_LOCK, 109 // USB_HID_LED_SCROLL_LOCK, 110 // USB_HID_LED_COMPOSE, 111 // USB_HID_LED_KANA 112 //}; 96 113 97 114 //#define USB_HID_BOOT_KEYBOARD_NUM_LOCK 0x01 -
uspace/lib/usb/src/hidparser.c
rf2ba5d9f rd972534 144 144 int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size) 145 145 { 146 if(size != 1){146 if(size < 2){ 147 147 return -1; 148 148 } 149 149 150 /* used only first five bits, others are only padding*/ 151 *data = leds; 150 data[1] = leds; 152 151 return EOK; 153 152 }
Note:
See TracChangeset
for help on using the changeset viewer.