@@ -85,13 +85,18 @@ static mp_obj_t i2ctarget_i2c_target_make_new(const mp_obj_type_t *type, size_t
85
85
//| """Releases control of the underlying hardware so other classes can use it."""
86
86
//| ...
87
87
static mp_obj_t i2ctarget_i2c_target_obj_deinit (mp_obj_t self_in ) {
88
- mp_check_self (mp_obj_is_type (self_in , & i2ctarget_i2c_target_type ));
89
88
i2ctarget_i2c_target_obj_t * self = MP_OBJ_TO_PTR (self_in );
90
89
common_hal_i2ctarget_i2c_target_deinit (self );
91
90
return mp_const_none ;
92
91
}
93
92
MP_DEFINE_CONST_FUN_OBJ_1 (i2ctarget_i2c_target_deinit_obj , i2ctarget_i2c_target_obj_deinit );
94
93
94
+ static void check_for_deinit (i2ctarget_i2c_target_obj_t * self ) {
95
+ if (common_hal_i2ctarget_i2c_target_deinited (self )) {
96
+ raise_deinited_error ();
97
+ }
98
+ }
99
+
95
100
//| def __enter__(self) -> I2CTarget:
96
101
//| """No-op used in Context Managers."""
97
102
//| ...
@@ -102,7 +107,6 @@ MP_DEFINE_CONST_FUN_OBJ_1(i2ctarget_i2c_target_deinit_obj, i2ctarget_i2c_target_
102
107
//| :ref:`lifetime-and-contextmanagers` for more info."""
103
108
//| ...
104
109
static mp_obj_t i2ctarget_i2c_target_obj___exit__ (size_t n_args , const mp_obj_t * args ) {
105
- mp_check_self (mp_obj_is_type (args [0
10000
span>], & i2ctarget_i2c_target_type ));
106
110
i2ctarget_i2c_target_obj_t * self = MP_OBJ_TO_PTR (args [0 ]);
107
111
common_hal_i2ctarget_i2c_target_deinit (self );
108
112
return mp_const_none ;
@@ -117,11 +121,9 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2ctarget_i2c_target___exit___obj, 4,
117
121
//| :rtype: ~i2ctarget.I2CTargetRequest"""
118
122
//|
119
123
static mp_obj_t i2ctarget_i2c_target_request (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
120
- mp_check_self (mp_obj_is_type (pos_args [0 ], & i2ctarget_i2c_target_type ));
121
124
i2ctarget_i2c_target_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
122
- if (common_hal_i2ctarget_i2c_target_deinited (self )) {
123
- raise_deinited_error ();
124
- }
125
+ check_for_deinit (self );
126
+
125
127
enum { ARG_timeout };
126
128
static const mp_arg_t allowed_args [] = {
127
129
{ MP_QSTR_timeout , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = MP_OBJ_NEW_SMALL_INT (-1 )} },
@@ -228,8 +230,9 @@ static mp_obj_t i2ctarget_i2c_target_request_make_new(const mp_obj_type_t *type,
228
230
//| """Close the request."""
229
231
//| ...
230
232
static mp_obj_t i2ctarget_i2c_target_request_obj___exit__ (size_t n_args , const mp_obj_t * args ) {
231
- mp_check_self (mp_obj_is_type (args [0 ], & i2ctarget_i2c_target_request_type ));
232
233
i2ctarget_i2c_target_request_obj_t * self = MP_OBJ_TO_PTR (args [0 ]);
234
+ check_for_deinit (self -> target );
235
+
233
236
common_hal_i2ctarget_i2c_target_close (self -> target );
234
237
return mp_const_none ;
235
238
}
@@ -238,26 +241,29 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2ctarget_i2c_target_request___exit__
238
241
//| address: int
239
242
//| """The I2C address of the request."""
240
243
static mp_obj_t i2ctarget_i2c_target_request_get_address (mp_obj_t self_in ) {
241
- mp_check_self (mp_obj_is_type (self_in , & i2ctarget_i2c_target_request_type ));
242
244
i2ctarget_i2c_target_request_obj_t * self = MP_OBJ_TO_PTR (self_in );
245
+ check_for_deinit (self -> target );
246
+
243
247
return mp_obj_new_int (self -> address );
244
248
}
245
249
MP_DEFINE_CONST_PROP_GET (i2ctarget_i2c_target_request_address_obj , i2ctarget_i2c_target_request_get_address );
246
250
247
251
//| is_read: bool
248
252
//| """The I2C main controller is reading from this target."""
249
253
static mp_obj_t i2ctarget_i2c_target_request_get_is_read (mp_obj_t self_in ) {
250
- mp_check_self (mp_obj_is_type (self_in , & i2ctarget_i2c_target_request_type ));
251
254
i2ctarget_i2c_target_request_obj_t * self = MP_OBJ_TO_PTR (self_in );
255
+ check_for_deinit (self -> target );
256
+
252
257
return mp_obj_new_bool (self -> is_read );
253
258
}
254
259
MP_DEFINE_CONST_PROP_GET (i2ctarget_i2c_target_request_is_read_obj , i2ctarget_i2c_target_request_get_is_read );
255
260
256
261
//| is_restart: bool
257
262
//| """Is Repeated Start Condition."""
258
263
static mp_obj_t i2ctarget_i2c_target_request_get_is_restart (mp_obj_t self_in ) {
259
- mp_check_self (mp_obj_is_type (self_in , & i2ctarget_i2c_target_request_type ));
260
264
i2ctarget_i2c_target_request_obj_t * self = MP_OBJ_TO_PTR (self_in );
265
+ check_for_deinit (self -> target );
266
+
261
267
return mp_obj_new_bool (self -> is_restart );
262
268
}
263
269
MP_DEFINE_CONST_PROP_GET (i2ctarget_i2c_target_request_is_restart_obj , i2ctarget_i2c_target_request_get_is_restart );
@@ -271,8 +277,9 @@ MP_DEFINE_CONST_PROP_GET(i2ctarget_i2c_target_request_is_restart_obj, i2ctarget_
271
277
//| :return: Bytes read"""
272
278
//| ...
273
279
static mp_obj_t i2ctarget_i2c_target_request_read (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
274
- mp_check_self (mp_obj_is_type (pos_args [0 ], & i2ctarget_i2c_target_request_type ));
275
280
i2ctarget_i2c_target_request_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
281
+ check_for_deinit (self -> target );
282
+
276
283
enum { ARG_n , ARG_ack };
277
284
static const mp_arg_t allowed_args [] = {
278
285
{ MP_QSTR_n , MP_ARG_INT , {.u_int = -1 } },
@@ -328,8 +335,8 @@ MP_DEFINE_CONST_FUN_OBJ_KW(i2ctarget_i2c_target_request_read_obj, 1, i2ctarget_i
328
335
//| :return: Number of bytes written"""
329
336
//| ...
330
337
static mp_obj_t i2ctarget_i2c_target_request_write (mp_obj_t self_in , mp_obj_t buf_in ) {
331
- mp_check_self (mp_obj_is_type (self_in , & i2ctarget_i2c_target_request_type ));
332
338
i2ctarget_i2c_target_request_obj_t * self = MP_OBJ_TO_PTR (self_in );
339
+ check_for_deinit (self -> target );
333
340
334
341
if (!self -> is_read ) {
335
342
mp_raise_OSError (MP_EACCES );
@@ -362,8 +369,9 @@ static MP_DEFINE_CONST_FUN_OBJ_2(i2ctarget_i2c_target_request_write_obj, i2ctarg
362
369
//| ...
363
370
//|
364
371
static mp_obj_t i2ctarget_i2c_tar
994E
get_request_ack (uint n_args , const mp_obj_t * args ) {
365
- mp_check_self (mp_obj_is_type (args [0 ], & i2ctarget_i2c_target_request_type ));
366
372
i2ctarget_i2c_target_request_obj_t * self = MP_OBJ_TO_PTR (args [0 ]);
373
+ check_for_deinit (self -> target );
374
+
367
375
bool ack = (n_args == 1 ) ? true : mp_obj_is_true (args [1 ]);
368
376
369
377
if (self -> is_read ) {
@@ -376,8 +384,8 @@ static mp_obj_t i2ctarget_i2c_target_request_ack(uint n_args, const mp_obj_t *ar
376
384
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (i2ctarget_i2c_target_request_ack_obj , 1 , 2 , i2ctarget_i2c_target_request_ack );
377
385
378
386
static mp_obj_t i2ctarget_i2c_target_request_close (mp_obj_t self_in ) {
379
- mp_check_self (mp_obj_is_type (self_in , & i2ctarget_i2c_target_request_type ));
380
387
i2ctarget_i2c_target_request_obj_t * self = MP_OBJ_TO_PTR (self_in );
388
+ check_for_deinit (self -> target );
381
389
382
390
common_hal_i2ctarget_i2c_target_close (self -> target );
383
391
return mp_const_none ;
0 commit comments