Changeset 00aece0 in mainline for uspace/drv/char/xtkbd/main.c
- Timestamp:
- 2012-02-18T16:47:38Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4449c6c
- Parents:
- bd5f3b7 (diff), f943dd3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/xtkbd/main.c
rbd5f3b7 r00aece0 1 1 /* 2 * Copyright (c) 2011 Vojtech Horky2 * Copyright (c) 2011 Jan Vesely 3 3 * All rights reserved. 4 4 * … … 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 29 /** @addtogroup drvusbmouse 28 /** @addtogroup drvkbd 30 29 * @{ 31 30 */ 32 /** 33 * @file 34 * Main routines of USB boot protocol mouse driver. 31 /** @file 32 * @brief XT keyboard driver 35 33 */ 36 34 37 #include "mouse.h" 38 #include <usb/debug.h> 39 #include <usb/dev/poll.h> 35 #include <libarch/inttypes.h> 36 #include <ddf/driver.h> 37 #include <devman.h> 38 #include <device/hw_res_parsed.h> 40 39 #include <errno.h> 41 40 #include <str_error.h> 41 #include <ddf/log.h> 42 #include <stdio.h> 42 43 43 # define NAME "usbmouse"44 #include "xtkbd.h" 44 45 45 /** Callback when new mouse device is attached and recognised by DDF. 46 #define NAME "xtkbd" 47 48 static int xt_kbd_add(ddf_dev_t *device); 49 50 /** DDF driver ops. */ 51 static driver_ops_t kbd_driver_ops = { 52 .dev_add = xt_kbd_add, 53 }; 54 55 /** DDF driver structure. */ 56 static driver_t kbd_driver = { 57 .name = NAME, 58 .driver_ops = &kbd_driver_ops 59 }; 60 61 /** Initialize global driver structures (NONE). 46 62 * 47 * @param dev Representation of a generic DDF device.48 * 63 * @param[in] argc Nmber of arguments in argv vector (ignored). 64 * @param[in] argv Cmdline argument vector (ignored). 49 65 * @return Error code. 50 66 * 67 * Driver debug level is set here. 51 68 */ 52 static int usbmouse_add_device(usb_device_t *dev)69 int main(int argc, char *argv[]) 53 70 { 54 int rc = usb_mouse_create(dev); 55 if (rc != EOK) { 56 usb_log_error("Failed to initialize device driver: %s.\n", 57 str_error(rc)); 58 return rc; 59 } 60 61 usb_log_debug("Polling pipe at endpoint %d.\n", 62 dev->pipes[0].pipe->endpoint_no); 63 64 rc = usb_device_auto_poll(dev, 0, usb_mouse_polling_callback, 65 dev->pipes[0].pipe->max_packet_size, 66 usb_mouse_polling_ended_callback, dev->driver_data); 67 68 if (rc != EOK) { 69 usb_log_error("Failed to start polling fibril: %s.\n", 70 str_error(rc)); 71 return rc; 72 } 73 74 usb_log_info("controlling new mouse (handle %" PRIun ").\n", 75 dev->ddf_dev->handle); 76 71 printf(NAME ": HelenOS XT keyboard driver.\n"); 72 ddf_log_init(NAME, LVL_NOTE); 73 return ddf_driver_main(&kbd_driver); 74 } 75 76 /** Initialize a new ddf driver instance of the driver 77 * 78 * @param[in] device DDF instance of the device to initialize. 79 * @return Error code. 80 */ 81 static int xt_kbd_add(ddf_dev_t *device) 82 { 83 if (!device) 84 return EINVAL; 85 86 #define CHECK_RET_RETURN(ret, message...) \ 87 if (ret != EOK) { \ 88 ddf_msg(LVL_ERROR, message); \ 89 return ret; \ 90 } else (void)0 91 92 xt_kbd_t *kbd = ddf_dev_data_alloc(device, sizeof(xt_kbd_t)); 93 int ret = (kbd == NULL) ? ENOMEM : EOK; 94 CHECK_RET_RETURN(ret, "Failed to allocate XT/KBD driver instance."); 95 96 ret = xt_kbd_init(kbd, device); 97 CHECK_RET_RETURN(ret, 98 "Failed to initialize XT_KBD driver: %s.", str_error(ret)); 99 100 ddf_msg(LVL_NOTE, "Controlling '%s' (%" PRIun ").", 101 device->name, device->handle); 77 102 return EOK; 78 103 } 79 80 /** USB mouse driver ops. */81 static usb_driver_ops_t mouse_driver_ops = {82 .add_device = usbmouse_add_device,83 };84 85 static usb_endpoint_description_t *endpoints[] = {86 &poll_endpoint_description,87 NULL88 };89 90 /** USB mouse driver. */91 static usb_driver_t mouse_driver = {92 .name = NAME,93 .ops = &mouse_driver_ops,94 .endpoints = endpoints95 };96 97 int main(int argc, char *argv[])98 {99 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);100 return usb_driver_main(&mouse_driver);101 }102 103 104 /** 104 105 * @}
Note:
See TracChangeset
for help on using the changeset viewer.