altos/drivers: Add explicit casts in ao_aprs, ao_bmx160 and ao_btm
authorKeith Packard <keithp@keithp.com>
Fri, 28 Jan 2022 17:15:57 +0000 (09:15 -0800)
committerKeith Packard <keithp@keithp.com>
Thu, 17 Feb 2022 01:26:49 +0000 (17:26 -0800)
No bugs spotted here, but this quiets -Wconversion warnings

Signed-off-by: Keith Packard <keithp@keithp.com>
src/drivers/ao_aprs.c
src/drivers/ao_bmx160.c
src/drivers/ao_btm.c

index 826985c6e06e2f0b004a05c36a2b6976cd6a49ba..3ac4cd535b231a8ac11622e5719dfe115839a202 100644 (file)
@@ -186,7 +186,7 @@ static uint16_t sysCRC16(const uint8_t *buffer, uint8_t length, uint16_t crc)
 
         for (bit = 0; bit < 8; ++bit)
         {
-            crc ^= (value & 0x01);
+           crc = (uint16_t) (crc ^ (value & 0x01));
             crc = ( crc & 0x01 ) ? ( crc >> 1 ) ^ 0x8408 : ( crc >> 1 );
             value = value >> 1;
         } // END for
@@ -282,7 +282,7 @@ tncSetCallsign(void)
                TNC_AX25_HEADER[TNC_CALLSIGN_OFF + i] = ' ' << 1;
 
        /* Fill in the SSID with the low digit of the serial number */
-       TNC_AX25_HEADER[TNC_SSID_OFF] = 0x60 | ((ao_config.aprs_ssid & 0xf) << 1);
+       TNC_AX25_HEADER[TNC_SSID_OFF] = (uint8_t) (0x60 | ((ao_config.aprs_ssid & 0xf) << 1));
 #endif
 }
 
@@ -490,7 +490,7 @@ static void tnc1200TimerTick()
 static void tncCompressInt(uint8_t *dest, int32_t value, int len) {
        int i;
        for (i = len - 1; i >= 0; i--) {
-               dest[i] = value % 91 + 33;
+               dest[i] = (uint8_t) (value % 91 + 33);
                value /= 91;
        }
 }
@@ -611,7 +611,7 @@ fixed23_mul(uint32_t x, uint32_t y)
 static inline uint32_t
 fixed30_mul(uint32_t x, uint32_t y)
 {
-       return ((uint64_t) x * y + fixed30_half) >> 30;
+       return (uint32_t) (((uint64_t) x * y + fixed30_half) >> 30);
 }
 
 /*
@@ -620,15 +620,18 @@ fixed30_mul(uint32_t x, uint32_t y)
  */
 
 static uint32_t
