arduino / arduino/ArduinoCore-avr

Support HID Control Pipe (SetFeature/GetFeature) in HID API

Open
#390 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
1.5k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Current implementation of HID API is lacking important mechanism of the USB HID protocol, which allows host to request the parameters from the device as necessary, or update these parameters, thus implementing the host-to-device feedback and control.

The proposed modification would allow to declare a public variable in the Arduino sketch and pass its address to the HID library. The library stores the address along with HID feature ID. Once the host requests the feature, the HID library retrieves the feature by ID and address and passes the value back to the host. The feature value can be also updated by the host.

The code in the sketch implementing the feature can be very simple, for example:

```
// SomeHIDDevice can be Mouse, Keyboard, PowerDevice etc and usually is the place where we define the
// HID device descriptor.
#include

uint16_t iPresentStatus = 0

void setup() {
SomeHIDDevice.begin();

// here we call the wrapper of the SetFeature method defined in the SomeHIDDevice and pass the
// address of the variable, which will hold the value of the feature, to the HID library
SomeHIDDevice.setFeature(HID_PRESENT_STATUS, &iPresentStatus, sizeof(iPresentStatus));
}

void loop() {
// iPresentStatus can be updated here at any point and the current value will be visible to the host.
// The host can also update this variable if the feature is declared as RW
iPresentStatus = 1;
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the HID API and the SomeHIDDevice wrapper referenced in the issue, then review how HID feature IDs and descriptors are currently handled. Done means supporting SetFeature and GetFeature requests so a sketch can register a variable by feature ID and size, expose its value to the host, and accept host updates.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.