@@ -108,6 +108,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
108
108
bool have_rx = rx != NULL ;
109
109
bool have_rts = rts != NULL ;
110
110
bool have_cts = cts != NULL ;
111
+
112
+ uart_config_t uart_config = {0 };
111
113
bool have_rs485_dir = rs485_dir != NULL ;
112
114
if (!have_tx && !have_rx ) {
113
115
mp_raise_ValueError (translate ("tx and rx cannot both be None" ));
@@ -135,25 +137,26 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
135
137
}
136
138
137
139
uart_mode_t mode = UART_MODE_UART ;
138
- uart_hw_flowcontrol_t flow_control = UART_HW_FLOWCTRL_DISABLE ;
140
+ uart_config . flow_ctrl = UART_HW_FLOWCTRL_DISABLE ;
139
141
if (have_rs485_dir ) {
140
142
mode = UART_MODE_RS485_HALF_DUPLEX ;
141
143
if (!rs485_invert ) {
144
+ // This one is not in the set
142
145
uart_set_line_inverse (self -> uart_num , UART_SIGNAL_DTR_INV );
143
146
}
144
147
} else if (have_rts && have_cts ) {
145
- flow_control = UART_HW_FLOWCTRL_CTS_RTS ;
148
+ uart_config . flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS ;
146
149
} else if (have_rts ) {
147
- flow_control = UART_HW_FLOWCTRL_RTS ;
150
+ uart_config . flow_ctrl = UART_HW_FLOWCTRL_RTS ;
148
151
} else if (have_rts ) {
149
- flow_control = UART_HW_FLOWCTRL_CTS ;
152
+ uart_config . flow_ctrl = UART_HW_FLOWCTRL_CTS ;
150
153
}
151
154
152
155
if (receiver_buffer_size <= UART_FIFO_LEN ) {
153
156
receiver_buffer_size = UART_FIFO_LEN + 8 ;
154
157
}
155
158
156
- uint8_t rx_threshold = UART_FIFO_LEN - 8 ;
159
+ uart_config . rx_flow_ctrl_thresh = UART_FIFO_LEN - 8 ;
157
160
// Install the driver before we change the settings.
158
161
if (uart_driver_install (self -> uart_num , receiver_buffer_size , 0 , 20 , & self -> event_queue , 0 ) != ESP_OK ||
159
162
uart_set_mode (self -> uart_num , mode ) != ESP_OK ) {
@@ -175,55 +178,62 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
175
178
CONFIG_PTHREAD_TASK_PRIO_DEFAULT ,
176
179
& self -> event_task ,
177
180
xPortGetCoreID ());
178
- uart_set_hw_flow_ctrl (self -> uart_num , flow_control , rx_threshold );
181
+ // uart_set_hw_flow_ctrl(self->uart_num, uart_config. flow_control, uart_config.rx_flow_ctrl_thresh );
179
182
180
183
// Set baud rate
181
- common_hal_busio_uart_set_baudrate (self , baudrate );
184
+ // common_hal_busio_uart_set_baudrate(self, baudrate);
185
+ uart_config .baud_rate = baudrate ;
182
186
183
- uart_word_length_t word_length = UART_DATA_8_BITS ;
187
+ uart_config . data_bits = UART_DATA_8_BITS ;
184
188
switch (bits ) {
185
189
// Shared bindings prevents data < 7 bits.
186
190
// case 5:
187
- // word_length = UART_DATA_5_BITS;
191
+ // uart_config.data_bits = UART_DATA_5_BITS;
188
192
// break;
189
193
// case 6:
190
- // word_length = UART_DATA_6_BITS;
194
+ // uart_config.data_bits = UART_DATA_6_BITS;
191
195
// break;
192
196
case 7 :
193
- word_length = UART_DATA_7_BITS ;
197
+ uart_config . data_bits = UART_DATA_7_BITS ;
194
198
break ;
195
199
case 8 :
196
- word_length = UART_DATA_8_BITS ;
200
+ uart_config . data_bits = UART_DATA_8_BITS ;
197
201
break ;
198
202
default :
199
203
// Won't hit this because shared-bindings limits to 7-9 bits. We error on 9 above.
200
204
break ;
201
205
}
202
- uart_set_word_length (self -> uart_num , word_length );
206
+ // uart_set_word_length(self->uart_num, uart_config.data_bits );
203
207
204
- uart_parity_t parity_mode = UART_PARITY_DISABLE ;
208
+ uart_config . parity = UART_PARITY_DISABLE ;
205
209
switch (parity ) {
206
210
case BUSIO_UART_PARITY_NONE :
207
- parity_mode = UART_PARITY_DISABLE ;
211
+ uart_config . parity = UART_PARITY_DISABLE ;
208
212
break ;
209
213
case BUSIO_UART_PARITY_EVEN :
210
- parity_mode = UART_PARITY_EVEN ;
214
+ uart_config . parity = UART_PARITY_EVEN ;
211
215
break ;
212
216
case BUSIO_UART_PARITY_ODD :
213
- parity_mode = UART_PARITY_ODD ;
217
+ uart_config . parity = UART_PARITY_ODD ;
214
218
break ;
215
219
default :
216
220
// Won't reach here because the input is an enum that is completely handled.
217
221
break ;
218
222
}
219
- uart_set_parity (self -> uart_num , parity_mode );
223
+ // uart_set_parity(self->uart_num, uart_config.parity );
220
224
221
225
// Stop is 1 or 2 always.
222
- uart_stop_bits_t stop_bits = UART_STOP_BITS_1 ;
226
+ uart_config . stop_bits = UART_STOP_BITS_1 ;
223
227
if (stop == 2 ) {
224
- stop_bits = UART_STOP_BITS_2 ;
228
+ uart_config .stop_bits = UART_STOP_BITS_2 ;
229
+ }
230
+ // uart_set_stop_bits(self->uart_num, stop_bits);
231
+ uart_config .source_clk = UART_SCLK_APB ; // guessing here...
232
+
233
+ // config all in one?
234
+ if (uart_param_config (self -> uart_num , & uart_config ) != ESP_OK ) {
235
+ mp_raise_RuntimeError (translate ("UART init" ));
225
236
}
226
- uart_set_stop_bits (self -> uart_num , stop_bits );
227
237
228
238
self -> tx_pin = NULL ;
229
239
self -> rx_pin = NULL ;
0 commit comments