drivers: Resolve -Wconversion in m25, mma655x, mmc5983, mpu and ms5607
authorKeith Packard <keithp@keithp.com>
Fri, 28 Jan 2022 21:59:26 +0000 (13:59 -0800)
committerKeith Packard <keithp@keithp.com>
Thu, 17 Feb 2022 01:26:49 +0000 (17:26 -0800)
No bugs identified.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/drivers/ao_m25.c
src/drivers/ao_mma655x.c
src/drivers/ao_mmc5983.c
src/drivers/ao_mpu6000.c
src/drivers/ao_mpu9250.c
src/drivers/ao_ms5607.c
src/drivers/ao_ms5607.h
src/drivers/ao_ms5607_convert.c

index 2e4cbedf989d23991c54245b6a6a18d392e2d1b1..accf943a3fbe6e079ad0825b21f53d08823828fb 100644 (file)
@@ -125,7 +125,7 @@ ao_m25_wait_wip(ao_port_t cs)
                        ao_spi_recv(ao_m25_instruction, 1, AO_M25_SPI_BUS);
                } while (ao_m25_instruction[0] & M25_STATUS_WIP);
                M25_DESELECT(cs);
-               ao_m25_wip &= ~cs;
+               ao_m25_wip &= (ao_port_t) ~cs;
        }
 }
 
@@ -192,9 +192,9 @@ ao_m25_set_address(uint32_t pos)
 #endif
        ao_m25_wait_wip(mask);
 
-       ao_m25_instruction[1] = pos >> 16;
-       ao_m25_instruction[2] = pos >> 8;
-       ao_m25_instruction[3] = pos;
+       ao_m25_instruction[1] = (uint8_t) (pos >> 16);
+       ao_m25_instruction[2] = (uint8_t) (pos >> 8);
+       ao_m25_instruction[3] = (uint8_t) (pos);
        return mask;
 }
 
index 7736a0f89c4889d49cb3a86a31667fb226d56794..3fd8e064602bc092f00319c2a3878c3b65f0fc80 100644 (file)
@@ -89,7 +89,7 @@ ao_mma655x_reg_read(uint8_t addr)
 {
        uint8_t d[2];
        ao_mma655x_start();
-       d[0] = addr | (ao_parity(addr) << 7);
+       d[0] = (uint8_t) (addr | (ao_parity(addr) << 7));
        d[1] = 0;
        ao_spi_send(&d, 2, AO_MMA655X_SPI_INDEX);
        ao_mma655x_restart();
@@ -110,13 +110,11 @@ ao_mma655x_reg_write(uint8_t addr, uint8_t value)
 
        PRINTD(DEBUG_LOW, "write %x %x\n", addr, value);
        addr |= (1 << 6);       /* write mode */
-       d[0] = addr | (ao_parity(addr^value) << 7);
+       d[0] = (uint8_t) (addr | (ao_parity(addr^value) << 7));
        d[1] = value;
        ao_mma655x_start();
        ao_spi_send(d, 2, AO_MMA655X_SPI_INDEX);
        ao_mma655x_stop();
-
-       addr &= ~(1 << 6);
 }
 
 static uint16_t
@@ -143,8 +141,8 @@ ao_mma655x_value(void)
        PRINTD(DEBUG_LOW, "value RECV %02x %02x\n", d[0], d[1]);
 
        v = (uint16_t) d[1] << 2;
-       v |= d[0] >> 6;
-       v |= (uint16_t) (d[0] & 3) << 10;
+       v = (uint16_t) (v | (d[0] >> 6));
+       v = (uint16_t) (v | ((d[0] & 3) << 10));
        return v;
 }
 
@@ -225,7 +223,7 @@ ao_mma655x_setup(void)
 
                a = ao_mma655x_value();
 
-               st_change = a_st - a;
+               st_change = (int16_t) (a_st - a);
 
                PRINTD(DEBUG_HIGH, "self test %d normal %d change %d\n", a_st, a, st_change);
 
index 4dd4a598c2c0ba04a3df2471e89c9b9af49f4e66..73e30d0390bde6e3cb8fc82b419c5a456d2b3fa8 100644 (file)
@@ -141,7 +141,7 @@ sat_sub(int16_t a, int16_t b)
                v = -32768;
        if (v > 32767)
                v = 32767;
-       return v;
+       return (int16_t) v;
 }
 
 /* Wait for a synchronous sample to finish */
@@ -179,9 +179,9 @@ ao_mmc5983_sample(struct ao_mmc5983_sample *s)
        ao_mmc5983_raw(&raw);
 
        /* Bias by 32768 to convert from uint16_t to int16_t */
-       s->x = (int32_t) (((uint16_t) raw.x0 << 8) | raw.x1) - 32768;
-       s->y = (int32_t) (((uint16_t) raw.y0 << 8) | raw.y1) - 32768;
-       s->z = (int32_t) (((uint16_t) raw.z0 << 8) | raw.z1) - 32768;;
+       s->x = (int16_t) ((((uint16_t) raw.x0 << 8) | raw.x1) - 32768);
+       s->y = (int16_t) ((((uint16_t) raw.y0 << 8) | raw.y1) - 32768);
+       s->z = (int16_t) ((((uint16_t) raw.z0 << 8) | raw.z1) - 32768);
 }
 
 /* Synchronously sample the sensors */
@@ -217,9 +217,9 @@ ao_mmc5983_cal(void)
        ao_mmc5983_sync_sample(&reset);
 
        /* The zero point is the average of SET and RESET values */
