@@ -72,13 +72,16 @@ typedef struct {
72
72
extern const busio_uart_parity_obj_t busio_uart_parity_even_obj ;
73
73
extern const busio_uart_parity_obj_t busio_uart_parity_odd_obj ;
74
74
75
+ #if CIRCUITPY_BUSIO_UART
75
76
STATIC void validate_timeout (mp_float_t timeout ) {
76
77
if (timeout < (mp_float_t )0.0f || timeout > (mp_float_t )100.0f ) {
77
78
mp_raise_ValueError (translate ("timeout must be 0.0-100.0 seconds" ));
78
79
}
79
80
}
81
+ #endif // CIRCUITPY_BUSIO_UART
80
82
81
83
STATIC mp_obj_t busio_uart_make_new (const mp_obj_type_t * type , size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
84
+ #if CIRCUITPY_BUSIO_UART
82
85
// Always initially allocate the UART object within the long-lived heap.
83
86
// This is needed to avoid crashes with certain UART implementations which
84
87
// cannot accomodate being moved after creation. (See
@@ -141,8 +144,12 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, co
141
144
args [ARG_baudrate ].u_int , bits , parity , stop , timeout ,
142
145
args [ARG_receiver_buffer_size ].u_int , NULL , false);
143
146
return (mp_obj_t )self ;
147
+ #else
148
+ mp_raise_ValueError (translate ("Invalid pins" ));
149
+ #endif // CIRCUITPY_BUSIO_UART
144
150
}
145
151
152
+ #if CIRCUITPY_BUSIO_UART
146
153
147
154
// Helper to ensure we have the native super class instead of a subclass.
148
155
busio_uart_obj_t * native_uart (mp_obj_t uart_obj ) {
@@ -358,6 +365,7 @@ STATIC mp_obj_t busio_uart_obj_reset_input_buffer(mp_obj_t self_in) {
358
365
return mp_const_none ;
359
366
}
360
367
STATIC MP_DEFINE_CONST_FUN_OBJ_1 (busio_uart_reset_input_buffer_obj , busio_uart_obj_reset_input_buffer );
368
+ #endif // CIRCUITPY_BUSIO_UART
361
369
362
370
//| class Parity:
363
371
//| """Enum-like class to define the parity used to verify correct data transfer."""
@@ -400,6 +408,7 @@ const mp_obj_type_t busio_uart_parity_type = {
400
408
};
401
409
402
410
STATIC const mp_rom_map_elem_t busio_uart_locals_dict_table [] = {
411
+ #if CIRCUITPY_BUSIO_UART
403
412
{ MP_ROM_QSTR (MP_QSTR___del__ ), MP_ROM_PTR (& busio_uart_deinit_obj ) },
404
413
{ MP_ROM_QSTR (MP_QSTR_deinit ), MP_ROM_PTR (& busio_uart_deinit_obj ) },
405
414
{ MP_ROM_QSTR (MP_QSTR___enter__ ), MP_ROM_PTR (& default___enter___obj ) },
@@ -417,12 +426,14 @@ STATIC const mp_rom_map_elem_t busio_uart_locals_dict_table[] = {
417
426
{ MP_ROM_QSTR (MP_QSTR_baudrate ), MP_ROM_PTR (& busio_uart_baudrate_obj ) },
418
427
{ MP_ROM_QSTR (MP_QSTR_in_waiting ), MP_ROM_PTR (& busio_uart_in_waiting_obj ) },
419
428
{ MP_ROM_QSTR (MP_QSTR_timeout ), MP_ROM_PTR (& busio_uart_timeout_obj ) },
429
+ #endif // CIRCUITPY_BUSIO_UART
420
430
421
431
// Nested Enum-like Classes.
422
432
{ MP_ROM_QSTR (MP_QSTR_Parity ), MP_ROM_PTR (& busio_uart_parity_type ) },
423
433
};
424
434
STATIC MP_DEFINE_CONST_DICT (busio_uart_locals_dict , busio_uart_locals_dict_table );
425
435
436
+ #if CIRCUITPY_BUSIO_UART
426
437
STATIC const mp_stream_p_t uart_stream_p = {
427
438
MP_PROTO_IMPLEMENT (MP_QSTR_protocol_stream )
428
439
.read = busio_uart_read ,
@@ -445,3 +456,11 @@ const mp_obj_type_t busio_uart_type = {
445
456
.protocol = & uart_stream_p ,
446
457
),
447
458
};
459
+ #else
460
+ const mp_obj_type_t busio_uart_type = {
461
+ { & mp_type_type },
462
+ .name = MP_QSTR_UART ,
463
+ .make_new = busio_uart_make_new ,
464
+ .locals_dict = (mp_obj_dict_t * )& busio_uart_locals_dict ,
465
+ };
466
+ #endif // CIRCUITPY_BUSIO_UART
0 commit comments