add individual LED configuration over USB ethernet

This commit is contained in:
2025-08-27 15:01:11 -04:00
parent c6ac21a15b
commit 2fac602e44
21 changed files with 3139 additions and 132 deletions
+28 -7
View File
@@ -9,6 +9,7 @@
#include "hyperx_elite2.h"
#include "usb_host.h"
#include "usb_server.h"
#include "usb_device.h"
@@ -44,6 +45,7 @@ static tusb_desc_device_t const desc_device =
.bNumConfigurations = 0x01
};
static char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
@@ -51,7 +53,9 @@ static char const* string_desc_arr [] =
"Pico HyperX Elite 2 RGB Controller", // 2: Product
NULL, // 3: Serials, should use chip ID
"Pico HyperX Elite 2 CDC", // 4: CDC
"Pico HyperX Elite 2 HID", // 5: HID
"Pico HyperX Elite 2 NCM", // 5: NCM
NULL, // 6: MAC address for NCM
"Pico HyperX Elite 2 HID", // 7: HID
};
static void usb_device_init(void);
@@ -65,6 +69,9 @@ void usb_device_main(void) {
device_state = DEVICE_INACTIVE;
usb_device_init();
// start the web server on USB
usb_server_init();
while (true) {
switch ( device_state ) {
case DEVICE_ACTIVE:
@@ -116,21 +123,24 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
{
(void) index; // for multiple configurations
// set configuration descriptor and CDC descriptor
memset(desc_configuration, 0, sizeof(desc_configuration));
uint8_t desc_initial[TUD_CONFIG_DESC_LEN+TUD_CDC_DESC_LEN+1] = {
TUD_CONFIG_DESCRIPTOR(1, 2+num_mounted, 0, TUD_CONFIG_DESC_LEN+TUD_CDC_DESC_LEN+num_mounted*TUD_HID_DESC_LEN, 0x00, 100),
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64)
uint8_t desc_initial[TUD_CONFIG_DESC_LEN+TUD_CDC_DESC_LEN+TUD_CDC_NCM_DESC_LEN+1] = {
TUD_CONFIG_DESCRIPTOR(1, 4+num_mounted, 0, TUD_CONFIG_DESC_LEN+TUD_CDC_DESC_LEN+TUD_CDC_NCM_DESC_LEN+num_mounted*TUD_HID_DESC_LEN, 0x00, 100),
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
TUD_CDC_NCM_DESCRIPTOR(ITF_NUM_NCM, 5, 6, EPNUM_NCM_NOTIF, 64, EPNUM_NCM_OUT, EPNUM_NCM_IN, CFG_TUD_NET_ENDPOINT_SIZE, CFG_TUD_NET_MTU)
};
memcpy(desc_configuration, desc_initial, TUD_CONFIG_DESC_LEN+TUD_CDC_DESC_LEN);
memcpy(desc_configuration, desc_initial, TUD_CONFIG_DESC_LEN+TUD_CDC_DESC_LEN+TUD_CDC_NCM_DESC_LEN);
// add a HID descriptor for each interface mounted on host
if ( descriptors != NULL) {
struct report_desc *descriptor;
for (uint8_t i=0; i<num_mounted; i++) {
descriptor = report_desc_find(descriptors->dev_addr, i);
uint8_t hid_desc[TUD_HID_DESC_LEN+1] = {
TUD_HID_DESCRIPTOR(ITF_NUM_HID+i, 5, HID_ITF_PROTOCOL_NONE, descriptor->desc_len, EPNUM_HID+i, CFG_TUD_HID_EP_BUFSIZE, 1)
TUD_HID_DESCRIPTOR(ITF_NUM_HID+i, 7, HID_ITF_PROTOCOL_NONE, descriptor->desc_len, EPNUM_HID+i, CFG_TUD_HID_EP_BUFSIZE, 1)
};
memcpy(&desc_configuration[TUD_CONFIG_DESC_LEN+TUD_CDC_DESC_LEN+i*TUD_HID_DESC_LEN], hid_desc, TUD_HID_DESC_LEN);
memcpy(&desc_configuration[TUD_CONFIG_DESC_LEN+TUD_CDC_DESC_LEN+TUD_CDC_NCM_DESC_LEN+i*TUD_HID_DESC_LEN], hid_desc, TUD_HID_DESC_LEN);
}
}
@@ -153,6 +163,17 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
case 3: // serial
chr_count = board_usb_get_serial(_desc_str+1, 32);
break;
case 6: // MAC address: link-local prefix of 02 and last 10 digits from board serial
chr_count = board_usb_get_serial(_desc_str+1, 32);
if (chr_count > 12) {
_desc_str[1] = '0';
_desc_str[2] = '2';
for (uint8_t i=0; i<10; i++) {
_desc_str[3+i] = _desc_str[chr_count-9+i];
}
chr_count=12;
}
break;
default:
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors