summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal/i2c.c
diff options
context:
space:
mode:
Diffstat (limited to 'stmhal/i2c.c')
-rw-r--r--stmhal/i2c.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/stmhal/i2c.c b/stmhal/i2c.c
index b6e3d9beee..4b44a1a313 100644
--- a/stmhal/i2c.c
+++ b/stmhal/i2c.c
@@ -157,7 +157,6 @@ STATIC const pyb_i2c_obj_t pyb_i2c_obj[] = {
#endif
{{&pyb_i2c_type}, &I2CHandle2}
};
-#define PYB_NUM_I2C (sizeof(pyb_i2c_obj) / sizeof(pyb_i2c_obj[0]))
STATIC void pyb_i2c_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_i2c_obj_t *self = self_in;
@@ -183,7 +182,7 @@ STATIC const mp_arg_parse_t pyb_i2c_init_accepted_args[] = {
{ MP_QSTR_baudrate, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_INT, {.u_int = 400000} },
{ MP_QSTR_gencall, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_BOOL, {.u_bool = false} },
};
-#define PYB_I2C_INIT_NUM_ARGS (sizeof(pyb_i2c_init_accepted_args) / sizeof(pyb_i2c_init_accepted_args[0]))
+#define PYB_I2C_INIT_NUM_ARGS ARRAY_SIZE(pyb_i2c_init_accepted_args)
STATIC mp_obj_t pyb_i2c_init_helper(const pyb_i2c_obj_t *self, uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// parse args
@@ -222,7 +221,7 @@ STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
machine_int_t i2c_id = mp_obj_get_int(args[0]) - 1;
// check i2c number
- if (!(0 <= i2c_id && i2c_id < PYB_NUM_I2C && pyb_i2c_obj[i2c_id].i2c != NULL)) {
+ if (!(0 <= i2c_id && i2c_id < ARRAY_SIZE(pyb_i2c_obj) && pyb_i2c_obj[i2c_id].i2c != NULL)) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "I2C bus %d does not exist", i2c_id + 1));
}
@@ -301,7 +300,7 @@ STATIC const mp_arg_parse_t pyb_i2c_send_accepted_args[] = {
{ MP_QSTR_addr, MP_ARG_PARSE_INT, {.u_int = PYB_I2C_MASTER_ADDRESS} },
{ MP_QSTR_timeout, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_INT, {.u_int = 5000} },
};
-#define PYB_I2C_SEND_NUM_ARGS (sizeof(pyb_i2c_send_accepted_args) / sizeof(pyb_i2c_send_accepted_args[0]))
+#define PYB_I2C_SEND_NUM_ARGS ARRAY_SIZE(pyb_i2c_send_accepted_args)
STATIC mp_obj_t pyb_i2c_send(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
pyb_i2c_obj_t *self = args[0];
@@ -341,7 +340,7 @@ STATIC const mp_arg_parse_t pyb_i2c_recv_accepted_args[] = {
{ MP_QSTR_addr, MP_ARG_PARSE_INT, {.u_int = PYB_I2C_MASTER_ADDRESS} },
{ MP_QSTR_timeout, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_INT, {.u_int = 5000} },
};
-#define PYB_I2C_RECV_NUM_ARGS (sizeof(pyb_i2c_recv_accepted_args) / sizeof(pyb_i2c_recv_accepted_args[0]))
+#define PYB_I2C_RECV_NUM_ARGS ARRAY_SIZE(pyb_i2c_recv_accepted_args)
STATIC mp_obj_t pyb_i2c_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
pyb_i2c_obj_t *self = args[0];
@@ -386,7 +385,7 @@ STATIC const mp_arg_parse_t pyb_i2c_mem_read_accepted_args[] = {
{ MP_QSTR_memaddr, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_INT, {.u_int = 0} },
{ MP_QSTR_timeout, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_INT, {.u_int = 5000} },
};
-#define PYB_I2C_MEM_READ_NUM_ARGS (sizeof(pyb_i2c_mem_read_accepted_args) / sizeof(pyb_i2c_mem_read_accepted_args[0]))
+#define PYB_I2C_MEM_READ_NUM_ARGS ARRAY_SIZE(pyb_i2c_mem_read_accepted_args)
STATIC mp_obj_t pyb_i2c_mem_read(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
pyb_i2c_obj_t *self = args[0];