@@ -171,6 +171,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_unlock_obj, busio_i2c_obj_unlock);
171
171
//|
172
172
//| Read into ``buffer`` from the slave specified by ``address``.
173
173
//| The number of bytes read will be the length of ``buffer``.
174
+ //| At least one byte must be read.
174
175
//|
175
176
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
176
177
//| as if ``buffer[start:end]``. This will not cause an allocation like
@@ -223,6 +224,9 @@ MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_readfrom_into_obj, 3, busio_i2c_readfrom_in
223
224
//| as if ``buffer[start:end]``. This will not cause an allocation like
224
225
//| ``buffer[start:end]`` will so it saves memory.
225
226
//|
227
+ //| Writing a buffer or slice of length zero is permitted, as it can be used
228
+ //| to poll for the existence of a device.
229
+ //|
226
230
//| :param int address: 7-bit device address
227
231
//| :param bytearray buffer: buffer containing the bytes to write
228
232
//| :param int start: Index to start writing from
@@ -254,10 +258,6 @@ STATIC mp_obj_t busio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, mp_ma
254
258
uint32_t length = bufinfo .len ;
255
259
normalize_buffer_bounds (& start , args [ARG_end ].u_int , & length );
256
260
257
- if (length == 0 ) {
258
- mp_raise_ValueError ("Buffer must be at least length 1" );
259
- }
260
-
261
261
// do the transfer
262
262
uint8_t status = common_hal_busio_i2c_write (self , args [ARG_address ].u_int ,
263
263
((uint8_t * ) bufinfo .buf ) + start , length , args [ARG_stop ].u_bool );
0 commit comments