8000 Merge pull request #6808 from maximkulkin/7.3.x-usb-hid-get-last-repo… · squix78/circuitpython@d13578f · GitHub
[go: up one dir, main page]

Skip to content

Commit d13578f

Browse files
authored
Merge pull request adafruit#6808 from maximkulkin/7.3.x-usb-hid-get-last-report-fix
shared-module/usb_hid: Fix behavior of Device.get_last_received_report()
2 parents 4276b06 + 429c722 commit d13578f

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

shared-module/usb_hid/Device.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
#include <stdbool.h>
2728
#include <string.h>
2829

2930
#include "py/gc.h"
@@ -246,6 +247,10 @@ void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t *
246247
mp_obj_t common_hal_usb_hid_device_get_last_received_report(usb_hid_device_obj_t *self, uint8_t report_id) {
247248
// report_id has already been validated for this device.
248249
size_t id_idx = get_report_id_idx(self, report_id);
250+
if (!self->out_report_buffers_updated[id_idx]) {
251+
return mp_const_none;
252+
}
253+
self->out_report_buffers_updated[id_idx] = false;
249254
return mp_obj_new_bytes(self->out_report_buffers[id_idx], self->out_report_lengths[id_idx]);
250255
}
251256

@@ -263,6 +268,7 @@ void usb_hid_device_create_report_buffers(usb_hid_device_obj_t *self) {
263268
? gc_alloc(self->out_report_lengths[i], false, true /*long-lived*/)
264269
: NULL;
265270
}
271+
memset(self->out_report_buffers_updated, 0, sizeof(self->out_report_buffers_updated));
266272
}
267273

268274

@@ -309,6 +315,7 @@ void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t rep
309315
hid_device->out_report_buffers[id_idx] &&
310316
hid_device->out_report_lengths[id_idx] >= bufsize) {
311317
memcpy(hid_device->out_report_buffers[id_idx], buffer, bufsize);
318+
hid_device->out_report_buffers_updated[id_idx] = true;
312319
}
313320
}
314321
}

shared-module/usb_hid/Device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ typedef struct {
3838
const uint8_t *report_descriptor;
3939
uint8_t *in_report_buffers[CIRCUITPY_USB_HID_MAX_REPORT_IDS_PER_DESCRIPTOR];
4040
uint8_t *out_report_buffers[CIRCUITPY_USB_HID_MAX_REPORT_IDS_PER_DESCRIPTOR];
41+
uint8_t out_report_buffers_updated[CIRCUITPY_USB_HID_MAX_REPORT_IDS_PER_DESCRIPTOR];
4142
uint16_t report_descriptor_length;
4243
uint8_t report_ids[CIRCUITPY_USB_HID_MAX_REPORT_IDS_PER_DESCRIPTOR];
4344
uint8_t in_report_lengths[CIRCUITPY_USB_HID_MAX_REPORT_IDS_PER_DESCRIPTOR];

0 commit comments

Comments
 (0)
0