Index: uspace/lib/usb/src/hiddescriptor.c
===================================================================
--- uspace/lib/usb/src/hiddescriptor.c	(revision 3d4aa05551843bc5de66e78e0dd0dbc2c4a21801)
+++ uspace/lib/usb/src/hiddescriptor.c	(revision 1ce4189d8c20ad8d4f1155c953fc3e12908ce6f1)
@@ -41,4 +41,9 @@
 #include <assert.h>
 
+
+#define OUTSIDE_DELIMITER_SET	0
+#define START_DELIMITER_SET	1
+#define INSIDE_DELIMITER_SET	2
+	
 /** The new report item flag. Used to determine when the item is completly
  * configured and should be added to the report structure
@@ -56,31 +61,6 @@
 #define USB_HID_UNKNOWN_TAG		-99
 
-
-/**
- * Initialize the report descriptor parser structure
- *
- * @param parser Report descriptor parser structure
- * @return Error code
- */
-int usb_hid_report_init(usb_hid_report_t *report)
-{
-	if(report == NULL) {
-		return EINVAL;
-	}
-
-	memset(report, 0, sizeof(usb_hid_report_t));
-	list_initialize(&report->reports);
-	list_initialize(&report->collection_paths);
-
-	report->use_report_ids = 0;
-    return EOK;   
-}
-
-int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item)
-{
-	usb_hid_report_field_t *field;
-	int i;
-
-
+usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path)
+{
 	/* find or append current collection path to the list */
 	link_t *path_it = report->collection_paths.next;
@@ -89,5 +69,5 @@
 		path = list_get_instance(path_it, usb_hid_report_path_t, link);
 		
-		if(usb_hid_report_compare_usage_path(path, report_item->usage_path, USB_HID_PATH_COMPARE_STRICT) == EOK){
+		if(usb_hid_report_compare_usage_path(path, cmp_path, USB_HID_PATH_COMPARE_STRICT) == EOK){
 			break;
 		}			
@@ -95,8 +75,44 @@
 	}
 	if(path_it == &report->collection_paths) {
-		path = usb_hid_report_path_clone(report_item->usage_path);			
+		path = usb_hid_report_path_clone(cmp_path);			
 		list_append(&path->link, &report->collection_paths);					
 		report->collection_paths_count++;
-	}
+
+		return path;
+	}
+	else {
+		return list_get_instance(path_it, usb_hid_report_path_t, link);
+	}
+}
+
+/**
+ * Initialize the report descriptor parser structure
+ *
+ * @param parser Report descriptor parser structure
+ * @return Error code
+ */
+int usb_hid_report_init(usb_hid_report_t *report)
+{
+	if(report == NULL) {
+		return EINVAL;
+	}
+
+	memset(report, 0, sizeof(usb_hid_report_t));
+	list_initialize(&report->reports);
+	list_initialize(&report->collection_paths);
+
+	report->use_report_ids = 0;
+    return EOK;   
+}
+
+
+/*
+ *
+ *
+ */
+int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item)
+{
+	usb_hid_report_field_t *field;
+	int i;
 
 	for(i=0; i<report_item->usages_count; i++){
@@ -104,5 +120,5 @@
 	}
 
-	
+	usb_hid_report_path_t *path = report_item->usage_path;	
 	for(i=0; i<report_item->count; i++){
 
@@ -112,5 +128,4 @@
 
 		/* fill the attributes */		
-		field->collection_path = path;
 		field->logical_minimum = report_item->logical_minimum;
 		field->logical_maximum = report_item->logical_maximum;
@@ -129,19 +144,9 @@
 		if(report_item->usages_count > 0 && ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) {
 			uint32_t usage;
-			if(report_item->type != USB_HID_REPORT_TYPE_OUTPUT) {
-				if(i < report_item->usages_count){
-					usage = report_item->usages[i];
-				}
-				else {
-					usage = report_item->usages[report_item->usages_count - 1];
-				}
+			if(i < report_item->usages_count){
+				usage = report_item->usages[i];
 			}
 			else {
-				if((report_item->count - i - 1) < report_item->usages_count){
-					usage = report_item->usages[(report_item->count - i - 1)];
-				}
-				else {
-					usage = report_item->usages[report_item->usages_count - 1];
-				}
+				usage = report_item->usages[report_item->usages_count - 1];
 			}
 
@@ -159,15 +164,18 @@
 
 		if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) != 0) && (!((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0)))) {
-			if(report_item->type == USB_HID_REPORT_TYPE_INPUT) {
-				field->usage = report_item->usage_maximum - i;
-			}
-			else {
-				field->usage = report_item->usage_minimum + i;					
-			}
-
-		}
-		
+			field->usage = report_item->usage_minimum + i;					
+		}
+		
+		usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_GLOBAL, field->usage_page);
+		usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_LOCAL, field->usage);
+
+		field->collection_path = usb_hid_report_path_try_insert(report, path);
+
 		field->size = report_item->size;
