Skip to content

Commit 8346ad3

Browse files
committed
pybricks.iodevices.I2CDevice: Limit write to reg to 32 bytes.
This is sufficient for most operations and more sensible for NXT. Larger amounts of data can still be written by prefxing the register in the user code.
1 parent 6e4db00 commit 8346ad3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pybricks/iodevices/pb_type_i2c_device.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
#include <pybricks/util_mp/pb_kwarg_helper.h>
2020
#include <pybricks/util_mp/pb_obj_helper.h>
21-
2221
#include <pybricks/util_pb/pb_error.h>
2322

2423
// Object representing a pybricks.iodevices.I2CDevice instance.
@@ -262,8 +261,10 @@ static mp_obj_t write(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args
262261
return pb_type_i2c_device_start_operation(MP_OBJ_FROM_PTR(device), (const uint8_t *)user_data, user_len, 0, NULL);
263262
}
264263

265-
// Otherwise need to prefix write data with given register.
266-
uint8_t write_data[256];
264+
// Otherwise need to prefix write data with given register. We're limiting
265+
// write data to 32 bytes in this case. To send more data, the user can
266+
// use reg=None and prefix the address to the data themselves.
267+
uint8_t write_data[33];
267268
if (user_len > MP_ARRAY_SIZE(write_data) - 1) {
268269
pb_assert(PBIO_ERROR_INVALID_ARG);
269270
}

0 commit comments

Comments
 (0)