]> sigrok.org Git - libsigrok.git/blobdiff - hardware/common/dmm/rs9lcd.c
build: Portability fixes.
[libsigrok.git] / hardware / common / dmm / rs9lcd.c
index e5b773b57c708e49e092621a9e6683c34ee8f845..539c2335e265931e328dae71d6fc8c452848a85a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file is part of the sigrok project.
+ * This file is part of the libsigrok project.
  *
  * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
  *
 #include "libsigrok.h"
 #include "libsigrok-internal.h"
 
-/* Message logging helpers with driver-specific prefix string. */
-#define DRIVER_LOG_DOMAIN "rs9lcd: "
-#define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args)
-#define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args)
-#define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args)
-#define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args)
-#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
-#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
+#define LOG_PREFIX "rs9lcd"
 
 /* Byte 1 of the packet, and the modes it represents */
-#define IND1_HZ                0x80
-#define IND1_OHM       0x40
-#define IND1_KILO      0x20
-#define IND1_MEGA      0x10
-#define IND1_FARAD     0x08
-#define IND1_AMP       0x04
-#define IND1_VOLT      0x02
-#define IND1_MILI      0x01
+#define IND1_HZ                (1 << 7)
+#define IND1_OHM       (1 << 6)
+#define IND1_KILO      (1 << 5)
+#define IND1_MEGA      (1 << 4)
+#define IND1_FARAD     (1 << 3)
+#define IND1_AMP       (1 << 2)
+#define IND1_VOLT      (1 << 1)
+#define IND1_MILI      (1 << 0)
 /* Byte 2 of the packet, and the modes it represents */
-#define IND2_MICRO     0x80
-#define IND2_NANO      0x40
-#define IND2_DBM       0x20
-#define IND2_SEC       0x10
-#define IND2_DUTY      0x08
-#define IND2_HFE       0x04
-#define IND2_REL       0x02
-#define IND2_MIN       0x01
+#define IND2_MICRO     (1 << 7)
+#define IND2_NANO      (1 << 6)
+#define IND2_DBM       (1 << 5)
+#define IND2_SEC       (1 << 4)
+#define IND2_DUTY      (1 << 3)
+#define IND2_HFE       (1 << 2)
+#define IND2_REL       (1 << 1)
+#define IND2_MIN       (1 << 0)
 /* Byte 7 of the packet, and the modes it represents */
-#define INFO_BEEP      0x80
-#define INFO_DIODE     0x30
-#define INFO_BAT       0x20
-#define INFO_HOLD      0x10
-#define INFO_NEG       0x08
-#define INFO_AC                0x04
-#define INFO_RS232     0x02
-#define INFO_AUTO      0x01
+#define INFO_BEEP      (1 << 7)
+#define INFO_DIODE     (1 << 6)
+#define INFO_BAT       (1 << 5)
+#define INFO_HOLD      (1 << 4)
+#define INFO_NEG       (1 << 3)
+#define INFO_AC                (1 << 2)
+#define INFO_RS232     (1 << 1)
+#define INFO_AUTO      (1 << 0)
 /* Instead of a decimal point, digit 4 carries the MAX flag */
-#define DIG4_MAX       0x08
+#define DIG4_MAX       (1 << 3)
 /* Mask to remove the decimal point from a digit */
-#define DP_MASK                0x08
+#define DP_MASK                (1 << 3)
 
 /* What the LCD values represent */
 #define LCD_0          0xd7
@@ -110,20 +103,20 @@ enum {
        MODE_OHM        = 8,
        MODE_FARAD      = 9,
        MODE_HZ         = 10,
-       MODE_VOLT_HZ    = 11,
-       MODE_AMP_HZ     = 12,
+       MODE_VOLT_HZ    = 11,   /* Dial set to V, Hz selected by Hz button */
+       MODE_AMP_HZ     = 12,   /* Dial set to A, Hz selected by Hz button */
        MODE_DUTY       = 13,
-       MODE_VOLT_DUTY  = 14,
-       MODE_AMP_DUTY   = 15,
+       MODE_VOLT_DUTY  = 14,   /* Dial set to V, duty cycle selected */
+       MODE_AMP_DUTY   = 15,   /* Dial set to A, duty cycle selected */
        MODE_WIDTH      = 16,
-       MODE_VOLT_WIDTH = 17,
-       MODE_AMP_WIDTH  = 18,
+       MODE_VOLT_WIDTH = 17,   /* Dial set to V, pulse width selected */
+       MODE_AMP_WIDTH  = 18,   /* Dial set to A, pulse width selected */
        MODE_DIODE      = 19,
        MODE_CONT       = 20,
        MODE_HFE        = 21,
        MODE_LOGIC      = 22,
        MODE_DBM        = 23,
-       // MODE_EF      = 24,
+       /* MODE_EF      = 24, */ /* Not encountered on any DMM */
        MODE_TEMP       = 25,
        MODE_INVALID    = 26,
 };
@@ -153,7 +146,7 @@ static gboolean checksum_valid(const struct rs9lcd_packet *rs_packet)
 
        raw = (void *)rs_packet;
 
-       for (i = 0; i < RS_22_812_PACKET_SIZE - 1; i++)
+       for (i = 0; i < RS9LCD_PACKET_SIZE - 1; i++)
                sum += raw[i];
 
        /* This is just a funky constant added to the checksum. */
