2626
2727#include "shared-bindings/busio/I2C.h"
2828#include "shared-bindings/busio/SPI.h"
29+ #include "shared-bindings/busio/UART.h"
30+
2931#include "shared-bindings/microcontroller/Pin.h"
3032#include "mpconfigboard.h"
3133#include "pins.h"
3436
3537
3638#if !defined(DEFAULT_I2C_BUS_SDA ) || !defined(DEFAULT_I2C_BUS_SCL )
37-
3839 STATIC mp_obj_t board_i2c (void ) {
39- //board_i2c_obj = NULL;
4040 mp_raise_NotImplementedError ("No default I2C bus" );
4141 return NULL ;
4242 }
43-
4443#else
4544 STATIC mp_obj_t i2c_singleton = NULL ;
4645
5958
6059 }
6160#endif
62-
6361MP_DEFINE_CONST_FUN_OBJ_0 (board_i2c_obj , board_i2c );
6462
6563#if !defined(DEFAULT_SPI_BUS_SCK ) || !defined(DEFAULT_SPI_BUS_MISO ) || !defined(DEFAULT_SPI_BUS_MOSI )
@@ -88,3 +86,30 @@ MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c);
8886 }
8987#endif
9088MP_DEFINE_CONST_FUN_OBJ_0 (board_spi_obj , board_spi );
89+
90+ #if !defined(DEFAULT_UART_BUS_RX ) || !defined(DEFAULT_UART_BUS_TX )
91+ STATIC mp_obj_t board_uart (void ) {
92+ mp_raise_NotImplementedError ("No default UART bus" );
93+ return NULL ;
94+ }
95+ #else
96+ STATIC mp_obj_t uart_singleton = NULL ;
97+
98+ STATIC mp_obj_t board_uart (void ) {
99+ if (uart_singleton == NULL ) {
100+ busio_uart_obj_t * self = m_new_obj (busio_uart_obj_t );
101+ self -> base .type = & busio_uart_type ;
102+
103+ assert_pin_free (DEFAULT_UART_BUS_RX );
104+ assert_pin_free (DEFAULT_UART_BUS_TX );
105+
106+ const mcu_pin_obj_t * rx = MP_OBJ_TO_PTR (DEFAULT_UART_BUS_RX );
107+ const mcu_pin_obj_t * tx = MP_OBJ_TO_PTR (DEFAULT_UART_BUS_TX );
108+
109+ common_hal_busio_uart_construct (self , tx , rx , 9600 , 8 , PARITY_NONE , 1 , 1000 , 64 );
110+ uart_singleton = (mp_obj_t )self ;
111+ }
112+ return uart_singleton ;
113+ }
114+ #endif
115+ MP_DEFINE_CONST_FUN_OBJ_0 (board_uart_obj , board_uart );
0 commit comments