Lines Matching refs:parser

17 static void hid_reset_parser(struct hid_parser *parser);
22 static int *__get_report_offset(struct hid_parser *parser, const uint8_t report_id, const uint8_t r…
81 static void hid_reset_parser(struct hid_parser *parser) in hid_reset_parser() argument
83 memset(parser, 0, sizeof(struct hid_parser)); in hid_reset_parser()
84 parser->data.report_id = 1; // we must give it a non-zero value or the parser doesn't work in hid_reset_parser()
93 static __always_inline void __pop_usage_stack(struct hid_parser *parser) in __pop_usage_stack() argument
95 if (parser->usage_size > 0) in __pop_usage_stack()
97 for (int js = 0; js < parser->usage_size - 1; ++js) in __pop_usage_stack()
98 … memmove(&parser->usage_table[js], &parser->usage_table[js + 1], sizeof(struct hid_node_t)); in __pop_usage_stack()
100 --parser->usage_size; in __pop_usage_stack()
113 static bool hid_parse(struct hid_parser *parser, struct hid_data_t *data) in hid_parse() argument
121 while (!found && (parser->pos < parser->report_desc_size)) in hid_parse()
124 if (parser->count == 0) in hid_parse()
128 printk("\n %02X ", parser->report_desc[parser->pos]); in hid_parse()
130 parser->item = parser->report_desc[parser->pos++]; in hid_parse()
131 parser->value = 0; in hid_parse()
133 …memcpy(&parser->value, &parser->report_desc[parser->pos], item_size[parser->item & HID_SIZE_MASK]); in hid_parse()
139 if (i < item_size[parser->item & HID_SIZE_MASK]) in hid_parse()
140 printk("%02X ", parser->report_desc[parser->pos + i]); in hid_parse()
146 parser->pos += item_size[parser->item & HID_SIZE_MASK]; in hid_parse()
149 switch (parser->item & HID_ITEM_MASK) in hid_parse()
153 parser->u_page = (int)parser->value; in hid_parse()
155 … printk("%sUsage Page (%s)", __spaces(space_cnt), hid_get_usage_page_str(parser->u_page)); in hid_parse()
157 parser->usage_table[parser->usage_size].u_page = parser->u_page; in hid_parse()
158 parser->usage_table[parser->usage_size].usage = 0xff; in hid_parse()
162 if ((parser->item & HID_SIZE_MASK) > 2) // item大小为32字节 in hid_parse()
163 parser->usage_table[parser->usage_size].u_page = (int)(parser->value >> 16); in hid_parse()
165 parser->usage_table[parser->usage_size].u_page = parser->u_page; in hid_parse()
169 hid_get_usage_type_str(parser->u_page, parser->value & 0xffff)); in hid_parse()
170 ++parser->usage_size; in hid_parse()
175 printk("%sUsage min (%i=%s)", __spaces(space_cnt), parser->value, in hid_parse()
176 hid_get_usage_type_str(parser->u_page, parser->value)); in hid_parse()
181 printk("%sUsage max (%i=%s)", __spaces(space_cnt), parser->value, in hid_parse()
182 hid_get_usage_type_str(parser->u_page, parser->value)); in hid_parse()
186 parser->data.path.node[parser->data.path.size].u_page = parser->usage_table[0].u_page; in hid_parse()
187 parser->data.path.node[parser->data.path.size].usage = parser->usage_table[0].usage; in hid_parse()
188 ++parser->data.path.size; in hid_parse()
191 __pop_usage_stack(parser); in hid_parse()
194 if (parser->value >= 0x80) in hid_parse()
197 parser->data.path.node[parser->data.path.size].u_page = 0xff; in hid_parse()
198 parser->data.path.node[parser->data.path.size].usage = parser->value & 0x7f; in hid_parse()
199 ++parser->data.path.size; in hid_parse()
203 … printk("%sCollection (%s)", __spaces(space_cnt), hid_get_collection_str(parser->value)); in hid_parse()
208 --parser->data.path.size; // 为什么要--????? in hid_parse()
210 if (parser->data.path.node[parser->data.path.size].u_page == 0xff) in hid_parse()
211 --parser->data.path.size; in hid_parse()
226 ++parser->cnt_objects; in hid_parse()
229 if (parser->count == 0) in hid_parse()
230 parser->count = parser->report_count; in hid_parse()
233 parser->data.path.node[parser->data.path.size].u_page = parser->usage_table[0].u_page; in hid_parse()
234 parser->data.path.node[parser->data.path.size].usage = parser->usage_table[0].usage; in hid_parse()
235 ++parser->data.path.size; in hid_parse()
238 __pop_usage_stack(parser); in hid_parse()
241 parser->data.type = (uint8_t)(parser->item & HID_ITEM_MASK); in hid_parse()
242 parser->data.attribute = (uint8_t)parser->value; in hid_parse()
244 … __get_report_offset(parser, parser->data.report_id, (uint8_t)(parser->item & HID_ITEM_MASK)); in hid_parse()
251 parser->data.offset = *offset_ptr; in hid_parse()
254 memcpy(data, &parser->data, sizeof(struct hid_data_t)); in hid_parse()
257 *offset_ptr = (*offset_ptr) + parser->data.size; in hid_parse()
260 --parser->data.path.size; in hid_parse()
263 if (parser->count > 0) in hid_parse()
264 --parser->count; in hid_parse()
270 if ((parser->item & HID_ITEM_MASK) == HID_ITEM_FEATURE) in hid_parse()
272 else if ((parser->item & HID_ITEM_MASK) == HID_ITEM_INPUT) in hid_parse()
274 else if ((parser->item & HID_ITEM_MASK) == HID_ITEM_OUTPUT) in hid_parse()
277 … printk("(%s,%s,%s" /* ",%s,%s,%s,%s" */ ")", !(parser->value & (1 << 0)) ? "Data" : "Constant", in hid_parse()
278 !(parser->value & (1 << 1)) ? "Array" : "Variable", in hid_parse()
279 !(parser->value & (1 << 2)) ? "Absolute" : "Relative" /*, in hid_parse()
293 parser->data.report_id = (uint8_t)parser->value; in hid_parse()
295 printk("%sReport ID: %i", __spaces(space_cnt), parser->data.report_id); in hid_parse()
298 parser->data.size = parser->value; in hid_parse()
300 printk("%sReport size (%i)", __spaces(space_cnt), parser->data.size); in hid_parse()
303 parser->report_count = parser->value; in hid_parse()
305 printk("%sReport count (%i)", __spaces(space_cnt), parser->report_count); in hid_parse()
308 parser->data.unit_exp = (int8_t)parser->value; in hid_parse()
309 if (parser->data.unit_exp > 7) in hid_parse()
310 parser->data.unit_exp |= 0xf0; in hid_parse()
312 printk("%sUnit Exp (%i)", __spaces(space_cnt), parser->data.unit_exp); in hid_parse()
315 parser->data.unit = parser->value; in hid_parse()
317 printk("%sUnit (%i)", __spaces(space_cnt), parser->data.unit); in hid_parse()
320parser->data.logical_min = __format_value(parser->value, item_size[parser->item & HID_SIZE_MASK]); in hid_parse()
322 printk("%sLogical Min (%i)", __spaces(space_cnt), parser->data.logical_min); in hid_parse()
325parser->data.logical_max = __format_value(parser->value, item_size[parser->item & HID_SIZE_MASK]); in hid_parse()
327 printk("%sLogical Max (%i)", __spaces(space_cnt), parser->data.logical_max); in hid_parse()
330parser->data.phys_min = __format_value(parser->value, item_size[parser->item & HID_SIZE_MASK]); in hid_parse()
332 printk("%Physical Min (%i)", __spaces(space_cnt), parser->data.phys_min); in hid_parse()
335parser->data.phys_max = __format_value(parser->value, item_size[parser->item & HID_SIZE_MASK]); in hid_parse()
337 printk("%Physical Max (%i)", __spaces(space_cnt), parser->data.phys_max); in hid_parse()
340 printk("\n Found unknown item %#02X\n", parser->item & HID_ITEM_MASK); in hid_parse()
356 struct hid_parser parser = {0}; in hid_parse_report() local
359 hid_reset_parser(&parser); in hid_parse_report()
360 parser.report_desc = (const uint8_t *)report_data; in hid_parse_report()
361 parser.report_desc_size = len; in hid_parse_report()
363 while (hid_parse(&parser, &data)) in hid_parse_report()
498 static int *__get_report_offset(struct hid_parser *parser, const uint8_t report_id, const uint8_t r… in __get_report_offset() argument
502 while ((pos < HID_MAX_REPORT) && (parser->offset_table[pos][0] != 0)) // 当offset的id不为0时 in __get_report_offset()
504 … if ((parser->offset_table[pos][0] == report_id) && (parser->offset_table[pos][1] == report_type)) in __get_report_offset()
505 return &parser->offset_table[pos][2]; in __get_report_offset()
511 ++parser->cnt_report; in __get_report_offset()
512 parser->offset_table[pos][0] = report_id; in __get_report_offset()
513 parser->offset_table[pos][1] = report_type; in __get_report_offset()
514 parser->offset_table[pos][2] = 0; in __get_report_offset()
515 return &parser->offset_table[pos][2]; in __get_report_offset()
521 static __always_inline bool __find_object(struct hid_parser *parser, struct hid_data_t *data) in __find_object() argument
526 while (hid_parse(parser, &found_data)) in __find_object()
547 data->report_count = parser->report_count; in __find_object()
561 struct hid_parser parser = {0}; in hid_parse_find_object() local
562 hid_reset_parser(&parser); in hid_parse_find_object()
563 parser.report_desc = hid_report; in hid_parse_find_object()
564 parser.report_desc_size = report_size; in hid_parse_find_object()
568 if (__find_object(&parser, data)) in hid_parse_find_object()