From c309956389acc01f784f3d0e11745f5ac0a77e06 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 28 Jan 2022 13:59:26 -0800 Subject: [PATCH] drivers: Resolve -Wconversion in m25, mma655x, mmc5983, mpu and ms5607 No bugs identified. Signed-off-by: Keith Packard --- src/drivers/ao_m25.c | 8 ++++---- src/drivers/ao_mma655x.c | 12 +++++------- src/drivers/ao_mmc5983.c | 14 +++++++------- src/drivers/ao_mpu6000.c | 2 +- src/drivers/ao_mpu9250.c | 2 +- src/drivers/ao_ms5607.c | 6 +++--- src/drivers/ao_ms5607.h | 2 +- src/drivers/ao_ms5607_convert.c | 8 ++++---- 8 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/drivers/ao_m25.c b/src/drivers/ao_m25.c index 2e4cbedf..accf943a 100644 --- a/src/drivers/ao_m25.c +++ b/src/drivers/ao_m25.c @@ -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; } diff --git a/src/drivers/ao_mma655x.c b/src/drivers/ao_mma655x.c index 7736a0f8..3fd8e064 100644 --- a/src/drivers/ao_mma655x.c +++ b/src/drivers/ao_mma655x.c @@ -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); diff --git a/src/drivers/ao_mmc5983.c b/src/drivers/ao_mmc5983.c index 4dd4a598..73e30d03 100644 --- a/src/drivers/ao_mmc5983.c +++ b/src/drivers/ao_mmc5983.c @@ -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 */ diff --git a/src/drivers/ao_mpu6000.c b/src/drivers/ao_mpu6000.c index 79658c55..c33032af 100644 --- a/src/drivers/ao_mpu6000.c +++ b/src/drivers/ao_mpu6000.c @@ -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 } diff --git a/src/drivers/ao_mpu9250.c b/src/drivers/ao_mpu9250.c index 09b65bfa..a77abf98 100644 --- a/src/drivers/ao_mpu9250.c +++ b/src/drivers/ao_mpu9250.c @@ -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 } diff --git a/src/drivers/ao_ms5607.c b/src/drivers/ao_ms5607.c index c5e733a4..f73b0956 100644 --- a/src/drivers/ao_ms5607.c +++ b/src/drivers/ao_ms5607.c @@ -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 diff --git a/src/drivers/ao_ms5607.h b/src/drivers/ao_ms5607.h index 322cc468..02350bb0 100644 --- a/src/drivers/ao_ms5607.h +++ b/src/drivers/ao_ms5607.h @@ -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; diff --git a/src/drivers/ao_ms5607_convert.c b/src/drivers/ao_ms5607_convert.c index 0e96f60b..a7c2fbc2 100644 --- a/src/drivers/ao_ms5607_convert.c +++ b/src/drivers/ao_ms5607_convert.c @@ -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; } -- 2.30.2