Skip to content

Commit 86f0b31

Browse files
committed
Change boolean 'use_16bit_addr' to int 'addr_size', can be either 8 or 16 bits, default value is 8
to maintain compatibility with existing code.
1 parent 721d624 commit 86f0b31

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

stmhal/i2c.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -453,15 +453,15 @@ STATIC mp_obj_t pyb_i2c_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
453453
}
454454
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_recv_obj, 1, pyb_i2c_recv);
455455

456-
/// \method mem_read(data, addr, memaddr, timeout=5000, use_16bit_addr=False)
456+
/// \method mem_read(data, addr, memaddr, timeout=5000, addr_size=8)
457457
///
458458
/// Read from the memory of an I2C device:
459459
///
460460
/// - `data` can be an integer or a buffer to read into
461461
/// - `addr` is the I2C device address
462462
/// - `memaddr` is the memory location within the I2C device
463463
/// - `timeout` is the timeout in milliseconds to wait for the read
464-
/// - `use_16bit_addr` selects width of memaddr: 8 or 16 bits
464+
/// - `addr_size` selects width of memaddr: 8 or 16 bits
465465
///
466466
/// Returns the read data.
467467
/// This is only valid in master mode.
@@ -470,7 +470,7 @@ STATIC const mp_arg_t pyb_i2c_mem_read_args[] = {
470470
{ MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
471471
{ MP_QSTR_memaddr, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
472472
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} },
473-
{ MP_QSTR_use_16bit_addr, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
473+
{ MP_QSTR_addr_size, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} },
474474
};
475475
#define PYB_I2C_MEM_READ_NUM_ARGS MP_ARRAY_SIZE(pyb_i2c_mem_read_args)
476476

@@ -492,9 +492,9 @@ STATIC mp_obj_t pyb_i2c_mem_read(uint n_args, const mp_obj_t *args, mp_map_t *kw
492492
// get the addresses
493493
mp_uint_t i2c_addr = vals[1].u_int << 1;
494494
mp_uint_t mem_addr = vals[2].u_int;
495-
// determine width of mem_addr
495+
// determine width of mem_addr; default is 8 bits, entering any other value gives 16 bit width
496496
mp_uint_t mem_addr_size = I2C_MEMADD_SIZE_8BIT;
497-
if (vals[4].u_bool) {
497+
if (vals[4].u_int != 8) {
498498
mem_addr_size = I2C_MEMADD_SIZE_16BIT;
499499
}
500500

@@ -514,15 +514,15 @@ STATIC mp_obj_t pyb_i2c_mem_read(uint n_args, const mp_obj_t *args, mp_map_t *kw
514514
}
515515
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_mem_read_obj, 1, pyb_i2c_mem_read);
516516

517-
/// \method mem_write(data, addr, memaddr, timeout=5000, use_16bit_addr=False)
517+
/// \method mem_write(data, addr, memaddr, timeout=5000, addr_size=8)
518518
///
519519
/// Write to the memory of an I2C device:
520520
///
521521
/// - `data` can be an integer or a buffer to write from
522522
/// - `addr` is the I2C device address
523523
/// - `memaddr` is the memory location within the I2C device
524524
/// - `timeout` is the timeout in milliseconds to wait for the write
525-
/// - `use_16bit_addr` selects width of memaddr: 8 or 16 bits
525+
/// - `addr_size` selects width of memaddr: 8 or 16 bits
526526
///
527527
/// Returns `None`.
528528
/// This is only valid in master mode.
@@ -545,9 +545,9 @@ STATIC mp_obj_t pyb_i2c_mem_write(uint n_args, const mp_obj_t *args, mp_map_t *k
545545
// get the addresses
546546
mp_uint_t i2c_addr = vals[1].u_int << 1;
547547
mp_uint_t mem_addr = vals[2].u_int;
548-
// determine width of mem_addr
548+
// determine width of mem_addr; default is 8 bits, entering any other value gives 16 bit width
549549
mp_uint_t mem_addr_size = I2C_MEMADD_SIZE_8BIT;
550-
if (vals[4].u_bool) {
550+
if (vals[4].u_int != 8) {
551551
mem_addr_size = I2C_MEMADD_SIZE_16BIT;
552552
}
553553

stmhal/qstrdefsport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Q(baudrate)
161161
Q(gencall)
162162
Q(data)
163163
Q(memaddr)
164-
Q(use_16bit_addr)
164+
Q(addr_size)
165165
Q(timeout)
166166
Q(init)
167167
Q(deinit)

0 commit comments

Comments
 (0)