-ao_fixed_log2(uint32_t x)
+ao_fixed_log2(int32_t ix)
 {
        uint32_t        result;
        uint32_t        frac = fixed23_one;
+       uint32_t        x;
 
        /* Bounds check for sanity */
-       if (x <= 0)
+       if (ix <= 0)
                return 0;
 
+       x = (uint32_t) ix;
+
        if (x >= fixed30_one)
                return 0xffffffff;
 
@@ -693,16 +696,16 @@ ao_fixed_log2(uint32_t x)
 #define APRS_LOG_CONVERT       fixed23_real(1.714065192056127)
 #define APRS_LOG_BASE          fixed23_real(346.920048461100941)
 
-static int
+static int32_t
 ao_aprs_encode_altitude(int meters)
 {
-       return fixed23_floor(fixed23_mul(ao_fixed_log2(meters) + APRS_LOG_CONVERT, APRS_LOG_BASE) + fixed23_half);
+       return (int32_t) fixed23_floor(fixed23_mul(ao_fixed_log2(meters) + APRS_LOG_CONVERT, APRS_LOG_BASE) + fixed23_half);
 }
 
 /**
  *   Generate the plain text position packet.
  */
-static int tncPositionPacket(void)
+static uint8_t tncPositionPacket(void)
 {
     static int32_t     latitude;
     static int32_t     longitude;
@@ -736,8 +739,8 @@ static int tncPositionPacket(void)
            /* Symbol table ID */
            *buf++ = '/';
 
-           lat = ((uint64_t) 380926 * (900000000 - latitude)) / 10000000;
-           lon = ((uint64_t) 190463 * (1800000000 + longitude)) / 10000000;
+           lat = (int32_t) (((int64_t) 380926 * (900000000 - latitude)) / 10000000);
+           lon = (int32_t) (((int64_t) 190463 * (1800000000 + longitude)) / 10000000);
 
            alt = ao_aprs_encode_altitude(altitude);
 
@@ -787,19 +790,19 @@ static int tncPositionPacket(void)
            if (lon > 1800000000)
                    lon = 1800000000;
 
-           lat_deg = lat / 10000000;
+           lat_deg = (uint16_t) (lat / 10000000);
            lat -= lat_deg * 10000000;
            lat *= 60;
-           lat_min = lat / 10000000;
+           lat_min = (uint16_t) (lat / 10000000);
            lat -= lat_min * 10000000;
-           lat_frac = lat / 100000;
+           lat_frac = (uint16_t) (lat / 100000);
 
-           lon_deg = lon / 10000000;
+           lon_deg = (uint16_t) (lon / 10000000);
            lon -= lon_deg * 10000000;
            lon *= 60;
-           lon_min = lon / 10000000;
+           lon_min = (uint16_t) (lon / 10000000);
            lon -= lon_min * 10000000;
-           lon_frac = lon / 100000;
+           lon_frac = (uint16_t) (lon / 100000);
 
            /* Convert from meters to feet */
            alt = (alt * 328 + 50) / 100;
@@ -814,7 +817,7 @@ static int tncPositionPacket(void)
 
     buf += tncComment(buf);
 
-    return buf - tncBuffer;
+    return (uint8_t) (buf - tncBuffer);
 }
 
 static int16_t
@@ -827,7 +830,7 @@ tncFill(uint8_t *buf, int16_t len)
     while (tncMode != TNC_TX_READY && l < len) {
        b = 0;
        for (bit = 0; bit < 8; bit++) {
-           b = b << 1 | (timeNCO >> 15);
+           b = (uint8_t) (b << 1 | (timeNCO >> 15));
            timeNCO += timeNCOFreq;
        }
        *buf++ = b;
@@ -860,8 +863,8 @@ void ao_aprs_send(void)
     crc = sysCRC16(tncBuffer, tncLength, crc ^ 0xffff);
 
     // Save the CRC in the message.
-    tncBuffer[tncLength++] = crc & 0xff;
-    tncBuffer[tncLength++] = (crc >> 8) & 0xff;
+    tncBuffer[tncLength++] = (uint8_t) (crc & 0xff);
+    tncBuffer[tncLength++] = (uint8_t) ((crc >> 8) & 0xff);
 
     // Prepare the variables that are used in the real-time clock interrupt.
     tncBitCount = 0;
index 427a081bc36e21db5e56a65e92101225f0690517..eabe0783253d05c788ff97c2cfc4cf9d12abe9c0 100644 (file)
@@ -109,7 +109,7 @@ _ao_bmm150_reg_read2(uint8_t lo_addr, uint8_t hi_addr)
        uint8_t lo = _ao_bmm150_reg_read(lo_addr);
        uint8_t hi = _ao_bmm150_reg_read(hi_addr);
 
-       return ((uint16_t) hi << 8) | lo;
+       return (uint16_t) (((uint16_t) hi << 8) | (uint16_t) lo);
 }
 
 /*
@@ -217,7 +217,7 @@ static int16_t compensate_x(int16_t mag_data_x, uint16_t data_rhall)
            //printf("comp_x10 %d\n", process_comp_x10);
             retval = ((int16_t)(process_comp_x10 / 8192));
            //printf("ret 1 %d\n", retval);
-            retval = (retval + (((int16_t)ao_bmm150_trim.dig_x1) * 8)) / 16;
+            retval = (int16_t) ((retval + (((int16_t)ao_bmm150_trim.dig_x1) * 8)) / 16);
            //printf("final %d\n", retval);
         }
         else
@@ -282,7 +282,7 @@ static int16_t compensate_y(int16_t mag_data_y, uint16_t data_rhall)
             process_comp_y8 = (((process_comp_y6 + ((int32_t)0x100000)) * process_comp_y7) / 4096);
             process_comp_y9 = (((int32_t)mag_data_y) * process_comp_y8);
             retval = (int16_t)(process_comp_y9 / 8192);
-            retval = (retval + (((int16_t)ao_bmm150_trim.dig_y1) * 8)) / 16;
+            retval = (int16_t) ((retval + (((int16_t)ao_bmm150_trim.dig_y1) * 8)) / 16);
         }
         else
         {
@@ -504,7 +504,7 @@ _ao_bmx160_setup(void)
                             BMX160_ACC_RANGE_16G);
 
        for (r = 0x3; r <= 0x1b; r++)
-               (void) _ao_bmx160_reg_read(r);
+               (void) _ao_bmx160_reg_read((uint8_t) r);
 
        /* Configure gyro:
         *
@@ -560,16 +560,16 @@ _ao_bmx160_setup(void)
        _ao_bmm150_reg_write(BMM150_REPZ, BMM150_REPZ_VALUE(15));
 
        /* Read Trim values */
-       ao_bmm150_trim.dig_x1   = _ao_bmm150_reg_read(BMM150_DIG_X1);
-       ao_bmm150_trim.dig_y1   = _ao_bmm150_reg_read(BMM150_DIG_Y1);
-       ao_bmm150_trim.dig_z4   = _ao_bmm150_reg_read2(BMM150_DIG_Z4_LSB, BMM150_DIG_Z4_MSB);
-       ao_bmm150_trim.dig_x2   = _ao_bmm150_reg_read(BMM150_DIG_X2);
-       ao_bmm150_trim.dig_y2   = _ao_bmm150_reg_read(BMM150_DIG_Y2);
-       ao_bmm150_trim.dig_z2   = _ao_bmm150_reg_read2(BMM150_DIG_Z2_LSB, BMM150_DIG_Z2_MSB);
+       ao_bmm150_trim.dig_x1   = (int8_t) _ao_bmm150_reg_read(BMM150_DIG_X1);
+       ao_bmm150_trim.dig_y1   = (int8_t) _ao_bmm150_reg_read(BMM150_DIG_Y1);
+       ao_bmm150_trim.dig_z4   = (int8_t) _ao_bmm150_reg_read2(BMM150_DIG_Z4_LSB, BMM150_DIG_Z4_MSB);
+       ao_bmm150_trim.dig_x2   = (int8_t) _ao_bmm150_reg_read(BMM150_DIG_X2);
+       ao_bmm150_trim.dig_y2   = (int8_t) _ao_bmm150_reg_read(BMM150_DIG_Y2);
+       ao_bmm150_trim.dig_z2   = (int8_t) _ao_bmm150_reg_read2(BMM150_DIG_Z2_LSB, BMM150_DIG_Z2_MSB);
        ao_bmm150_trim.dig_z1   = _ao_bmm150_reg_read2(BMM150_DIG_Z1_LSB, BMM150_DIG_Z1_MSB);
        ao_bmm150_trim.dig_xyz1 = _ao_bmm150_reg_read2(BMM150_DIG_XYZ1_LSB, BMM150_DIG_XYZ1_MSB);
-       ao_bmm150_trim.dig_z3   = _ao_bmm150_reg_read2(BMM150_DIG_Z3_LSB, BMM150_DIG_Z3_MSB);
-       ao_bmm150_trim.dig_xy2  = _ao_bmm150_reg_read(BMM150_DIG_XY2);
+       ao_bmm150_trim.dig_z3   = (int8_t) _ao_bmm150_reg_read2(BMM150_DIG_Z3_LSB, BMM150_DIG_Z3_MSB);
+       ao_bmm150_trim.dig_xy2  = (int8_t) _ao_bmm150_reg_read(BMM150_DIG_XY2);
        ao_bmm150_trim.dig_xy1  = _ao_bmm150_reg_read(BMM150_DIG_XY1);
 
        /* To get data out of the magnetometer, set the control op mode to 'forced', then read
index b7ff0b9edb4d383da76e414ae1b67baccc0bd1dc..b82fb999fe8957536c42bab002ebeda57161486b 100644 (file)
@@ -29,7 +29,7 @@
 #define ao_serial_btm_drain    ao_serial1_drain
 #endif
 
-int8_t                 ao_btm_stdio;
+uint8_t                ao_btm_stdio;
 uint8_t                ao_btm_connected;
 
 #define BT_DEBUG 0
@@ -197,7 +197,7 @@ ao_btm_get_line(void)
        while ((c = ao_btm_getchar()) != AO_READ_AGAIN) {
                ao_btm_log_in_char(c);
                if (ao_btm_reply_len < sizeof (ao_btm_reply))
-                       ao_btm_reply[ao_btm_reply_len++] = c;
+                       ao_btm_reply[ao_btm_reply_len++] = (char) c;
                if (c == '\r' || c == '\n')
                        break;
        }
@@ -242,7 +242,7 @@ ao_btm_putchar(char c)
  * Wait for the bluetooth device to return
  * status from the previously executed command
  */
-static uint8_t
+static int
 ao_btm_wait_reply(void)
 {
        for (;;) {
@@ -265,7 +265,7 @@ ao_btm_string(const char *cmd)
                ao_btm_putchar(c);
 }
 
-static uint8_t
+static int
 ao_btm_cmd(const char *cmd)
 {
        ao_btm_drain();
@@ -282,7 +282,7 @@ ao_btm_cmd(const char *cmd)
        return ao_btm_wait_reply();
 }
 
-static uint8_t
+static int
 ao_btm_set_name(void)
 {
        char    sn[8];
@@ -294,7 +294,7 @@ ao_btm_set_name(void)
        *--s = '\r';
        n = ao_serial_number;
        do {
-               *--s = '0' + n % 10;
+               *--s = (uint8_t) ('0' + n % 10);
        } while (n /= 10);
        while ((c = *s++))
                ao_btm_putchar(c);