@@ -171,6 +171,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_unlock_obj, busio_i2c_obj_unlock);
171171//|
172172//| Read into ``buffer`` from the slave specified by ``address``.
173173//| The number of bytes read will be the length of ``buffer``.
174+ //| At least one byte must be read.
174175//|
175176//| If ``start`` or ``end`` is provided, then the buffer will be sliced
176177//| 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
223224//| as if ``buffer[start:end]``. This will not cause an allocation like
224225//| ``buffer[start:end]`` will so it saves memory.
225226//|
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+ //|
226230//| :param int address: 7-bit device address
227231//| :param bytearray buffer: buffer containing the bytes to write
228232//| :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
254258 uint32_t length = bufinfo .len ;
255259 normalize_buffer_bounds (& start , args [ARG_end ].u_int , & length );
256260
257- if (length == 0 ) {
258- mp_raise_ValueError ("Buffer must be at least length 1" );
259- }
260-
261261 // do the transfer
262262 uint8_t status = common_hal_busio_i2c_write (self , args [ARG_address ].u_int ,
263263 ((uint8_t * ) bufinfo .buf ) + start , length , args [ARG_stop ].u_bool );
0 commit comments