Skip to content

Commit 5662b58

Browse files
committed
Use size_t and document buffers can be the same.
1 parent 82d436d commit 5662b58

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

shared-bindings/bitbangio/I2C.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ STATIC void readfrom(bitbangio_i2c_obj_t *self, mp_int_t address, mp_obj_t buffe
180180
mp_buffer_info_t bufinfo;
181181
mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_WRITE);
182182

183-
uint32_t length = bufinfo.len;
183+
size_t length = bufinfo.len;
184184
normalize_buffer_bounds(&start, end, &length);
185185
if (length == 0) {
186186
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
238238
mp_buffer_info_t bufinfo;
239239
mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_READ);
240240

241-
uint32_t length = bufinfo.len;
241+
size_t length = bufinfo.len;
242242
normalize_buffer_bounds(&start, end, &length);
243243

244244
// do the transfer
@@ -275,7 +275,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_writeto_obj, 1, bitbangio_i2c_wr
275275
//| .. method:: writeto_then_readfrom(address, out_buffer, in_buffer, *, out_start=0, out_end=None, in_start=0, in_end=None)
276276
//|
277277
//| Write the bytes from ``out_buffer`` to the slave specified by ``address``, generate no stop
278-
//| bit, generate a repeated start and read into ``in_buffer``.
278+
//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and
279+
//| ``in_buffer`` can be the same buffer because they are used sequentially.
279280
//|
280281
//| If ``start`` or ``end`` is provided, then the corresponding buffer will be sliced
281282
//| as if ``buffer[start:end]``. This will not cause an allocation like ``buf[start:end]``

shared-bindings/busio/I2C.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ STATIC void readfrom(busio_i2c_obj_t *self, mp_int_t address, mp_obj_t buffer, i
194194
mp_buffer_info_t bufinfo;
195195
mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_WRITE);
196196

197-
uint32_t length = bufinfo.len;
197+
size_t length = bufinfo.len;
198198
normalize_buffer_bounds(&start, end, &length);
199199
if (length == 0) {
200200
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
253253
mp_buffer_info_t bufinfo;
254254
mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_READ);
255255

256-
uint32_t length = bufinfo.len;
256+
size_t length = bufinfo.len;
257257
normalize_buffer_bounds(&start, end, &length);
258258

259259
// do the transfer
@@ -288,7 +288,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_writeto_obj, 1, busio_i2c_writeto);
288288
//| .. method:: writeto_then_readfrom(address, out_buffer, in_buffer, *, out_start=0, out_end=None, in_start=0, in_end=None)
289289
//|
290290
//| Write the bytes from ``out_buffer`` to the slave specified by ``address``, generate no stop
291-
//| bit, generate a repeated start and read into ``in_buffer``.
291+
//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and
292+
//| ``in_buffer`` can be the same buffer because they are used sequentially.
292293
//|
293294
//| If ``start`` or ``end`` is provided, then the corresponding buffer will be sliced
294295
//| as if ``buffer[start:end]``. This will not cause an allocation like ``buf[start:end]``

0 commit comments

Comments
 (0)