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

shared-module/usb_hid: Fix behavior of Device.get_last_received_report() #6767

Merged
merged 1 commit into from Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions shared-module/usb_hid/Device.c
Expand Up @@ -24,6 +24,7 @@
* THE SOFTWARE.
*/

#include <stdbool.h>
#include <string.h>

#include "py/gc.h"
Expand Down Expand Up @@ -241,6 +242,10 @@ void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t *
mp_obj_t common_hal_usb_hid_device_get_last_received_report(usb_hid_device_obj_t *self, uint8_t report_id) {
// report_id has already been validated for this device.
size_t id_idx = get_report_id_idx(self, report_id);
if (!self->out_report_buffers_updated[id_idx]) {
return mp_const_none;
}
self->out_report_buffers_updated[id_idx] = false;
return mp_obj_new_bytes(self->out_report_buffers[id_idx], self->out_report_lengths[id_idx]);
}

Expand All @@ -258,6 +263,7 @@ void usb_hid_device_create_report_buffers(usb_hid_device_obj_t *self) {
? gc_alloc(self->out_report_lengths[i], false, true /*long-lived*/)
: NULL;
}
memset(self->out_report_buffers_updated, 0, sizeof(self->out_report_buffers_updated));
}


Expand Down Expand Up @@ -304,6 +310,7 @@ void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t rep
hid_device->out_report_buffers[id_idx] &&
hid_device->out_report_lengths[id_idx] >= bufsize) {
memcpy(hid_device->out_report_buffers[id_idx], buffer, bufsize);
hid_device->out_report_buffers_updated[id_idx] = true;
}
}
}
1 change: 1 addition & 0 deletions shared-module/usb_hid/Device.h
Expand Up @@ -38,6 +38,7 @@ typedef struct {
const uint8_t *report_descriptor;
uint8_t *in_report_buffers[CIRCUITPY_USB_HID_MAX_REPORT_IDS_PER_DESCRIPTOR];
uint8_t *out_report_buffers[CIRCUITPY_USB_HID_MAX_REPORT_IDS_PER_DESCRIPTOR];
uint8_t out_report_buffers_updated[CIRCUITPY_USB_HID_MAX_REPORT_IDS_PER_DESCRIPTOR];
uint16_t report_descriptor_length;
uint8_t report_ids[CIRCUITPY_USB_HID_MAX_REPORT_IDS_PER_DESCRIPTOR];
uint8_t in_report_lengths[CIRCUITPY_USB_HID_MAX_REPORT_IDS_PER_DESCRIPTOR];
Expand Down