]> sigrok.org Git - libsigrok.git/commitdiff
sysclk-lwla: Use ARRAY_SIZE instead of G_N_ELEMENTS.
authorUwe Hermann <redacted>
Thu, 26 Mar 2015 20:57:56 +0000 (21:57 +0100)
committerUwe Hermann <redacted>
Thu, 26 Mar 2015 22:53:52 +0000 (23:53 +0100)
Both do exactly the same, but we consistently use ARRAY_SIZE
in the rest of the code-base.

src/hardware/sysclk-lwla/api.c
src/hardware/sysclk-lwla/lwla.c
src/hardware/sysclk-lwla/protocol.c

index 7da96eec4e91c3bea57db1ba9ed5f1bd0952a60d..066f914db1016615c9ede8898e192366bdb282c0 100644 (file)
@@ -277,19 +277,19 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
                break;
        case SR_CONF_CLOCK_EDGE:
                idx = devc->cfg_clock_edge;
-               if (idx >= G_N_ELEMENTS(signal_edge_names))
+               if (idx >= ARRAY_SIZE(signal_edge_names))
                        return SR_ERR_BUG;
                *data = g_variant_new_string(signal_edge_names[idx]);
                break;
        case SR_CONF_TRIGGER_SOURCE:
                idx = devc->cfg_trigger_source;
-               if (idx >= G_N_ELEMENTS(trigger_source_names))
+               if (idx >= ARRAY_SIZE(trigger_source_names))
                        return SR_ERR_BUG;
                *data = g_variant_new_string(trigger_source_names[idx]);
                break;
        case SR_CONF_TRIGGER_SLOPE:
                idx = devc->cfg_trigger_slope;
-               if (idx >= G_N_ELEMENTS(signal_edge_names))
+               if (idx >= ARRAY_SIZE(signal_edge_names))
                        return SR_ERR_BUG;
                *data = g_variant_new_string(signal_edge_names[idx]);
                break;
@@ -336,7 +336,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
        switch (key) {
        case SR_CONF_SAMPLERATE:
                value = g_variant_get_uint64(data);
-               if (value < samplerates[G_N_ELEMENTS(samplerates) - 1]
+               if (value < samplerates[ARRAY_SIZE(samplerates) - 1]
                                || value > samplerates[0])
                        return SR_ERR_SAMPLERATE;
                devc->samplerate = value;
@@ -359,21 +359,21 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                break;
        case SR_CONF_CLOCK_EDGE:
                idx = lookup_index(data, signal_edge_names,
-                                  G_N_ELEMENTS(signal_edge_names));
+                                  ARRAY_SIZE(signal_edge_names));
                if (idx < 0)
                        return SR_ERR_ARG;
                devc->cfg_clock_edge = idx;
                break;
        case SR_CONF_TRIGGER_SOURCE:
                idx = lookup_index(data, trigger_source_names,
-                                  G_N_ELEMENTS(trigger_source_names));
+                                  ARRAY_SIZE(trigger_source_names));
                if (idx < 0)
                        return SR_ERR_ARG;
                devc->cfg_trigger_source = idx;
                break;
        case SR_CONF_TRIGGER_SLOPE:
                idx = lookup_index(data, signal_edge_names,
-                                  G_N_ELEMENTS(signal_edge_names));
+                                  ARRAY_SIZE(signal_edge_names));
                if (idx < 0)
                        return SR_ERR_ARG;
                devc->cfg_trigger_slope = idx;
@@ -438,12 +438,12 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                break;
        case SR_CONF_DEVICE_OPTIONS:
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, G_N_ELEMENTS(devopts), sizeof(uint32_t));
+                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
                break;
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
-                               samplerates, G_N_ELEMENTS(samplerates),
+                               samplerates, ARRAY_SIZE(samplerates),
                                sizeof(uint64_t));
                g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
                *data = g_variant_builder_end(&gvb);
@@ -455,12 +455,12 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                break;
        case SR_CONF_TRIGGER_SOURCE:
                *data = g_variant_new_strv(trigger_source_names,
-                                          G_N_ELEMENTS(trigger_source_names));
+                                          ARRAY_SIZE(trigger_source_names));
                break;
        case SR_CONF_TRIGGER_SLOPE:
        case SR_CONF_CLOCK_EDGE:
                *data = g_variant_new_strv(signal_edge_names,
-                                          G_N_ELEMENTS(signal_edge_names));
+                                          ARRAY_SIZE(signal_edge_names));
                break;
        default:
                return SR_ERR_NA;
index e0e1c87b713b2a26b6212f5bead0ee4ebc35481c..4cc1b656ea46bb90b71e5e5d66755ab666efee94 100644 (file)
@@ -193,12 +193,12 @@ SR_PRIV int lwla_read_reg(const struct sr_usb_dev_inst *usb,
        command[0] = LWLA_WORD(CMD_READ_REG);
        command[1] = LWLA_WORD(reg);
 
-       ret = lwla_send_command(usb, command, G_N_ELEMENTS(command));
+       ret = lwla_send_command(usb, command, ARRAY_SIZE(command));
 
        if (ret != SR_OK)
                return ret;
 
-       ret = lwla_receive_reply(usb, reply, G_N_ELEMENTS(reply), 1);
+       ret = lwla_receive_reply(usb, reply, ARRAY_SIZE(reply), 1);
 
        if (ret == SR_OK)
                *value = LWLA_TO_UINT32(reply[0]);
@@ -216,7 +216,7 @@ SR_PRIV int lwla_write_reg(const struct sr_usb_dev_inst *usb,
        command[2] = LWLA_WORD_0(value);
        command[3] = LWLA_WORD_1(value);
 
-       return lwla_send_command(usb, command, G_N_ELEMENTS(command));
+       return lwla_send_command(usb, command, ARRAY_SIZE(command));
 }
 
 SR_PRIV int lwla_write_regs(const struct sr_usb_dev_inst *usb,
index a8659a6b04082d98ba0801f72eff555c2fed3947..dba336d9aee4924802511774d8a07ed0827c59f2 100644 (file)
@@ -134,7 +134,7 @@ static int capture_setup(const struct sr_dev_inst *sdi)
        /* Fill remaining 64-bit words with zeroes. */
        memset(&command[27], 0, 16 * sizeof(uint16_t));
 
-       return lwla_send_command(sdi->conn, command, G_N_ELEMENTS(command));
+       return lwla_send_command(sdi->conn, command, ARRAY_SIZE(command));
 }
 
 /* Issue a register write command as an asynchronous USB transfer.
@@ -894,7 +894,7 @@ SR_PRIV int lwla_setup_acquisition(const struct sr_dev_inst *sdi)
        regvals[6].reg = REG_DIV_BYPASS;
        regvals[6].val = acq->bypass_clockdiv;
 
-       ret = lwla_write_regs(usb, regvals, G_N_ELEMENTS(regvals));
+       ret = lwla_write_regs(usb, regvals, ARRAY_SIZE(regvals));
        if (ret != SR_OK)
                return ret;