]> sigrok.org Git - libsigrok.git/commitdiff
ols: refactor channel initialization
authorWolfram Sang <redacted>
Wed, 2 Jan 2019 12:15:19 +0000 (13:15 +0100)
committerUwe Hermann <redacted>
Sun, 13 Jan 2019 19:07:27 +0000 (20:07 +0100)
We needs this twice so put it into a seperate function, so updates to it
will automatically handled for both callers.

Signed-off-by: Wolfram Sang <redacted>
src/hardware/openbench-logic-sniffer/protocol.c

index 0041b21a3b744144252e611d8ee8a9bb6c15089d..0a9a34a204e6bcb9e13ebc9586cd9b52e57e575b 100644 (file)
@@ -146,11 +146,20 @@ SR_PRIV struct dev_context *ols_dev_new(void)
        return devc;
 }
 
        return devc;
 }
 
+static void ols_channel_new(struct sr_dev_inst *sdi, int num_chan)
+{
+       int i;
+
+       for (i = 0; i < num_chan; i++)
+               sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
+                               ols_channel_names[i]);
+}
+
 SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial)
 {
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
 SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial)
 {
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
-       uint32_t tmp_int, ui;
+       uint32_t tmp_int;
        uint8_t key, type, token;
        int delay_ms;
        GString *tmp_str, *devname, *version;
        uint8_t key, type, token;
        int delay_ms;
        GString *tmp_str, *devname, *version;
@@ -221,9 +230,7 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial)
                        switch (token) {
                        case 0x00:
                                /* Number of usable channels */
                        switch (token) {
                        case 0x00:
                                /* Number of usable channels */
-                               for (ui = 0; ui < tmp_int; ui++)
-                                       sr_channel_new(sdi, ui, SR_CHANNEL_LOGIC, TRUE,
-                                                       ols_channel_names[ui]);
+                               ols_channel_new(sdi, tmp_int);
                                break;
                        case 0x01:
                                /* Amount of sample memory available (bytes) */
                                break;
                        case 0x01:
                                /* Amount of sample memory available (bytes) */
@@ -257,9 +264,7 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial)
                        switch (token) {
                        case 0x00:
                                /* Number of usable channels */
                        switch (token) {
                        case 0x00:
                                /* Number of usable channels */
-                               for (ui = 0; ui < tmp_c; ui++)
-                                       sr_channel_new(sdi, ui, SR_CHANNEL_LOGIC, TRUE,
-                                                       ols_channel_names[ui]);
+                               ols_channel_new(sdi, tmp_c);
                                break;
                        case 0x01:
                                /* protocol version */
                                break;
                        case 0x01:
                                /* protocol version */