-		field->offset = report_item->offset + (i * report_item->size);
+		
+		size_t offset_byte = (report_item->offset + (i * report_item->size)) / 8;
+		size_t offset_bit = 8 - ((report_item->offset + (i * report_item->size)) % 8) - report_item->size;
+
+		field->offset = 8 * offset_byte + offset_bit;
 		if(report_item->id != 0) {
 			field->offset += 8;
@@ -264,4 +272,5 @@
 		return ENOMEM;
 	}
+	usb_hid_report_path_append_item(usage_path, 0, 0);	
 	
 	while(i<size){	
@@ -349,5 +358,6 @@
 					tmp_usage_path = list_get_instance(report_item->usage_path->link.prev, usb_hid_report_usage_path_t, link);
 					
-					usb_hid_report_set_last_item(usage_path, tmp_usage_path->usage_page, tmp_usage_path->usage);
+					usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, tmp_usage_path->usage_page);
+					usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, tmp_usage_path->usage);
 
 					usb_hid_report_path_free(report_item->usage_path);
@@ -438,6 +448,17 @@
 			
 		case USB_HID_REPORT_TAG_COLLECTION:
-			// TODO usage_path->flags = *data;
-			usb_hid_report_path_append_item(usage_path, report_item->usage_page, report_item->usages[report_item->usages_count-1]);						
+			//TODO: usage_path->flags = *data;
+			
+			usb_log_debug("APPENDED ITEM TO USAGE PATH (PAGE %d, USAGE %d\n", report_item->usage_page, report_item->usages[report_item->usages_count-1]);
+			usb_hid_print_usage_path(usage_path);
+
+			// set last item
+			usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, report_item->usage_page);
+			usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, report_item->usages[report_item->usages_count-1]);
+			// append the new one which will be set by common
+			// usage/usage page
+			usb_hid_report_path_append_item(usage_path, report_item->usage_page, report_item->usages[report_item->usages_count-1]);	
+			usb_hid_print_usage_path(usage_path);
+
 			usb_hid_report_reset_local_items (report_item);
 			return USB_HID_NO_ACTION;
@@ -575,7 +596,11 @@
 			break;			
 		case USB_HID_REPORT_TAG_DELIMITER:
-			//report_item->delimiter = usb_hid_report_tag_data_uint32(data,item_size);
-			//TODO: 
-			//	DELIMITER STUFF
+			if (report_item->in_delimiter == OUTSIDE_DELIMITER_SET) {
+				report_item->in_delimiter = START_DELIMITER_SET;
+			}
+			else {
+				report_item->in_delimiter = OUTSIDE_DELIMITER_SET;
+			}
+			
 			break;
 		
@@ -629,5 +654,5 @@
 
 		usb_log_debug("\t\tOFFSET: %X\n", report_item->offset);
-		usb_log_debug("\t\tSIZE: %zu\n", report_item->size);
+		usb_log_debug("\t\tSIZE: %X\n", report_item->size);				
 		usb_log_debug("\t\tLOGMIN: %d\n", report_item->logical_minimum);
 		usb_log_debug("\t\tLOGMAX: %d\n", report_item->logical_maximum);		
@@ -640,6 +665,8 @@
 		usb_log_debug("\t\ttUSAGE: %X\n", report_item->usage);
 		usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page);
-						
-//		usb_log_debug("\n");		
+		
+		//usb_hid_print_usage_path(report_item->collection_path);
+
+		usb_log_debug("\n");		
 
 	}
@@ -666,6 +693,6 @@
 		usb_log_debug("Report ID: %d\n", report_des->report_id);
 		usb_log_debug("\tType: %d\n", report_des->type);
-		usb_log_debug("\tLength: %zu\n", report_des->bit_length);
-		usb_log_debug("\tItems: %zu\n", report_des->item_length);
+		usb_log_debug("\tLength: %d\n", report_des->bit_length);		
+		usb_log_debug("\tItems: %d\n", report_des->item_length);		
 
 		usb_hid_descriptor_print_list(&report_des->report_items);
Index: uspace/lib/usb/src/hidparser.c
===================================================================
--- uspace/lib/usb/src/hidparser.c	(revision 3d4aa05551843bc5de66e78e0dd0dbc2c4a21801)
+++ uspace/lib/usb/src/hidparser.c	(revision 1ce4189d8c20ad8d4f1155c953fc3e12908ce6f1)
@@ -405,5 +405,5 @@
 				}
 
-				size_t shift = offset%8;
+				size_t shift = 8 - offset%8 - length;
 
 				value = value << shift;							
