summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorBernhard Boser <boser@berkeley.edu>2021-01-27 09:22:41 -0800
committerBernhard Boser <boser@berkeley.edu>2021-01-27 09:22:41 -0800
commite285b5b98ca24c877b794f1a4e019693c130b1bc (patch)
tree4d4d5c420e9e5a56b7ae1d196438e4694b298642 /shared-bindings
parent16d54586c1b5cbf839ee8fbb78cf56dd105096f3 (diff)
parent45b3c9ae4213008da092d5bb35e8602e1e90bca2 (diff)
Merge remote-tracking branch 'adafruit/main' into cp-flow
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/_eve/__init__.c150
-rw-r--r--shared-bindings/_eve/__init__.h8
-rw-r--r--shared-bindings/adafruit_bus_device/I2CDevice.c81
-rw-r--r--shared-bindings/adafruit_bus_device/I2CDevice.h4
-rw-r--r--shared-bindings/microcontroller/Pin.c8
-rw-r--r--shared-bindings/microcontroller/__init__.h7
-rw-r--r--shared-bindings/rgbmatrix/RGBMatrix.c28
-rw-r--r--shared-bindings/rgbmatrix/RGBMatrix.h2
-rw-r--r--shared-bindings/socketpool/Socket.c156
-rw-r--r--shared-bindings/socketpool/Socket.h5
-rw-r--r--shared-bindings/socketpool/SocketPool.c6
-rw-r--r--shared-bindings/support_matrix.rst4
12 files changed, 216 insertions, 243 deletions
diff --git a/shared-bindings/_eve/__init__.c b/shared-bindings/_eve/__init__.c
index 0f628b6fb..c043aa5fa 100644
--- a/shared-bindings/_eve/__init__.c
+++ b/shared-bindings/_eve/__init__.c
@@ -604,22 +604,6 @@ STATIC mp_obj_t _jump(mp_obj_t self, mp_obj_t a0) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(jump_obj, _jump);
-//| def LineWidth(self, width: int) -> None:
-//| """Set the width of rasterized lines
-//|
-//| :param int width: line width in :math:`1/16` pixel. Range 0-4095. The initial value is 16
-//|
-//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
-//| ...
-//|
-
-STATIC mp_obj_t _linewidth(mp_obj_t self, mp_obj_t a0) {
- uint32_t width = mp_obj_get_int_truncated(a0);
- common_hal__eve_LineWidth(EVEHAL(self), width);
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_2(linewidth_obj, _linewidth);
-
//| def Macro(self, m: int) -> None:
//| """Execute a single command from a macro register
//|
@@ -662,22 +646,6 @@ STATIC mp_obj_t _palettesource(mp_obj_t self, mp_obj_t a0) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(palettesource_obj, _palettesource);
-//| def PointSize(self, size: int) -> None:
-//| """Set the radius of rasterized points
-//|
-//| :param int size: point radius in :math:`1/16` pixel. Range 0-8191. The initial value is 16
-//|
-//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
-//| ...
-//|
-
-STATIC mp_obj_t _pointsize(mp_obj_t self, mp_obj_t a0) {
- uint32_t size = mp_obj_get_int_truncated(a0);
- common_hal__eve_PointSize(EVEHAL(self), size);
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_2(pointsize_obj, _pointsize);
-
//| def RestoreContext(self) -> None:
//| """Restore the current graphics context from the context stack"""
//| ...
@@ -836,48 +804,6 @@ STATIC mp_obj_t _tag(mp_obj_t self, mp_obj_t a0) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(tag_obj, _tag);
-//| def VertexTranslateX(self, x: int) -> None:
-//| """Set the vertex transformation's x translation component
-//|
-//| :param int x: signed x-coordinate in :math:`1/16` pixel. Range 0-131071. The initial value is 0
-//|
-//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
-//| ...
-//|
-
-STATIC mp_obj_t _vertextranslatex(mp_obj_t self, mp_obj_t a0) {
- uint32_t x = mp_obj_get_int_truncated(a0);
- common_hal__eve_VertexTranslateX(EVEHAL(self), x);
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_2(vertextranslatex_obj, _vertextranslatex);
-
-//| def VertexTranslateY(self, y: int) -> None:
-//| """Set the vertex transformation's y translation component
-//|
-//| :param int y: signed y-coordinate in :math:`1/16` pixel. Range 0-131071. The initial value is 0
-//|
-//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
-//| ...
-//|
-
-
-STATIC mp_obj_t _vertextranslatey(mp_obj_t self, mp_obj_t a0) {
- uint32_t y = mp_obj_get_int_truncated(a0);
- common_hal__eve_VertexTranslateY(EVEHAL(self), y);
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_2(vertextranslatey_obj, _vertextranslatey);
-
-//| def VertexFormat(self, frac: int) -> None:
-//| """Set the precision of vertex2f coordinates
-//|
-//| :param int frac: Number of fractional bits in X,Y coordinates, 0-4. Range 0-7. The initial value is 4
-//|
-//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
-//| ...
-//|
-
STATIC mp_obj_t _vertexformat(mp_obj_t self, mp_obj_t a0) {
uint32_t frac = mp_obj_get_int_truncated(a0);
common_hal__eve_VertexFormat(EVEHAL(self), frac);
@@ -975,6 +901,82 @@ STATIC mp_obj_t _vertex2f(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(vertex2f_obj, _vertex2f);
+//| def LineWidth(self, width: float) -> None:
+//| """Set the width of rasterized lines
+//|
+//| :param float width: line width in pixels. Range 0-511. The initial value is 1
+//|
+//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
+//| ...
+//|
+
+STATIC mp_obj_t _linewidth(mp_obj_t self, mp_obj_t a0) {
+ mp_float_t width = mp_obj_get_float(a0);
+ common_hal__eve_LineWidth(EVEHAL(self), width);
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_2(linewidth_obj, _linewidth);
+
+//| def PointSize(self, size: float) -> None:
+//| """Set the diameter of rasterized points
+//|
+//| :param float size: point diameter in pixels. Range 0-1023. The initial value is 1
+//|
+//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
+//| ...
+//|
+
+STATIC mp_obj_t _pointsize(mp_obj_t self, mp_obj_t a0) {
+ mp_float_t size = mp_obj_get_float(a0);
+ common_hal__eve_PointSize(EVEHAL(self), size);
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_2(pointsize_obj, _pointsize);
+
+//| def VertexTranslateX(self, x: float) -> None:
+//| """Set the vertex transformation's x translation component
+//|
+//| :param float x: signed x-coordinate in pixels. Range ±4095. The initial value is 0
+//|
+//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
+//| ...
+//|
+
+STATIC mp_obj_t _vertextranslatex(mp_obj_t self, mp_obj_t a0) {
+ mp_float_t x = mp_obj_get_float(a0);
+ common_hal__eve_VertexTranslateX(EVEHAL(self), x);
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_2(vertextranslatex_obj, _vertextranslatex);
+
+//| def VertexTranslateY(self, y: float) -> None:
+//| """Set the vertex transformation's y translation component
+//|
+//| :param float y: signed y-coordinate in pixels. Range ±4095. The initial value is 0
+//|
+//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
+//| ...
+//|
+
+
+STATIC mp_obj_t _vertextranslatey(mp_obj_t self, mp_obj_t a0) {
+ mp_float_t y = mp_obj_get_float(a0);
+ common_hal__eve_VertexTranslateY(EVEHAL(self), y);
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_2(vertextranslatey_obj, _vertextranslatey);
+
+//| def VertexFormat(self, frac: int) -> None:
+//| """Set the precision of vertex2f coordinates
+//|
+//| :param int frac: Number of fractional bits in X,Y coordinates, 0-4. Range 0-7. The initial value is 4
+//|
+//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
+//| ...
+//|
+
+//}
+
// Append an object x to the FIFO
#define ADD_X(self, x) \
common_hal__eve_add(EVEHAL(self), sizeof(x), &(x));
diff --git a/shared-bindings/_eve/__init__.h b/shared-bindings/_eve/__init__.h
index 759a629bb..883b1a15b 100644
--- a/shared-bindings/_eve/__init__.h
+++ b/shared-bindings/_eve/__init__.h
@@ -61,11 +61,11 @@ void common_hal__eve_ColorRGB(common_hal__eve_t *eve, uint32_t red, uint32_t gre
void common_hal__eve_Display(common_hal__eve_t *eve);
void common_hal__eve_End(common_hal__eve_t *eve);
void common_hal__eve_Jump(common_hal__eve_t *eve, uint32_t dest);
-void common_hal__eve_LineWidth(common_hal__eve_t *eve, uint32_t width);
+void common_hal__eve_LineWidth(common_hal__eve_t *eve, mp_float_t width);
void common_hal__eve_Macro(common_hal__eve_t *eve, uint32_t m);
void common_hal__eve_Nop(common_hal__eve_t *eve);
void common_hal__eve_PaletteSource(common_hal__eve_t *eve, uint32_t addr);
-void common_hal__eve_PointSize(common_hal__eve_t *eve, uint32_t size);
+void common_hal__eve_PointSize(common_hal__eve_t *eve, mp_float_t size);
void common_hal__eve_RestoreContext(common_hal__eve_t *eve);
void common_hal__eve_Return(common_hal__eve_t *eve);
void common_hal__eve_SaveContext(common_hal__eve_t *eve);
@@ -76,8 +76,8 @@ void common_hal__eve_StencilMask(common_hal__eve_t *eve, uint32_t mask);
void common_hal__eve_StencilOp(common_hal__eve_t *eve, uint32_t sfail, uint32_t spass);
void common_hal__eve_TagMask(common_hal__eve_t *eve, uint32_t mask);
void common_hal__eve_Tag(common_hal__eve_t *eve, uint32_t s);
-void common_hal__eve_VertexTranslateX(common_hal__eve_t *eve, uint32_t x);
-void common_hal__eve_VertexTranslateY(common_hal__eve_t *eve, uint32_t y);
+void common_hal__eve_VertexTranslateX(common_hal__eve_t *eve, mp_float_t x);
+void common_hal__eve_VertexTranslateY(common_hal__eve_t *eve, mp_float_t y);
void common_hal__eve_VertexFormat(common_hal__eve_t *eve, uint32_t frac);
void common_hal__eve_Vertex2ii(common_hal__eve_t *eve, uint32_t x, uint32_t y, uint32_t handle, uint32_t cell);
diff --git a/shared-bindings/adafruit_bus_device/I2CDevice.c b/shared-bindings/adafruit_bus_device/I2CDevice.c
index a4c04e198..15e8cc706 100644
--- a/shared-bindings/adafruit_bus_device/I2CDevice.c
+++ b/shared-bindings/adafruit_bus_device/I2CDevice.c
@@ -76,7 +76,7 @@ STATIC mp_obj_t adafruit_bus_device_i2cdevice_make_new(const mp_obj_type_t *type
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);
- busio_i2c_obj_t* i2c = args[ARG_i2c].u_obj;
+ mp_obj_t* i2c = args[ARG_i2c].u_obj;
common_hal_adafruit_bus_device_i2cdevice_construct(MP_OBJ_TO_PTR(self), i2c, args[ARG_device_address].u_int);
if (args[ARG_probe].u_bool == true) {
@@ -107,7 +107,7 @@ STATIC mp_obj_t adafruit_bus_device_i2cdevice_obj___exit__(size_t n_args, const
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(adafruit_bus_device_i2cdevice___exit___obj, 4, 4, adafruit_bus_device_i2cdevice_obj___exit__);
-//| def readinto(self, buf: WriteableBuffer, *, start: int = 0, end: int = 0) -> None:
+//| def readinto(self, buf: WriteableBuffer, *, start: int = 0, end: Optional[int] = None) -> None:
//| """Read into ``buf`` from the device. The number of bytes read will be the
//| length of ``buf``.
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
@@ -118,22 +118,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(adafruit_bus_device_i2cdevice___exit_
//| :param int end: Index to write up to but not include; if None, use ``len(buf)``"""
//| ...
//|
-STATIC void readinto(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, int32_t start, mp_int_t end) {
- mp_buffer_info_t bufinfo;
- mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_WRITE);
-
- size_t length = bufinfo.len;
- normalize_buffer_bounds(&start, end, &length);
- if (length == 0) {
- mp_raise_ValueError(translate("Buffer must be at least length 1"));
- }
-
- uint8_t status = common_hal_adafruit_bus_device_i2cdevice_readinto(MP_OBJ_TO_PTR(self), ((uint8_t*)bufinfo.buf) + start, length);
- if (status != 0) {
- mp_raise_OSError(status);
- }
-}
-
STATIC mp_obj_t adafruit_bus_device_i2cdevice_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_buffer, ARG_start, ARG_end };
static const mp_arg_t allowed_args[] = {
@@ -147,12 +131,22 @@ STATIC mp_obj_t adafruit_bus_device_i2cdevice_readinto(size_t n_args, const mp_o
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
- readinto(self, args[ARG_buffer].u_obj, args[ARG_start].u_int, args[ARG_end].u_int);
+ mp_obj_t dest[8];
+ mp_load_method(self->i2c, MP_QSTR_readfrom_into, dest);
+ dest[2] = mp_obj_new_int_from_ull(self->device_address);
+ dest[3] = args[ARG_buffer].u_obj;
+ //dest[4] = mp_obj_new_str("start", 5);
+ dest[4] = MP_OBJ_NEW_QSTR(MP_QSTR_start);
+ dest[5] = mp_obj_new_int(args[ARG_start].u_int);
+ dest[6] = MP_OBJ_NEW_QSTR(MP_QSTR_end);
+ dest[7] = mp_obj_new_int(args[ARG_end].u_int);
+ mp_call_method_n_kw(2, 2, dest);
+
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_readinto_obj, 2, adafruit_bus_device_i2cdevice_readinto);
-//| def write(self, buf: ReadableBuffer, *, start: int = 0, end: int = 0) -> None:
+//| def write(self, buf: ReadableBuffer, *, start: int = 0, end: Optional[int] = None) -> None:
//| """Write the bytes from ``buffer`` to the device, then transmit a stop bit.
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
//| as if ``buffer[start:end]``. This will not cause an allocation like
@@ -163,22 +157,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_readinto_obj, 2,
//| """
//| ...
//|
-STATIC void write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, int32_t start, mp_int_t end, bool transmit_stop_bit) {
- mp_buffer_info_t bufinfo;
- mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_READ);
-
- size_t length = bufinfo.len;
- normalize_buffer_bounds(&start, end, &length);
- if (length == 0) {
- mp_raise_ValueError(translate("Buffer must be at least length 1"));
- }
-
- uint8_t status = common_hal_adafruit_bus_device_i2cdevice_write(MP_OBJ_TO_PTR(self), ((uint8_t*)bufinfo.buf) + start, length, transmit_stop_bit);
- if (status != 0) {
- mp_raise_OSError(status);
- }
-}
-
STATIC mp_obj_t adafruit_bus_device_i2cdevice_write(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_buffer, ARG_start, ARG_end };
static const mp_arg_t allowed_args[] = {
@@ -191,13 +169,22 @@ STATIC mp_obj_t adafruit_bus_device_i2cdevice_write(size_t n_args, const mp_obj_
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
- write(self, args[ARG_buffer].u_obj, args[ARG_start].u_int, args[ARG_end].u_int, true);
+ mp_obj_t dest[8];
+ mp_load_method(self->i2c, MP_QSTR_writeto, dest);
+ dest[2] = mp_obj_new_int_from_ull(self->device_address);
+ dest[3] = args[ARG_buffer].u_obj;
+ dest[4] = MP_OBJ_NEW_QSTR(MP_QSTR_start);
+ dest[5] = mp_obj_new_int(args[ARG_start].u_int);
+ dest[6] = MP_OBJ_NEW_QSTR(MP_QSTR_end);
+ dest[7] = mp_obj_new_int(args[ARG_end].u_int);
+ mp_call_method_n_kw(2, 2, dest);
+
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_write_obj, 2, adafruit_bus_device_i2cdevice_write);
-//| def write_then_readinto(self, out_buffer: WriteableBuffer, in_buffer: ReadableBuffer, *, out_start: int = 0, out_end: int = 0, in_start: int = 0, in_end: int = 0) -> None:
+//| def write_then_readinto(self, out_buffer: WriteableBuffer, in_buffer: ReadableBuffer, *, out_start: int = 0, out_end: Optional[int] = None, in_start: int = 0, in_end: Optional[int] = None) -> None:
//| """Write the bytes from ``out_buffer`` to the device, then immediately
//| reads into ``in_buffer`` from the device. The number of bytes read
//| will be the length of ``in_buffer``.
@@ -233,9 +220,21 @@ STATIC mp_obj_t adafruit_bus_device_i2cdevice_write_then_readinto(size_t n_args,
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
- write(self, args[ARG_out_buffer].u_obj, args[ARG_out_start].u_int, args[ARG_out_end].u_int, false);
-
- readinto(self, args[ARG_in_buffer].u_obj, args[ARG_in_start].u_int, args[ARG_in_end].u_int);
+ mp_obj_t dest[13];
+ mp_load_method(self->i2c, MP_QSTR_writeto_then_readfrom, dest);
+ dest[2] = mp_obj_new_int_from_ull(self->device_address);
+ dest[3] = args[ARG_out_buffer].u_obj;
+ dest[4] = args[ARG_in_buffer].u_obj;
+ dest[5] = MP_OBJ_NEW_QSTR(MP_QSTR_out_start);
+ dest[6] = mp_obj_new_int(args[ARG_out_start].u_int);
+ dest[7] = MP_OBJ_NEW_QSTR(MP_QSTR_out_end);
+ dest[8] = mp_obj_new_int(args[ARG_out_end].u_int);
+ dest[9] = MP_OBJ_NEW_QSTR(MP_QSTR_in_start);
+ dest[10] = mp_obj_new_int(args[ARG_in_start].u_int);
+ dest[11] = MP_OBJ_NEW_QSTR(MP_QSTR_in_end);
+ dest[12] = mp_obj_new_int(args[ARG_in_end].u_int);
+
+ mp_call_method_n_kw(3, 4, dest);
return mp_const_none;
}
diff --git a/shared-bindings/adafruit_bus_device/I2CDevice.h b/shared-bindings/adafruit_bus_device/I2CDevice.h
index cf7b1321a..82ef1feb8 100644
--- a/shared-bindings/adafruit_bus_device/I2CDevice.h
+++ b/shared-bindings/adafruit_bus_device/I2CDevice.h
@@ -43,9 +43,7 @@
extern const mp_obj_type_t adafruit_bus_device_i2cdevice_type;
// Initializes the hardware peripheral.
-extern void common_hal_adafruit_bus_device_i2cdevice_construct(adafruit_bus_device_i2cdevice_obj_t *self, busio_i2c_obj_t *i2c, uint8_t device_address);
-extern uint8_t common_hal_adafruit_bus_device_i2cdevice_readinto(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length);
-extern uint8_t common_hal_adafruit_bus_device_i2cdevice_write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length, bool transmit_stop_bit);
+extern void common_hal_adafruit_bus_device_i2cdevice_construct(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t *i2c, uint8_t device_address);
extern void common_hal_adafruit_bus_device_i2cdevice_lock(adafruit_bus_device_i2cdevice_obj_t *self);
extern void common_hal_adafruit_bus_device_i2cdevice_unlock(adafruit_bus_device_i2cdevice_obj_t *self);
extern void common_hal_adafruit_bus_device_i2cdevice_probe_for_device(adafruit_bus_device_i2cdevice_obj_t *self);
diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c
index 6ba02a0e7..2a97b54b3 100644
--- a/shared-bindings/microcontroller/Pin.c
+++ b/shared-bindings/microcontroller/Pin.c
@@ -66,12 +66,12 @@ static void get_pin_name(const mcu_pin_obj_t *self, qstr* package, qstr* module,
STATIC void mcu_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
mcu_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
- qstr package;
+ qstr package = MP_QSTR_Pin;
qstr module;
- qstr name;
+ qstr name = MP_QSTR_Pin;
get_pin_name(self, &package, &module, &name);
- if (package){
+ if (package) {
mp_printf(print, "%q.%q.%q", package, module, name);
} else {
mp_printf(print, "%q.%q", module , name);
@@ -131,7 +131,7 @@ void assert_pin_free(const mcu_pin_obj_t* pin) {
if (pin != NULL && pin != MP_OBJ_TO_PTR(mp_const_none) && !common_hal_mcu_pin_is_free(pin)) {
qstr package;
qstr module;
- qstr name;
+ qstr name = MP_QSTR_Pin;
get_pin_name(pin, &package, &module, &name);
mp_raise_ValueError_varg(translate("%q in use"), name);
diff --git a/shared-bindings/microcontroller/__init__.h b/shared-bindings/microcontroller/__init__.h
index 0dafc74c7..39d3e718b 100644
--- a/shared-bindings/microcontroller/__init__.h
+++ b/shared-bindings/microcontroller/__init__.h
@@ -29,6 +29,7 @@
#include "py/obj.h"
#include "py/mpconfig.h"
+#include "py/objtuple.h"
#include "common-hal/microcontroller/Processor.h"
#include "shared-bindings/microcontroller/ResetReason.h"
@@ -44,7 +45,13 @@ extern void common_hal_mcu_reset(void);
extern const mp_obj_dict_t mcu_pin_globals;
+#if CIRCUITPY_PROCESSOR_COUNT == 1
extern const mcu_processor_obj_t common_hal_mcu_processor_obj;
+#elif CIRCUITPY_PROCESSOR_COUNT > 1
+extern const mp_rom_obj_tuple_t common_hal_mcu_processor_obj;
+#else
+#error "Invalid processor count"
+#endif
#if CIRCUITPY_INTERNAL_NVM_SIZE > 0
diff --git a/shared-bindings/rgbmatrix/RGBMatrix.c b/shared-bindings/rgbmatrix/RGBMatrix.c
index 5f5ea4fae..2a81bb53c 100644
--- a/shared-bindings/rgbmatrix/RGBMatrix.c
+++ b/shared-bindings/rgbmatrix/RGBMatrix.c
@@ -132,11 +132,11 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_
}
}
-//| def __init__(self, *, width: int, bit_depth: int, rgb_pins: Sequence[digitalio.DigitalInOut], addr_pins: Sequence[digitalio.DigitalInOut], clock_pin: digitalio.DigitalInOut, latch_pin: digitalio.DigitalInOut, output_enable_pin: digitalio.DigitalInOut, doublebuffer: bool = True, framebuffer: Optional[WriteableBuffer] = None, height: int = 0) -> None:
+//| def __init__(self, *, width: int, bit_depth: int, rgb_pins: Sequence[digitalio.DigitalInOut], addr_pins: Sequence[digitalio.DigitalInOut], clock_pin: digitalio.DigitalInOut, latch_pin: digitalio.DigitalInOut, output_enable_pin: digitalio.DigitalInOut, doublebuffer: bool = True, framebuffer: Optional[WriteableBuffer] = None, height: int = 0, tile: int = 1, serpentine: bool = False) -> None:
//| """Create a RGBMatrix object with the given attributes. The height of
-//| the display is determined by the number of rgb and address pins:
-//| len(rgb_pins) // 3 * 2 ** len(address_pins). With 6 RGB pins and 4
-//| address lines, the display will be 32 pixels tall. If the optional height
+//| the display is determined by the number of rgb and address pins and the number of tiles:
+//| ``len(rgb_pins) // 3 * 2 ** len(address_pins) * abs(tile)``. With 6 RGB pins, 4
+//| address lines, and a single matrix, the display will be 32 pixels tall. If the optional height
//| parameter is specified and is not 0, it is checked against the calculated
//| height.
//|
@@ -172,7 +172,7 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_
STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_width, ARG_bit_depth, ARG_rgb_list, ARG_addr_list,
- ARG_clock_pin, ARG_latch_pin, ARG_output_enable_pin, ARG_doublebuffer, ARG_framebuffer, ARG_height };
+ ARG_clock_pin, ARG_latch_pin, ARG_output_enable_pin, ARG_doublebuffer, ARG_framebuffer, ARG_height, ARG_tile, ARG_serpentine };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_width, MP_ARG_INT | MP_ARG_REQUIRED | MP_ARG_KW_ONLY },
{ MP_QSTR_bit_depth, MP_ARG_INT | MP_ARG_REQUIRED | MP_ARG_KW_ONLY },
@@ -184,6 +184,8 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
{ MP_QSTR_doublebuffer, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = true } },
{ MP_QSTR_framebuffer, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = mp_const_none } },
{ MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY, { .u_int = 0 } },
+ { MP_QSTR_tile, MP_ARG_INT | MP_ARG_KW_ONLY, { .u_int = 1 } },
+ { MP_QSTR_serpentine, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
};
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);
@@ -210,12 +212,18 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
mp_raise_ValueError_varg(translate("Must use a multiple of 6 rgb pins, not %d"), rgb_count);
}
- // TODO(@jepler) Use fewer than all rows of pixels if height < computed_height
+ int tile = args[ARG_tile].u_int;
+
+ if (tile <= 0) {
+ mp_raise_ValueError_varg(
+ translate("tile must be greater than zero"));
+ }
+
+ int computed_height = (rgb_count / 3) * (1 << (addr_count)) * tile;
if (args[ARG_height].u_int != 0) {
- int computed_height = (rgb_count / 3) << (addr_count);
if (computed_height != args[ARG_height].u_int) {
mp_raise_ValueError_varg(
- translate("%d address pins and %d rgb pins indicate a height of %d, not %d"), addr_count, rgb_count, computed_height, args[ARG_height].u_int);
+ translate("%d address pins, %d rgb pins and %d tiles indicate a height of %d, not %d"), addr_count, rgb_count, tile, computed_height, args[ARG_height].u_int);
}
}
@@ -228,7 +236,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
mp_obj_t framebuffer = args[ARG_framebuffer].u_obj;
if (framebuffer == mp_const_none) {
int width = args[ARG_width].u_int;
- int bufsize = 2 * width * rgb_count / 3 * (1 << addr_count);
+ int bufsize = 2 * width * computed_height;
framebuffer = mp_obj_new_bytearray_of_zeros(bufsize);
}
@@ -239,7 +247,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
addr_count, addr_pins,
clock_pin, latch_pin, output_enable_pin,
args[ARG_doublebuffer].u_bool,
- framebuffer, NULL);
+ framebuffer, tile, args[ARG_serpentine].u_bool, NULL);
claim_and_never_reset_pins(args[ARG_rgb_list].u_obj);
claim_and_never_reset_pins(args[ARG_addr_list].u_obj);
diff --git a/shared-bindings/rgbmatrix/RGBMatrix.h b/shared-bindings/rgbmatrix/RGBMatrix.h
index bfe37c340..4eb3c04b2 100644
--- a/shared-bindings/rgbmatrix/RGBMatrix.h
+++ b/shared-bindings/rgbmatrix/RGBMatrix.h
@@ -31,7 +31,7 @@
extern const mp_obj_type_t rgbmatrix_RGBMatrix_type;
-void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t* self, int width, int bit_depth, uint8_t rgb_count, uint8_t* rgb_pins, uint8_t addr_count, uint8_t* addr_pins, uint8_t clock_pin, uint8_t latch_pin, uint8_t oe_pin, bool doublebuffer, mp_obj_t framebuffer, void* timer);
+void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t* self, int width, int bit_depth, uint8_t rgb_count, uint8_t* rgb_pins, uint8_t addr_count, uint8_t* addr_pins, uint8_t clock_pin, uint8_t latch_pin, uint8_t oe_pin, bool doublebuffer, mp_obj_t framebuffer, int8_t tile, bool serpentine, void* timer);
void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t*);
void rgbmatrix_rgbmatrix_collect_ptrs(rgbmatrix_rgbmatrix_obj_t*);
void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self, mp_obj_t framebuffer);
diff --git a/shared-bindings/socketpool/Socket.c b/shared-bindings/socketpool/Socket.c
index 0e6968d5f..007417340 100644
--- a/shared-bindings/socketpool/Socket.c
+++ b/shared-bindings/socketpool/Socket.c
@@ -64,94 +64,65 @@ STATIC mp_obj_t socketpool_socket___exit__(size_t n_args, const mp_obj_t *args)
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socketpool_socket___exit___obj, 4, 4, socketpool_socket___exit__);
-// //| def bind(self, address: tuple) -> None:
-// //| """Bind a socket to an address
-// //|
-// //| :param ~tuple address: tuple of (remote_address, remote_port)"""
-// //| ...
-// //|
-
-// STATIC mp_obj_t socketpool_socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
-// // mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
-
-// // // get address
-// // uint8_t ip[MOD_NETWORK_IPADDR_BUF_SIZE];
-// // mp_uint_t port = netutils_parse_inet_addr(addr_in, ip, NETUTILS_BIG);
-
-// // // check if we need to select a NIC
-// // socket_select_nic(self, ip);
-
-// // // call the NIC to bind the socket
-// // int _errno;
-// // if (self->nic_type->bind(self, ip, port, &_errno) != 0) {
-// // mp_raise_OSError(_errno);
-// // }
-
-// return mp_const_none;
-// }
-// STATIC MP_DEFINE_CONST_FUN_OBJ_2(socketpool_socket_bind_obj, socketpool_socket_bind);
-
-// //| def listen(self, backlog: int) -> None:
-// //| """Set socket to listen for incoming connections
-// //|
-// //| :param ~int backlog: length of backlog queue for waiting connetions"""
-// //| ...
-// //|
-
-// STATIC mp_obj_t socketpool_socket_listen(mp_obj_t self_in, mp_obj_t backlog) {
-// // mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
+//| def bind(self, address: Tuple[str, int]) -> None:
+//| """Bind a socket to an address
+//|
+//| :param ~tuple address: tuple of (remote_address, remote_port)"""
+//| ...
+//|
+STATIC mp_obj_t socketpool_socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
+ socketpool_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
-// // if (self->nic == MP_OBJ_NULL) {
-// // // not connected
-// // // TODO I think we can listen even if not bound...
-// // mp_raise_OSError(MP_ENOTCONN);
-// // }
+ mp_obj_t *addr_items;
+ mp_obj_get_array_fixed_n(addr_in, 2, &addr_items);
-// // int _errno;
-// // if (self->nic_type->listen(self, mp_obj_get_int(backlog), &_errno) != 0) {
-// // mp_raise_OSError(_errno);
-// // }
+ size_t hostlen;
+ const char* host = mp_obj_str_get_data(addr_items[0], &hostlen);
+ mp_int_t port = mp_obj_get_int(addr_items[1]);
-// return mp_const_none;
-// }
-// STATIC MP_DEFINE_CONST_FUN_OBJ_2(socketpool_socket_listen_obj, socketpool_socket_listen);
+ bool ok = common_hal_socketpool_socket_bind(self, host, hostlen, port);
+ if (!ok) {
+ mp_raise_ValueError(translate("Error: Failure to bind"));
+ }
-// //| def accept(self) -> tuple:
-// //| """Accept a connection on a listening socket of type SOCK_STREAM,
-// //| creating a new socket of type SOCK_STREAM.
-// //| Returns a tuple of (new_socket, remote_address)"""
-// //|
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_2(socketpool_socket_bind_obj, socketpool_socket_bind);
-// STATIC mp_obj_t socketpool_socket_accept(mp_obj_t self_in) {
-// // mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
+//| def listen(self, backlog: int) -> None:
+//| """Set socket to listen for incoming connections
+//|
+//| :param ~int backlog: length of backlog queue for waiting connetions"""
+//| ...
+//|
+STATIC mp_obj_t socketpool_socket_listen(mp_obj_t self_in, mp_obj_t backlog_in) {
+ socketpool_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
-// // // create new socket object
-// // // starts with empty NIC so that finaliser doesn't run close() method if accept() fails
-// // mod_network_socket_obj_t *socket2 = m_new_obj_with_finaliser(mod_network_socket_obj_t);
-// // socket2->base.type = &socket_type;
-// // socket2->nic = MP_OBJ_NULL;
-// // socket2->nic_type = NULL;
+ int backlog = mp_obj_get_int(backlog_in);
-// // // accept incoming connection
-// // uint8_t ip[MOD_NETWORK_IPADDR_BUF_SIZE];
-// // mp_uint_t port;
-// // int _errno;
-// // if (self->nic_type->accept(self, socket2, ip, &port, &_errno) != 0) {
-// // mp_raise_OSError(_errno);
-// // }
+ common_hal_socketpool_socket_listen(self, backlog);
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_2(socketpool_socket_listen_obj, socketpool_socket_listen);
-// // // new socket has valid state, so set the NIC to the same as parent
-// // socket2->nic = self->nic;
-// // socket2->nic_type = self->nic_type;
+//| def accept(self) -> Tuple[Socket, Tuple[str, int]]:
+//| """Accept a connection on a listening socket of type SOCK_STREAM,
+//| creating a new socket of type SOCK_STREAM.
+//| Returns a tuple of (new_socket, remote_address)"""
+//|
+STATIC mp_obj_t socketpool_socket_accept(mp_obj_t self_in) {
+ socketpool_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ uint8_t ip[4];
+ uint port;
-// // // make the return value
-// // mp_obj_tuple_t *client = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL));
-// // client->items[0] = MP_OBJ_FROM_PTR(socket2);
-// // client->items[1] = netutils_format_inet_addr(ip, port, NETUTILS_BIG);
+ socketpool_socket_obj_t * sock = common_hal_socketpool_socket_accept(self, ip, &port);
-// return mp_const_none;
-// }
-// STATIC MP_DEFINE_CONST_FUN_OBJ_1(socketpool_socket_accept_obj, socketpool_socket_accept);
+ mp_obj_t tuple_contents[2];
+ tuple_contents[0] = MP_OBJ_FROM_PTR(sock);
+ tuple_contents[1] = netutils_format_inet_addr(ip, port, NETUTILS_BIG);
+ return mp_obj_new_tuple(2, tuple_contents);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(socketpool_socket_accept_obj, socketpool_socket_accept);
//| def close(self) -> None:
//| """Closes this Socket and makes its resources available to its SocketPool."""
@@ -169,7 +140,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(socketpool_socket_close_obj, socketpool_socket_
//| :param ~tuple address: tuple of (remote_address, remote_port)"""
//| ...
//|
-
STATIC mp_obj_t socketpool_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
socketpool_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -196,7 +166,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socketpool_socket_connect_obj, socketpool_socke
//| :param ~bytes bytes: some bytes to send"""
//| ...
//|
-
STATIC mp_obj_t socketpool_socket_send(mp_obj_t self_in, mp_obj_t buf_in) {
socketpool_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (common_hal_socketpool_socket_get_closed(self)) {
@@ -216,19 +185,6 @@ STATIC mp_obj_t socketpool_socket_send(mp_obj_t self_in, mp_obj_t buf_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socketpool_socket_send_obj, socketpool_socket_send);
-
-// helper function for socket_recv and socket_recv_into to handle common operations of both
-// STATIC mp_int_t _socket_recv_into(mod_network_socket_obj_t *sock, byte *buf, mp_int_t len) {
-// mp_int_t ret = 0;
-// // int _errno;
-// // mp_int_t ret = sock->nic_type->recv(sock, buf, len, &_errno);
-// // if (ret == -1) {
-// // mp_raise_OSError(_errno);
-// // }
-// return ret;
-// }
-
-
//| def recv_into(self, buffer: WriteableBuffer, bufsize: int) -> int:
//| """Reads some bytes from the connected remote address, writing
//| into the provided buffer. If bufsize <= len(buffer) is given,
@@ -250,10 +206,10 @@ STATIC mp_obj_t socketpool_socket_recv_into(size_t n_args, const mp_obj_t *args)
// Bad file number.
mp_raise_OSError(MP_EBADF);
}
- if (!common_hal_socketpool_socket_get_connected(self)) {
- // not connected
- mp_raise_OSError(MP_ENOTCONN);
- }
+ // if (!common_hal_socketpool_socket_get_connected(self)) {
+ // // not connected
+ // mp_raise_OSError(MP_ENOTCONN);
+ // }
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_WRITE);
mp_int_t len = bufinfo.len;
@@ -430,9 +386,9 @@ STATIC const mp_rom_map_elem_t socketpool_socket_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&socketpool_socket_close_obj) },
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&socketpool_socket_close_obj) },
- // { MP_ROM_QSTR(MP_QSTR_bind), MP_ROM_PTR(&socketpool_socket_bind_obj) },
- // { MP_ROM_QSTR(MP_QSTR_listen), MP_ROM_PTR(&socketpool_socket_listen_obj) },
- // { MP_ROM_QSTR(MP_QSTR_accept), MP_ROM_PTR(&socketpool_socket_accept_obj) },
+ { MP_ROM_QSTR(MP_QSTR_bind), MP_ROM_PTR(&socketpool_socket_bind_obj) },
+ { MP_ROM_QSTR(MP_QSTR_listen), MP_ROM_PTR(&socketpool_socket_listen_obj) },
+ { MP_ROM_QSTR(MP_QSTR_accept), MP_ROM_PTR(&socketpool_socket_accept_obj) },
{ MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&socketpool_socket_connect_obj) },
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&socketpool_socket_send_obj) },
{ MP_ROM_QSTR(MP_QSTR_sendto), MP_ROM_PTR(&socketpool_socket_sendto_obj) },
diff --git a/shared-bindings/socketpool/Socket.h b/shared-bindings/socketpool/Socket.h
index 54fbe59b2..b5dceb50f 100644
--- a/shared-bindings/socketpool/Socket.h
+++ b/shared-bindings/socketpool/Socket.h
@@ -32,6 +32,11 @@
extern const mp_obj_type_t socketpool_socket_type;
void common_hal_socketpool_socket_settimeout(socketpool_socket_obj_t* self, mp_uint_t timeout_ms);
+
+bool common_hal_socketpool_socket_bind(socketpool_socket_obj_t* self, const char* host, size_t hostlen, uint8_t port);
+bool common_hal_socketpool_socket_listen(socketpool_socket_obj_t* self, int backlog);
+socketpool_socket_obj_t * common_hal_socketpool_socket_accept(socketpool_socket_obj_t* self, uint8_t* ip, uint *port);
+
bool common_hal_socketpool_socket_connect(socketpool_socket_obj_t* self, const char* host, size_t hostlen, mp_int_t port);
mp_uint_t common_hal_socketpool_socket_send(socketpool_socket_obj_t* self, const uint8_t* buf, mp_uint_t len);
mp_uint_t common_hal_socketpool_socket_recv_into(socketpool_socket_obj_t* self, const uint8_t* buf, mp_uint_t len);
diff --git a/shared-bindings/socketpool/SocketPool.c b/shared-bindings/socketpool/SocketPool.c
index 73eeed265..8f4069faa 100644
--- a/shared-bindings/socketpool/SocketPool.c
+++ b/shared-bindings/socketpool/SocketPool.c
@@ -62,14 +62,12 @@ STATIC mp_obj_t socketpool_socketpool_make_new(const mp_obj_type_t *type, size_t
//| SOCK_STREAM: int
//| SOCK_DGRAM: int
//| SOCK_RAW: int
-//| IPPROTO_TCP: int
//|
-//| def socket(self, family: int = AF_INET, type: int = SOCK_STREAM, proto: int = IPPROTO_TCP) -> socketpool.Socket:
+//| def socket(self, family: int = AF_INET, type: int = SOCK_STREAM) -> socketpool.Socket:
//| """Create a new socket
//|
//| :param ~int family: AF_INET or AF_INET6
-//| :param ~int type: SOCK_STREAM, SOCK_DGRAM or SOCK_RAW
-//| :param ~int proto: IPPROTO_TCP, IPPROTO_UDP or IPPROTO_RAW (ignored)"""
+//| :param ~int type: SOCK_STREAM, SOCK_DGRAM or SOCK_RAW"""
//| ...
//|
diff --git a/shared-bindings/support_matrix.rst b/shared-bindings/support_matrix.rst
index 1b75e0256..a2fb7987d 100644
--- a/shared-bindings/support_matrix.rst
+++ b/shared-bindings/support_matrix.rst
@@ -1,7 +1,7 @@
.. _module-support-matrix:
-Support Matrix
-===============
+Module Support Matrix - Which Modules Are Available on Which Boards
+===================================================================
The following table lists the available built-in modules for each CircuitPython
capable board.