Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
abratchik opened this issue Jan 22, 2021 · 0 comments · May be fixed by #387
Open

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

abratchik opened this issue Jan 22, 2021 · 0 comments · May be fixed by #387

Comments

@abratchik
Copy link

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 <SomeHIDDevice.h>

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant