Skip to content

Commit 61073db

Browse files
committed
tree-wide: fix compiler type warnings
Upstream micropython has enabled a few more compiler warnings to detect implicit casting. This fixes those errors.
1 parent b2241f2 commit 61073db

File tree

12 files changed

+24
-25
lines changed

12 files changed

+24
-25
lines changed

extmod/modbuiltins.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ STATIC mp_obj_t builtins_LightArray_on(size_t n_args, const mp_obj_t *pos_args,
107107
builtins_LightArray_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
108108

109109
// We may either have one brightness or all brightness values
110-
if (!(n_args == 2 || n_args == self->number_of_lights + 1)) {
110+
if (!(n_args == 2 || n_args == (size_t)self->number_of_lights + 1)) {
111111
pb_assert(PBIO_ERROR_INVALID_ARG);
112112
}
113113

extmod/modev3devices.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ STATIC mp_obj_t ev3devices_ColorSensor_rgb(mp_obj_t self_in) {
316316
pbdevice_get_values(self->pbdev, PBIO_IODEV_MODE_EV3_COLOR_SENSOR__RGB_RAW, rgb);
317317
mp_obj_t tup[3];
318318

319-
rgb[0] = (0.258 * rgb[0]) - 0.3;
320-
rgb[1] = (0.280 * rgb[1]) - 0.8;
321-
rgb[2] = (0.523 * rgb[2]) - 3.7;
319+
rgb[0] = (int)((0.258 * rgb[0]) - 0.3);
320+
rgb[1] = (int)((0.280 * rgb[1]) - 0.8);
321+
rgb[2] = (int)((0.523 * rgb[2]) - 3.7);
322322

323323
for (uint8_t i = 0; i < 3; i++) {
324324
rgb[i] = (rgb[i] > 100 ? 100 : rgb[i]);

extmod/modmotor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ STATIC mp_obj_t motor_Motor_make_new(const mp_obj_type_t *type, size_t n_args, s
193193
}
194194

195195
// Iterate through each of the n_trains lists
196-
for (int16_t train = 0; train < n_trains; train++) {
196+
for (size_t train = 0; train < n_trains; train++) {
197197
// Unless we have just one list of gears, unpack the list of gears for this train
198198
if (!is_one_train) {
199199
mp_obj_get_array(trains[train], &n_gears, &gear_list);

lib/ev3dev/src/ev3dev_stretch/lego_port.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static pbio_error_t ev3dev_lego_port_get_mode(pbio_port_t port, const char *attr
8181
}
8282

8383
// Find matching port mode string
84-
for (int i = 0; i < PBIO_ARRAY_SIZE(port_modes); i++) {
84+
for (size_t i = 0; i < PBIO_ARRAY_SIZE(port_modes); i++) {
8585
if (!strcmp(mode, port_modes[i])) {
8686
*port_mode = i;
8787
return PBIO_SUCCESS;
@@ -110,7 +110,7 @@ static pbio_error_t ev3dev_lego_port_set_mode(pbio_port_t port, ev3dev_lego_port
110110
return PBIO_ERROR_IO;
111111
}
112112
// Write mode
113-
if (fprintf(f_port_mode, "%s", port_modes[mode]) != strlen(port_modes[mode])) {
113+
if (fprintf(f_port_mode, "%s", port_modes[mode]) != (int)strlen(port_modes[mode])) {
114114
return PBIO_ERROR_IO;
115115
}
116116
// Close the mode file
@@ -122,7 +122,6 @@ static pbio_error_t ev3dev_lego_port_set_mode(pbio_port_t port, ev3dev_lego_port
122122

123123
// Set compatible port configuration for given device
124124
pbio_error_t ev3dev_lego_port_configure(pbio_port_t port, pbio_iodev_type_id_t id) {
125-
126125
pbio_error_t err;
127126

128127
// Get the current port mode and status

lib/ev3dev/src/ev3dev_stretch/lego_sensor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ pbio_error_t lego_sensor_get_info(lego_sensor_t *sensor, uint8_t *data_len, lego
254254
pbio_error_t lego_sensor_get_mode_id_from_str(lego_sensor_t *sensor, const char *mode_str, uint8_t *mode) {
255255

256256
// Find matching port mode string
257-
for (int i = 0; i < PBIO_ARRAY_SIZE(sensor->modes); i++) {
257+
for (size_t i = 0; i < PBIO_ARRAY_SIZE(sensor->modes); i++) {
258258
if (!strcmp(mode_str, sensor->modes[i])) {
259259
*mode = i;
260260
return PBIO_SUCCESS;

lib/ev3dev/src/ev3dev_stretch/nxtcolor.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static pbio_error_t nxtcolor_get_digi1(nxtcolor_t *nxtcolor, bool *val) {
151151
return PBIO_SUCCESS;
152152
}
153153

154-
static pbio_error_t nxtcolor_get_adc(nxtcolor_t *nxtcolor, int32_t *analog) {
154+
static pbio_error_t nxtcolor_get_adc(nxtcolor_t *nxtcolor, uint32_t *analog) {
155155

156156
pbio_error_t err;
157157

@@ -164,7 +164,7 @@ static pbio_error_t nxtcolor_get_adc(nxtcolor_t *nxtcolor, int32_t *analog) {
164164
nxtcolor->digi1_dir = IN;
165165
}
166166
// Get the state
167-
return sysfs_read_int(nxtcolor->f_adc_val, analog);
167+
return sysfs_read_int(nxtcolor->f_adc_val, (int *)analog);
168168
}
169169

170170
static pbio_error_t nxtcolor_reset(nxtcolor_t *nxtcolor)
@@ -482,7 +482,7 @@ pbio_error_t nxtcolor_get_values_at_mode(pbio_port_t port, uint8_t mode, int32_t
482482
}
483483

484484
// In measure mode, cycle through the colors and calculate color id
485-
int32_t rgba[4];
485+
uint32_t rgba[4];
486486

487487
// Read analog for each color
488488
for (uint8_t i = 0; i < 4; i++) {

lib/ev3dev/src/ev3dev_stretch/sysfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pbio_error_t sysfs_write_str(FILE *file, const char *str) {
112112
return PBIO_ERROR_IO;
113113
}
114114

115-
if (fprintf(file, "%s", str) != strlen(str)) {
115+
if (fprintf(file, "%s", str) != (int)strlen(str)) {
116116
return PBIO_ERROR_IO;
117117
}
118118

lib/pbio/drv/counter/counter_ev3dev_stretch_iio.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ static pbio_error_t counter_ev3dev_stretch_iio_init() {
110110
}
111111

112112

113-
for (int i = 0; i < PBIO_ARRAY_SIZE(private_data); i++) {
113+
for (size_t i = 0; i < PBIO_ARRAY_SIZE(private_data); i++) {
114114
private_data_t *data = &private_data[i];
115115

116-
snprintf(buf, sizeof(buf), "%s/in_count%d_raw", udev_list_entry_get_name(entry), i);
116+
snprintf(buf, sizeof(buf), "%s/in_count%d_raw", udev_list_entry_get_name(entry), (int)i);
117117
data->count = fopen(buf, "r");
118118
if (!data->count) {
119119
dbg_err("failed to open count attribute");
@@ -122,7 +122,7 @@ static pbio_error_t counter_ev3dev_stretch_iio_init() {
122122

123123
setbuf(data->count, NULL);
124124

125-
snprintf(buf, sizeof(buf), "%s/in_frequency%d_input", udev_list_entry_get_name(entry), i);
125+
snprintf(buf, sizeof(buf), "%s/in_frequency%d_input", udev_list_entry_get_name(entry), (int)i);
126126
data->rate = fopen(buf, "r");
127127
if (!data->rate) {
128128
dbg_err("failed to open rate attribute");
@@ -151,7 +151,7 @@ static pbio_error_t counter_ev3dev_stretch_iio_init() {
151151
}
152152

153153
static pbio_error_t counter_ev3dev_stretch_iio_exit() {
154-
for (int i = 0; i < PBIO_ARRAY_SIZE(private_data); i++) {
154+
for (size_t i = 0; i < PBIO_ARRAY_SIZE(private_data); i++) {
155155
private_data_t *data = &private_data[i];
156156

157157
data->dev.initalized = false;

lib/pbio/drv/ev3dev_stretch/serial.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pbio_error_t pbdrv_serial_get(pbdrv_serial_t **_ser, pbio_port_t port, int baudr
167167
}
168168

169169
pbio_error_t pbdrv_serial_write(pbdrv_serial_t *ser, const void *buf, size_t count) {
170-
if (write(ser->file, buf, count) != count) {
170+
if (write(ser->file, buf, count) != (int)count) {
171171
return PBIO_ERROR_IO;
172172
}
173173
return PBIO_SUCCESS;

lib/pbio/include/pbio/serial.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ typedef struct _pbio_serial_t pbio_serial_t;
1212

1313
#if PBIO_CONFIG_SERIAL
1414

15-
pbio_error_t pbio_serial_get(pbio_serial_t **_ser, pbio_port_t port, int baudrate, int timeout);
15+
pbio_error_t pbio_serial_get(pbio_serial_t **_ser, pbio_port_t port, uint32_t baudrate, int32_t timeout);
1616

1717
pbio_error_t pbio_serial_write(pbio_serial_t *ser, const void *buf, size_t count);
1818

@@ -24,7 +24,7 @@ pbio_error_t pbio_serial_clear(pbio_serial_t *ser);
2424

2525
#else // PBIO_CONFIG_SERIAL
2626

27-
static inline pbio_error_t pbio_serial_get(pbio_serial_t **_ser, pbio_port_t port, int baudrate, int timeout) {
27+
static inline pbio_error_t pbio_serial_get(pbio_serial_t **_ser, pbio_port_t port, uint32_t baudrate, int32_t timeout) {
2828
return PBIO_ERROR_NOT_SUPPORTED;
2929
}
3030
static inline pbio_error_t pbio_serial_write(pbio_serial_t *ser, const void *buf, size_t count) {

0 commit comments

Comments
 (0)