From 5662b5813e477a515dc3252fef29d6a92d338a4b Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 23 Aug 2019 12:13:11 -0700 Subject: [PATCH] Use size_t and document buffers can be the same. --- shared-bindings/bitbangio/I2C.c | 7 ++++--- shared-bindings/busio/I2C.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/shared-bindings/bitbangio/I2C.c b/shared-bindings/bitbangio/I2C.c index a6276dca0b..01a128393b 100644 --- a/shared-bindings/bitbangio/I2C.c +++ b/shared-bindings/bitbangio/I2C.c @@ -180,7 +180,7 @@ STATIC void readfrom(bitbangio_i2c_obj_t *self, mp_int_t address, mp_obj_t buffe mp_buffer_info_t bufinfo; mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_WRITE); - uint32_t length = bufinfo.len; + 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")); @@ -238,7 +238,7 @@ STATIC void writeto(bitbangio_i2c_obj_t *self, mp_int_t address, mp_obj_t buffer mp_buffer_info_t bufinfo; mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_READ); - uint32_t length = bufinfo.len; + size_t length = bufinfo.len; normalize_buffer_bounds(&start, end, &length); // do the transfer @@ -275,7 +275,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_writeto_obj, 1, bitbangio_i2c_wr //| .. method:: writeto_then_readfrom(address, out_buffer, in_buffer, *, out_start=0, out_end=None, in_start=0, in_end=None) //| //| Write the bytes from ``out_buffer`` to the slave specified by ``address``, generate no stop -//| bit, generate a repeated start and read into ``in_buffer``. +//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and +//| ``in_buffer`` can be the same buffer because they are used sequentially. //| //| If ``start`` or ``end`` is provided, then the corresponding buffer will be sliced //| as if ``buffer[start:end]``. This will not cause an allocation like ``buf[start:end]`` diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c index f3c1503edb..3bd89e2e20 100644 --- a/shared-bindings/busio/I2C.c +++ b/shared-bindings/busio/I2C.c @@ -194,7 +194,7 @@ STATIC void readfrom(busio_i2c_obj_t *self, mp_int_t address, mp_obj_t buffer, i mp_buffer_info_t bufinfo; mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_WRITE); - uint32_t length = bufinfo.len; + 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")); @@ -253,7 +253,7 @@ STATIC void writeto(busio_i2c_obj_t *self, mp_int_t address, mp_obj_t buffer, in mp_buffer_info_t bufinfo; mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_READ); - uint32_t length = bufinfo.len; + size_t length = bufinfo.len; normalize_buffer_bounds(&start, end, &length); // do the transfer @@ -288,7 +288,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_writeto_obj, 1, busio_i2c_writeto); //| .. method:: writeto_then_readfrom(address, out_buffer, in_buffer, *, out_start=0, out_end=None, in_start=0, in_end=None) //| //| Write the bytes from ``out_buffer`` to the slave specified by ``address``, generate no stop -//| bit, generate a repeated start and read into ``in_buffer``. +//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and +//| ``in_buffer`` can be the same buffer because they are used sequentially. //| //| If ``start`` or ``end`` is provided, then the corresponding buffer will be sliced //| as if ``buffer[start:end]``. This will not cause an allocation like ``buf[start:end]``