@@ -174,7 +167,7 @@ static gboolean selection_good(const struct rs9lcd_packet *rs_packet)
        count += (rs_packet->indicatrix2 & IND2_MICRO) ? 1 : 0;
        count += (rs_packet->indicatrix2 & IND2_NANO)  ? 1 : 0;
        if (count > 1) {
-               sr_err("More than one multiplier detected in packet.");
+               sr_dbg("More than one multiplier detected in packet.");
                return FALSE;
        }
 
@@ -190,7 +183,7 @@ static gboolean selection_good(const struct rs9lcd_packet *rs_packet)
        count += (rs_packet->indicatrix2 & IND2_DUTY)  ? 1 : 0;
        count += (rs_packet->indicatrix2 & IND2_HFE)   ? 1 : 0;
        if (count > 1) {
-               sr_err("More than one measurement type detected in packet.");
+               sr_dbg("More than one measurement type detected in packet.");
                return FALSE;
        }
 
@@ -255,14 +248,14 @@ static uint8_t decode_digit(uint8_t raw_digit)
        case LCD_9:
                return 9;
        default:
-               sr_err("Invalid digit byte: 0x%02x.", raw_digit);
+               sr_dbg("Invalid digit byte: 0x%02x.", raw_digit);
                return 0xff;
        }
 }
 
 static double lcd_to_double(const struct rs9lcd_packet *rs_packet, int type)
 {
-       double rawval, multiplier = 1;
+       double rawval = 0, multiplier = 1;
        uint8_t digit, raw_digit;
        gboolean dp_reached = FALSE;
        int i, end;
@@ -344,15 +337,15 @@ SR_PRIV int sr_rs9lcd_parse(const uint8_t *buf, float *floatval,
                analog->unit = SR_UNIT_VOLT;
                analog->mqflags |= SR_MQFLAG_AC;
                break;
-       case MODE_DC_UA:
-       case MODE_DC_MA:
+       case MODE_DC_UA:        /* Fall through */
+       case MODE_DC_MA:        /* Fall through */
        case MODE_DC_A:
                analog->mq = SR_MQ_CURRENT;
                analog->unit = SR_UNIT_AMPERE;
                analog->mqflags |= SR_MQFLAG_DC;
                break;
-       case MODE_AC_UA:
-       case MODE_AC_MA:
+       case MODE_AC_UA:        /* Fall through */
+       case MODE_AC_MA:        /* Fall through */
        case MODE_AC_A:
                analog->mq = SR_MQ_CURRENT;
                analog->unit = SR_UNIT_AMPERE;
@@ -369,15 +362,15 @@ SR_PRIV int sr_rs9lcd_parse(const uint8_t *buf, float *floatval,
        case MODE_CONT:
                analog->mq = SR_MQ_CONTINUITY;
                analog->unit = SR_UNIT_BOOLEAN;
-               *analog->data = is_shortcirc(rs_packet);
+               rawval = is_shortcirc(rs_packet);
                break;
        case MODE_DIODE:
                analog->mq = SR_MQ_VOLTAGE;
                analog->unit = SR_UNIT_VOLT;
                analog->mqflags |= SR_MQFLAG_DIODE | SR_MQFLAG_DC;
                break;
-       case MODE_HZ:
-       case MODE_VOLT_HZ:
+       case MODE_HZ:           /* Fall through */
+       case MODE_VOLT_HZ:      /* Fall through */
        case MODE_AMP_HZ:
                analog->mq = SR_MQ_FREQUENCY;
                analog->unit = SR_UNIT_HERTZ;
@@ -394,28 +387,29 @@ SR_PRIV int sr_rs9lcd_parse(const uint8_t *buf, float *floatval,
                } else {
                        /* We have either HI or LOW. */
                        analog->unit = SR_UNIT_BOOLEAN;
-                       *analog->data = is_logic_high(rs_packet);
+                       rawval = is_logic_high(rs_packet);
                }
                break;
        case MODE_HFE:
                analog->mq = SR_MQ_GAIN;
                analog->unit = SR_UNIT_UNITLESS;
                break;
-       case MODE_DUTY:
-       case MODE_VOLT_DUTY:
+       case MODE_DUTY:         /* Fall through */
+       case MODE_VOLT_DUTY:    /* Fall through */
        case MODE_AMP_DUTY:
                analog->mq = SR_MQ_DUTY_CYCLE;
                analog->unit = SR_UNIT_PERCENTAGE;
                break;
-       case MODE_WIDTH:
-       case MODE_VOLT_WIDTH:
+       case MODE_WIDTH:        /* Fall through */
+       case MODE_VOLT_WIDTH:   /* Fall through */
        case MODE_AMP_WIDTH:
                analog->mq = SR_MQ_PULSE_WIDTH;
                analog->unit = SR_UNIT_SECOND;
+               break;
        case MODE_TEMP:
                analog->mq = SR_MQ_TEMPERATURE;
                /* We need to reparse. */
-               *analog->data = lcd_to_double(rs_packet, READ_TEMP);
+               rawval = lcd_to_double(rs_packet, READ_TEMP);
                analog->unit = is_celsius(rs_packet) ?
                                SR_UNIT_CELSIUS : SR_UNIT_FAHRENHEIT;
                break;
@@ -425,7 +419,7 @@ SR_PRIV int sr_rs9lcd_parse(const uint8_t *buf, float *floatval,
                analog->mqflags |= SR_MQFLAG_AC;
                break;
        default:
-               sr_err("Unknown mode: %d.", rs_packet->mode);
+               sr_dbg("Unknown mode: %d.", rs_packet->mode);
                break;
        }