Changes in / [03eea27:66a54cc] in mainline


Ignore:
Location:
uspace
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/ohci/ohci.c

    r03eea27 r66a54cc  
    3131 */
    3232/** @file
    33  * @brief OHCI driver
     33 * @brief UHCI driver
    3434 */
    3535#include <errno.h>
     
    117117/** Initialize hc and rh ddf structures and their respective drivers.
    118118 *
    119  * @param[in] instance OHCI structure to use.
     119 * @param[in] instance UHCI structure to use.
    120120 * @param[in] device DDF instance of the device to use.
    121121 *
    122122 * This function does all the preparatory work for hc and rh drivers:
    123123 *  - gets device hw resources
    124  *  - disables OHCI legacy support
     124 *  - disables UHCI legacy support
    125125 *  - asks for interrupt
    126126 *  - registers interrupt handler
     
    185185        ret = ddf_fun_bind(instance->hc_fun);
    186186        CHECK_RET_DEST_FUN_RETURN(ret,
    187             "Failed(%d) to bind OHCI device function: %s.\n",
     187            "Failed(%d) to bind UHCI device function: %s.\n",
    188188            ret, str_error(ret));
    189189#undef CHECK_RET_HC_RETURN
     
    216216        ret = ddf_fun_bind(instance->rh_fun);
    217217        CHECK_RET_FINI_RETURN(ret,
    218             "Failed(%d) to register OHCI root hub.\n", ret);
     218            "Failed(%d) to register UHCI root hub.\n", ret);
    219219
    220220        return EOK;
  • uspace/drv/usbkbd/kbddev.c

    r03eea27 r66a54cc  
    5656#include <usb/classes/hidreq.h>
    5757#include <usb/classes/hidreport.h>
    58 #include <usb/classes/hid/utled.h>
    5958
    6059#include <usb/devdrv.h>
     
    7069static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK;
    7170
    72 ///** Boot protocol report size (key part). */
    73 //static const size_t BOOTP_REPORT_SIZE = 6;
    74 
    75 ///** Boot protocol total report size. */
    76 //static const size_t BOOTP_BUFFER_SIZE = 8;
    77 
    78 ///** Boot protocol output report size. */
    79 //static const size_t BOOTP_BUFFER_OUT_SIZE = 1;
    80 
    81 ///** Boot protocol error key code. */
    82 //static const uint8_t BOOTP_ERROR_ROLLOVER = 1;
    83 static const uint8_t ERROR_ROLLOVER = 1;
     71/** Boot protocol report size (key part). */
     72static const size_t BOOTP_REPORT_SIZE = 6;
     73
     74/** Boot protocol total report size. */
     75static const size_t BOOTP_BUFFER_SIZE = 8;
     76
     77/** Boot protocol output report size. */
     78static const size_t BOOTP_BUFFER_OUT_SIZE = 1;
     79
     80/** Boot protocol error key code. */
     81static const uint8_t BOOTP_ERROR_ROLLOVER = 1;
    8482
    8583/** Default idle rate for keyboards. */
     
    265263static void usb_kbd_set_led(usb_kbd_t *kbd_dev)
    266264{
    267         unsigned i = 0;
    268        
    269         /* Reset the LED data. */
    270         memset(kbd_dev->led_data, 0, kbd_dev->led_output_size * sizeof(int32_t));
    271        
    272         if ((kbd_dev->mods & KM_NUM_LOCK) && (i < kbd_dev->led_output_size)) {
    273                 kbd_dev->led_data[i++] = USB_HID_LED_NUM_LOCK;
    274         }
    275        
    276         if ((kbd_dev->mods & KM_CAPS_LOCK) && (i < kbd_dev->led_output_size)) {
    277                 kbd_dev->led_data[i++] = USB_HID_LED_CAPS_LOCK;
    278         }
    279        
    280         if ((kbd_dev->mods & KM_SCROLL_LOCK)
    281             && (i < kbd_dev->led_output_size)) {
    282                 kbd_dev->led_data[i++] = USB_HID_LED_SCROLL_LOCK;
     265        uint8_t buffer[BOOTP_BUFFER_OUT_SIZE];
     266        int rc= 0;
     267       
     268        memset(buffer, 0, BOOTP_BUFFER_OUT_SIZE);
     269        uint8_t leds = 0;
     270
     271        if (kbd_dev->mods & KM_NUM_LOCK) {
     272                leds |= USB_HID_LED_NUM_LOCK;
     273        }
     274       
     275        if (kbd_dev->mods & KM_CAPS_LOCK) {
     276                leds |= USB_HID_LED_CAPS_LOCK;
     277        }
     278       
     279        if (kbd_dev->mods & KM_SCROLL_LOCK) {
     280                leds |= USB_HID_LED_SCROLL_LOCK;
    283281        }
    284282
     
    286284       
    287285        usb_log_debug("Creating output report.\n");
    288        
    289         int rc = usb_hid_report_output_translate(kbd_dev->parser,
    290             kbd_dev->led_path, USB_HID_PATH_COMPARE_END, kbd_dev->output_buffer,
    291             kbd_dev->output_size, kbd_dev->led_data, kbd_dev->led_output_size);
    292        
    293         if (rc != EOK) {
    294                 usb_log_warning("Error translating LED output to output report"
    295                     ".\n");
     286        usb_log_debug("Leds: 0x%x\n", leds);
     287        if ((rc = usb_hid_boot_keyboard_output_report(
     288            leds, buffer, BOOTP_BUFFER_OUT_SIZE)) != EOK) {
     289                usb_log_warning("Error composing output report to the keyboard:"
     290                    "%s.\n", str_error(rc));
    296291                return;
    297292        }
    298293       
    299294        usb_log_debug("Output report buffer: %s\n",
    300             usb_debug_str_buffer(kbd_dev->output_buffer, kbd_dev->output_size,
    301                 0));
     295            usb_debug_str_buffer(buffer, BOOTP_BUFFER_OUT_SIZE, 0));
     296       
     297        assert(kbd_dev->usb_dev != NULL);
    302298       
    303299        usbhid_req_set_report(&kbd_dev->usb_dev->ctrl_pipe,
    304300            kbd_dev->usb_dev->interface_no, USB_HID_REPORT_TYPE_OUTPUT,
    305             kbd_dev->output_buffer, kbd_dev->output_size);
     301            buffer, BOOTP_BUFFER_OUT_SIZE);
    306302}
    307303
     
    454450         * First of all, check if the kbd have reported phantom state.
    455451         *
    456          * As there is no way to distinguish keys from modifiers, we do not have
    457          * a way to check that 'all keys report Error Rollover'. We thus check
    458          * if there is at least one such error and in such case we ignore the
    459          * whole input report.
     452         *  this must be changed as we don't know which keys are modifiers
     453         *       and which are regular keys.
    460454         */
    461455        i = 0;
    462         while (i < count && key_codes[i] != ERROR_ROLLOVER) {
     456        // all fields should report Error Rollover
     457        while (i < count &&
     458            key_codes[i] == BOOTP_ERROR_ROLLOVER) {
    463459                ++i;
    464460        }
    465         if (i != count) {
     461        if (i == count) {
    466462                usb_log_debug("Phantom state occured.\n");
    467463                // phantom state, do nothing
     
    590586 */
    591587static void usb_kbd_process_data(usb_kbd_t *kbd_dev,
    592                                  uint8_t *buffer, size_t actual_size)
     588                                    uint8_t *buffer, size_t actual_size)
    593589{
    594590        assert(kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED);
     
    764760        usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
    765761       
    766         kbd_dev->keys = (uint8_t *)calloc(kbd_dev->key_count, sizeof(uint8_t));
     762        kbd_dev->keys = (uint8_t *)calloc(
     763            kbd_dev->key_count, sizeof(uint8_t));
    767764       
    768765        if (kbd_dev->keys == NULL) {
     
    771768        }
    772769       
    773         /*
    774          * Output report
    775          */
    776         kbd_dev->output_size = 0;
    777         kbd_dev->output_buffer = usb_hid_report_output(kbd_dev->parser,
    778             &kbd_dev->output_size);
    779         if (kbd_dev->output_buffer == NULL) {
    780                 usb_log_warning("Error creating output report buffer.\n");
    781                 free(kbd_dev->keys);
    782                 return ENOMEM;  /* TODO: other error code */
    783         }
    784        
    785         usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size);
    786        
    787         kbd_dev->led_path = usb_hid_report_path();
    788         usb_hid_report_path_append_item(
    789             kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
    790        
    791         kbd_dev->led_output_size = usb_hid_report_output_size(kbd_dev->parser,
    792             kbd_dev->led_path, USB_HID_PATH_COMPARE_END);
    793        
    794         usb_log_debug("Output report size (in items): %zu\n",
    795             kbd_dev->led_output_size);
    796        
    797         kbd_dev->led_data = (int32_t *)calloc(
    798             kbd_dev->led_output_size, sizeof(int32_t));
    799        
    800         if (kbd_dev->led_data == NULL) {
    801                 usb_log_warning("Error creating buffer for LED output report."
    802                     "\n");
    803                 free(kbd_dev->keys);
    804                 usb_hid_report_output_free(kbd_dev->output_buffer);
    805                 return ENOMEM;
    806         }
    807        
    808         /*
    809          * Modifiers and locks
    810          */     
    811770        kbd_dev->modifiers = 0;
    812771        kbd_dev->mods = DEFAULT_ACTIVE_MODS;
    813772        kbd_dev->lock_keys = 0;
    814773       
    815         /*
    816          * Autorepeat
    817          */     
    818774        kbd_dev->repeat.key_new = 0;
    819775        kbd_dev->repeat.key_repeated = 0;
     
    923879        }
    924880       
    925         // free the output buffer
    926         usb_hid_report_output_free((*kbd_dev)->output_buffer);
    927        
    928881        /* TODO: what about the USB device structure?? */
    929882
  • uspace/drv/usbkbd/kbddev.h

    r03eea27 r66a54cc  
    9494        /** Report descriptor size. */
    9595        size_t report_desc_size;
    96        
    97         uint8_t *output_buffer;
    98        
    99         size_t output_size;
    100        
    101         size_t led_output_size;
    102        
    103         usb_hid_report_path_t *led_path;
    104        
    105         int32_t *led_data;
    10696
    10797        /** HID Report parser. */
  • uspace/lib/usb/include/usb/classes/hidparser.h

    r03eea27 r66a54cc  
    3131 */
    3232/** @file
    33  * USB HID report descriptor and report data parser
     33 * @brief USB HID parser.
    3434 */
    3535#ifndef LIBUSB_HIDPARSER_H_
     
    7474#define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY    4
    7575
    76 /** */
    77 typedef struct {
    78         /** */
     76typedef struct {
    7977        int32_t usage_page;
    80         /** */ 
    8178        int32_t usage;
    82         /** */
     79
    8380        link_t link;
    8481} usb_hid_report_usage_path_t;
    8582
    86 /** */
    87 typedef struct {
    88         /** */ 
     83typedef struct {
    8984        int depth;     
    90        
    91         /** */ 
    9285        link_t link;
    9386} usb_hid_report_path_t;
     
    9790 */
    9891typedef struct {
    99         /** */ 
    10092        int32_t id;
    101         /** */ 
    10293        int32_t usage_minimum;
    103         /** */ 
    10494        int32_t usage_maximum;
    105         /** */ 
    10695        int32_t logical_minimum;
    107         /** */ 
    10896        int32_t logical_maximum;
    109         /** */ 
    11097        int32_t size;
    111         /** */ 
    11298        int32_t count;
    113         /** */ 
    11499        size_t offset;
    115         /** */ 
    116100        int32_t delimiter;
    117         /** */ 
     101
    118102        int32_t unit_exponent;
    119         /** */ 
    120103        int32_t unit;
    121104
    122         /** */
     105        /*
     106         * some not yet used fields
     107         */
    123108        int32_t string_index;
    124         /** */ 
    125109        int32_t string_minimum;
    126         /** */ 
    127110        int32_t string_maximum;
    128         /** */ 
    129111        int32_t designator_index;
    130         /** */ 
    131112        int32_t designator_minimum;
    132         /** */ 
    133113        int32_t designator_maximum;
    134         /** */ 
    135114        int32_t physical_minimum;
    136         /** */ 
    137115        int32_t physical_maximum;
    138116
    139         /** */ 
    140117        uint8_t item_flags;
    141118
    142         /** */ 
    143119        usb_hid_report_path_t *usage_path;
    144         /** */ 
    145120        link_t link;
    146121} usb_hid_report_item_t;
     
    149124/** HID report parser structure. */
    150125typedef struct {       
    151         /** */ 
    152126        link_t input;
    153         /** */ 
    154127        link_t output;
    155         /** */ 
    156128        link_t feature;
    157129} usb_hid_report_parser_t;     
     
    182154} usb_hid_modifiers_t;
    183155
    184 //typedef enum {
    185 //      USB_HID_LED_NUM_LOCK = 0x1,
    186 //      USB_HID_LED_CAPS_LOCK = 0x2,
    187 //      USB_HID_LED_SCROLL_LOCK = 0x4,
    188 //      USB_HID_LED_COMPOSE = 0x8,
    189 //      USB_HID_LED_KANA = 0x10,
    190 //      USB_HID_LED_COUNT = 5
    191 //} usb_hid_led_t;
     156typedef enum {
     157        USB_HID_LED_NUM_LOCK = 0x1,
     158        USB_HID_LED_CAPS_LOCK = 0x2,
     159        USB_HID_LED_SCROLL_LOCK = 0x4,
     160        USB_HID_LED_COMPOSE = 0x8,
     161        USB_HID_LED_KANA = 0x10,
     162        USB_HID_LED_COUNT = 5
     163} usb_hid_led_t;
    192164
    193165static const usb_hid_modifiers_t
     
    218190
    219191/*
    220  * Descriptor parser functions
    221  */
    222 /** */
     192 * modifiers definitions
     193 */
     194
     195int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size,
     196        const usb_hid_report_in_callbacks_t *callbacks, void *arg);
     197
     198int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size);
     199
    223200int usb_hid_parser_init(usb_hid_report_parser_t *parser);
    224 
    225 /** */
    226201int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser,
    227202    const uint8_t *data, size_t size);
    228203
    229 /** */
    230 void usb_hid_free_report_parser(usb_hid_report_parser_t *parser);
    231 
    232 /** */
    233 void usb_hid_descriptor_print(usb_hid_report_parser_t *parser);
    234 
    235 /*
    236  * Boot protocol functions
    237  */
    238 /** */
    239 int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size,
    240         const usb_hid_report_in_callbacks_t *callbacks, void *arg);
    241 
    242 /** */
    243 int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size);
    244 
    245 
    246 /*
    247  * Input report parser functions
    248  */
    249 /** */
    250204int usb_hid_parse_report(const usb_hid_report_parser_t *parser, 
    251205    const uint8_t *data, size_t size,
     
    253207    const usb_hid_report_in_callbacks_t *callbacks, void *arg);
    254208
    255 /** */
    256 size_t usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
     209int usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
    257210        usb_hid_report_path_t *path, int flags);
    258211
    259212
    260 
    261 /*
    262  * usage path functions
    263  */
    264 /** */
     213void usb_hid_free_report_parser(usb_hid_report_parser_t *parser);
     214
     215void usb_hid_descriptor_print(usb_hid_report_parser_t *parser);
     216
     217/* usage path functions */
    265218usb_hid_report_path_t *usb_hid_report_path(void);
    266 
    267 /** */
    268219void usb_hid_report_path_free(usb_hid_report_path_t *path);
    269 
    270 /** */
    271220int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, int32_t usage_page, int32_t usage);
    272 
    273 /** */
    274221void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path);
    275 
    276 /** */
    277222void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path);
    278 
    279 /** */
    280223void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data);
    281 
    282 /** */
    283224int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, usb_hid_report_path_t *path, int flags);
    284 
    285 /** */
    286 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path);
    287 
    288 
    289 /*
    290  * Output report parser functions
    291  */
    292 /** Allocates output report buffer*/
    293 uint8_t *usb_hid_report_output(usb_hid_report_parser_t *parser, size_t *size);
    294 
    295 /** Frees output report buffer*/
    296 void usb_hid_report_output_free(uint8_t *output);
    297 
    298 /** Returns size of output for given usage path */
    299 size_t usb_hid_report_output_size(usb_hid_report_parser_t *parser,
    300                                   usb_hid_report_path_t *path, int flags);
    301 
    302 /** Updates the output report buffer by translated given data */
    303 int usb_hid_report_output_translate(usb_hid_report_parser_t *parser,
    304                                     usb_hid_report_path_t *path, int flags,
    305                                     uint8_t *buffer, size_t size,
    306                                     int32_t *data, size_t data_size);
     225int     usb_hid_report_path_clone(usb_hid_report_path_t *new_usage_path, usb_hid_report_path_t *usage_path);
     226
     227
     228// output
     229//      - funkce co vrati cesty poli v output reportu
     230//      - funkce co pro danou cestu nastavi data
     231//      - finalize
     232
    307233#endif
    308234/**
  • uspace/lib/usb/src/hidparser.c

    r03eea27 r66a54cc  
    3131 */
    3232/** @file
    33  * HID report descriptor and report data parser implementation.
     33 * @brief HID parser implementation.
    3434 */
    3535#include <usb/classes/hidparser.h>
     
    4040#include <usb/debug.h>
    4141
    42 /** */
    4342#define USB_HID_NEW_REPORT_ITEM 1
    44 
    45 /** */
    4643#define USB_HID_NO_ACTION               2
    47 
    48 /** */
    4944#define USB_HID_UNKNOWN_TAG             -99
    5045
    51 /*
    52  * Private descriptor parser functions
    53  */
     46#define BAD_HACK_USAGE_PAGE             0x07
     47
    5448int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size,
    5549                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
     
    6458int usb_hid_report_reset_local_items();
    6559void usb_hid_free_report_list(link_t *head);
    66 
    67 /*
    68  * Data translation private functions
    69  */
    7060int32_t usb_hid_report_tag_data_int32(const uint8_t *data, size_t size);
    7161inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset);
    7262int usb_hid_translate_data(usb_hid_report_item_t *item, const uint8_t *data, size_t j);
    73 int32_t usb_hid_translate_data_reverse(usb_hid_report_item_t *item, int32_t value);
    7463int usb_pow(int a, int b);
    7564
    76 // TODO: tohle ma bejt asi jinde
     65
    7766int usb_pow(int a, int b)
    7867{
     
    9180
    9281/**
    93  * Initialize the report descriptor parser structure
    94  *
    95  * @param parser Report descriptor parser structure
    96  * @return Error code
     82 *
    9783 */
    9884int usb_hid_parser_init(usb_hid_report_parser_t *parser)
    9985{
    100         if(parser == NULL) {
    101                 return EINVAL;
    102         }
    103 
    104         list_initialize(&(parser->input));
     86   if(parser == NULL) {
     87        return EINVAL;
     88   }
     89
     90    list_initialize(&(parser->input));
    10591    list_initialize(&(parser->output));
    10692    list_initialize(&(parser->feature));
     
    178164                                        // store current usage path
    179165                                        report_item->usage_path = usage_path;
     166
     167                                        // new current usage path
     168                                        tmp_usage_path = usb_hid_report_path();
    180169                                       
    181                                         // clone path to the new one
    182                                         tmp_usage_path = usb_hid_report_path_clone(usage_path);
     170                                        // copy old path to the new one
     171                                        usb_hid_report_path_clone(tmp_usage_path, usage_path);
    183172
    184173                                        // swap
     
    315304
    316305/**
    317  * Parse one tag of the report descriptor
    318306 *
    319307 * @param Tag to parse
     
    403391 * @return Error code
    404392 */
     393
    405394int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size,
    406395                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
     
    531520 * Prints content of given list of report items.
    532521 *
    533  * @param List of report items (usb_hid_report_item_t)
     522 * @param List of report items
    534523 * @return void
    535524 */
     
    563552                        path = path->next;
    564553                }
    565                                
     554               
     555               
     556//              usb_log_debug("\tUSAGE: %X\n", report_item->usage);
     557//              usb_log_debug("\tUSAGE PAGE: %X\n", report_item->usage_page);
    566558                usb_log_debug("\tLOGMIN: %X\n", report_item->logical_minimum);
    567559                usb_log_debug("\tLOGMAX: %X\n", report_item->logical_maximum);         
     
    578570}
    579571/**
    580  * Prints content of given report descriptor in human readable format.
    581  *
    582  * @param parser Parsed descriptor to print
     572 * Prints content of given descriptor in human readable format.
     573 *
     574 * @param Parsed descriptor to print
    583575 * @return void
    584576 */
     
    603595 * Releases whole linked list of report items
    604596 *
    605  * @param head Head of list of report descriptor items (usb_hid_report_item_t)
    606  * @return void
     597 *
    607598 */
    608599void usb_hid_free_report_list(link_t *head)
     
    636627}
    637628
    638 /** Frees the HID report descriptor parser structure
     629/** Free the HID report parser structure
    639630 *
    640631 * @param parser Opaque HID report parser structure
    641  * @return void
     632 * @return Error code
    642633 */
    643634void usb_hid_free_report_parser(usb_hid_report_parser_t *parser)
     
    669660    const usb_hid_report_in_callbacks_t *callbacks, void *arg)
    670661{
     662        /*
     663         *
     664         * only key codes (usage page 0x07) will be processed
     665         * other usages will be ignored
     666         */
    671667        link_t *list_item;
    672668        usb_hid_report_item_t *item;
     
    680676                return EINVAL;
    681677        }
    682        
    683         /* get the size of result array */
     678
     679       
     680        // get the size of result keycodes array
    684681        key_count = usb_hid_report_input_length(parser, path, flags);
    685682
     
    688685        }
    689686
    690         /* read data */
     687        // read data           
    691688        list_item = parser->input.next;   
    692689        while(list_item != &(parser->input)) {
     
    722719}
    723720
    724 /**
    725  * Translate data from the report as specified in report descriptor
    726  *
    727  * @param item Report descriptor item with definition of translation
    728  * @param data Data to translate
    729  * @param j Index of processed field in report descriptor item
    730  * @return Translated data
    731  */
     721
    732722int usb_hid_translate_data(usb_hid_report_item_t *item, const uint8_t *data, size_t j)
    733723{
     
    806796}
    807797
    808 /**
    809  *
    810  *
    811  * @param parser
    812  * @param path
    813  * @param flags
    814  * @return
    815  */
    816 size_t usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
     798int usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
    817799        usb_hid_report_path_t *path, int flags)
    818800{       
    819         size_t ret = 0;
     801        int ret = 0;
    820802        link_t *item;
    821803        usb_hid_report_item_t *report_item;
    822804
    823805        if(parser == NULL) {
    824                 return 0;
    825         }
    826        
    827         item = parser->input.next;
     806                return EINVAL;
     807        }
     808       
     809        item = (&parser->input)->next;
    828810        while(&parser->input != item) {
    829811                report_item = list_get_instance(item, usb_hid_report_item_t, link);
     
    842824/**
    843825 *
    844  * @param usage_path
    845  * @param usage_page
    846  * @param usage
    847  * @return
    848826 */
    849827int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path,
     
    867845/**
    868846 *
    869  * @param usage_path
    870  * @return
    871847 */
    872848void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path)
     
    884860/**
    885861 *
    886  * @param usage_path
    887  * @return
    888862 */
    889863void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path)
     
    899873/**
    900874 *
    901  * @param usage_path
    902  * @param tag
    903  * @param data
    904  * @return
    905875 */
    906876void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data)
     
    924894
    925895/**
    926  *
    927  *
    928  * @param report_path
    929  * @param path
    930  * @param flags
    931  * @return
     896 *
    932897 */
    933898int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path,
     
    984949                        break;
    985950
    986                 /* compare with only the end of path*/
     951                /* given path must be the end of the report one*/
    987952                case USB_HID_PATH_COMPARE_END:
    988953                                report_link = report_path->link.prev;
     
    1027992/**
    1028993 *
    1029  * @return
    1030994 */
    1031995usb_hid_report_path_t *usb_hid_report_path(void)
     
    10451009/**
    10461010 *
    1047  * @param path
    1048  * @return void
    10491011 */
    10501012void usb_hid_report_path_free(usb_hid_report_path_t *path)
     
    10571019
    10581020/**
    1059  * Clone content of given usage path to the new one
    1060  *
    1061  * @param usage_path
    1062  * @return
    1063  */
    1064 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path)
     1021 *
     1022 */
     1023int     usb_hid_report_path_clone(usb_hid_report_path_t *new_usage_path, usb_hid_report_path_t *usage_path)
    10651024{
    10661025        usb_hid_report_usage_path_t *path_item;
    10671026        link_t *path_link;
    1068         usb_hid_report_path_t *new_usage_path = usb_hid_report_path ();
    1069 
    1070         if(new_usage_path == NULL){
    1071                 return NULL;
    1072         }
     1027
    10731028       
    10741029        if(list_empty(&usage_path->link)){
    1075                 return new_usage_path;
     1030                return EOK;
    10761031        }
    10771032
     
    10841039        }
    10851040
    1086         return new_usage_path;
    1087 }
    1088 
    1089 
    1090 /*** OUTPUT API **/
    1091 
    1092 /** Allocates output report buffer
    1093  *
    1094  * @param parser
    1095  * @param size
    1096  * @return
    1097  */
    1098 uint8_t *usb_hid_report_output(usb_hid_report_parser_t *parser, size_t *size)
    1099 {
    1100         if(parser == NULL) {
    1101                 *size = 0;
    1102                 return NULL;
    1103         }
    1104        
    1105         // read the last output report item
    1106         usb_hid_report_item_t *last;
    1107         link_t *link;
    1108 
    1109         link = parser->output.prev;
    1110         if(link != &parser->output) {
    1111                 last = list_get_instance(link, usb_hid_report_item_t, link);
    1112                 *size = (last->offset + (last->size * last->count)) / 8;
    1113 
    1114                 uint8_t *buffer = malloc(sizeof(uint8_t) * (*size));
    1115                 memset(buffer, 0, sizeof(uint8_t) * (*size));
    1116                 usb_log_debug("output buffer: %s\n", usb_debug_str_buffer(buffer, *size, 0));
    1117 
    1118                 return buffer;
    1119         }
    1120         else {
    1121                 *size = 0;             
    1122                 return NULL;
    1123         }
    1124 }
    1125 
    1126 
    1127 /** Frees output report buffer
    1128  *
    1129  * @param output Output report buffer
    1130  * @return
    1131  */
    1132 void usb_hid_report_output_free(uint8_t *output)
    1133 
    1134 {
    1135         if(output != NULL) {
    1136                 free (output);
    1137         }
    1138 }
    1139 
    1140 /** Returns size of output for given usage path
    1141  *
    1142  * @param parser
    1143  * @param path
    1144  * @param flags
    1145  * @return
    1146  */
    1147 size_t usb_hid_report_output_size(usb_hid_report_parser_t *parser,
    1148                                   usb_hid_report_path_t *path, int flags)
    1149 {
    1150         size_t ret = 0;
    1151         link_t *item;
    1152         usb_hid_report_item_t *report_item;
    1153 
    1154         if(parser == NULL) {
    1155                 return 0;
    1156         }
    1157        
    1158         item = parser->output.next;
    1159         while(&parser->output != item) {
    1160                 report_item = list_get_instance(item, usb_hid_report_item_t, link);
    1161                 if(!USB_HID_ITEM_FLAG_CONSTANT(report_item->item_flags) &&
    1162                    (usb_hid_report_compare_usage_path(report_item->usage_path, path, flags) == EOK)) {
    1163                         ret += report_item->count;
    1164                 }
    1165 
    1166                 item = item->next;
    1167         }
    1168 
    1169         return ret;
    1170        
    1171 }
    1172 
    1173 /** Updates the output report buffer by translated given data
    1174  *
    1175  * @param parser
    1176  * @param path
    1177  * @param flags
    1178  * @param buffer
    1179  * @param size
    1180  * @param data
    1181  * @param data_size
    1182  * @return
    1183  */
    1184 int usb_hid_report_output_translate(usb_hid_report_parser_t *parser,
    1185                                     usb_hid_report_path_t *path, int flags,
    1186                                     uint8_t *buffer, size_t size,
    1187                                     int32_t *data, size_t data_size)
    1188 {
    1189         usb_hid_report_item_t *report_item;
    1190         link_t *item;   
    1191         size_t idx=0;
    1192         int i=0;
    1193         int32_t value=0;
    1194         int offset;
    1195         int length;
    1196         int32_t tmp_value;
    1197        
    1198         if(parser == NULL) {
    1199                 return EINVAL;
    1200         }
    1201 
    1202         usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
    1203         usb_log_debug("OUTPUT DATA[0]: %d, DATA[1]: %d, DATA[2]: %d\n", data[0], data[1], data[2]);
    1204 
    1205         item = parser->output.next;     
    1206         while(item != &parser->output) {
    1207                 report_item = list_get_instance(item, usb_hid_report_item_t, link);
    1208 
    1209                 for(i=0; i<report_item->count; i++) {
    1210 
    1211                         if(idx >= data_size) {
    1212                                 break;
    1213                         }
    1214 
    1215                         if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) ||
    1216                                 ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) {
    1217                                        
    1218 //                              // variable item
    1219                                 value = usb_hid_translate_data_reverse(report_item, data[idx++]);
    1220                                 offset = report_item->offset + (i * report_item->size);
    1221                                 length = report_item->size;
    1222                         }
    1223                         else {
    1224                                 //bitmap
    1225                                 value += usb_hid_translate_data_reverse(report_item, data[idx++]);
    1226                                 offset = report_item->offset;
    1227                                 length = report_item->size * report_item->count;
    1228                         }
    1229 
    1230                         if((offset/8) == ((offset+length-1)/8)) {
    1231                                 // je to v jednom bytu
    1232                                 if(((size_t)(offset/8) >= size) || ((size_t)(offset+length-1)/8) >= size) {
    1233                                         break; // TODO ErrorCode
    1234                                 }
    1235 
    1236                                 size_t shift = offset%8;
    1237 
    1238                                 value = value << shift;                                                 
    1239                                 value = value & (((1 << length)-1) << shift);
    1240                                
    1241                                 uint8_t mask = 0;
    1242                                 mask = 0xff - (((1 << length) - 1) << shift);
    1243                                 buffer[offset/8] = (buffer[offset/8] & mask) | value;
    1244                         }
    1245                         else {
    1246                                 // je to ve dvou!! FIXME: melo by to umet delsi jak 2
    1247 
    1248                                 // konec prvniho -- dolni x bitu
    1249                                 tmp_value = value;
    1250                                 tmp_value = tmp_value & ((1 << (8-(offset%8)))-1);                             
    1251                                 tmp_value = tmp_value << (offset%8);
    1252 
    1253                                 uint8_t mask = 0;
    1254                                 mask = ~(((1 << (8-(offset%8)))-1) << (offset%8));
    1255                                 buffer[offset/8] = (buffer[offset/8] & mask) | tmp_value;
    1256 
    1257                                 // a ted druhej -- hornich length-x bitu
    1258                                 value = value >> (8 - (offset % 8));
    1259                                 value = value & ((1 << (length - (8 - (offset % 8)))) - 1);
    1260                                
    1261                                 mask = ((1 << (length - (8 - (offset % 8)))) - 1);
    1262                                 buffer[(offset+length-1)/8] = (buffer[(offset+length-1)/8] & mask) | value;
    1263                         }
    1264 
    1265                 }
    1266 
    1267                 item = item->next;
    1268         }
    1269 
    1270         usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
    1271 
    12721041        return EOK;
    12731042}
    12741043
    1275 /**
    1276  *
    1277  * @param item
    1278  * @param value
    1279  * @return
    1280  */
    1281 int32_t usb_hid_translate_data_reverse(usb_hid_report_item_t *item, int value)
    1282 {
    1283         int ret=0;
    1284         int resolution;
    1285 
    1286         if(USB_HID_ITEM_FLAG_CONSTANT(item->item_flags)) {
    1287                 ret = item->logical_minimum;
    1288         }
    1289 
    1290         if((USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0)) {
    1291 
    1292                 // variable item
    1293                 if((item->physical_minimum == 0) && (item->physical_maximum == 0)) {
    1294                         item->physical_minimum = item->logical_minimum;
    1295                         item->physical_maximum = item->logical_maximum;
    1296                 }
    1297 
    1298                 if(item->physical_maximum == item->physical_minimum){
    1299                     resolution = 1;
    1300                 }
    1301                 else {
    1302                     resolution = (item->logical_maximum - item->logical_minimum) /
    1303                         ((item->physical_maximum - item->physical_minimum) *
    1304                         (usb_pow(10,(item->unit_exponent))));
    1305                 }
    1306 
    1307                 ret = ((value - item->physical_minimum) * resolution) + item->logical_minimum;
    1308         }
    1309         else {
    1310                 // bitmapa
    1311                 if(value == 0) {
    1312                         ret = 0;
    1313                 }
    1314                 else {
    1315                         size_t bitmap_idx = (value - item->usage_minimum);
    1316                         ret = 1 << bitmap_idx;
    1317                 }
    1318         }
    1319 
    1320 
    1321         return ret;
    1322 }
    1323 
    13241044
    13251045/**
Note: See TracChangeset for help on using the changeset viewer.