@@ -40,11 +40,13 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
40
40
const mcu_pin_obj_t * tx , const mcu_pin_obj_t * rx , uint32_t baudrate ,
41
41
uint8_t bits , uart_parity_t parity , uint8_t stop , uint32_t timeout ,
42
42
uint8_t receiver_buffer_size ) {
43
- if (rx != NULL || tx != & pin_GPIO2 ) {
43
+ if (rx != mp_const_none || tx != & pin_GPIO2 ) {
44
44
nlr_raise (mp_obj_new_exception_msg (& mp_type_OSError , "Only tx supported on UART1 (GPIO2)." ));
45
45
}
46
+
46
47
// set baudrate
47
48
UartDev .baut_rate = baudrate ;
49
+ self -> baudrate = baudrate ;
48
50
49
51
// set data bits
50
52
switch (bits ) {
@@ -90,6 +92,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
90
92
}
91
93
92
94
uart_setup (UART1 );
95
+ self -> deinited = false;
93
96
}
94
97
95
98
bool common_hal_busio_uart_deinited (busio_uart_obj_t * self ) {
@@ -100,7 +103,8 @@ void common_hal_busio_uart_deinit(busio_uart_obj_t *self) {
100
103
if (common_hal_busio_uart_deinited (self )) {
101
104
return ;
102
105
}
103
- PIN_FUNC_SELECT (FUNC_U1TXD_BK , 0 );
106
+ // Switch GPIO2 back to a GPIO pin.
107
+ PIN_FUNC_SELECT (PERIPHS_IO_MUX_GPIO2_U , FUNC_GPIO2 );
104
108
self -> deinited = true;
105
109
}
106
110
@@ -119,6 +123,16 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data,
119
123
return len ;
120
124
}
121
125
126
+ uint32_t common_hal_busio_uart_get_baudrate (busio_uart_obj_t * self ) {
127
+ return self -> baudrate ;
128
+ }
129
+
130
+ void common_hal_busio_uart_set_baudrate (busio_uart_obj_t * self , uint32_t baudrate ) {
131
+ UartDev .baut_rate = baudrate ;
132
+ uart_setup (UART1 );
133
+ self -> baudrate = baudrate ;
134
+ }
135
+
122
136
uint32_t common_hal_busio_uart_rx_characters_available (busio_uart_obj_t * self ) {
123
137
return 0 ;
124
138
}
0 commit comments