-       ao_mmc5983_offset.x = ((int32_t) set.x + (int32_t) reset.x) / 2;
-       ao_mmc5983_offset.y = ((int32_t) set.y + (int32_t) reset.y) / 2;
-       ao_mmc5983_offset.z = ((int32_t) set.z + (int32_t) reset.z) / 2;
+       ao_mmc5983_offset.x = (int16_t) (((int32_t) set.x + (int32_t) reset.x) / 2);
+       ao_mmc5983_offset.y = (int16_t) (((int32_t) set.y + (int32_t) reset.y) / 2);
+       ao_mmc5983_offset.z = (int16_t) (((int32_t) set.z + (int32_t) reset.z) / 2);
 }
 
 /* Configure the device to automatically sample at 200Hz */
index 79658c552bf2e38b7c917d287523f148df86d271..c33032af7e5dc017e363b19171a585eb62e0f76a 100644 (file)
@@ -113,7 +113,7 @@ _ao_mpu6000_sample(struct ao_mpu6000_sample *sample)
        /* byte swap */
        while (i--) {
                uint16_t        t = *d;
-               *d++ = (t >> 8) | (t << 8);
+               *d++ = (uint16_t) ((t >> 8) | (t << 8));
        }
 #endif
 }
index 09b65bfa749c8cd7de7b1e5f6ff712d5cc602c74..a77abf98dfe7bcfa2d6ce3b8267b1571dd7d642b 100644 (file)
@@ -176,7 +176,7 @@ _ao_mpu9250_sample(struct ao_mpu9250_sample *sample)
        /* byte swap */
        while (i--) {
                uint16_t        t = *d;
-               *d++ = (t >> 8) | (t << 8);
+               *d++ = (uint16_t) ((uint16_t) (t >> 8) | (uint16_t) (t << 8));
        }
 #endif
 }
index c5e733a46e6bf4dacca71dd40ba9e581cd745d90..f73b095622cd5a4eccf9f1d0b7e28a7ade50caf7 100644 (file)
@@ -59,17 +59,17 @@ ao_ms5607_crc(uint8_t *prom)
 
        prom[15] = 0;
        for (cnt = 0; cnt < 16; cnt++) {
-               n_rem ^= *p++;
+               n_rem ^= (uint16_t) *p++;
                for (n_bit = 8; n_bit > 0; n_bit--) {
                        if (n_rem & 0x8000)
-                               n_rem = (n_rem << 1) ^ 0x3000;
+                               n_rem = (uint16_t) ((n_rem << 1) ^ 0x3000U);
                        else
                                n_rem = (n_rem << 1);
                }
        }
        n_rem = (n_rem >> 12) & 0xf;
        prom[15] = crc_byte;
-       return n_rem;
+       return (uint8_t) n_rem;
 }
 
 static bool
index 322cc4684a292ddba5bf9e9cc667b1a38237f06a..02350bb0cbf5977a05cc5a3fa141216b24cfdbf6 100644 (file)
@@ -34,7 +34,7 @@
 #define AO_MS5607_CONVERT_D2_4096      0x58
 
 #define AO_MS5607_ADC_READ             0x00
-#define AO_MS5607_PROM_READ(ad)                (0xA0 | ((ad) << 1))
+#define AO_MS5607_PROM_READ(ad)                (0xA0U | (uint8_t) ((ad) << 1))
 
 struct ao_ms5607_prom {
        uint16_t        reserved;
index 0e96f60bbff3284e21edd6f78dd03c5cb28a87f7..a7c2fbc26e0099e5521a159c8c27334f6a4fa951 100644 (file)
@@ -26,9 +26,9 @@ ao_ms5607_convert(struct ao_ms5607_sample *sample, struct ao_ms5607_value *value
        int64_t OFF;
        int64_t SENS;
 
-       dT = sample->temp - ((int32_t) ao_ms5607_prom.tref << 8);
+       dT = (int32_t) ((int32_t) sample->temp - ((int32_t) ao_ms5607_prom.tref << 8));
        
-       TEMP = 2000 + (((int64_t) dT * ao_ms5607_prom.tempsens) >> 23);
+       TEMP = (int32_t) (2000 + (((int64_t) dT * ao_ms5607_prom.tempsens) >> 23));
 
 #if HAS_MS5611
        OFF = ((int64_t) ao_ms5607_prom.off << 16) + (((int64_t) ao_ms5607_prom.tco * dT) >> 7);
@@ -39,7 +39,7 @@ ao_ms5607_convert(struct ao_ms5607_sample *sample, struct ao_ms5607_value *value
 #endif
 
        if (TEMP < 2000) {
-               int32_t T2 = ((int64_t) dT * (int64_t) dT) >> 31;
+               int32_t T2 = (int32_t) (((int64_t) dT * (int64_t) dT) >> 31);
                int32_t TEMPM = TEMP - 2000;
                int64_t OFF2 = (61 * (int64_t) TEMPM * (int64_t) TEMPM) >> 4;
                int64_t SENS2 = 2 * (int64_t) TEMPM * (int64_t) TEMPM;
@@ -57,6 +57,6 @@ ao_ms5607_convert(struct ao_ms5607_sample *sample, struct ao_ms5607_value *value
                SENS -= SENS2;
        }
 
-       value->pres = ((((int64_t) sample->pres * SENS) >> 21) - OFF) >> 15;
+       value->pres = (int32_t) (((((int64_t) sample->pres * SENS) >> 21) - OFF) >> 15);
        value->temp = TEMP;
 }