Get bytes from a HID Report Descriptor. Only call with a num_bytes of 0, 1, 2, or 4. */
| 160 | /* Get bytes from a HID Report Descriptor. |
| 161 | Only call with a num_bytes of 0, 1, 2, or 4. */ |
| 162 | static uint32_t get_bytes(uint8_t *rpt, size_t len, size_t num_bytes, size_t cur) |
| 163 | { |
| 164 | /* Return if there aren't enough bytes. */ |
| 165 | if (cur + num_bytes >= len) |
| 166 | return 0; |
| 167 | |
| 168 | if (num_bytes == 0) |
| 169 | return 0; |
| 170 | else if (num_bytes == 1) { |
| 171 | return rpt[cur+1]; |
| 172 | } |
| 173 | else if (num_bytes == 2) { |
| 174 | return (rpt[cur+2] * 256 + rpt[cur+1]); |
| 175 | } |
| 176 | else if (num_bytes == 4) { |
| 177 | return (rpt[cur+4] * 0x01000000 + |
| 178 | rpt[cur+3] * 0x00010000 + |
| 179 | rpt[cur+2] * 0x00000100 + |
| 180 | rpt[cur+1] * 0x00000001); |
| 181 | } |
| 182 | else |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | /* Retrieves the device's Usage Page and Usage from the report |
| 187 | descriptor. The algorithm is simple, as it just returns the first |