Changeset af897ff0 in mainline


Ignore:
Timestamp:
2011-06-12T14:51:24Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5f88293
Parents:
f2f99ae
Message:

Let kbd server discover new devices.

Location:
uspace/srv/hid
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/console/console.c

    rf2f99ae raf897ff0  
    973973       
    974974        /* Start fibril for checking on hot-plugged keyboards. */
    975 //      check_new_devices_in_background(connect_keyboard, "keyboard");
    976975        check_new_devices_in_background(connect_mouse, "mouse");
    977976       
  • uspace/srv/hid/kbd/generic/kbd.c

    rf2f99ae raf897ff0  
    6262#include <kernel/ipc/ipc_methods.h>
    6363
    64 #define NAME       "kbd"
    65 #define NAMESPACE  "hid_in"
     64/* In microseconds */
     65#define DISCOVERY_POLL_INTERVAL         (10*1000*1000)
    6666
    6767static void kbd_devs_yield(void);
     
    223223}
    224224
    225 /** Add new keyboard device. */
     225/** Add new legacy keyboard device. */
    226226static void kbd_add_dev(kbd_port_ops_t *port, kbd_ctl_ops_t *ctl)
    227227{
     
    235235
    236236        link_initialize(&kdev->kbd_devs);
     237        kdev->dev_path = NULL;
    237238        kdev->port_ops = port;
    238239        kdev->ctl_ops = ctl;
    239240
    240241        /* Initialize port driver. */
    241         if (kdev->port_ops != NULL) {
    242                 if ((*kdev->port_ops->init)(kdev) != 0)
    243                         goto fail;
    244         }
     242        if ((*kdev->port_ops->init)(kdev) != 0)
     243                goto fail;
    245244
    246245        /* Initialize controller driver. */
     
    254253fail:
    255254        free(kdev);
     255}
     256
     257/** Add new kbdev device.
     258 *
     259 * @param dev_path      Filesystem path to the device (/dev/class/...)
     260 */
     261static int kbd_add_kbdev(const char *dev_path)
     262{
     263        kbd_dev_t *kdev;
     264
     265        kdev = malloc(sizeof(kbd_dev_t));
     266        if (kdev == NULL) {
     267                printf(NAME ": Failed adding keyboard device. Out of memory.\n");
     268                return -1;
     269        }
     270
     271        link_initialize(&kdev->kbd_devs);
     272        kdev->dev_path = dev_path;
     273        kdev->port_ops = NULL;
     274        kdev->ctl_ops = &kbdev_ctl;
     275
     276        /* Initialize controller driver. */
     277        if ((*kdev->ctl_ops->init)(kdev) != 0) {
     278                goto fail;
     279        }
     280
     281        list_append(&kdev->kbd_devs, &kbd_devs);
     282        return EOK;
     283fail:
     284        free(kdev);
     285        return -1;
    256286}
    257287
     
    309339        kbd_add_dev(&ns16550_port, &sun_ctl);
    310340#endif
     341        /* Silence warning on abs32le about kbd_add_dev() being unused */
     342        (void) kbd_add_dev;
    311343}
    312344
     
    337369}
    338370
     371/** Periodically check for new kbdev devices in /dev/class/keyboard.
     372 *
     373 * @param arg   Ignored
     374 */
     375static int dev_discovery_fibril(void *arg)
     376{
     377        char *dev_path;
     378        size_t id = 1;
     379        int rc;
     380
     381        while (true) {
     382                async_usleep(DISCOVERY_POLL_INTERVAL);
     383
     384                rc = asprintf(&dev_path, "/dev/class/keyboard\\%zu", id);
     385                if (rc < 0)
     386                        continue;
     387
     388                if (kbd_add_kbdev(dev_path) == EOK) {
     389                        printf(NAME ": Connected kbdev device '%s'\n",
     390                            dev_path);
     391
     392                        /* XXX Handle device removal */
     393                        ++id;
     394                }
     395
     396                free(dev_path);
     397        }
     398
     399        return EOK;
     400}
     401
     402/** Start a fibril for discovering new devices. */
     403static void kbd_start_dev_discovery(void)
     404{
     405        fid_t fid;
     406
     407        fid = fibril_create(dev_discovery_fibril, NULL);
     408        if (!fid) {
     409                printf(NAME ": Failed to create device discovery fibril.\n");
     410                return;
     411        }
     412
     413        fibril_add_ready(fid);
     414}
     415
    339416int main(int argc, char **argv)
    340417{
     
    357434        /* Add legacy devices. */
    358435        kbd_add_legacy_devs();
    359 
    360         /* Add kbdev device */
    361         kbd_add_dev(NULL, &kbdev_ctl);
    362436
    363437        /* Initialize (reset) layout. */
     
    380454        }
    381455
     456        /* Start looking for new kbdev devices */
     457        kbd_start_dev_discovery();
     458
    382459        printf(NAME ": Accepting connections\n");
    383460        async_manager();
  • uspace/srv/hid/kbd/include/kbd.h

    rf2f99ae raf897ff0  
    4242#include <bool.h>
    4343
     44#define NAME       "kbd"
     45#define NAMESPACE  "hid_in"
     46
    4447struct kbd_port_ops;
    4548struct kbd_ctl_ops;
     
    4851        /** Link to kbd_devs list */
    4952        link_t kbd_devs;
     53
     54        /** Path to the device (only for kbdev devices) */
     55        const char *dev_path;
    5056
    5157        /** Port ops */
  • uspace/srv/hid/kbd/port/chardev.c

    rf2f99ae raf897ff0  
    4444#include <errno.h>
    4545#include <stdio.h>
    46 
    47 #define NAME  "kbd/chardev"
    4846
    4947static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall);
Note: See TracChangeset for help on using the changeset viewer.