Changeset a694a58 in mainline for uspace/lib/usb/src/hidparser.c


Ignore:
Timestamp:
2011-04-07T21:18:37Z (13 years ago)
Author:
Matej Klonfar <maklf@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cf81757
Parents:
c156c2d
Message:

Output API modified for handle report ids

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/hidparser.c

    rc156c2d ra694a58  
    4040#include <usb/debug.h>
    4141
    42 /** */
     42/** The new report item flag. Used to determine when the item is completly
     43 * configured and should be added to the report structure
     44 */
    4345#define USB_HID_NEW_REPORT_ITEM 1
    4446
    45 /** */
    46 #define USB_HID_NO_ACTION               2
    47 
    48 /** */
     47/** No special action after the report descriptor tag is processed should be
     48 * done
     49 */
     50#define USB_HID_NO_ACTION       2
     51
     52/** Unknown tag was founded in report descriptor data*/
    4953#define USB_HID_UNKNOWN_TAG             -99
    5054
     
    236240                                        new_report_item->string_maximum = 0;
    237241
     242                                        /* set the report id */
     243                                        new_report_item->id = report_item->id;
     244
    238245                                        /* reset usage from current usage path */
    239246                                        usb_hid_report_usage_path_t *path = list_get_instance(&usage_path->link, usb_hid_report_usage_path_t, link);
     
    290297}
    291298
    292 
    293 /**
    294  * Parse input report.
    295  *
    296  * @param data Data for report
    297  * @param size Size of report
    298  * @param callbacks Callbacks for report actions
    299  * @param arg Custom arguments
    300  *
    301  * @return Error code
    302  */
    303 int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size,
    304         const usb_hid_report_in_callbacks_t *callbacks, void *arg)
    305 {
    306         int i;
    307         usb_hid_report_item_t item;
    308 
    309         /* fill item due to the boot protocol report descriptor */
    310         // modifier keys are in the first byte
    311         uint8_t modifiers = data[0];
    312 
    313         item.offset = 2; /* second byte is reserved */
    314         item.size = 8;
    315         item.count = 6;
    316         item.usage_minimum = 0;
    317         item.usage_maximum = 255;
    318         item.logical_minimum = 0;
    319         item.logical_maximum = 255;
    320 
    321         if (size != 8) {
    322                 return -1; //ERANGE;
    323         }
    324 
    325         uint8_t keys[6];
    326         for (i = 0; i < item.count; i++) {
    327                 keys[i] = data[i + item.offset];
    328         }
    329 
    330         callbacks->keyboard(keys, 6, modifiers, arg);
    331         return EOK;
    332 }
    333 
    334 /**
    335  * Makes output report for keyboard boot protocol
    336  *
    337  * @param leds
    338  * @param output Output report data buffer
    339  * @param size Size of the output buffer
    340  * @return Error code
    341  */
    342 int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size)
    343 {
    344         if(size != 1){
    345                 return -1;
    346         }
    347 
    348         /* used only first five bits, others are only padding*/
    349         *data = leds;
    350         return EOK;
    351 }
    352299
    353300/**
     
    859806
    860807/**
    861  *
    862  *
    863  * @param parser
    864  * @param path
    865  * @param flags
    866  * @return
     808 * Returns number of items in input report which are accessible by given usage path
     809 *
     810 * @param parser Opaque report descriptor structure
     811 * @param path Usage path specification
     812 * @param flags Usage path comparison flags
     813 * @return Number of items in input report
    867814 */
    868815size_t usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
     
    893840
    894841/**
    895  *
    896  * @param usage_path
    897  * @param usage_page
    898  * @param usage
    899  * @return
     842 * Appends one item (couple of usage_path and usage) into the usage path
     843 * structure
     844 *
     845 * @param usage_path Usage path structure
     846 * @param usage_page Usage page constant
     847 * @param usage Usage constant
     848 * @return Error code
    900849 */
    901850int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path,
     
    918867
    919868/**
    920  *
    921  * @param usage_path
    922  * @return
     869 * Removes last item from the usage path structure
     870 * @param usage_path 
     871 * @return void
    923872 */
    924873void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path)
     
    935884
    936885/**
     886 * Nulls last item of the usage path structure.
    937887 *
    938888 * @param usage_path
    939  * @return
     889 * @return void
    940890 */
    941891void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path)
     
    950900
    951901/**
    952  *
    953  * @param usage_path
    954  * @param tag
    955  * @param data
    956  * @return
     902 * Modifies last item of usage path structure by given usage page or usage
     903 *
     904 * @param usage_path Opaque usage path structure
     905 * @param tag Class of currently processed tag (Usage page tag falls into Global
     906 * class but Usage tag into the Local)
     907 * @param data Value of the processed tag
     908 * @return void
    957909 */
    958910void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data)
     
    976928
    977929/**
    978  *
    979  *
    980  * @param report_path
    981  * @param path
    982  * @param flags
    983  * @return
     930 * Compares two usage paths structures
     931 *
     932 * @param report_path usage path structure to compare
     933 * @param path usage patrh structure to compare
     934 * @param flags Flags determining the mode of comparison
     935 * @return EOK if both paths are identical, non zero number otherwise
    984936 */
    985937int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path,
     
    10821034
    10831035/**
    1084  *
    1085  * @return
     1036 * Allocates and initializes new usage path structure.
     1037 *
     1038 * @return Initialized usage path structure
    10861039 */
    10871040usb_hid_report_path_t *usb_hid_report_path(void)
     
    11011054
    11021055/**
    1103  *
    1104  * @param path
     1056 * Releases given usage path structure.
     1057 *
     1058 * @param path usage path structure to release
    11051059 * @return void
    11061060 */
     
    11161070 * Clone content of given usage path to the new one
    11171071 *
    1118  * @param usage_path
    1119  * @return
     1072 * @param usage_path Usage path structure to clone
     1073 * @return New copy of given usage path structure
    11201074 */
    11211075usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path)
     
    11471101/*** OUTPUT API **/
    11481102
    1149 /** Allocates output report buffer
    1150  *
    1151  * @param parser
    1152  * @param size
    1153  * @return
    1154  */
    1155 uint8_t *usb_hid_report_output(usb_hid_report_parser_t *parser, size_t *size)
     1103/**
     1104 * Allocates output report buffer for output report
     1105 *
     1106 * @param parser Report parsed structure
     1107 * @param size Size of returned buffer
     1108 * @param report_id Report id of created output report
     1109 * @return Returns allocated output buffer for specified output
     1110 */
     1111uint8_t *usb_hid_report_output(usb_hid_report_parser_t *parser, size_t *size, uint8_t report_id)
    11561112{
    11571113        if(parser == NULL) {
     
    11651121
    11661122        link = parser->output.prev;
     1123        while((link != &parser->output)){
     1124                last = list_get_instance(link, usb_hid_report_item_t, link);
     1125
     1126                usb_log_debug("pro id: %d, posledni %d\n", report_id, last->id);
     1127                if(last->id == report_id){
     1128                        break;
     1129                }
     1130                else {
     1131                        link =  link->prev;
     1132                }
     1133        }
     1134
     1135       
     1136
    11671137        if(link != &parser->output) {
    11681138                last = list_get_instance(link, usb_hid_report_item_t, link);
     
    11891159 *
    11901160 * @param output Output report buffer
    1191  * @return
     1161 * @return void
    11921162 */
    11931163void usb_hid_report_output_free(uint8_t *output)
     
    12011171/** Returns size of output for given usage path
    12021172 *
    1203  * @param parser
    1204  * @param path
    1205  * @param flags
    1206  * @return
     1173 * @param parser Opaque report parser structure
     1174 * @param path Usage path specified which items will be thought for the output
     1175 * @param flags Flags of usage path structure comparison
     1176 * @return Number of items matching the given usage path
    12071177 */
    12081178size_t usb_hid_report_output_size(usb_hid_report_parser_t *parser,
     
    12321202}
    12331203
    1234 /** Updates the output report buffer by translated given data
    1235  *
    1236  * @param parser
    1237  * @param path
    1238  * @param flags
    1239  * @param buffer
    1240  * @param size
    1241  * @param data
    1242  * @param data_size
    1243  * @return
     1204/** Updates the output report buffer by given data
     1205 *
     1206 * @param parser Opaque report parser structure
     1207 * @param path Usage path specifing which parts of output will be set
     1208 * @param flags Usage path structure comparison flags
     1209 * @param buffer Output buffer
     1210 * @param size Size of output buffer
     1211 * @param data Data buffer
     1212 * @param data_size Size of data buffer
     1213 * @return Error code
    12441214 */
    12451215int usb_hid_report_output_translate(usb_hid_report_parser_t *parser,
     
    13411311
    13421312/**
    1343  *
    1344  * @param item
    1345  * @param value
    1346  * @return
     1313 * Translate given data for putting them into the outoput report
     1314 * @param item Report item structure
     1315 * @param value Value to translate
     1316 * @return ranslated value
    13471317 */
    13481318int32_t usb_hid_translate_data_reverse(usb_hid_report_item_t *item, int value)
     
    13891359}
    13901360
    1391 
     1361/**
     1362 * Sets report id in usage path structure
     1363 *
     1364 * @param path Usage path structure
     1365 * @param report_id Report id to set
     1366 * @return Error code
     1367 */
    13921368int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, uint8_t report_id)
    13931369{
     
    14001376}
    14011377
    1402 
     1378/**
     1379 * Clones given report item structure and returns the new one
     1380 *
     1381 * @param item Report item structure to clone
     1382 * @return Clonned item
     1383 */
    14031384usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item)
    14041385{
Note: See TracChangeset for help on using the changeset viewer.