39
39
40
40
#include "py/objproperty.h"
41
41
#include "shared-bindings/usb/core/Device.h"
42
+ #include "shared-bindings/util.h"
42
43
#include "py/runtime.h"
43
44
44
45
//| class Device:
49
50
//| ...
50
51
//|
51
52
53
+ static void check_for_deinit (usb_core_device_obj_t * self ) {
54
+ if (common_hal_usb_core_device_deinited (self )) {
55
+ raise_deinited_error ();
56
+ }
57
+ }
58
+
52
59
//| def __del__(self) -> None:
53
60
//| """Closes any resources used for this device."""
54
61
//| ...
@@ -64,6 +71,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_deinit_obj, usb_core_device_dei
64
71
//| """The USB vendor ID of the device"""
65
72
static mp_obj_t usb_core_device_obj_get_idVendor (mp_obj_t self_in ) {
66
73
usb_core_device_obj_t * self = MP_OBJ_TO_PTR (self_in );
74
+ check_for_deinit (self );
67
75
return MP_OBJ_NEW_SMALL_INT (common_hal_usb_core_device_get_idVendor (self ));
68
76
}
69
77
MP_DEFINE_CONST_FUN_OBJ_1 (usb_core_device_get_idVendor_obj , usb_core_device_obj_get_idVendor );
@@ -75,6 +83,7 @@ MP_PROPERTY_GETTER(usb_core_device_idVendor_obj,
75
83
//| """The USB product ID of the device"""
76
84
static mp_obj_t usb_core_device_obj_get_idProduct (mp_obj_t self_in ) {
77
85
usb_core_device_obj_t * self = MP_OBJ_TO_PTR (self_in );
86
+ check_for_deinit (self );
78
87
return MP_OBJ_NEW_SMALL_INT (common_hal_usb_core_device_get_idProduct (self ));
79
88
}
80
89
MP_DEFINE_CONST_FUN_OBJ_1 (usb_core_device_get_idProduct_obj , usb_core_device_obj_get_idProduct );
@@ -86,6 +95,7 @@ MP_PROPERTY_GETTER(usb_core_device_idProduct_obj,
86
95
//| """The USB device's serial number string."""
87
96
static mp_obj_t usb_core_device_obj_get_serial_number (mp_obj_t self_in ) {
88
97
usb_core_device_obj_t * self = MP_OBJ_TO_PTR (self_in );
98
+ check_for_deinit (self );
89
99
return common_hal_usb_core_device_get_serial_number (self );
90
100
}
91
101
MP_DEFINE_CONST_FUN_OBJ_1 (usb_core_device_get_serial_number_obj , usb_core_device_obj_get_serial_number );
@@ -97,6 +107,7 @@ MP_PROPERTY_GETTER(usb_core_device_serial_number_obj,
97
107
//| """The USB device's product string."""
98
108
static mp_obj_t usb_core_device_obj_get_product (mp_obj_t self_in ) {
99
109
usb_core_device_obj_t * self = MP_OBJ_TO_PTR (self_in );
110
+ check_for_deinit (self );
100
111
return common_hal_usb_core_device_get_product (self );
101
112
}
102
113
MP_DEFINE_CONST_FUN_OBJ_1 (usb_core_device_get_product_obj , usb_core_device_obj_get_product );
@@ -109,6 +120,7 @@ MP_PROPERTY_GETTER(usb_core_device_product_obj,
109
120
//|
110
121
static mp_obj_t usb_core_device_obj_get_manufacturer (mp_obj_t self_in ) {
111
122
usb_core_device_obj_t * self = MP_OBJ_TO_PTR (self_in );
123
+ check_for_deinit (self );
112
124
return common_hal_usb_core_device_get_manufacturer (self );
113
125
}
114
126
MP_DEFINE_CONST_FUN_OBJ_1 (usb_core_device_get_manufacturer_obj , usb_core_device_obj_get_manufacturer );
@@ -121,6 +133,7 @@ MP_PROPERTY_GETTER(usb_core_device_manufacturer_obj,
121
133
//|
122
134
static mp_obj_t usb_core_device_obj_get_bus (mp_obj_t self_in ) {
123
135
usb_core_device_obj_t * self = MP_OBJ_TO_PTR (self_in );
136
+ check_for_deinit (self );
124
137
return MP_OBJ_NEW_SMALL_INT (common_hal_usb_core_device_get_bus (self ));
125
138
}
126
139
MP_DEFINE_CONST_FUN_OBJ_1 (usb_core_device_get_bus_obj , usb_core_device_obj_get_bus );
@@ -134,6 +147,7 @@ MP_PROPERTY_GETTER(usb_core_device_bus_obj,
134
147
//|
135
148
static mp_obj_t usb_core_device_obj_get_port_numbers (mp_obj_t self_in ) {
136
149
usb_core_device_obj_t * self = MP_OBJ_TO_PTR (self_in );
150
+ check_for_deinit (self );
137
151
return common_hal_usb_core_device_get_port_numbers (self );
138
152
}
139
153
MP_DEFINE_CONST_FUN_OBJ_1 (usb_core_device_get_port_numbers_obj , usb_core_device_obj_get_port_numbers );
@@ -147,6 +161,7 @@ MP_PROPERTY_GETTER(usb_core_device_port_numbers_obj,
147
161
//|
148
162
static mp_obj_t usb_core_device_obj_get_speed (mp_obj_t self_in ) {
149
163
usb_core_device_obj_t * self = MP_OBJ_TO_PTR (self_in );
164
+ check_for_deinit (self );
150
165
return MP_OBJ_NEW_SMALL_INT (common_hal_usb_core_device_get_speed (self ));
151
166
}
152
167
MP_DEFINE_CONST_FUN_OBJ_1 (usb_core_device_get_speed_obj , usb_core_device_obj_get_speed );
@@ -171,6 +186,7 @@ static mp_obj_t usb_core_device_set_configuration(size_t n_args, const mp_obj_t
171
186
{ MP_QSTR_configuration , MP_ARG_INT , {.u_int = 1 } },
172
187
};
173
188
usb_core_device_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
189
+ check_for_deinit (self );
174
190
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
175
191
mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
176
192
@@ -197,6 +213,7 @@ static mp_obj_t usb_core_device_write(size_t n_args, const mp_obj_t *pos_args, m
197
213
{ MP_QSTR_timeout , MP_ARG_INT , {.u_int = 0 } },
198
214
};
199
215
usb_core_device_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
216
+ check_for_deinit (self );
200
217
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
201
218
mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
202
219
@@ -228,6 +245,7 @@ static mp_obj_t usb_core_device_read(size_t n_args, const mp_obj_t *pos_args, mp
228
245
{ MP_QSTR_timeout , MP_ARG_INT , {.u_int = 0 } },
229
246
};
230
247
usb_core_device_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
248
+ check_for_deinit (self );
231
249
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
232
250
mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
233
251
@@ -277,6 +295,7 @@ static mp_obj_t usb_core_device_ctrl_transfer(size_t n_args, const mp_obj_t *pos
277
295
{ MP_QSTR_timeout , MP_ARG_INT , {.u_int = 0 } },
278
296
};
279
297
usb_core_device_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
298
+ check_for_deinit (self );
280
299
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
281
300
mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
282
301
@@ -310,6 +329,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(usb_core_device_ctrl_transfer_obj, 2, usb_core_device
310
329
//|
311
330
static mp_obj_t usb_core_device_is_kernel_driver_active (mp_obj_t self_in , mp_obj_t interface_in ) {
312
331
usb_core_device_obj_t * self = MP_OBJ_TO_PTR (self_in );
332
+ check_for_deinit (self );
313
333
mp_int_t interface = mp_obj_get_int (interface_in );
314
334
bool active = common_hal_usb_core_device_is_kernel_driver_active (self , interface );
315
335
return mp_obj_new_bool (active );
@@ -327,6 +347,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(usb_core_device_is_kernel_driver_active_obj, usb_core_
327
347
//|
328
348
static mp_obj_t usb_core_device_detach_kernel_driver (mp_obj_t self_in , mp_obj_t interface_in ) {
329
349
usb_core_device_obj_t * self = MP_OBJ_TO_PTR (self_in );
350
+ check_for_deinit (self );
330
351
mp_int_t interface = mp_obj_get_int (interface_in );
331
352
common_hal_usb_core_device_detach_kernel_driver (self , interface );
332
353
return mp_const_none ;
@@ -343,6 +364,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(usb_core_device_detach_kernel_driver_obj, usb_core_dev
343
364
//|
344
365
static mp_obj_t usb_core_device_attach_kernel_driver (mp_obj_t self_in , mp_obj_t interface_in ) {
345
366
usb_core_device_obj_t * self = MP_OBJ_TO_PTR (self_in );
367
+ check_for_deinit (self );
346
368
mp_int_t interface = mp_obj_get_int (interface_in );
347
369
common_hal_usb_core_device_attach_kernel_driver (self , interface );
348
370
return mp_const_none ;
0 commit comments