/usr/include/hidrd/item/short.h is in libhidrd0-dev 0.2.0-11.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 | /** @file
* @brief HID report descriptor - short item
*
* Copyright (C) 2009 Nikolai Kondrashov
*
* This file is part of hidrd.
*
* Hidrd is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Hidrd is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with hidrd; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @author Nikolai Kondrashov <spbnick@gmail.com>
*
* @(#) $Id: short.h 413 2010-05-12 19:31:17Z spb_nick $
*/
#ifndef __HIDRD_ITEM_SHORT_H__
#define __HIDRD_ITEM_SHORT_H__
#include <assert.h>
#include "hidrd/cfg.h"
#include "hidrd/item/basic.h"
#include "hidrd/util/bit.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Minimum size of a short item */
#define HIDRD_ITEM_SHORT_MIN_SIZE 1
/** Maximum size of a short item data, in bytes */
#define HIDRD_ITEM_SHORT_DATA_BYTES_MAX 4
/** Maximum size of a short item */
#define HIDRD_ITEM_SHORT_MAX_SIZE (HIDRD_ITEM_SHORT_MIN_SIZE + \
HIDRD_ITEM_SHORT_DATA_BYTES_MAX)
/** Short item type */
typedef hidrd_item_basic_type hidrd_item_short_type;
#define HIDRD_ITEM_SHORT_TYPE_MAIN HIDRD_ITEM_BASIC_TYPE_MAIN
#define HIDRD_ITEM_SHORT_TYPE_GLOBAL HIDRD_ITEM_BASIC_TYPE_GLOBAL
#define HIDRD_ITEM_SHORT_TYPE_LOCAL HIDRD_ITEM_BASIC_TYPE_LOCAL
/**
* Check if a short item type is valid.
*
* @param type Short item type to check.
*
* @return True if the type is valid, false otherwise.
*/
static inline bool
hidrd_item_short_type_valid(hidrd_item_short_type type)
{
switch (type)
{
case HIDRD_ITEM_SHORT_TYPE_MAIN:
case HIDRD_ITEM_SHORT_TYPE_GLOBAL:
case HIDRD_ITEM_SHORT_TYPE_LOCAL:
return true;
default:
return false;
}
}
/* Declare type numeric string conversion functions */
HIDRD_NUM_CONV_DECLS(item_short_type);
#ifdef HIDRD_WITH_TOKENS
/* Declare type token conversion functions */
HIDRD_TKN_CONV_DECLS(item_short_type);
#endif /* HIDRD_WITH_TOKENS */
/** Short item tag */
typedef hidrd_item_basic_tag hidrd_item_short_tag;
#define HIDRD_ITEM_SHORT_TAG_MIN HIDRD_ITEM_BASIC_TAG_MIN
#define HIDRD_ITEM_SHORT_TAG_MAX HIDRD_ITEM_BASIC_TAG_MAX
/**
* Check if a short item tag is valid.
*
* @param tag Short item tag to check.
*
* @return True if the tag is valid, false otherwise.
*/
static inline bool
hidrd_item_short_tag_valid(hidrd_item_short_tag tag)
{
return hidrd_item_basic_tag_valid(tag);
}
/* Declare tag numeric string conversion functions */
HIDRD_NUM_CONV_DECLS(item_short_tag);
/** Short item data size code */
typedef hidrd_item_basic_data_size hidrd_item_short_data_size;
#define HIDRD_ITEM_SHORT_DATA_SIZE_0B HIDRD_ITEM_BASIC_DATA_SIZE_0B
#define HIDRD_ITEM_SHORT_DATA_SIZE_1B HIDRD_ITEM_BASIC_DATA_SIZE_1B
#define HIDRD_ITEM_SHORT_DATA_SIZE_2B HIDRD_ITEM_BASIC_DATA_SIZE_2B
#define HIDRD_ITEM_SHORT_DATA_SIZE_4B HIDRD_ITEM_BASIC_DATA_SIZE_4B
/**
* Check if a short item data size code is valid.
*
* @param size Short item data size code to check.
*
* @return True if the size code is valid, false otherwise.
*/
static inline bool
hidrd_item_short_data_size_valid(hidrd_item_short_data_size size)
{
return hidrd_item_basic_data_size_valid(size);
}
/** Short item data size in bytes */
typedef hidrd_item_basic_data_bytes hidrd_item_short_data_bytes;
/**
* Check if a short item data size in bytes is valid.
*
* @return Short item data size in bytes to check.
*
* @return True if data size in bytes is valid, false otherwise.
*/
static inline bool
hidrd_item_short_data_bytes_valid(hidrd_item_short_data_bytes bytes)
{
return hidrd_item_basic_data_bytes_valid(bytes);
}
/**
* Convert short item data size code to bytes.
*
* @param size Short item data size code.
*
* @return Short item data size to bytes.
*/
static inline hidrd_item_short_data_bytes
hidrd_item_short_data_size_to_bytes(hidrd_item_short_data_size size)
{
return hidrd_item_basic_data_size_to_bytes(size);
}
/**
* Convert short item data size from bytes to code.
*
* @param bytes Short item data size in bytes.
*
* @return Short item data size code.
*/
static inline hidrd_item_short_data_size
hidrd_item_short_data_size_from_bytes(hidrd_item_short_data_bytes bytes)
{
return hidrd_item_basic_data_size_from_bytes(bytes);
}
/* Declare numeric string conversion functions for data size in bytes */
HIDRD_NUM_CONV_DECLS(item_short_data_bytes);
/**
* Check if a short item class identification is valid.
*
* @param item Item to check the class identification of.
*
* @return True if the item class identification matches short, false
* otherwise.
*/
static inline bool
hidrd_item_short_valid_class(const hidrd_item *item)
{
return hidrd_item_basic_valid_class(item) &&
hidrd_item_basic_is_short(item);
}
/**
* Check if a short item instance data is valid.
*
* @param item Item to check the instance data of.
*
* @return True if the short item instance data is valid, false otherwise.
*/
static inline bool
hidrd_item_short_valid_inst(const hidrd_item *item)
{
assert(hidrd_item_short_valid_class(item));
return hidrd_item_basic_valid_inst(item);
}
/**
* Check if an item is short and its instance data is valid.
*
* @param item Item to check the validity of.
*
* @return True if the item is valid, false otherwise.
*/
static inline bool
hidrd_item_short_valid(const hidrd_item *item)
{
return hidrd_item_short_valid_class(item) &&
hidrd_item_short_valid_inst(item);
}
/**
* Validate item as short.
*
* @param item Item to validate.
*
* @return Validated item.
*/
static inline hidrd_item *
hidrd_item_short_validate(hidrd_item *item)
{
assert(hidrd_item_short_valid(item));
return item;
}
/**
* Get a short item type.
*
* @param item Short item to get type from.
*
* @return Short item type.
*/
static inline hidrd_item_short_type
hidrd_item_short_get_type(const hidrd_item *item)
{
assert(hidrd_item_short_valid(item));
return hidrd_item_basic_get_type(item);
}
/**
* Set a short item type.
*
* @param item Short item to set type to.
* @param type Short item type to set.
*
* @return The item with the type set.
*/
static inline hidrd_item *
hidrd_item_short_set_type(hidrd_item *item, hidrd_item_short_type type)
{
assert(hidrd_item_short_valid(item));
assert(hidrd_item_short_type_valid(type));
return hidrd_item_basic_set_type(item, type);
}
/**
* Get a short item tag.
*
* @param item Short item to get tag from.
*
* @return Short item tag.
*/
static inline hidrd_item_short_tag
hidrd_item_short_get_tag(const hidrd_item *item)
{
assert(hidrd_item_short_valid(item));
return hidrd_item_basic_get_tag(item);
}
/**
* Set a short item tag.
*
* @param item Short item to set tag to.
* @param tag Short item tag to set.
*
* @return The item with the tag set.
*/
static inline hidrd_item *
hidrd_item_short_set_tag(hidrd_item *item, hidrd_item_short_tag tag)
{
assert(hidrd_item_short_valid(item));
assert(hidrd_item_short_tag_valid(tag));
return hidrd_item_basic_set_tag(item, tag);
}
/**
* Get a short item data size code.
*
* @param item Short item to get data size code from.
*
* @return Short item data size code.
*/
static inline hidrd_item_short_data_size
hidrd_item_short_get_data_size(const hidrd_item *item)
{
assert(hidrd_item_short_valid(item));
return hidrd_item_basic_get_data_size(item);
}
/**
* Get a short item data size in bytes.
*
* @param item Short item to get data size from.
*
* @return Short item data size in bytes.
*/
static inline size_t
hidrd_item_short_get_data_bytes(const hidrd_item *item)
{
assert(hidrd_item_short_valid(item));
return hidrd_item_short_data_size_to_bytes(
hidrd_item_short_get_data_size(item));
}
/**
* Set a short item data size code.
*
* @param item Short item to set data size code to.
* @param size Short item data size code to set.
*
* @return The item with the data size code set.
*/
static inline hidrd_item *
hidrd_item_short_set_data_size(hidrd_item *item,
hidrd_item_short_data_size size)
{
assert(hidrd_item_short_valid(item));
assert(hidrd_item_short_data_size_valid(size));
return hidrd_item_basic_set_data_size(item, size);
}
/**
* Get data pointer of a short item.
*
* @param item Short item to get data pointer of.
*
* @return Data pointer.
*/
static inline void *
hidrd_item_short_get_data(hidrd_item *item)
{
assert(hidrd_item_short_valid(item));
return hidrd_item_basic_get_data(item);
}
/**
* Get short item size.
*
* @param item Short item to get size of.
*
* @return The item size.
*/
static inline size_t
hidrd_item_short_get_size(const hidrd_item *item)
{
assert(hidrd_item_short_valid(item));
return 1 + hidrd_item_short_data_size_to_bytes(
hidrd_item_short_get_data_size(item));
}
/**
* Get short item data as an unsigned integer.
*
* @param item Short item to get data from.
*
* @return Short item data as an unsigned integer.
*/
extern uint32_t hidrd_item_short_get_unsigned(const hidrd_item *item);
/**
* Set short item data as an unsigned integer.
*
* @param item Short item to set data to.
* @param data Short item data as an unsigned integer.
*
* @return The item with the data set.
*/
extern hidrd_item* hidrd_item_short_set_unsigned(hidrd_item *item,
uint32_t data);
/**
* Get short item data as a signed integer.
*
* @param item Short item to get data from.
*
* @return Short item data as a signed integer.
*/
extern int32_t hidrd_item_short_get_signed(const hidrd_item *item);
/**
* Set short item data as a signed integer.
*
* @param item Short item to set data to.
* @param data Short item data as a signed integer.
*
* @return The item with the data set.
*/
extern hidrd_item* hidrd_item_short_set_signed(hidrd_item *item,
int32_t data);
/**
* Get value of a short item data bit.
*
* @param item Short item to get data from.
* @param idx Bit index to get value of.
*
* @return The data bit value.
*/
static inline bool
hidrd_item_short_get_bit(const hidrd_item *item, uint8_t idx)
{
assert(hidrd_item_short_valid(item));
assert(idx <= 31);
return HIDRD_BIT_GET(hidrd_item_short_get_unsigned(item), idx) != 0;
}
/**
* Set value of a short item data bit.
*
* @param item Short item to set data to.
* @param idx Bit index to set value of.
* @param val Bit value; any non-zero value considered 1.
*
* @return The item with the data bit set.
*/
static inline hidrd_item *
hidrd_item_short_set_bit(hidrd_item *item, uint8_t idx, bool val)
{
assert(hidrd_item_short_valid(item));
assert(idx <= 31);
return hidrd_item_short_set_unsigned(
item,
HIDRD_BIT_SET(hidrd_item_short_get_unsigned(item), idx, val));
}
/**
* Initialize a short item.
*
* @param item An item to initialize as short.
* @param type Short item type to set.
* @param tag Short item tag to set.
*
* @return The item initialized as short.
*/
static inline hidrd_item *
hidrd_item_short_init(hidrd_item *item,
hidrd_item_short_type type,
hidrd_item_short_tag tag)
{
assert(hidrd_item_short_type_valid(type));
assert(hidrd_item_short_tag_valid(tag));
return hidrd_item_short_validate(
hidrd_item_basic_init(item, type, tag, 0));
}
/**
* Initialize a short item with data specified as a signed integer.
*
* @param item An item to initialize as short.
* @param type Short item type to set.
* @param tag Short item tag to set.
* @param data Short item data as a signed integer.
*
* @return The item initialized as short.
*/
static inline hidrd_item *
hidrd_item_short_init_signed(hidrd_item *item,
hidrd_item_short_type type,
hidrd_item_short_tag tag,
int32_t data)
{
assert(hidrd_item_short_type_valid(type));
assert(hidrd_item_short_tag_valid(tag));
return hidrd_item_short_set_signed(
hidrd_item_short_init(item, type, tag), data);
}
/**
* Initialize a short item with data specified as an unsigned integer.
*
* @param item An item to initialize as short.
* @param type Short item type to set.
* @param tag Short item tag to set.
* @param data Short item data as an unsigned integer.
*
* @return The item initialized as short.
*/
static inline hidrd_item *
hidrd_item_short_init_unsigned(hidrd_item *item,
hidrd_item_short_type type,
hidrd_item_short_tag tag,
uint32_t data)
{
assert(hidrd_item_short_type_valid(type));
assert(hidrd_item_short_tag_valid(tag));
return hidrd_item_short_set_unsigned(
hidrd_item_short_init(item, type, tag), data);
}
#define HIDRD_ITEM_SHORT_GEN_CORE_FUNCS(_name, _NAME) \
static inline bool \
hidrd_item_##_name##_valid_class(const hidrd_item *item) \
{ \
return hidrd_item_short_valid_class(item) && \
(hidrd_item_short_get_type(item) == \
HIDRD_ITEM_SHORT_TYPE_##_NAME); \
} \
\
static inline bool \
hidrd_item_##_name##_valid_inst(const hidrd_item *item) \
{ \
assert(hidrd_item_##_name##_valid_class(item)); \
return hidrd_item_short_valid_inst(item) && \
hidrd_item_##_name##_tag_valid( \
hidrd_item_short_get_tag(item)); \
} \
\
static inline bool \
hidrd_item_##_name##_valid(const hidrd_item *item) \
{ \
return hidrd_item_##_name##_valid_class(item) && \
hidrd_item_##_name##_valid_inst(item); \
} \
\
static inline hidrd_item * \
hidrd_item_##_name##_validate(hidrd_item *item) \
{ \
assert(hidrd_item_##_name##_valid(item)); \
return item; \
} \
\
static inline hidrd_item_##_name##_tag \
hidrd_item_##_name##_get_tag(const hidrd_item *item) \
{ \
assert(hidrd_item_##_name##_valid(item)); \
return hidrd_item_short_get_tag(item); \
} \
\
static inline hidrd_item * \
hidrd_item_##_name##_set_tag(hidrd_item *item, \
hidrd_item_##_name##_tag tag) \
{ \
assert(hidrd_item_##_name##_valid(item)); \
return hidrd_item_short_set_tag(item, tag); \
} \
\
/* Declare tag numeric string conversion functions */ \
HIDRD_NUM_CONV_DECLS(item_##_name##_tag); \
\
static inline hidrd_item * \
hidrd_item_##_name##_init(hidrd_item *item, \
hidrd_item_##_name##_tag tag) \
{ \
assert(hidrd_item_##_name##_tag_valid(tag)); \
\
return hidrd_item_##_name##_validate( \
hidrd_item_short_init(item, \
HIDRD_ITEM_SHORT_TYPE_##_NAME, \
tag)); \
} \
\
static inline int32_t \
hidrd_item_##_name##_get_signed(const hidrd_item *item) \
{ \
assert(hidrd_item_##_name##_valid(item)); \
\
return hidrd_item_short_get_signed(item); \
} \
\
static inline uint32_t \
hidrd_item_##_name##_get_unsigned(const hidrd_item *item) \
{ \
assert(hidrd_item_##_name##_valid(item)); \
\
return hidrd_item_short_get_unsigned(item); \
} \
\
static inline hidrd_item * \
hidrd_item_##_name##_set_signed(hidrd_item *item, int32_t data) \
{ \
assert(hidrd_item_##_name##_valid(item)); \
\
return hidrd_item_short_set_signed(item, data); \
} \
\
static inline hidrd_item * \
hidrd_item_##_name##_set_unsigned(hidrd_item *item, uint32_t data) \
{ \
assert(hidrd_item_##_name##_valid(item)); \
\
return hidrd_item_short_set_unsigned(item, data); \
} \
\
static inline hidrd_item * \
hidrd_item_##_name##_init_signed(hidrd_item *item, \
hidrd_item_##_name##_tag tag, \
int32_t data) \
{ \
assert(hidrd_item_##_name##_tag_valid(tag)); \
\
return hidrd_item_##_name##_validate( \
hidrd_item_##_name##_set_signed( \
hidrd_item_##_name##_init(item, tag), data)); \
} \
\
static inline hidrd_item * \
hidrd_item_##_name##_init_unsigned(hidrd_item *item, \
hidrd_item_##_name##_tag tag, \
uint32_t data) \
{ \
assert(hidrd_item_##_name##_tag_valid(tag)); \
\
return hidrd_item_##_name##_validate( \
hidrd_item_##_name##_set_unsigned( \
hidrd_item_##_name##_init(item, tag), data)); \
}
#ifdef HIDRD_WITH_TOKENS
#define HIDRD_ITEM_SHORT_GEN_TOKEN_FUNCS(_name) \
/* Declare tag token conversion functions */ \
HIDRD_TKN_CONV_DECLS(item_##_name##_tag);
#else
#define HIDRD_ITEM_SHORT_GEN_TOKEN_FUNCS(_name)
#endif
#define HIDRD_ITEM_SHORT_GEN_FUNCS(_name, _NAME) \
HIDRD_ITEM_SHORT_GEN_CORE_FUNCS(_name, _NAME) \
HIDRD_ITEM_SHORT_GEN_TOKEN_FUNCS(_name)
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __HIDRD_ITEM_SHORT_H__ */
|