diff options
Diffstat (limited to 'cc3200/mods/pybuart.c')
-rw-r--r-- | cc3200/mods/pybuart.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c index fe710be92..92bb3e46e 100644 --- a/cc3200/mods/pybuart.c +++ b/cc3200/mods/pybuart.c @@ -279,7 +279,7 @@ STATIC void UARTGenericIntHandler(uint32_t uart_id) { STATIC void uart_check_init(pyb_uart_obj_t *self) { // not initialized if (!self->baudrate) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } } @@ -375,10 +375,13 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, const mp_arg_val_t *a config |= UART_CONFIG_PAR_NONE; } else { uint parity = mp_obj_get_int(args[2].u_obj); - if (parity != UART_CONFIG_PAR_ODD && parity != UART_CONFIG_PAR_EVEN) { + if (parity == 0) { + config |= UART_CONFIG_PAR_EVEN; + } else if (parity == 1) { + config |= UART_CONFIG_PAR_ODD; + } else { goto error; } - config |= parity; } // stop bits config |= (args[3].u_int == 1 ? UART_CONFIG_STOP_ONE : UART_CONFIG_STOP_TWO); @@ -388,7 +391,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, const mp_arg_val_t *a uint flowcontrol = UART_FLOWCONTROL_NONE; if (pins_o != mp_const_none) { mp_obj_t *pins; - mp_uint_t n_pins = 2; + size_t n_pins = 2; if (pins_o == MP_OBJ_NULL) { // use the default pins pins = (mp_obj_t *)pyb_uart_def_pin[self->uart_id]; @@ -454,7 +457,7 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size if (args[0].u_obj == MP_OBJ_NULL) { if (args[5].u_obj != MP_OBJ_NULL) { mp_obj_t *pins; - mp_uint_t n_pins = 2; + size_t n_pins = 2; mp_obj_get_array(args[5].u_obj, &n_pins, &pins); // check the Tx pin (or the Rx if Tx is None) if (pins[0] == mp_const_none) { @@ -471,7 +474,7 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size } if (uart_id > PYB_UART_1) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // get the correct uart instance @@ -577,8 +580,6 @@ STATIC const mp_map_elem_t pyb_uart_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj }, // class constants - { MP_OBJ_NEW_QSTR(MP_QSTR_EVEN), MP_OBJ_NEW_SMALL_INT(UART_CONFIG_PAR_EVEN) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ODD), MP_OBJ_NEW_SMALL_INT(UART_CONFIG_PAR_ODD) }, { MP_OBJ_NEW_QSTR(MP_QSTR_RX_ANY), MP_OBJ_NEW_SMALL_INT(UART_TRIGGER_RX_ANY) }, }; @@ -596,8 +597,8 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i // wait for first char to become available if (!uart_rx_wait(self)) { - // return EAGAIN error to indicate non-blocking (then read() method returns None) - *errcode = EAGAIN; + // return MP_EAGAIN error to indicate non-blocking (then read() method returns None) + *errcode = MP_EAGAIN; return MP_STREAM_ERROR; } @@ -619,7 +620,7 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t // write the data if (!uart_tx_strn(self, buf, size)) { - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); + mp_raise_OSError(MP_EIO); } return size; } @@ -639,7 +640,7 @@ STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t a ret |= MP_STREAM_POLL_WR; } } else { - *errcode = EINVAL; + *errcode = MP_EINVAL; ret = MP_STREAM_ERROR; } return ret; @@ -664,7 +665,7 @@ const mp_obj_type_t pyb_uart_type = { .name = MP_QSTR_UART, .print = pyb_uart_print, .make_new = pyb_uart_make_new, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = mp_stream_unbuffered_iter, .protocol = &uart_stream_p, .locals_dict = (mp_obj_t)&pyb_uart_locals_dict, |