/* driver/hid/usb/hid/data.h
 *
 * (c) 2002 Simtec Electronics
 *
 * Ben Dooks
 *
 * USB HID Driver - Data parsing
 *
 * $Id: data.h,v 1.9 2003/08/08 11:17:17 ben Exp $
 *
 * This Library file is part of the Simtec Electronics USB stack development
 *   suite.
 * Specific licence is granted to use this file by third parties for the
 *   development of USB device drivers.
 *
*/

#ifndef __USB_HID_DATA_H
#define __USB_HID_DATA_H "$Id: data.h,v 1.9 2003/08/08 11:17:17 ben Exp $"

struct hid_data_ptr {
  unsigned char *data;
  unsigned char *end;
};

struct hid_data_item;

struct hid_data_item {
  struct hid_report     *report;     /* the report info this relates to */
  unsigned int          offset;      /* offset into the report */
  unsigned short        size;        /* size */
  unsigned short        index;       /* index into hid_report struct usage */
};

#define hid_data_item_is_array(it)((it->report->flags & HID_REPORT_IOF_VARIABLE) == 0)

extern int hid_data_next(struct hid_data_ptr *ptr, struct hid_data_item *item);

hid_unsigned_t hid_data_read_u(struct hid_data_item *,
                               struct hid_data_ptr *data,
                               int index);

hid_data_t    hid_data_read_s(struct hid_data_item *,
                              struct hid_data_ptr *data,
                              int index);

int           hid_data_write_u(struct hid_data_item *,
                               struct hid_data_ptr *data,
                               hid_unsigned_t value);

int           hid_data_write_s(struct hid_data_item *,
                               struct hid_data_ptr *data,
                               hid_data_t value);

/* hid_data_defn
 *
 * this forms a definition of how a report is layed out in 'real' terms
 * byte-by-byte.
*/

struct hid_data_defn {

  unsigned int          size;          /* the size, calculated on build */
  unsigned int          item_count;    /* number of items in the array */
  struct hid_data_item  **items;       /* an array of items, in byte order */
};

struct hid_defnset_item {
  unsigned short no;
  unsigned short in_size, out_size;

  struct hid_data_defn    *in, *out;
};

struct hid_defn_set {
  int                       count;      /* size of list */
  struct hid_defnset_item   *items;     /* list of data definitions */
};


typedef int (*hid_defn_filter_rtn_t)(struct hid_report *report, void *pw);

extern struct hid_data_defn *hid_create_defn(struct hid_reports *report,
                                             int reportid,
                                             hid_defn_filter_rtn_t filter);

extern struct hid_data_set *hid_create_defnset(struct hid_reports *);

extern struct hid_data_defn *hid_defnset_get_in(struct hid_defn_set *,
                                                int report);

extern struct hid_data_defn *hid_defnset_get_out(struct hid_defn_set *,
                                                 int report);


extern void hid_defn_free(struct hid_data_defn *defn);
extern void hid_defn_set_free(struct hid_defn_set *data);

extern int hid_report_size(struct hid_data_defn *defn);

#endif /* __USB_HID_DATA_H */
