summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2021-02-25 16:59:15 -0800
committerScott Shawcroft <scott@tannewt.org>2021-02-25 16:59:15 -0800
commit3f08cb47b846fff41ef9a45d49758f0cef61e723 (patch)
tree66d5093b24d127a1fb60cc70f5087b39e87fbff5 /py
parent52bc935fa7aa9e5c94f75fec8b2fa746c83f0be7 (diff)
parentb69cb0144ca0d54011be540213d1e25e673a63de (diff)
Merge remote-tracking branch 'adafruit/main' into busio-uart-rp
Diffstat (limited to 'py')
-rw-r--r--py/circuitpy_defns.mk9
-rw-r--r--py/circuitpy_mpconfig.h24
-rw-r--r--py/circuitpy_mpconfig.mk99
-rw-r--r--py/obj.h1
-rw-r--r--py/objarray.c32
-rw-r--r--py/objfloat.c9
-rw-r--r--py/stream.c32
-rw-r--r--py/stream.h4
8 files changed, 155 insertions, 55 deletions
diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk
index 47870ede1..943c99f93 100644
--- a/py/circuitpy_defns.mk
+++ b/py/circuitpy_defns.mk
@@ -132,9 +132,6 @@ endif
ifeq ($(CIRCUITPY_AUDIOMP3),1)
SRC_PATTERNS += audiomp3/%
endif
-ifeq ($(CIRCUITPY_BITOPS),1)
-SRC_PATTERNS += bitops/%
-endif
ifeq ($(CIRCUITPY_BITBANGIO),1)
SRC_PATTERNS += bitbangio/%
endif
@@ -142,6 +139,9 @@ endif
ifeq ($(CIRCUITPY_BITBANG_APA102),1)
SRC_PATTERNS += bitbangio/SPI%
endif
+ifeq ($(CIRCUITPY_BITOPS),1)
+SRC_PATTERNS += bitops/%
+endif
ifeq ($(CIRCUITPY_BLEIO),1)
SRC_PATTERNS += _bleio/%
endif
@@ -289,6 +289,9 @@ endif
ifeq ($(CIRCUITPY_UHEAP),1)
SRC_PATTERNS += uheap/%
endif
+ifeq ($(CIRCUITPY_USB_CDC),1)
+SRC_PATTERNS += usb_cdc/%
+endif
ifeq ($(CIRCUITPY_USB_HID),1)
SRC_PATTERNS += usb_hid/%
endif
diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h
index d72146c42..cbe668289 100644
--- a/py/circuitpy_mpconfig.h
+++ b/py/circuitpy_mpconfig.h
@@ -299,6 +299,13 @@ extern const struct _mp_obj_module_t audiopwmio_module;
#define BINASCII_MODULE
#endif
+#if CIRCUITPY_BITBANGIO
+#define BITBANGIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_bitbangio), (mp_obj_t)&bitbangio_module },
+extern const struct _mp_obj_module_t bitbangio_module;
+#else
+#define BITBANGIO_MODULE
+#endif
+
#if CIRCUITPY_BITOPS
extern const struct _mp_obj_module_t bitops_module;
#define BITOPS_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_bitops),(mp_obj_t)&bitops_module },
@@ -307,13 +314,6 @@ extern const struct _mp_obj_module_t bitops_module;
#endif
-#if CIRCUITPY_BITBANGIO
-#define BITBANGIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_bitbangio), (mp_obj_t)&bitbangio_module },
-extern const struct _mp_obj_module_t bitbangio_module;
-#else
-#define BITBANGIO_MODULE
-#endif
-
#if CIRCUITPY_BLEIO
#define BLEIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR__bleio), (mp_obj_t)&bleio_module },
extern const struct _mp_obj_module_t bleio_module;
@@ -744,6 +744,13 @@ extern const struct _mp_obj_module_t uheap_module;
#define UHEAP_MODULE
#endif
+#if CIRCUITPY_USB_CDC
+extern const struct _mp_obj_module_t usb_cdc_module;
+#define USB_CDC_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_usb_cdc),(mp_obj_t)&usb_cdc_module },
+#else
+#define USB_CDC_MODULE
+#endif
+
#if CIRCUITPY_USB_HID
extern const struct _mp_obj_module_t usb_hid_module;
#define USB_HID_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_usb_hid),(mp_obj_t)&usb_hid_module },
@@ -827,8 +834,8 @@ extern const struct _mp_obj_module_t msgpack_module;
AUDIOMP3_MODULE \
AUDIOPWMIO_MODULE \
BINASCII_MODULE \
- BITOPS_MODULE \
BITBANGIO_MODULE \
+ BITOPS_MODULE \
BLEIO_MODULE \
BOARD_MODULE \
BUSDEVICE_MODULE \
@@ -884,6 +891,7 @@ extern const struct _mp_obj_module_t msgpack_module;
SUPERVISOR_MODULE \
TOUCHIO_MODULE \
UHEAP_MODULE \
+ USB_CDC_MODULE \
USB_HID_MODULE \
USB_MIDI_MODULE \
USTACK_MODULE \
diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk
index 6244ed136..ad6386636 100644
--- a/py/circuitpy_mpconfig.mk
+++ b/py/circuitpy_mpconfig.mk
@@ -89,12 +89,15 @@ CFLAGS += -DCIRCUITPY_AUDIOMP3=$(CIRCUITPY_AUDIOMP3)
CIRCUITPY_BINASCII ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_BINASCII=$(CIRCUITPY_BINASCII)
-CIRCUITPY_BITOPS ?= 0
-CFLAGS += -DCIRCUITPY_BITOPS=$(CIRCUITPY_BITOPS)
+CIRCUITPY_BITBANG_APA102 ?= 0
+CFLAGS += -DCIRCUITPY_BITBANG_APA102=$(CIRCUITPY_BITBANG_APA102)
CIRCUITPY_BITBANGIO ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_BITBANGIO=$(CIRCUITPY_BITBANGIO)
+CIRCUITPY_BITOPS ?= 0
+CFLAGS += -DCIRCUITPY_BITOPS=$(CIRCUITPY_BITOPS)
+
# _bleio can be supported on most any board via HCI
CIRCUITPY_BLEIO_HCI ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_BLEIO_HCI=$(CIRCUITPY_BLEIO_HCI)
@@ -103,6 +106,9 @@ CFLAGS += -DCIRCUITPY_BLEIO_HCI=$(CIRCUITPY_BLEIO_HCI)
CIRCUITPY_BLEIO ?= $(CIRCUITPY_BLEIO_HCI)
CFLAGS += -DCIRCUITPY_BLEIO=$(CIRCUITPY_BLEIO)
+CIRCUITPY_BLE_FILE_SERVICE ?= 0
+CFLAGS += -DCIRCUITPY_BLE_FILE_SERVICE=$(CIRCUITPY_BLE_FILE_SERVICE)
+
CIRCUITPY_BOARD ?= 1
CFLAGS += -DCIRCUITPY_BOARD=$(CIRCUITPY_BOARD)
@@ -130,6 +136,13 @@ CFLAGS += -DCIRCUITPY_COUNTIO=$(CIRCUITPY_COUNTIO)
CIRCUITPY_DISPLAYIO ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_DISPLAYIO=$(CIRCUITPY_DISPLAYIO)
+CIRCUITPY_DUALBANK ?= 0
+CFLAGS += -DCIRCUITPY_DUALBANK=$(CIRCUITPY_DUALBANK)
+
+# Enabled micropython.native decorator (experimental)
+CIRCUITPY_ENABLE_MPY_NATIVE ?= 0
+CFLAGS += -DCIRCUITPY_ENABLE_MPY_NATIVE=$(CIRCUITPY_ENABLE_MPY_NATIVE)
+
CIRCUITPY_ERRNO ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_ERRNO=$(CIRCUITPY_ERRNO)
@@ -182,6 +195,9 @@ CFLAGS += -DCIRCUITPY_MEMORYMONITOR=$(CIRCUITPY_MEMORYMONITOR)
CIRCUITPY_MICROCONTROLLER ?= 1
CFLAGS += -DCIRCUITPY_MICROCONTROLLER=$(CIRCUITPY_MICROCONTROLLER)
+CIRCUITPY_MSGPACK ?= $(CIRCUITPY_FULL_BUILD)
+CFLAGS += -DCIRCUITPY_MSGPACK=$(CIRCUITPY_MSGPACK)
+
CIRCUITPY_NEOPIXEL_WRITE ?= 1
CFLAGS += -DCIRCUITPY_NEOPIXEL_WRITE=$(CIRCUITPY_NEOPIXEL_WRITE)
@@ -195,8 +211,8 @@ CFLAGS += -DCIRCUITPY_NVM=$(CIRCUITPY_NVM)
CIRCUITPY_OS ?= 1
CFLAGS += -DCIRCUITPY_OS=$(CIRCUITPY_OS)
-CIRCUITPY_DUALBANK ?= 0
-CFLAGS += -DCIRCUITPY_DUALBANK=$(CIRCUITPY_DUALBANK)
+CIRCUITPY_PEW ?= 0
+CFLAGS += -DCIRCUITPY_PEW=$(CIRCUITPY_PEW)
CIRCUITPY_PIXELBUF ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_PIXELBUF=$(CIRCUITPY_PIXELBUF)
@@ -219,6 +235,20 @@ CFLAGS += -DCIRCUITPY_RANDOM=$(CIRCUITPY_RANDOM)
CIRCUITPY_RE ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_RE=$(CIRCUITPY_RE)
+CIRCUITPY_REPL_BLE ?= 0
+CFLAGS += -DCIRCUITPY_REPL_BLE=$(CIRCUITPY_REPL_BLE)
+
+CIRCUITPY_REPL_UART ?= 0
+CFLAGS += -DCIRCUITPY_REPL_UART=$(CIRCUITPY_REPL_UART)
+
+CIRCUITPY_REPL_USB ?= 1
+CFLAGS += -DCIRCUITPY_REPL_USB=$(CIRCUITPY_REPL_USB)
+
+# Should busio.I2C() check for pullups?
+# Some boards in combination with certain peripherals may not want this.
+CIRCUITPY_REQUIRE_I2C_PULLUPS ?= 1
+CFLAGS += -DCIRCUITPY_REQUIRE_I2C_PULLUPS=$(CIRCUITPY_REQUIRE_I2C_PULLUPS)
+
# CIRCUITPY_RP2PIO is handled in the raspberrypi tree.
# Only for rp2 chips.
# Assume not a rp2 build.
@@ -285,46 +315,54 @@ CFLAGS += -DCIRCUITPY_TOUCHIO=$(CIRCUITPY_TOUCHIO)
CIRCUITPY_UHEAP ?= 0
CFLAGS += -DCIRCUITPY_UHEAP=$(CIRCUITPY_UHEAP)
+# Secondary CDC is usually available if there are at least 8 endpoints.
+CIRCUITPY_USB_CDC ?= $(shell expr $(USB_NUM_EP) '>=' 8)
+CFLAGS += -DCIRCUITPY_USB_CDC=$(CIRCUITPY_USB_CDC)
+
CIRCUITPY_USB_HID ?= 1
CFLAGS += -DCIRCUITPY_USB_HID=$(CIRCUITPY_USB_HID)
+CIRCUITPY_USB_HID_CONSUMER ?= 1
+CFLAGS += -DCIRCUITPY_USB_HID_CONSUMER=$(CIRCUITPY_USB_HID_CONSUMER)
+
+CIRCUITPY_USB_HID_DIGITIZER ?= 0
+CFLAGS += -DCIRCUITPY_USB_HID_DIGITIZER=$(CIRCUITPY_USB_HID_DIGITIZER)
+
+CIRCUITPY_USB_HID_GAMEPAD ?= 1
+CFLAGS += -DCIRCUITPY_USB_HID_GAMEPAD=$(CIRCUITPY_USB_HID_GAMEPAD)
+
+CIRCUITPY_USB_HID_KEYBOARD ?= 1
+CFLAGS += -DCIRCUITPY_USB_HID_KEYBOARD=$(CIRCUITPY_USB_HID_KEYBOARD)
+
+CIRCUITPY_USB_HID_MOUSE ?= 1
+CFLAGS += -DCIRCUITPY_USB_HID_MOUSE=$(CIRCUITPY_USB_HID_MOUSE)
+
+CIRCUITPY_USB_HID_SYS_CONTROL ?= 0
+CFLAGS += -DCIRCUITPY_USB_HID_SYS_CONTROL=$(CIRCUITPY_USB_HID_SYS_CONTROL)
+
+CIRCUITPY_USB_HID_XAC_COMPATIBLE_GAMEPAD ?= 0
+CFLAGS += -DCIRCUITPY_USB_HID_XAC_COMPATIBLE_GAMEPAD=$(CIRCUITPY_USB_HID_XAC_COMPATIBLE_GAMEPAD)
+
CIRCUITPY_USB_MIDI ?= 1
CFLAGS += -DCIRCUITPY_USB_MIDI=$(CIRCUITPY_USB_MIDI)
+CIRCUITPY_USB_MSC ?= 1
+CFLAGS += -DCIRCUITPY_USB_MSC=$(CIRCUITPY_USB_MSC)
+
# Defaulting this to OFF initially because it has only been tested on a
# limited number of platforms, and the other platforms do not have this
# setting in their mpconfigport.mk and/or mpconfigboard.mk files yet.
CIRCUITPY_USB_VENDOR ?= 0
CFLAGS += -DCIRCUITPY_USB_VENDOR=$(CIRCUITPY_USB_VENDOR)
-CIRCUITPY_PEW ?= 0
-CFLAGS += -DCIRCUITPY_PEW=$(CIRCUITPY_PEW)
+ifndef USB_NUM_EP
+$(error "USB_NUM_EP (number of USB endpoint pairs)must be defined")
+endif
# For debugging.
CIRCUITPY_USTACK ?= 0
CFLAGS += -DCIRCUITPY_USTACK=$(CIRCUITPY_USTACK)
-# Non-module conditionals
-
-CIRCUITPY_BITBANG_APA102 ?= 0
-CFLAGS += -DCIRCUITPY_BITBANG_APA102=$(CIRCUITPY_BITBANG_APA102)
-
-# Should busio.I2C() check for pullups?
-# Some boards in combination with certain peripherals may not want this.
-CIRCUITPY_REQUIRE_I2C_PULLUPS ?= 1
-CFLAGS += -DCIRCUITPY_REQUIRE_I2C_PULLUPS=$(CIRCUITPY_REQUIRE_I2C_PULLUPS)
-
-# REPL over BLE
-CIRCUITPY_SERIAL_BLE ?= 0
-CFLAGS += -DCIRCUITPY_SERIAL_BLE=$(CIRCUITPY_SERIAL_BLE)
-
-CIRCUITPY_BLE_FILE_SERVICE ?= 0
-CFLAGS += -DCIRCUITPY_BLE_FILE_SERVICE=$(CIRCUITPY_BLE_FILE_SERVICE)
-
-# REPL over UART
-CIRCUITPY_SERIAL_UART ?= 0
-CFLAGS += -DCIRCUITPY_SERIAL_UART=$(CIRCUITPY_SERIAL_UART)
-
# ulab numerics library
CIRCUITPY_ULAB ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_ULAB=$(CIRCUITPY_ULAB)
@@ -335,10 +373,3 @@ CFLAGS += -DCIRCUITPY_WATCHDOG=$(CIRCUITPY_WATCHDOG)
CIRCUITPY_WIFI ?= 0
CFLAGS += -DCIRCUITPY_WIFI=$(CIRCUITPY_WIFI)
-
-# Enabled micropython.native decorator (experimental)
-CIRCUITPY_ENABLE_MPY_NATIVE ?= 0
-CFLAGS += -DCIRCUITPY_ENABLE_MPY_NATIVE=$(CIRCUITPY_ENABLE_MPY_NATIVE)
-
-CIRCUITPY_MSGPACK ?= $(CIRCUITPY_FULL_BUILD)
-CFLAGS += -DCIRCUITPY_MSGPACK=$(CIRCUITPY_MSGPACK)
diff --git a/py/obj.h b/py/obj.h
index 066562cc4..c3ab63b5c 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -684,6 +684,7 @@ mp_obj_t mp_obj_new_bytearray_by_ref(size_t n, void *items);
mp_obj_t mp_obj_new_int_from_float(mp_float_t val);
mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag);
extern mp_float_t uint64_to_float(uint64_t ui64);
+extern uint64_t float_to_uint64(float f);
#endif
mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type);
mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg);
diff --git a/py/objarray.c b/py/objarray.c
index e0b4cbd55..9640f596a 100644
--- a/py/objarray.c
+++ b/py/objarray.c
@@ -238,6 +238,26 @@ STATIC mp_obj_t memoryview_make_new(const mp_obj_type_t *type_in, size_t n_args,
return MP_OBJ_FROM_PTR(self);
}
+
+#if MICROPY_CPYTHON_COMPAT
+STATIC mp_obj_t memoryview_cast(const mp_obj_t self_in, const mp_obj_t typecode_in) {
+ mp_obj_array_t *self = MP_OBJ_TO_PTR(self_in);
+ const char *typecode = mp_obj_str_get_str(typecode_in);
+ size_t element_size = mp_binary_get_size('@', typecode[0], NULL);
+ size_t bytelen = self->len * mp_binary_get_size('@', self->typecode & ~MP_OBJ_ARRAY_TYPECODE_FLAG_RW, NULL);
+ if (bytelen % element_size != 0) {
+ mp_raise_TypeError(translate("memoryview: length is not a multiple of itemsize"));
+ }
+ mp_obj_array_t *result = MP_OBJ_TO_PTR(mp_obj_new_memoryview(*typecode, bytelen / element_size, self->items));
+
+ // test if the object can be written to
+ if (self->typecode & MP_OBJ_ARRAY_TYPECODE_FLAG_RW) {
+ result->typecode |= MP_OBJ_ARRAY_TYPECODE_FLAG_RW; // indicate writable buffer
+ }
+ return MP_OBJ_FROM_PTR(result);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_2(memoryview_cast_obj, memoryview_cast);
+#endif
#endif
STATIC mp_obj_t array_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
@@ -691,6 +711,15 @@ const mp_obj_type_t mp_type_bytearray = {
#endif
#if MICROPY_PY_BUILTINS_MEMORYVIEW
+
+#if MICROPY_CPYTHON_COMPAT
+STATIC const mp_rom_map_elem_t memoryview_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_cast), MP_ROM_PTR(&memoryview_cast_obj) },
+};
+
+STATIC MP_DEFINE_CONST_DICT(memoryview_locals_dict, memoryview_locals_dict_table);
+#endif
+
const mp_obj_type_t mp_type_memoryview = {
{ &mp_type_type },
.name = MP_QSTR_memoryview,
@@ -700,6 +729,9 @@ const mp_obj_type_t mp_type_memoryview = {
.binary_op = array_binary_op,
.subscr = array_subscr,
.buffer_p = { .get_buffer = array_get_buffer },
+#if MICROPY_CPYTHON_COMPAT
+ .locals_dict = (mp_obj_dict_t*)&memoryview_locals_dict,
+#endif
};
#endif
diff --git a/py/objfloat.c b/py/objfloat.c
index 80f10e816..329a8b90e 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -340,6 +340,15 @@ mp_float_t uint64_to_float(uint64_t ui64) {
return (mp_float_t) ((uint32_t) (ui64 >> 32) * 4294967296.0f + (uint32_t) (ui64 & 0xffffffff));
}
+// Convert a uint64_t to a 32-bit float to a uint64_t without invoking extra math routines.
+// which are large.
+// Assume f >= 0.
+uint64_t float_to_uint64(float f) {
+ // 4294967296 = 2^32
+ const uint32_t upper_half = (uint32_t) (f / 4294967296.0f);
+ const uint32_t lower_half = (uint32_t) f;
+ return (((uint64_t) upper_half) << 32) + lower_half;
+}
#pragma GCC diagnostic pop
#endif // MICROPY_PY_BUILTINS_FLOAT
diff --git a/py/stream.c b/py/stream.c
index ae702bb1b..0813c1d7f 100644
--- a/py/stream.c
+++ b/py/stream.c
@@ -99,14 +99,22 @@ const mp_stream_p_t *mp_get_stream_raise(mp_obj_t self_in, int flags) {
STATIC mp_obj_t stream_read_generic(size_t n_args, const mp_obj_t *args, byte flags) {
// What to do if sz < -1? Python docs don't specify this case.
- // CPython does a readall, but here we silently let negatives through,
- // and they will cause a MemoryError.
+ // CPython does a readall, let's do the same.
mp_int_t sz;
- if (n_args == 1 || args[1] == mp_const_none || ((sz = mp_obj_get_int(args[1])) == -1)) {
- return stream_readall(args[0]);
- }
-
const mp_stream_p_t *stream_p = mp_get_stream(args[0]);
+ if (stream_p->pyserial_read_compatibility) {
+ // Pyserial defaults to sz=1 if not specified.
+ if (n_args == 1) {
+ sz = 1;
+ } else {
+ // Pyserial treats negative size as 0.
+ sz = MAX(0, mp_obj_get_int(args[1]));
+ }
+ } else {
+ if (n_args == 1 || args[1] == mp_const_none || (sz = mp_obj_get_int(args[1])) <= -1) {
+ return stream_readall(args[0]);
+ }
+ }
#if MICROPY_PY_BUILTINS_STR_UNICODE
if (stream_p->is_text) {
@@ -284,7 +292,7 @@ STATIC mp_obj_t stream_readinto(size_t n_args, const mp_obj_t *args) {
// https://docs.python.org/3/library/socket.html#socket.socket.recv_into
mp_uint_t len = bufinfo.len;
if (n_args > 2) {
- if (mp_get_stream(args[0])->pyserial_compatibility) {
+ if (mp_get_stream(args[0])->pyserial_readinto_compatibility) {
mp_raise_ValueError(translate("length argument not allowed for this type"));
}
len = mp_obj_get_int(args[2]);
@@ -297,7 +305,10 @@ STATIC mp_obj_t stream_readinto(size_t n_args, const mp_obj_t *args) {
mp_uint_t out_sz = mp_stream_read_exactly(args[0], bufinfo.buf, len, &error);
if (error != 0) {
if (mp_is_nonblocking_error(error)) {
- return mp_const_none;
+ // pyserial readinto never returns None, just 0.
+ return mp_get_stream(args[0])->pyserial_dont_return_none_compatibility
+ ? MP_OBJ_NEW_SMALL_INT(0)
+ : mp_const_none;
}
mp_raise_OSError(error);
} else {
@@ -323,7 +334,10 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in) {
// If we read nothing, return None, just like read().
// Otherwise, return data read so far.
if (total_size == 0) {
- return mp_const_none;
+ // pyserial read() never returns None, just b''.
+ return stream_p->pyserial_dont_return_none_compatibility
+ ? mp_const_empty_bytes
+ : mp_const_none;
}
break;
}
diff --git a/py/stream.h b/py/stream.h
index be6b23d40..c05dcfc50 100644
--- a/py/stream.h
+++ b/py/stream.h
@@ -72,7 +72,9 @@ typedef struct _mp_stream_p_t {
mp_uint_t (*write)(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode);
mp_uint_t (*ioctl)(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *errcode);
mp_uint_t is_text : 1; // default is bytes, set this for text stream
- bool pyserial_compatibility: 1; // adjust API to match pyserial more closely
+ bool pyserial_readinto_compatibility: 1; // Disallow size parameter in readinto()
+ bool pyserial_read_compatibility: 1; // Disallow omitting read(size) size parameter
+ bool pyserial_dont_return_none_compatibility: 1; // Don't return None for read() or readinto()
} mp_stream_p_t;
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_read_obj);