@@ -53,8 +53,8 @@ static const uint8_t usb_hid_descriptor_template[] = {
5353
5454// Is the HID device enabled?
5555bool usb_hid_enabled ;
56- supervisor_allocation * combined_hid_report_descriptor_allocation ;
57- supervisor_allocation * devices_allocation ;
56+ supervisor_allocation * hid_report_descriptor_allocation ;
57+ supervisor_allocation * hid_devices_allocation ;
5858
5959
6060// This is the interface descriptor, not the report descriptor.
@@ -64,7 +64,7 @@ size_t usb_hid_descriptor_length(void) {
6464
6565static const char [] usb_hid_interface_name = USB_INTERFACE_NAME " HID" ;
6666
67- // This is the interface descriptor, nto the report descriptor.
67+ // This is the interface descriptor, not the report descriptor.
6868size_t usb_hid_add_descriptor (uint8_t * descriptor_buf , uint8_t * current_interface , uint8_t * current_endpoint , uint8_t * current_interface_string , uint16_t report_descriptor_length ) {
6969 memcpy (descriptor_buf , usb_hid_descriptor_template , sizeof (usb_hid_descriptor_template ));
7070
@@ -78,27 +78,27 @@ size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfac
7878 return sizeof (usb_hid_descriptor_template );
7979}
8080
81- usb_hid_configure_status common_hal_usb_hid_configure_usb (mp_obj_t devices ) {
81+ usb_hid_configure_status common_hal_usb_hid_configure_usb (mp_obj_t devices_seq ) {
8282 // We can't change the devices once we're connected.
8383 if (tud_connected ()) {
8484 return USB_CONFIG_TOO_LATE ;
8585 }
8686
8787 // Assume no devices to start.
8888 usb_hid_enabled = false;
89- if (devices == mp_const_none ) {
89+ if (devices_seq == mp_const_none ) {
9090 return USB_CONFIG_OK ;
9191 }
9292
9393 size_t total_report_descriptors_length = 0 ;
9494
9595 // Build a combined report descriptor
9696
97- mp_int_t len = mp_obj_get_int (mp_obj_len (devices ));
97+ mp_int_t len = mp_obj_get_int (mp_obj_len (devices_seq ));
9898
9999 // First get the total size.
100100 for (size_t i = 0 ; i < len ; i ++ ) {
101- mp_obj_t item = mp_obj_subscr (devices , mp_obj_new_small_int (i ), MP_OBJ_SENTINEL );
101+ mp_obj_t item = mp_obj_subscr (devices_seq , mp_obj_new_small_int (i ), MP_OBJ_SENTINEL );
102102 if (!MP_OBJ_IS_TYPE (item , & usb_hid_device_type )) {
103103 return USB_CONFIG_NON_DEVICE ; for (size_t i = 0 ; i < len ; i ++ ) {
104104 mp_obj_t item = (devices , mp_obj_new_small_int (i ), MP_OBJ_SENTINEL );
@@ -119,16 +119,16 @@ usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices) {
119119 // Allocate storage that persists across VMs to build the combined descriptor
120120 // and to remember the device details.
121121
122- // allocate_memory(length, highaddress=false, movable=true)
123- combined_hid_report_descriptor_allocation = allocate_memory (total_report_descriptors_length , false, true);
122+ hid_report_descriptor_allocation =
123+ allocate_memory (total_report_descriptors_length , false /*highaddress*/ , true /*movable*/ );
124124
125- devices_allocation = allocate_memory (sizeof (usb_hid_device_obj_t ) * len );
126- usb_hid_device_obj_t devices [] = (devices []) device_details_allocation -> ptr ;
125+ hid_devices_allocation = allocate_memory (sizeof (usb_hid_device_obj_t ) * len );
126+ usb_hid_device_obj_t hid_devices [] = (usb_hid_device_obj_t []) hid_devices_allocation -> ptr ;
127127
128- uint8_t * descriptor_start = combined_hid_report_descriptor_allocation -> ptr ;
128+ uint8_t * descriptor_start = ( uint8_t * ) hid_report_descriptor_allocation -> ptr ;
129129
130130 for (size_t i = 0 ; i < len ; i ++ ) {
131- usb_hid_device_obj_t * device = MP_OBJ_TO_PTR (devices , mp_obj_new_small_int (i ), MP_OBJ_SENTINEL );
131+ usb_hid_device_obj_t * device = MP_OBJ_TO_PTR (devices_seq , mp_obj_new_small_int (i ), MP_OBJ_SENTINEL );
132132
133133 // Copy the report descriptor for this device.
134134 if (len == 1 ) {
@@ -146,18 +146,19 @@ usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices) {
146146 }
147147
148148 // Copy the device data and discard any descriptor-bytes object pointer.
149- memcpy (& devices [i ], device , sizeof (usb_hid_device_obj_t ));
150- devices [i ].descriptor_obj = mp_const_none ;
149+ memcpy (& hid_devices [i ], device , sizeof (usb_hid_device_obj_t ));
150+ hid_devices [i ].descriptor_obj = mp_const_none ;
151151 }
152152
153153}
154154
155155void usb_hid_gc_collect (void ) {
156156 // Once tud_mounted() is true, we're done with the constructed descriptors.
157157 if (tud_mounted ()) {
158- // GC will pick up the inaccessible blocks.
159- usb_hid_devices_to_configure = NULL ;
158+ free_memory ( hid_report_descriptor_allocation );
159+ free_memory ( usb_hid_devices_allocation ) ;
160160 } else {
161- gc_collect_ptr (usb_hid_devices );
161+ gc_collect_ptr (hid_report_descriptor_allocation -> ptr );
162+ gc_collect_ptr (usb_hid_devices_allocation );
162163 }
163164}
0 commit comments