diff options
| author | Dan Halbert <halbert@halwitz.org> | 2018-12-03 11:00:35 -0500 |
|---|---|---|
| committer | Dan Halbert <halbert@halwitz.org> | 2018-12-03 12:04:32 -0500 |
| commit | 80db2cec99ca5c995a0302b1d6d00ad77cfcd736 (patch) | |
| tree | 023d45974945a347590808e114843d2100cfc66e /shared-bindings/busio/UART.c | |
| parent | 57c2c4134c52405b78e8d9cd8ed0ed05fefc2827 (diff) | |
UART changes: timeout in secs, write bytes, etc.
Diffstat (limited to 'shared-bindings/busio/UART.c')
| -rw-r--r-- | shared-bindings/busio/UART.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/shared-bindings/busio/UART.c b/shared-bindings/busio/UART.c index e7b8fc0c5..861b36ff2 100644 --- a/shared-bindings/busio/UART.c +++ b/shared-bindings/busio/UART.c @@ -45,7 +45,7 @@ //| ================================================= //| //| -//| .. class:: UART(tx, rx, \*, baudrate=9600, bits=8, parity=None, stop=1, timeout=1000, receiver_buffer_size=64) +//| .. class:: UART(tx, rx, \*, baudrate=9600, bits=8, parity=None, stop=1, timeout=1, receiver_buffer_size=64) //| //| A common bidirectional serial protocol that uses an an agreed upon speed //| rather than a shared clock line. @@ -53,12 +53,14 @@ //| :param ~microcontroller.Pin tx: the pin to transmit with, or ``None`` if this ``UART`` is receive-only. //| :param ~microcontroller.Pin rx: the pin to receive on, or ``None`` if this ``UART`` is transmit-only. //| :param int baudrate: the transmit and receive speed. -/// :param int bits: the number of bits per byte, 7, 8 or 9. -/// :param Parity parity: the parity used for error checking. -/// :param int stop: the number of stop bits, 1 or 2. -/// :param int timeout: the timeout in milliseconds to wait for the first character and between subsequent characters. -/// :param int receiver_buffer_size: the character length of the read buffer (0 to disable). (When a character is 9 bits the buffer will be 2 * receiver_buffer_size bytes.) +//| :param int bits: the number of bits per byte, 7, 8 or 9. +//| :param Parity parity: the parity used for error checking. +//| :param int stop: the number of stop bits, 1 or 2. +//| :param int timeout: the timeout in seconds to wait for the first character and between subsequent characters. +//| :param int receiver_buffer_size: the character length of the read buffer (0 to disable). (When a character is 9 bits the buffer will be 2 * receiver_buffer_size bytes.) //| +//| *New in CircuitPython 4.0:* ``timeout`` has incompatibly changed units from milliseconds to seconds. + typedef struct { mp_obj_base_t base; } busio_uart_parity_obj_t; @@ -83,7 +85,7 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, si { MP_QSTR_bits, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} }, { MP_QSTR_parity, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_stop, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, - { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1000} }, + { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(1)} }, { MP_QSTR_receiver_buffer_size, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 64} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -115,8 +117,9 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, si } common_hal_busio_uart_construct(self, tx, rx, - args[ARG_baudrate].u_int, bits, parity, stop, args[ARG_timeout].u_int, - args[ARG_receiver_buffer_size].u_int); + args[ARG_baudrate].u_int, bits, parity, stop, + mp_obj_get_float(args[ARG_timeout].u_obj), + args[ARG_receiver_buffer_size].u_int); return (mp_obj_t)self; } @@ -161,14 +164,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_uart___exit___obj, 4, 4, busio_ //| :return: Data read //| :rtype: bytes or None //| -//| .. method:: readinto(buf, nbytes=None) +//| .. method:: readinto(buf) //| -//| Read bytes into the ``buf``. If ``nbytes`` is specified then read at most -//| that many bytes. Otherwise, read at most ``len(buf)`` bytes. +//| Read bytes into the ``buf``. Read at most ``len(buf)`` bytes. //| //| :return: number of bytes read and stored into ``buf`` //| :rtype: bytes or None //| +//| *New in CircuitPython 4.0:* No length parameter is permitted. + //| .. method:: readline() //| //| Read a line, ending in a newline character. @@ -180,6 +184,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_uart___exit___obj, 4, 4, busio_ //| //| Write the buffer of bytes to the bus. //| +//| *New in CircuitPython 4.0:* ``buf`` must be bytes, not a string. +//| //| :return: the number of bytes written //| :rtype: int or None //| @@ -353,6 +359,8 @@ STATIC const mp_stream_p_t uart_stream_p = { .write = busio_uart_write, .ioctl = busio_uart_ioctl, .is_text = false, + // Match PySerial when possible, such as disallowing optional length argument for .readinto() + .pyserial_compatibility = true, }; const mp_obj_type_t busio_uart_type = { |
