Skip to content

Commit 4809c92

Browse files
committed
WIP - Add native helper based on displayio
1 parent fb21614 commit 4809c92

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

shared-bindings/busio/UART.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include "py/ioctl.h"
3737
#include "py/objproperty.h"
38+
#include "py/objtype.h"
3839
#include "py/runtime.h"
3940
#include "py/stream.h"
4041
#include "supervisor/shared/translate.h"
@@ -142,6 +143,18 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, co
142143
return (mp_obj_t)self;
143144
}
144145

146+
147+
// Helper to ensure we have the native super class instead of a subclass.
148+
busio_uart_obj_t* native_uart(mp_obj_t uart_obj) {
149+
mp_obj_t native_uart = mp_instance_cast_to_native_base(uart_obj, &busio_uart_type);
150+
if (native_uart == MP_OBJ_NULL) {
151+
mp_raise_ValueError_varg(translate("Must be a %q subclass."), MP_QSTR_UART);
152+
}
153+
mp_obj_assert_native_inited(native_uart);
154+
return MP_OBJ_TO_PTR(native_uart);
155+
}
156+
157+
145158
//| def deinit(self) -> None:
146159
//| """Deinitialises the UART and releases any hardware resources for reuse."""
147160
//| ...

0 commit comments

Comments
 (0)