Skip to content

Commit 7102e51

Browse files
committed
cc3200: Add UART __del__ method.
1 parent a7208bc commit 7102e51

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cc3200/mods/pybuart.c

+15
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,20 @@ STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
523523
}
524524
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_deinit_obj, pyb_uart_deinit);
525525

526+
/// \method delete()
527+
/// Deinits the UART and removes its references so that it can be cleaned by the gc
528+
STATIC mp_obj_t pyb_uart_delete(mp_obj_t self_in) {
529+
pyb_uart_obj_t *self = self_in;
530+
531+
// deinit the peripheral
532+
pyb_uart_deinit(self);
533+
// remove it from the list
534+
mp_obj_list_remove(&MP_STATE_PORT(pyb_uart_list), self);
535+
536+
return mp_const_none;
537+
}
538+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_delete_obj, pyb_uart_delete);
539+
526540
/// \method any()
527541
/// Return `True` if any characters waiting, else `False`.
528542
STATIC mp_obj_t pyb_uart_any(mp_obj_t self_in) {
@@ -569,6 +583,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_readchar_obj, pyb_uart_readchar);
569583

570584
STATIC const mp_map_elem_t pyb_uart_locals_dict_table[] = {
571585
// instance methods
586+
{ MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)&pyb_uart_delete_obj },
572587
{ MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_uart_init_obj },
573588
{ MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&pyb_uart_deinit_obj },
574589
{ MP_OBJ_NEW_QSTR(MP_QSTR_any), (mp_obj_t)&pyb_uart_any_obj },

0 commit comments

Comments
 (0)