]> sigrok.org Git - libsigrok.git/blobdiff - hardware/zeroplus-logic-cube/zeroplus.c
Add ARRAY_SIZE helper.
[libsigrok.git] / hardware / zeroplus-logic-cube / zeroplus.c
index 51f3cb9c4bf2d91eae73f03955c9fd709cfbd22c..e5b05ac6c5725e9d078aaa23800bdfc5902cb2e7 100644 (file)
@@ -108,12 +108,12 @@ static struct samplerates samplerates = {
 /* TODO: all of these should go in a device-specific struct */
 static uint64_t cur_samplerate = 0;
 static uint64_t limit_samples = 0;
-uint8_t num_channels = 32; // XXX this is not getting initialized before it is needed :(
+int num_channels = 32; // XXX this is not getting initialized before it is needed :(
 uint64_t memory_size = 0;
-static uint8_t probe_mask = 0, \
-               trigger_mask[NUM_TRIGGER_STAGES] = {0}, \
-               trigger_value[NUM_TRIGGER_STAGES] = {0}, \
-               trigger_buffer[NUM_TRIGGER_STAGES] = {0};;
+static uint8_t probe_mask = 0;
+static uint8_t trigger_mask[NUM_TRIGGER_STAGES] = {0};
+static uint8_t trigger_value[NUM_TRIGGER_STAGES] = {0};
+// static uint8_t trigger_buffer[NUM_TRIGGER_STAGES] = {0};
 
 
 static int hw_set_configuration(int device_index, int capability, void *value);
@@ -137,7 +137,8 @@ struct sigrok_device_instance *zp_open_device(int device_index)
        struct sigrok_device_instance *sdi;
        libusb_device **devlist;
        struct libusb_device_descriptor des;
-       int err, i, j;
+       unsigned int j;
+       int err, i;
 
        if(!(sdi = get_sigrok_device_instance(device_instances, device_index)))
                return NULL;
@@ -155,7 +156,7 @@ struct sigrok_device_instance *zp_open_device(int device_index)
                        if(des.idVendor == USB_VENDOR) {
                                if(libusb_get_bus_number(devlist[i]) == sdi->usb->bus &&
                                                libusb_get_device_address(devlist[i]) == sdi->usb->address) {
-                                                       for (j = 0; j < sizeof(zeroplus_models) / sizeof(zeroplus_models[0]); j++) {
+                                                       for (j = 0; j < ARRAY_SIZE(zeroplus_models); j++) {
                                                                if (des.idProduct == zeroplus_models[j].pid) {
                                                                        g_message("Found PID=%04X (%s)", des.idProduct, zeroplus_models[j].model_name);
                                                                        num_channels = zeroplus_models[j].channels;
@@ -242,7 +243,7 @@ static int configure_probes(GSList *probes)
                                        trigger_value[stage] |= probe_bit;
                                stage++;
                                if(stage > NUM_TRIGGER_STAGES)
-                                       return SIGROK_NOK;
+                                       return SIGROK_ERR;
                        }
                }
        }
@@ -263,6 +264,9 @@ static int hw_init(char *deviceinfo)
        libusb_device **devlist;
        int err, devcnt, i;
 
+       /* QUICK HACK */
+       deviceinfo = deviceinfo;
+
        if(libusb_init(&usb_context) != 0) {
                g_warning("Failed to initialize USB.");
                return 0;
@@ -304,13 +308,13 @@ static int hw_opendev(int device_index)
 
        if( !(sdi = zp_open_device(device_index)) ) {
                g_warning("unable to open device");
-               return SIGROK_NOK;
+               return SIGROK_ERR;
        }
 
        err = libusb_claim_interface(sdi->usb->devhdl, USB_INTERFACE);
        if(err != 0) {
                g_warning("Unable to claim interface: %d", err);
-               return SIGROK_NOK;
+               return SIGROK_ERR;
        }
        analyzer_reset(sdi->usb->devhdl);
        analyzer_initialize(sdi->usb->devhdl);
@@ -331,8 +335,8 @@ static int hw_opendev(int device_index)
 
        if(cur_samplerate == 0) {
                /* sample rate hasn't been set; default to the slowest it has */
-               if(hw_set_configuration(device_index, HWCAP_SAMPLERATE, &samplerates.low) == SIGROK_NOK)
-                       return SIGROK_NOK;
+               if(hw_set_configuration(device_index, HWCAP_SAMPLERATE, &samplerates.low) == SIGROK_ERR)
+                       return SIGROK_ERR;
        }
 
        return SIGROK_OK;
@@ -416,12 +420,11 @@ static int hw_get_status(int device_index)
 
 static int *hw_get_capabilities(void)
 {
-
        return capabilities;
 }
 
 // XXX this will set the same samplerate for all devices
-int set_configuration_samplerate(struct sigrok_device_instance *sdi, uint64_t samplerate)
+static int set_configuration_samplerate(uint64_t samplerate)
 {
        g_message("%s(%llu)", __FUNCTION__, samplerate);
        if (samplerate > MHZ(1))
@@ -442,12 +445,12 @@ static int hw_set_configuration(int device_index, int capability, void *value)
        uint64_t *tmp_u64;
 
        if( !(sdi = get_sigrok_device_instance(device_instances, device_index)) )
-               return SIGROK_NOK;
+               return SIGROK_ERR;
 
        switch (capability) {
                case HWCAP_SAMPLERATE:
                        tmp_u64 = value;
-                       return set_configuration_samplerate(sdi, *tmp_u64);
+                       return set_configuration_samplerate(*tmp_u64);
 
                case HWCAP_PROBECONFIG:
                        return configure_probes( (GSList *) value);
@@ -457,7 +460,7 @@ static int hw_set_configuration(int device_index, int capability, void *value)
                        return SIGROK_OK;
 
                default:
-                       return SIGROK_NOK;
+                       return SIGROK_ERR;
        }
 }
 
@@ -467,11 +470,11 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
        struct datafeed_packet packet;
        struct datafeed_header header;
        int res;
-       int packet_num;
+       unsigned int packet_num;
        unsigned char *buf;
 
        if( !(sdi = get_sigrok_device_instance(device_instances, device_index)))
-               return SIGROK_NOK;
+               return SIGROK_ERR;
 
        analyzer_start(sdi->usb->devhdl);
        g_message("Waiting for data");
@@ -493,7 +496,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
 
        buf = g_malloc(PACKET_SIZE);
        if (!buf)
-               return SIGROK_NOK;
+               return SIGROK_ERR;
        analyzer_read_start(sdi->usb->devhdl);
        /* send the incoming transfer to the session bus */
        for(packet_num = 0; packet_num < (memory_size * 4 / PACKET_SIZE); packet_num++) {