Skip to content

Instantly share code, notes, and snippets.

@Pillar1989
Last active September 12, 2023 01:06
Show Gist options
  • Save Pillar1989/df2615ab29bf9c98f90775ce41635c10 to your computer and use it in GitHub Desktop.
Save Pillar1989/df2615ab29bf9c98f90775ce41635c10 to your computer and use it in GitHub Desktop.
TinyUSB UPS
/*********************************************************************
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
MIT license, check LICENSE for more information
Copyright (c) 2019 Ha Thach for Adafruit Industries
All text above, and the splash screen below must be included in
any redistribution
*********************************************************************/
/* This example demonstrate HID Generic raw Input & Output.
* It will receive data from Host (In endpoint) and echo back (Out endpoint).
* HID Report descriptor use vendor for usage page (using template TUD_HID_REPORT_DESC_GENERIC_INOUT)
*
* There are 2 ways to test the sketch
* 1. Using nodejs
* - Install nodejs and npm to your PC
*
* - Install excellent node-hid (https://github.com/node-hid/node-hid) by
* $ npm install node-hid
*
* - Run provided hid test script
* $ node hid_test.js
*
* 2. Using python
* - Install `hid` package (https://pypi.org/project/hid/) by
* $ pip install hid
*
* - hid package replies on hidapi (https://github.com/libusb/hidapi) for backend,
* which already available in Linux. However on windows, you may need to download its dlls from their release page and
* copy it over to folder where python is installed.
*
* - Run provided hid test script to send and receive data to this device.
* $ python3 hid_test.py
*/
/*
refer to:
1, https://electronics.stackexchange.com/questions/662073/custom-hid-ups-not-detected-by-upower-in-linux
*/
/*
(py39) baozhu@bz:/tmp/Adafruit_TinyUSB_Arduino (master)$ lsusb
Bus 006 Device 002: ID 05e3:0626 Genesys Logic, Inc. USB3.1 Hub
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 124: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
05 84 09 04 A1 01 09 24 A1 00 85 01 09 FE 79 02
75 08 95 01 15 00 26 FF 00 B1 22 85 02 09 FF 79
03 B1 22 85 03 05 85 09 89 79 04 B1 22 85 04 09
8F 79 01 B1 22 85 05 09 8B B1 22 85 0A 05 84 09
FD 75 08 26 FF 00 65 00 55 00 79 01 B1 22 85 0B
05 85 09 2C B1 03 75 08 85 0C 09 66 25 FF B1 A2
09 66 81 A2 85 0D 09 83 75 08 25 64 65 00 B1 22
85 0E 09 67 B1 22 85 0F 09 68 75 10 27 FF FF 00
00 66 01 10 B1 A2 85 11 75 08 05 85 09 29 15 01
B1 A2 85 13 09 D0 15 00 25 01 81 A2 09 D0 B1 A2
85 14 09 42 81 A2 09 42 B1 A2 85 15 05 84 09 57
75 10 16 FF FF 26 FF 7F 66 01 10 B1 A2 85 17 05
85 09 2A 95 01 75 10 27 FF FF 00 00 66 01 10 B1
A2 85 18 05 84 09 5A 75 08 15 01 25 03 65 00 B1
A2 09 02 A1 02 85 16 05 85 65 00 75 01 15 00 25
01 09 44 81 A2 09 44 B1 A2 09 45 81 A2 09 45 B1
A2 09 D0 81 A2 09 D0 B1 A2 09 D1 81 A2 09 D1 B1
A2 05 84 09 69 81 A2 09 69 B1 A2 05 85 09 43 81
A2 09 43 B1 A2 05 85 09 4B 81 A2 09 4B B1 A2 05
84 09 65 81 A2 09 65 B1 A2 05 85 09 DB 81 A2 09
DB B1 A2 95 17 81 01 B1 01 C0 C0 05 84 09 12 A1
00 95 01 85 20 05 85 09 85 75 10 15 00 27 FF FF
00 00 81 22 09 85 B1 A2 85 21 05 84 09 58 75 08
25 06 81 A2 09 58 B1 A2 85 22 05 85 09 66 25 FF
B1 A2 85 23 09 68 75 10 27 FF FF 00 00 66 01 10
B1 A2 85 24 09 2A B1 A2 85 25 05 84 09 40 67 21
D1 F0 00 55 05 B1 22 85 26 09 30 B1 A2 C0 05 84
09 1A A1 00 85 30 05 84 09 40 75 08 15 00 26 FF
00 67 21 D1 F0 00 55 07 B1 22 85 31 09 30 75 10
B1 A2 85 32 09 53 16 A0 00 26 C4 00 B1 A2 85 33
09 54 16 00 01 26 16 01 B1 A2 85 35 75 08 06 86
FF 09 61 15 00 25 02 B1 A2 85 36 09 52 25 0D B1
A2 C0 09 05 A1 00 85 40 09 7C 25 FF B1 A2 C0 05
84 09 16 A1 00 85 50 09 35 75 08 15 00 25 64 65
00 55 00 B1 A2 85 52 05 84 09 44 75 10 15 00 27
FF FF 00 00 66 21 D1 55 07 B1 A2 C0 85 7F 05 84
09 FE 79 05 75 08 95 01 15 00 26 FF 00 65 00 55
00 B1 22 85 7E 06 86 FF 09 42 79 07 75 08 95 01
15 00 26 FF 00 B1 22 85 7D 05 84 09 FF 79 03 B1
22 85 7C 09 FD 79 01 B1 22 85 7B 05 85 09 85 75
10 27 FF FF 00 00 B1 A2 05 84 09 02 A1 02 85 7A
05 85 09 44 75 01 25 01 B1 A2 09 45 B1 A2 09 D0
B1 A2 09 D1 B1 A2 05 85 09 4B B1 A2 05 85 09 DB
B1 A2 05 84 09 65 B1 A2 95 19 B1 01 C0 85 78 05
84 09 5A 75 08 95 01 15 01 25 03 B1 A2 06 FF FF
09 FF A1 02 85 E3 09 EF 75 08 95 07 26 FF 00 15
00 81 82 09 EF B1 82 C0 C0
*/
#include "Adafruit_TinyUSB.h"
// HID report descriptor using TinyUSB's template
// Generic In Out with 64 bytes report (max)
uint8_t const desc_hid_report[] =
{
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0x04, // Usage (0x04)
0xA1, 0x01, // Collection (Application)
0x09, 0x24, // Usage (0x24)
0xA1, 0x00, // Collection (Physical)
0x85, 0x01, // Report ID (1)
0x09, 0xFE, // Usage (0xFE)
0x79, 0x02, // String Index (2)
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0xB1, 0x22, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Non-volatile)
0x85, 0x02, // Report ID (2)
0x09, 0xFF, // Usage (0xFF)
0x79, 0x03, // String Index (3)
0xB1, 0x22, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Non-volatile)
0x85, 0x03, // Report ID (3)
0x05, 0x85, // Usage Page (Power Pages)
0x09, 0x89, // Usage (0x89)
0x79, 0x04, // String Index (4)
0xB1, 0x22, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Non-volatile)
0x85, 0x04, // Report ID (4)
0x09, 0x8F, // Usage (0x8F)
0x79, 0x01, // String Index (1)
0xB1, 0x22, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Non-volatile)
0x85, 0x05, // Report ID (5)
0x09, 0x8B, // Usage (0x8B)
0xB1, 0x22, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Non-volatile)
0x85, 0x0A, // Report ID (10)
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0xFD, // Usage (0xFD)
0x75, 0x08, // Report Size (8)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x65, 0x00, // Unit (None)
0x55, 0x00, // Unit Exponent (0)
0x79, 0x01, // String Index (1)
0xB1, 0x22, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Non-volatile)
0x85, 0x0B, // Report ID (11)
0x05, 0x85, // Usage Page (Power Pages)
0x09, 0x2C, // Usage (0x2C)
0xB1, 0x03, // Feature (Const,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0x75, 0x08, // Report Size (8)
0x85, 0x0C, // Report ID (12)
0x09, 0x66, // Usage (0x66)
0x25, 0xFF, // Logical Maximum (-1)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x09, 0x66, // Usage (0x66)
0x81, 0xA2, // Input (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position)
0x85, 0x0D, // Report ID (13)
0x09, 0x83, // Usage (0x83)
0x75, 0x08, // Report Size (8)
0x25, 0x64, // Logical Maximum (100)
0x65, 0x00, // Unit (None)
0xB1, 0x22, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Non-volatile)
0x85, 0x0E, // Report ID (14)
0x09, 0x67, // Usage (0x67)
0xB1, 0x22, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Non-volatile)
0x85, 0x0F, // Report ID (15)
0x09, 0x68, // Usage (0x68)
0x75, 0x10, // Report Size (16)
0x27, 0xFF, 0xFF, 0x00, 0x00, // Logical Maximum (65534)
0x66, 0x01, 0x10, // Unit (System: SI Linear, Time: Seconds)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x85, 0x11, // Report ID (17)
0x75, 0x08, // Report Size (8)
0x05, 0x85, // Usage Page (Power Pages)
0x09, 0x29, // Usage (0x29)
0x15, 0x01, // Logical Minimum (1)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x85, 0x13, // Report ID (19)
0x09, 0xD0, // Usage (0xD0)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x81, 0xA2, // Input (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position)
0x09, 0xD0, // Usage (0xD0)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x85, 0x14, // Report ID (20)
0x09, 0x42, // Usage (0x42)
0x81, 0xA2, // Input (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position)
0x09, 0x42, // Usage (0x42)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x85, 0x15, // Report ID (21)
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0x57, // Usage (0x57)
0x75, 0x10, // Report Size (16)
0x16, 0xFF, 0xFF, // Logical Minimum (-1)
0x26, 0xFF, 0x7F, // Logical Maximum (32767)
0x66, 0x01, 0x10, // Unit (System: SI Linear, Time: Seconds)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x85, 0x17, // Report ID (23)
0x05, 0x85, // Usage Page (Power Pages)
0x09, 0x2A, // Usage (0x2A)
0x95, 0x01, // Report Count (1)
0x75, 0x10, // Report Size (16)
0x27, 0xFF, 0xFF, 0x00, 0x00, // Logical Maximum (65534)
0x66, 0x01, 0x10, // Unit (System: SI Linear, Time: Seconds)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x85, 0x18, // Report ID (24)
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0x5A, // Usage (0x5A)
0x75, 0x08, // Report Size (8)
0x15, 0x01, // Logical Minimum (1)
0x25, 0x03, // Logical Maximum (3)
0x65, 0x00, // Unit (None)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x09, 0x02, // Usage (0x02)
0xA1, 0x02, // Collection (Logical)
0x85, 0x16, // Report ID (22)
0x05, 0x85, // Usage Page (Power Pages)
0x65, 0x00, // Unit (None)
0x75, 0x01, // Report Size (1)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x09, 0x44, // Usage (0x44)
0x81, 0xA2, // Input (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position)
0x09, 0x44, // Usage (0x44)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x09, 0x45, // Usage (0x45)
0x81, 0xA2, // Input (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position)
0x09, 0x45, // Usage (0x45)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x09, 0xD0, // Usage (0xD0)
0x81, 0xA2, // Input (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position)
0x09, 0xD0, // Usage (0xD0)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x09, 0xD1, // Usage (0xD1)
0x81, 0xA2, // Input (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position)
0x09, 0xD1, // Usage (0xD1)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0x69, // Usage (0x69)
0x81, 0xA2, // Input (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position)
0x09, 0x69, // Usage (0x69)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x05, 0x85, // Usage Page (Power Pages)
0x09, 0x43, // Usage (0x43)
0x81, 0xA2, // Input (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position)
0x09, 0x43, // Usage (0x43)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x05, 0x85, // Usage Page (Power Pages)
0x09, 0x4B, // Usage (0x4B)
0x81, 0xA2, // Input (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position)
0x09, 0x4B, // Usage (0x4B)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0x65, // Usage (0x65)
0x81, 0xA2, // Input (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position)
0x09, 0x65, // Usage (0x65)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x05, 0x85, // Usage Page (Power Pages)
0x09, 0xDB, // Usage (0xDB)
0x81, 0xA2, // Input (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position)
0x09, 0xDB, // Usage (0xDB)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x95, 0x17, // Report Count (23)
0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
0xB1, 0x01, // Feature (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0xC0, // End Collection
0xC0, // End Collection
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0x12, // Usage (0x12)
0xA1, 0x00, // Collection (Physical)
0x95, 0x01, // Report Count (1)
0x85, 0x20, // Report ID (32)
0x05, 0x85, // Usage Page (Power Pages)
0x09, 0x85, // Usage (0x85)
0x75, 0x10, // Report Size (16)
0x15, 0x00, // Logical Minimum (0)
0x27, 0xFF, 0xFF, 0x00, 0x00, // Logical Maximum (65534)
0x81, 0x22, // Input (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position)
0x09, 0x85, // Usage (0x85)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x85, 0x21, // Report ID (33)
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0x58, // Usage (0x58)
0x75, 0x08, // Report Size (8)
0x25, 0x06, // Logical Maximum (6)
0x81, 0xA2, // Input (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position)
0x09, 0x58, // Usage (0x58)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x85, 0x22, // Report ID (34)
0x05, 0x85, // Usage Page (Power Pages)
0x09, 0x66, // Usage (0x66)
0x25, 0xFF, // Logical Maximum (-1)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x85, 0x23, // Report ID (35)
0x09, 0x68, // Usage (0x68)
0x75, 0x10, // Report Size (16)
0x27, 0xFF, 0xFF, 0x00, 0x00, // Logical Maximum (65534)
0x66, 0x01, 0x10, // Unit (System: SI Linear, Time: Seconds)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x85, 0x24, // Report ID (36)
0x09, 0x2A, // Usage (0x2A)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x85, 0x25, // Report ID (37)
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0x40, // Usage (0x40)
0x67, 0x21, 0xD1, 0xF0, 0x00, // Unit (System: SI Linear, Length: Radians, Mass: Gram)
0x55, 0x05, // Unit Exponent (5)
0xB1, 0x22, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Non-volatile)
0x85, 0x26, // Report ID (38)
0x09, 0x30, // Usage (0x30)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0xC0, // End Collection
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0x1A, // Usage (0x1A)
0xA1, 0x00, // Collection (Physical)
0x85, 0x30, // Report ID (48)
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0x40, // Usage (0x40)
0x75, 0x08, // Report Size (8)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x67, 0x21, 0xD1, 0xF0, 0x00, // Unit (System: SI Linear, Length: Radians, Mass: Gram)
0x55, 0x07, // Unit Exponent (7)
0xB1, 0x22, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Non-volatile)
0x85, 0x31, // Report ID (49)
0x09, 0x30, // Usage (0x30)
0x75, 0x10, // Report Size (16)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x85, 0x32, // Report ID (50)
0x09, 0x53, // Usage (0x53)
0x16, 0xA0, 0x00, // Logical Minimum (160)
0x26, 0xC4, 0x00, // Logical Maximum (196)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x85, 0x33, // Report ID (51)
0x09, 0x54, // Usage (0x54)
0x16, 0x00, 0x01, // Logical Minimum (256)
0x26, 0x16, 0x01, // Logical Maximum (278)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x85, 0x35, // Report ID (53)
0x75, 0x08, // Report Size (8)
0x06, 0x86, 0xFF, // Usage Page (Vendor Defined 0xFF86)
0x09, 0x61, // Usage (0x61)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x02, // Logical Maximum (2)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x85, 0x36, // Report ID (54)
0x09, 0x52, // Usage (0x52)
0x25, 0x0D, // Logical Maximum (13)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0xC0, // End Collection
0x09, 0x05, // Usage (0x05)
0xA1, 0x00, // Collection (Physical)
0x85, 0x40, // Report ID (64)
0x09, 0x7C, // Usage (0x7C)
0x25, 0xFF, // Logical Maximum (-1)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0xC0, // End Collection
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0x16, // Usage (0x16)
0xA1, 0x00, // Collection (Physical)
0x85, 0x50, // Report ID (80)
0x09, 0x35, // Usage (0x35)
0x75, 0x08, // Report Size (8)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x64, // Logical Maximum (100)
0x65, 0x00, // Unit (None)
0x55, 0x00, // Unit Exponent (0)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x85, 0x52, // Report ID (82)
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0x44, // Usage (0x44)
0x75, 0x10, // Report Size (16)
0x15, 0x00, // Logical Minimum (0)
0x27, 0xFF, 0xFF, 0x00, 0x00, // Logical Maximum (65534)
0x66, 0x21, 0xD1, // Unit (System: SI Linear, Length: Radians, Mass: Gram)
0x55, 0x07, // Unit Exponent (7)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0xC0, // End Collection
0x85, 0x7F, // Report ID (127)
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0xFE, // Usage (0xFE)
0x79, 0x05, // String Index (5)
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x65, 0x00, // Unit (None)
0x55, 0x00, // Unit Exponent (0)
0xB1, 0x22, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Non-volatile)
0x85, 0x7E, // Report ID (126)
0x06, 0x86, 0xFF, // Usage Page (Vendor Defined 0xFF86)
0x09, 0x42, // Usage (0x42)
0x79, 0x07, // String Index (7)
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0xB1, 0x22, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Non-volatile)
0x85, 0x7D, // Report ID (125)
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0xFF, // Usage (0xFF)
0x79, 0x03, // String Index (3)
0xB1, 0x22, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Non-volatile)
0x85, 0x7C, // Report ID (124)
0x09, 0xFD, // Usage (0xFD)
0x79, 0x01, // String Index (1)
0xB1, 0x22, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Non-volatile)
0x85, 0x7B, // Report ID (123)
0x05, 0x85, // Usage Page (Power Pages)
0x09, 0x85, // Usage (0x85)
0x75, 0x10, // Report Size (16)
0x27, 0xFF, 0xFF, 0x00, 0x00, // Logical Maximum (65534)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0x02, // Usage (0x02)
0xA1, 0x02, // Collection (Logical)
0x85, 0x7A, // Report ID (122)
0x05, 0x85, // Usage Page (Power Pages)
0x09, 0x44, // Usage (0x44)
0x75, 0x01, // Report Size (1)
0x25, 0x01, // Logical Maximum (1)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x09, 0x45, // Usage (0x45)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x09, 0xD0, // Usage (0xD0)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x09, 0xD1, // Usage (0xD1)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x05, 0x85, // Usage Page (Power Pages)
0x09, 0x4B, // Usage (0x4B)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x05, 0x85, // Usage Page (Power Pages)
0x09, 0xDB, // Usage (0xDB)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0x65, // Usage (0x65)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x95, 0x19, // Report Count (25)
0xB1, 0x01, // Feature (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0xC0, // End Collection
0x85, 0x78, // Report ID (120)
0x05, 0x84, // Usage Page (Power Pages)
0x09, 0x5A, // Usage (0x5A)
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0x15, 0x01, // Logical Minimum (1)
0x25, 0x03, // Logical Maximum (3)
0xB1, 0xA2, // Feature (Data,Var,Abs,No Wrap,Linear,No Preferred State,No Null Position,Volatile)
0x06, 0xFF, 0xFF, // Usage Page (Vendor Defined 0xFFFF)
0x09, 0xFF, // Usage (0xFF)
0xA1, 0x02, // Collection (Logical)
0x85, 0xE3, // Report ID (-29)
0x09, 0xEF, // Usage (0xEF)
0x75, 0x08, // Report Size (8)
0x95, 0x07, // Report Count (7)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x15, 0x00, // Logical Minimum (0)
0x81, 0x82, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x09, 0xEF, // Usage (0xEF)
0xB1, 0x82, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Volatile)
0xC0, // End Collection
0xC0, // End Collection
// 745 bytes
};
// USB HID object. For ESP32 these values cannot be changed after this declaration
// desc report, desc len, protocol, interval, use out endpoint
Adafruit_USBD_HID usb_hid(desc_hid_report, sizeof(desc_hid_report), HID_ITF_PROTOCOL_NONE, 2, true);
// the setup function runs once when you press reset or power the board
void setup()
{
#if defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_RP2040)
// Manual begin() is required on core without built-in support for TinyUSB such as mbed rp2040
TinyUSB_Device_Init(0);
#endif
// Notes: following commented-out functions has no affect on ESP32
// usb_hid.enableOutEndpoint(true);
// usb_hid.setPollInterval(2);
// usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report));
// usb_hid.setStringDescriptor("TinyUSB HID Generic");
usb_hid.enableOutEndpoint(false);
usb_hid.setPollInterval(10);
TinyUSBDevice.setID(0x051D,0x0003);
TinyUSBDevice.setDeviceVersion(0x0100);
TinyUSBDevice.setLanguageDescriptor(0x0409);
TinyUSBDevice.setManufacturerDescriptor("American Power Conversion");
TinyUSBDevice.setProductDescriptor("Back-UPS BK650M2-CH FW:294803G -292804G");
TinyUSBDevice.setSerialDescriptor("9B2334A45622");
//usb_hid.setReportCallback(NULL, NULL);
usb_hid.begin();
Serial.begin(115200);
// wait until device mounted
while( !TinyUSBDevice.mounted() ) delay(1);
Serial.println("Adafruit TinyUSB HID Generic In Out example");
}
byte test = 0 ;
uint16_t test1 = 0x000D;
//0x000D charging
//0x000A discharging
//0x000C empty
void loop()
{
delay(100);
usb_hid.sendReport(0x0c, &test, sizeof(test));
test ++;
if(test > 0x64)
test = 0x01;
delay(100);
usb_hid.sendReport(0x16, &test1, sizeof(test1));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment