Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 3facf63a in mainline


Ignore:
Timestamp:
2011-05-03T09:48:35Z (11 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master
Children:
4bfd85b, 8cbd512
Parents:
31cfee16
Message:

DFF function for generic HID subdriver.

  • Changed usbhid interface - sending only the raw buffer.
  • Implemented interface in generic HID subdriver.

Just a proof-of-concept, this implementation has many issues
(e.g. synchronization, reporting old events, etc.).

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/generic/hiddev.c

    r31cfee16 r3facf63a  
    3737#include <usb/debug.h>
    3838#include <usb/classes/classes.h>
     39#include <errno.h>
     40#include <str_error.h>
     41
     42#include <usbhid_iface.h>
    3943
    4044#include "hiddev.h"
     
    5559/*----------------------------------------------------------------------------*/
    5660
     61static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun);
     62
     63static int usb_generic_hid_get_event(ddf_fun_t *fun, int32_t *buffer,
     64    size_t size, size_t *act_size, unsigned int flags);
     65
     66/*----------------------------------------------------------------------------*/
     67
     68static usbhid_iface_t usb_generic_iface = {
     69        .get_event = usb_generic_hid_get_event,
     70        .get_event_length = usb_generic_hid_get_event_length
     71};
     72
     73static ddf_dev_ops_t usb_generic_hid_ops = {
     74        .interfaces[USBHID_DEV_IFACE] = &usb_generic_iface
     75};
     76
     77/*----------------------------------------------------------------------------*/
     78
     79static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun)
     80{
     81        if (fun == NULL || fun->driver_data) {
     82                return 0;
     83        }
     84
     85        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
     86       
     87        return hid_dev->input_report_size;
     88}
     89
     90/*----------------------------------------------------------------------------*/
     91
     92static int usb_generic_hid_get_event(ddf_fun_t *fun, int32_t *buffer,
     93    size_t size, size_t *act_size, unsigned int flags)
     94{
     95        if (fun == NULL || fun->driver_data) {
     96                return EINVAL;
     97        }
     98
     99        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
     100       
     101        if (hid_dev->input_report_size > size) {
     102                return EINVAL;  // TODO: other error code
     103        }
     104       
     105        /*! @todo This should probably be atomic. */
     106        memcpy(buffer, hid_dev->input_report, hid_dev->input_report_size);
     107        *act_size = hid_dev->input_report_size;
     108       
     109        // clear the buffer so that it will not be received twice
     110        memset(hid_dev->input_report, 0, hid_dev->input_report_size);
     111       
     112        return EOK;
     113}
     114
     115/*----------------------------------------------------------------------------*/
     116
     117static int usb_generic_hid_create_function(usb_hid_dev_t *hid_dev)
     118{       
     119        /* Create the function exposed under /dev/devices. */
     120        /** @todo Generate numbers for the devices? */
     121        usb_log_debug("Creating DDF function %s...\n", HID_GENERIC_FUN_NAME);
     122        ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
     123            HID_GENERIC_FUN_NAME);
     124        if (fun == NULL) {
     125                usb_log_error("Could not create DDF function node.\n");
     126                return ENOMEM;
     127        }
     128
     129        int rc = ddf_fun_bind(fun);
     130        if (rc != EOK) {
     131                usb_log_error("Could not bind DDF function: %s.\n",
     132                    str_error(rc));
     133                ddf_fun_destroy(fun);
     134                return rc;
     135        }
     136       
     137        fun->ops = &usb_generic_hid_ops;
     138        fun->driver_data = hid_dev;
     139       
     140        return EOK;
     141}
     142
     143/*----------------------------------------------------------------------------*/
     144
     145int usb_generic_hid_init(usb_hid_dev_t *hid_dev)
     146{
     147        if (hid_dev == NULL) {
     148                return EINVAL;
     149        }
     150       
     151        return usb_generic_hid_create_function(hid_dev);
     152}
     153
     154/*----------------------------------------------------------------------------*/
     155
    57156bool usb_generic_hid_polling_callback(usb_hid_dev_t *hid_dev,
    58157    uint8_t *buffer, size_t buffer_size)
  • uspace/drv/usbhid/generic/hiddev.h

    r31cfee16 r3facf63a  
    4646const char *HID_GENERIC_CLASS_NAME;
    4747
     48/*----------------------------------------------------------------------------*/
     49
     50int usb_generic_hid_init(struct usb_hid_dev *hid_dev);
     51
    4852bool usb_generic_hid_polling_callback(struct usb_hid_dev *hid_dev,
    4953    uint8_t *buffer, size_t buffer_size);
  • uspace/drv/usbhid/usbhid.c

    r31cfee16 r3facf63a  
    136136       
    137137        // set the init callback
    138         hid_dev->subdrivers[0].init = NULL;
     138        hid_dev->subdrivers[0].init = usb_generic_hid_init;
    139139       
    140140        // set the polling callback
  • uspace/lib/drv/include/usbhid_iface.h

    r31cfee16 r3facf63a  
    7272/** USB HID device communication interface. */
    7373typedef struct {
    74         /** Get number of items in the event.
     74        /** Get size of the event in bytes.
    7575         *
    7676         * @param[in] fun DDF function answering the request.
    7777         * @return Number of events or error code.
    7878         */
    79         int (*get_event_length)(ddf_fun_t *fun);
     79        size_t (*get_event_length)(ddf_fun_t *fun);
    8080
    8181        /** Get single event from the HID device.
    8282         *
    8383         * @param[in] fun DDF function answering the request.
    84          * @param[out] usage_page Array of usage pages and usages.
    85          * @param[out] usage Array of data (1:1 with @p usage).
    86          * @param[in] size Size of @p usage and @p data arrays.
     84         * @param[out] buffer Buffer with raw data from the device.
    8785         * @param[out] act_size Actual number of returned events.
    8886         * @param[in] flags Flags (see USBHID_IFACE_FLAG_*).
    8987         * @return Error code.
    9088         */
    91         int (*get_event)(ddf_fun_t *fun,
    92             uint16_t *usage_page, uint16_t *usage, size_t size, size_t *act_size,
    93             unsigned int flags);
     89        int (*get_event)(ddf_fun_t *fun, int32_t *buffer, size_t size,
     90            size_t *act_size, unsigned int flags);
    9491} usbhid_iface_t;
    9592
Note: See TracChangeset for help on using the changeset viewer.