@@ -84,7 +84,7 @@ STATIC const char *_parity_name[] = {"None", "1", "0"};
84
84
STATIC void mp_machine_uart_print (const mp_print_t * print , mp_obj_t self_in , mp_print_kind_t kind ) {
85
85
machine_uart_obj_t * self = MP_OBJ_TO_PTR (self_in );
86
86
uint32_t baudrate ;
87
- uart_get_baudrate (self -> uart_num , & baudrate );
87
+ check_esp_err ( uart_get_baudrate (self -> uart_num , & baudrate ) );
88
88
mp_printf (print , "UART(%u, baudrate=%u, bits=%u, parity=%s, stop=%u, tx=%d, rx=%d, rts=%d, cts=%d, txbuf=%u, rxbuf=%u, timeout=%u, timeout_char=%u" ,
89
89
self -> uart_num , baudrate , self -> bits , _parity_name [self -> parity ],
90
90
self -> stop , self -> tx , self -> rx , self -> rts , self -> cts , self -> txbuf , self -> rxbuf , self -> timeout , self -> timeout_char );
@@ -177,22 +177,22 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args,
177
177
.source_clk = UART_SOURCE_CLK ,
178
178
};
179
179
uint32_t baudrate ;
180
- uart_get_baudrate (self -> uart_num , & baudrate );
180
+ check_esp_err ( uart_get_baudrate (self -> uart_num , & baudrate ) );
181
181
uartcfg .baud_rate = baudrate ;
182
- uart_get_word_length (self -> uart_num , & uartcfg .data_bits );
183
- uart_get_parity (self -> uart_num , & uartcfg .parity );
184
- uart_get_stop_bits (self -> uart_num , & uartcfg .stop_bits );
185
- uart_driver_delete (self -> uart_num );
186
- uart_param_config (self -> uart_num , & uartcfg );
187
- uart_driver_install (self -> uart_num , self -> rxbuf , self -> txbuf , 0 , NULL , 0 );
182
+ check_esp_err ( uart_get_word_length (self -> uart_num , & uartcfg .data_bits ) );
183
+ check_esp_err ( uart_get_parity (self -> uart_num , & uartcfg .parity ) );
184
+ check_esp_err ( uart_get_stop_bits (self -> uart_num , & uartcfg .stop_bits ) );
185
+ check_esp_err ( uart_driver_delete (self -> uart_num ) );
186
+ check_esp_err ( uart_param_config (self -> uart_num , & uartcfg ) );
187
+ check_esp_err ( uart_driver_install (self -> uart_num , self -> rxbuf , self -> txbuf , 0 , NULL , 0 ) );
188
188
}
189
189
190
190
// set baudrate
191
191
uint32_t baudrate = 115200 ;
192
192
if (args [ARG_baudrate ].u_int > 0 ) {
193
- uart_set_baudrate (self -> uart_num , args [ARG_baudrate ].u_int );
193
+ check_esp_err ( uart_set_baudrate (self -> uart_num , args [ARG_baudrate ].u_int ) );
194
194
}
195
- uart_get_baudrate (self -> uart_num , & baudrate );
195
+ check_esp_err ( uart_get_baudrate (self -> uart_num , & baudrate ) );
196
196
197
197
if (args [ARG_tx ].u_obj != MP_OBJ_NULL ) {
198
198
self -> tx = machine_pin_get_id (args [ARG_tx ].u_obj );
@@ -209,26 +209,26 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args,
209
209
if (args [ARG_cts ].u_obj != MP_OBJ_NULL ) {
210
210
self -> cts = machine_pin_get_id (args [ARG_cts ].u_obj );
211
211
}
212
- uart_set_pin (self -> uart_num , self -> tx , self -> rx , self -> rts , self -> cts );
212
+ check_esp_err ( uart_set_pin (self -> uart_num , self -> tx , self -> rx , self -> rts , self -> cts ) );
213
213
214
214
// set data bits
215
215
switch (args [ARG_bits ].u_int ) {
216
216
case 0 :
217
217
break ;
218
218
case 5 :
219
- uart_set_word_length (self -> uart_num , UART_DATA_5_BITS );
219
+ check_esp_err ( uart_set_word_length (self -> uart_num , UART_DATA_5_BITS ) );
220
220
self -> bits = 5 ;
221
221
break ;
222
222
case 6 :
223
- uart_set_word_length (self -> uart_num , UART_DATA_6_BITS );
223
+ check_esp_err ( uart_set_word_length (self -> uart_num , UART_DATA_6_BITS ) );
224
224
self -> bits = 6 ;
225
225
break ;
226
226
case 7 :
227
- uart_set_word_length (self -> uart_num , UART_DATA_7_BITS );
227
+ check_esp_err ( uart_set_word_length (self -> uart_num , UART_DATA_7_BITS ) );
228
228
self -> bits = 7 ;
229
229
break ;
230
230
case 8 :
231
- uart_set_word_length (self -> uart_num , UART_DATA_8_BITS );
231
+ check_esp_err ( uart_set_word_length (self -> uart_num , UART_DATA_8_BITS ) );
232
232
self -> bits = 8 ;
233
233
break ;
234
234
default :
@@ -239,15 +239,15 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args,
239
239
// set parity
240
240
if (args [ARG_parity ].u_obj != MP_OBJ_NULL ) {
241
241
if (args [ARG_parity ].u_obj == mp_const_none ) {
242
- uart_set_parity (self -> uart_num , UART_PARITY_DISABLE );
242
+ check_esp_err ( uart_set_parity (self -> uart_num , UART_PARITY_DISABLE ) );
243
243
self -> parity = 0 ;
244
244
} else {
245
245
mp_int_t parity = mp_obj_get_int (args [ARG_parity ].u_obj );
246
246
if (parity & 1 ) {
247
- uart_set_parity (self -> uart_num , UART_PARITY_ODD );
247
+ check_esp_err ( uart_set_parity (self -> uart_num , UART_PARITY_ODD ) );
248
248
self -> parity = 1 ;
249
249
} else {
250
- uart_set_parity (self -> uart_num , UART_PARITY_EVEN );
250
+ check_esp_err ( uart_set_parity (self -> uart_num , UART_PARITY_EVEN ) );
251
251
self -> parity = 2 ;
252
252
}
253
253
}
@@ -259,11 +259,11 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args,
259
259
case 0 :
260
260
break ;
261
261
case 1 :
262
- uart_set_stop_bits (self -> uart_num , UART_STOP_BITS_1 );
262
+ check_esp_err ( uart_set_stop_bits (self -> uart_num , UART_STOP_BITS_1 ) );
263
263
self -> stop = 1 ;
264
264
break ;
265
265
case 2 :
266
- uart_set_stop_bits (self -> uart_num , UART_STOP_BITS_2 );
266
+ check_esp_err ( uart_set_stop_bits (self -> uart_num , UART_STOP_BITS_2 ) );
267
267
self -> stop = 2 ;
268
268
break ;
269
269
default :
@@ -283,10 +283,10 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args,
283
283
uint32_t char_time_ms = 12000 / baudrate + 1 ;
284
284
uint32_t rx_timeout = self -> timeout_char / char_time_ms ;
285
285
if (rx_timeout < 1 ) {
286
- uart_set_rx_full_threshold (self -> uart_num , 1 );
287
- uart_set_rx_timeout (self -> uart_num , 1 );
286
+ check_esp_err ( uart_set_rx_full_threshold (self -> uart_num , 1 ) );
287
+ check_esp_err ( uart_set_rx_timeout (self -> uart_num , 1 ) );
288
288
} else {
289
- uart_set_rx_timeout (self -> uart_num , rx_timeout );
289
+ check_esp_err ( uart_set_rx_timeout (self -> uart_num , rx_timeout ) );
290
290
}
291
291
}
292
292
@@ -297,7 +297,7 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args,
297
297
}
298
298
self -> invert = args [ARG_invert ].u_int ;
299
299
}
300
- uart_set_line_inverse (self -> uart_num , self -> invert );
300
+ check_esp_err ( uart_set_line_inverse (self -> uart_num , self -> invert ) );
301
301
302
302
// set hardware flow control
303
303
if (args [ARG_flow ].u_int != -1 ) {
@@ -306,7 +306,7 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args,
306
306
}
307
307
self -> flowcontrol = args [ARG_flow ].u_int ;
308
308
}
309
- uart_set_hw_flow_ctrl (self -> uart_num , self -> flowcontrol , UART_FIFO_LEN - UART_FIFO_LEN / 4 );
309
+ check_esp_err ( uart_set_hw_flow_ctrl (self -> uart_num , self -> flowcontrol , UART_FIFO_LEN - UART_FIFO_LEN / 4 ) );
310
310
}
311
311
312
312
STATIC mp_obj_t mp_machine_uart_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * args ) {
@@ -367,32 +367,32 @@ STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg
367
367
#endif
368
368
{
369
369
// Remove any existing configuration
370
- uart_driver_delete (self -> uart_num );
370
+ check_esp_err ( uart_driver_delete (self -> uart_num ) );
371
371
372
372
// init the peripheral
373
373
// Setup
374
- uart_param_config (self -> uart_num , & uartcfg );
374
+ check_esp_err ( uart_param_config (self -> uart_num , & uartcfg ) );
375
375
376
- uart_driver_install (uart_num , self -> rxbuf , self -> txbuf , 0 , NULL , 0 );
376
+ check_esp_err ( uart_driver_install (uart_num , self -> rxbuf , self -> txbuf , 0 , NULL , 0 ) );
377
377
}
378
378
379
379
mp_map_t kw_args ;
380
380
mp_map_init_fixed_table (& kw_args , n_kw , args + n_args );
381
381
mp_machine_uart_init_helper (self , n_args - 1 , args + 1 , & kw_args );
382
382
383
383
// Make sure pins are connected.
384
- uart_set_pin (self -> uart_num , self -> tx , self -> rx , self -> rts , self -> cts );
384
+ check_esp_err ( uart_set_pin (self -> uart_num , self -> tx , self -> rx , self -> rts , self -> cts ) );
385
385
386
386
return MP_OBJ_FROM_PTR (self );
387
387
}
388
388
389
389
STATIC void mp_machine_uart_deinit (machine_uart_obj_t * self ) {
390
- uart_driver_delete (self -> uart_num );
390
+ check_esp_err ( uart_driver_delete (self -> uart_num ) );
391
391
}
392
392
393
393
STATIC mp_int_t mp_machine_uart_any (machine_uart_obj_t * self ) {
394
394
size_t rxbufsize ;
395
- uart_get_buffered_data_len (self -> uart_num , & rxbufsize );
395
+ check_esp_err ( uart_get_buffered_data_len (self -> uart_num , & rxbufsize ) );
396
396
return rxbufsize ;
397
397
}
398
398
@@ -403,18 +403,18 @@ STATIC bool mp_machine_uart_txdone(machine_uart_obj_t *self) {
403
403
STATIC void mp_machine_uart_sendbreak (machine_uart_obj_t * self ) {
404
404
// Save settings
405
405
uint32_t baudrate ;
406
- uart_get_baudrate (self -> uart_num , & baudrate );
406
+ check_esp_err ( uart_get_baudrate (self -> uart_num , & baudrate ) );
407
407
408
408
// Synthesise the break condition by reducing the baud rate,
409
409
// and cater for the worst case of 5 data bits, no parity.
410
- uart_wait_tx_done (self -> uart_num , pdMS_TO_TICKS (1000 ));
411
- uart_set_baudrate (self -> uart_num , baudrate * 6 / 15 );
410
+ check_esp_err ( uart_wait_tx_done (self -> uart_num , pdMS_TO_TICKS (1000 ) ));
411
+ check_esp_err ( uart_set_baudrate (self -> uart_num , baudrate * 6 / 15 ) );
412
412
char buf [1 ] = {0 };
413
413
uart_write_bytes (self -> uart_num , buf , 1 );
414
- uart_wait_tx_done (self -> uart_num , pdMS_TO_TICKS (1000 ));
414
+ check_esp_err ( uart_wait_tx_done (self -> uart_num , pdMS_TO_TICKS (1000 ) ));
415
415
416
416
// Restore original setting
417
- uart_set_baudrate (self -> uart_num , baudrate );
417
+ check_esp_err ( uart_set_baudrate (self -> uart_num , baudrate ) );
418
418
}
419
419
420
420
STATIC mp_uint_t mp_machine_uart_read (mp_obj_t self_in , void * buf_in , mp_uint_t size , int * errcode ) {
@@ -472,7 +472,7 @@ STATIC mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uint
472
472
mp_uint_t flags = arg ;
473
473
ret = 0 ;
474
474
size_t rxbufsize ;
475
- uart_get_buffered_data_len (self -> uart_num , & rxbufsize );
475
+ check_esp_err ( uart_get_buffered_data_len (self -> uart_num , & rxbufsize ) );
476
476
if ((flags & MP_STREAM_POLL_RD ) && rxbufsize > 0 ) {
477
477
ret |= MP_STREAM_POLL_RD ;
478
478
}
@@ -483,7 +483,7 @@ STATIC mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uint
483
483
// The timeout is estimated using the buffer size and the baudrate.
484
484
// Take the worst case assumptions at 13 bit symbol size times 2.
485
485
uint32_t baudrate ;
486
- uart_get_baudrate (self -> uart_num , & baudrate );
486
+ check_esp_err ( uart_get_baudrate (self -> uart_num , & baudrate ) );
487
487
uint32_t timeout = (3 + self -> txbuf ) * 13000 * 2 / baudrate ;
488
488
if (uart_wait_tx_done (self -> uart_num , timeout ) == ESP_OK ) {
489
489
ret = 0 ;
0 commit comments