kopia lustrzana https://github.com/micropython/micropython
cc3200: Make UART API more similar to stmhal.
rodzic
640d00ea9d
commit
8a6d93aeed
|
@ -352,11 +352,11 @@ STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_k
|
||||||
/// Initialise the UART bus with the given parameters:
|
/// Initialise the UART bus with the given parameters:
|
||||||
///
|
///
|
||||||
/// - `baudrate` is the clock rate.
|
/// - `baudrate` is the clock rate.
|
||||||
/// - `bits` is the number of bits per byte, 7, 8 or 9.
|
/// - `bits` is the number of bits per byte, 5, 6, 7, 8
|
||||||
/// - `parity` is the parity, `None`, 0 (even) or 1 (odd).
|
/// - `parity` is the parity, `None`, 0 (even) or 1 (odd).
|
||||||
/// - `stop` is the number of stop bits, 1 or 2.
|
/// - `stop` is the number of stop bits, 1 or 2.
|
||||||
/// - `flowcontrol` is the flow control mode, `None`, `UART.FLOW_TX`,
|
/// - `flow` is the flow control mode, `None`, `UART.RTS`,
|
||||||
/// `UART.FLOW_RX', 'UART.FLOW_TXRX`.
|
/// `UART.CTS', or `UART.CTS | UART.RTS`
|
||||||
/// - `timeout` is the timeout (in milliseconds) when waiting for the first character.
|
/// - `timeout` is the timeout (in milliseconds) when waiting for the first character.
|
||||||
/// - `timeout_char` is the timeout (in milliseconds) between characters.
|
/// - `timeout_char` is the timeout (in milliseconds) between characters.
|
||||||
STATIC const mp_arg_t pyb_uart_init_args[] = {
|
STATIC const mp_arg_t pyb_uart_init_args[] = {
|
||||||
|
@ -403,7 +403,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_uint_t n_args, con
|
||||||
self->config = UART_CONFIG_WLEN_8;
|
self->config = UART_CONFIG_WLEN_8;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
|
goto error;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Parity
|
// Parity
|
||||||
|
@ -415,6 +415,10 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_uint_t n_args, con
|
||||||
// Stop bits
|
// Stop bits
|
||||||
self->config |= (args[3].u_int == 1 ? UART_CONFIG_STOP_ONE : UART_CONFIG_STOP_TWO);
|
self->config |= (args[3].u_int == 1 ? UART_CONFIG_STOP_ONE : UART_CONFIG_STOP_TWO);
|
||||||
// Flow control
|
// Flow control
|
||||||
|
if (args[4].u_int != UART_FLOWCONTROL_NONE || args[4].u_int != UART_FLOWCONTROL_TX ||
|
||||||
|
args[4].u_int != UART_FLOWCONTROL_RX || args[4].u_int != (UART_FLOWCONTROL_TX | UART_FLOWCONTROL_RX)) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
self->flowcontrol = args[4].u_int;
|
self->flowcontrol = args[4].u_int;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -428,6 +432,9 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_uint_t n_args, con
|
||||||
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)uart_init);
|
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)uart_init);
|
||||||
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
|
|
||||||
|
error:
|
||||||
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \classmethod \constructor(bus, ...)
|
/// \classmethod \constructor(bus, ...)
|
||||||
|
@ -583,10 +590,8 @@ STATIC const mp_map_elem_t pyb_uart_locals_dict_table[] = {
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_readchar), (mp_obj_t)&pyb_uart_readchar_obj },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_readchar), (mp_obj_t)&pyb_uart_readchar_obj },
|
||||||
|
|
||||||
// class constants
|
// class constants
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_FLOW_NONE), MP_OBJ_NEW_SMALL_INT(UART_FLOWCONTROL_NONE) },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_CTS), MP_OBJ_NEW_SMALL_INT(UART_FLOWCONTROL_TX) },
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_FLOW_TX), MP_OBJ_NEW_SMALL_INT(UART_FLOWCONTROL_TX) },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_RTS), MP_OBJ_NEW_SMALL_INT(UART_FLOWCONTROL_RX) },
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_FLOW_RX), MP_OBJ_NEW_SMALL_INT(UART_FLOWCONTROL_RX) },
|
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_FLOW_TXRX), MP_OBJ_NEW_SMALL_INT(UART_FLOWCONTROL_TX | UART_FLOWCONTROL_RX) },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
STATIC MP_DEFINE_CONST_DICT(pyb_uart_locals_dict, pyb_uart_locals_dict_table);
|
STATIC MP_DEFINE_CONST_DICT(pyb_uart_locals_dict, pyb_uart_locals_dict_table);
|
||||||
|
|
|
@ -154,10 +154,8 @@ Q(timeout)
|
||||||
Q(timeout_char)
|
Q(timeout_char)
|
||||||
Q(repl_uart)
|
Q(repl_uart)
|
||||||
Q(flow)
|
Q(flow)
|
||||||
Q(FLOW_NONE)
|
Q(RTS)
|
||||||
Q(FLOW_TX)
|
Q(CTS)
|
||||||
Q(FLOW_RX)
|
|
||||||
Q(FLOW_TXRX)
|
|
||||||
|
|
||||||
// for I2C class
|
// for I2C class
|
||||||
Q(I2C)
|
Q(I2C)
|
||||||
|
@ -370,4 +368,3 @@ Q(sha256)
|
||||||
Q(ubinascii)
|
Q(ubinascii)
|
||||||
Q(hexlify)
|
Q(hexlify)
|
||||||
Q(unhexlify)
|
Q(unhexlify)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue