summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2018-12-06 12:41:38 -0500
committerDan Halbert <halbert@halwitz.org>2018-12-06 12:41:38 -0500
commit125901e4e20cfbdef8b8a0a71b424d1545b203b1 (patch)
treea0d60257438fa32aa4bdbbd59254fb83ece85c79 /shared-bindings
parent3164b16196e437c544d03059f2475bfed0a15f30 (diff)
parentca3c9920375909245f4efed1de4b2c192dbbad3a (diff)
Merge remote-tracking branch 'adafruit/master' into bleio-rev
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/audioio/AudioOut.c2
-rw-r--r--shared-bindings/busio/I2C.c2
-rw-r--r--shared-bindings/busio/UART.c38
-rw-r--r--shared-bindings/busio/UART.h2
4 files changed, 29 insertions, 15 deletions
diff --git a/shared-bindings/audioio/AudioOut.c b/shared-bindings/audioio/AudioOut.c
index 18d908eef..94340d62c 100644
--- a/shared-bindings/audioio/AudioOut.c
+++ b/shared-bindings/audioio/AudioOut.c
@@ -101,7 +101,7 @@ STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_left_channel, MP_ARG_OBJ | MP_ARG_REQUIRED },
{ MP_QSTR_right_channel, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = mp_const_none} },
- { MP_QSTR_quiescent_value, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_int = 0x8000} },
+ { MP_QSTR_quiescent_value, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x8000} },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c
index dedcc0150..9581f3a3d 100644
--- a/shared-bindings/busio/I2C.c
+++ b/shared-bindings/busio/I2C.c
@@ -58,7 +58,7 @@
//| :param ~microcontroller.Pin scl: The clock pin
//| :param ~microcontroller.Pin sda: The data pin
//| :param int frequency: The clock frequency in Hertz
-//| :param int timeout: The maximum clock stretching timeut - only for bitbang
+//| :param int timeout: The maximum clock stretching timeut - (used only for bitbangio.I2C; ignored for busio.I2C)
//|
STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, true);
diff --git a/shared-bindings/busio/UART.c b/shared-bindings/busio/UART.c
index e7b8fc0c5..1cba386d2 100644
--- a/shared-bindings/busio/UART.c
+++ b/shared-bindings/busio/UART.c
@@ -31,6 +31,7 @@
#include "shared-bindings/util.h"
#include "lib/utils/context_manager_helpers.h"
+#include "lib/utils/interrupt_char.h"
#include "py/ioctl.h"
#include "py/objproperty.h"
@@ -45,7 +46,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 +54,15 @@
//| :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. Raises ``ValueError`` if timeout >100 seconds.
+//| :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.
+//| The new upper limit on ``timeout`` is meant to catch mistaken use of milliseconds.
+
typedef struct {
mp_obj_base_t base;
} busio_uart_parity_obj_t;
@@ -83,7 +87,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)];
@@ -114,9 +118,14 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, si
mp_raise_ValueError(translate("stop must be 1 or 2"));
}
+ mp_float_t timeout = mp_obj_get_float(args[ARG_timeout].u_obj);
+ if (timeout > 100.0f) {
+ mp_raise_ValueError(translate("timeout >100 (units are now seconds, not msecs)"));
+ }
+
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, timeout,
+ args[ARG_receiver_buffer_size].u_int);
return (mp_obj_t)self;
}
@@ -161,14 +170,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 +190,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 +365,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 = {
diff --git a/shared-bindings/busio/UART.h b/shared-bindings/busio/UART.h
index 513ff50c8..e171f8bb4 100644
--- a/shared-bindings/busio/UART.h
+++ b/shared-bindings/busio/UART.h
@@ -41,7 +41,7 @@ typedef enum {
// Construct an underlying UART object.
extern void common_hal_busio_uart_construct(busio_uart_obj_t *self,
const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate,
- uint8_t bits, uart_parity_t parity, uint8_t stop, uint32_t timeout,
+ uint8_t bits, uart_parity_t parity, uint8_t stop, mp_float_t timeout,
uint8_t receiver_buffer_size);
extern void common_hal_busio_uart_deinit(busio_uart_obj_t *self);