Skip to content

Commit f73fd5b

Browse files
committed
Add -Wconversion and -Wsign-conversion and fix resulting issues
Signed-off-by: Javier Balloffet <javier.balloffet@gmail.com>
1 parent f471354 commit f73fd5b

18 files changed

Lines changed: 97 additions & 59 deletions

File tree

andino_firmware/include/andino/app/app.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@
2929
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
#pragma once
3131

32+
#if defined(__GNUC__)
33+
#pragma GCC diagnostic push
34+
#pragma GCC diagnostic ignored "-Wconversion"
35+
#endif
3236
#include <Adafruit_BNO055.h>
37+
#if defined(__GNUC__)
38+
#pragma GCC diagnostic pop
39+
#endif
3340

3441
#include "andino/app/constants.h"
3542
#include "andino/app/pid.h"

andino_firmware/include/andino/app/constants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct Constants {
4949
/// @brief PID computation rate [Hz].
5050
static constexpr int kPidRate{30};
5151
/// @brief PID computation period [ms].
52-
static constexpr double kPidPeriod{1000 / kPidRate};
52+
static constexpr long kPidPeriod{1000 / kPidRate};
5353
/// @brief PID default tuning proportional gain.
5454
static constexpr int kPidKp{30};
5555
/// @brief PID default tuning derivative gain.

andino_firmware/include/andino/app/hw.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,42 +29,44 @@
2929
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
#pragma once
3131

32+
#include <stdint.h>
33+
3234
namespace andino {
3335

3436
/// @brief Hardware configuration.
3537
struct Hw {
3638
/// @brief Left encoder channel A pin. Connected to PD2 (digital pin 2).
37-
static constexpr int kLeftEncoderChannelAGpioPin{2};
39+
static constexpr uint8_t kLeftEncoderChannelAGpioPin{2};
3840
/// @brief Left encoder channel B pin. Connected to PD3 (digital pin 3).
39-
static constexpr int kLeftEncoderChannelBGpioPin{3};
41+
static constexpr uint8_t kLeftEncoderChannelBGpioPin{3};
4042

4143
/// @brief Right encoder channel A pin. Connected to PC2 (digital pin 16, analog pin A2).
42-
static constexpr int kRightEncoderChannelAGpioPin{16};
44+
static constexpr uint8_t kRightEncoderChannelAGpioPin{16};
4345
/// @brief Right encoder channel B pin. Connected to PC3 (digital pin 17, analog pin A3).
44-
static constexpr int kRightEncoderChannelBGpioPin{17};
46+
static constexpr uint8_t kRightEncoderChannelBGpioPin{17};
4547

4648
/// @brief Left motor driver backward pin. Connected to PD6 (digital pin 6).
47-
static constexpr int kLeftMotorBackwardGpioPin{6};
49+
static constexpr uint8_t kLeftMotorBackwardGpioPin{6};
4850
/// @brief Left motor driver forward pin. Connected to PB2 (digital pin 10).
49-
static constexpr int kLeftMotorForwardGpioPin{10};
51+
static constexpr uint8_t kLeftMotorForwardGpioPin{10};
5052
/// @brief Left motor driver enable pin. Connected to PB5 (digital pin 13).
5153
/// @note The enable input of the L298N motor driver may be directly jumped to 5V if the board has
5254
/// a jumper to do so.
53-
static constexpr int kLeftMotorEnableGpioPin{13};
55+
static constexpr uint8_t kLeftMotorEnableGpioPin{13};
5456

5557
/// @brief Right motor driver backward pin. Connected to PD5 (digital pin 5).
56-
static constexpr int kRightMotorBackwardGpioPin{5};
58+
static constexpr uint8_t kRightMotorBackwardGpioPin{5};
5759
/// @brief Right motor driver forward pin. Connected to PB1 (digital pin 9).
58-
static constexpr int kRightMotorForwardGpioPin{9};
60+
static constexpr uint8_t kRightMotorForwardGpioPin{9};
5961
/// @brief Right motor driver enable pin. Connected to PB4 (digital pin 12).
6062
/// @note The enable input of the L298N motor driver may be directly jumped to 5V if the board has
6163
/// a jumper to do so.
62-
static constexpr int kRightMotorEnableGpioPin{12};
64+
static constexpr uint8_t kRightMotorEnableGpioPin{12};
6365

6466
/// @brief IMU sensor I2C SCL pin. Connected to PC5 (digital pin 19, analog pin A5).
65-
static constexpr int kImuI2cSclPin{19};
67+
static constexpr uint8_t kImuI2cSclPin{19};
6668
/// @brief IMU sensor I2C SDA pin. Connected to PC4 (digital pin 18, analog pin A4).
67-
static constexpr int kImuI2cSdaPin{18};
69+
static constexpr uint8_t kImuI2cSdaPin{18};
6870
};
6971

7072
} // namespace andino

andino_firmware/include/andino/app/pid.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Pid {
4949
/// @brief Resets the PID controller.
5050
///
5151
/// @param encoder_count Current encoder value.
52-
void reset(int encoder_count);
52+
void reset(long encoder_count);
5353

5454
/// @brief Returns if the PID controller is enabled or not.
5555
bool enabled();
@@ -64,7 +64,7 @@ class Pid {
6464
///
6565
/// @param encoder_count Current encoder value.
6666
/// @param computed_output Computed output value.
67-
void compute(int encoder_count, int& computed_output);
67+
void compute(long encoder_count, int& computed_output);
6868

6969
/// @brief Sets the setpoint.
7070
///

andino_firmware/include/andino/bsp/digital_out_arduino.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
#pragma once
3131

32+
#include <stdint.h>
33+
3234
#include "andino/hal/digital_out.h"
3335

3436
namespace andino {
@@ -39,16 +41,16 @@ class DigitalOutArduino : public DigitalOut {
3941
/// @brief Constructs a DigitalOutArduino using the specified GPIO pin.
4042
///
4143
/// @param gpio_pin GPIO pin.
42-
explicit DigitalOutArduino(const int gpio_pin) : gpio_pin_(gpio_pin) {
44+
explicit DigitalOutArduino(const uint8_t gpio_pin) : gpio_pin_(gpio_pin) {
4345
}
4446

4547
void begin() const override;
4648

47-
void write(int value) const override;
49+
void write(uint8_t value) const override;
4850

4951
private:
5052
/// GPIO pin.
51-
const int gpio_pin_;
53+
const uint8_t gpio_pin_;
5254
};
5355

5456
} // namespace andino

andino_firmware/include/andino/bsp/interrupt_in_arduino.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
#pragma once
3131

32+
#include <stdint.h>
33+
3234
#include "andino/hal/interrupt_in.h"
3335

3436
namespace andino {
@@ -39,7 +41,7 @@ class InterruptInArduino : public InterruptIn {
3941
/// @brief Constructs a InterruptInArduino using the specified GPIO pin.
4042
///
4143
/// @param gpio_pin GPIO pin.
42-
explicit InterruptInArduino(const int gpio_pin) : gpio_pin_(gpio_pin) {
44+
explicit InterruptInArduino(const uint8_t gpio_pin) : gpio_pin_(gpio_pin) {
4345
}
4446

4547
void begin() const override;
@@ -50,7 +52,7 @@ class InterruptInArduino : public InterruptIn {
5052

5153
private:
5254
/// GPIO pin.
53-
const int gpio_pin_;
55+
const uint8_t gpio_pin_;
5456
};
5557

5658
} // namespace andino

andino_firmware/include/andino/bsp/pwm_out_arduino.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
#pragma once
3131

32+
#include <stdint.h>
33+
3234
#include "andino/hal/pwm_out.h"
3335

3436
namespace andino {
@@ -39,7 +41,7 @@ class PwmOutArduino : public PwmOut {
3941
/// @brief Constructs a PwmOutArduino using the specified GPIO pin.
4042
///
4143
/// @param gpio_pin GPIO pin.
42-
explicit PwmOutArduino(const int gpio_pin) : gpio_pin_(gpio_pin) {
44+
explicit PwmOutArduino(const uint8_t gpio_pin) : gpio_pin_(gpio_pin) {
4345
}
4446

4547
void begin() const override;
@@ -48,7 +50,7 @@ class PwmOutArduino : public PwmOut {
4850

4951
private:
5052
/// GPIO pin.
51-
const int gpio_pin_;
53+
const uint8_t gpio_pin_;
5254
};
5355

5456
} // namespace andino

andino_firmware/include/andino/hal/digital_out.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
#pragma once
3131

32+
#include <stdint.h>
33+
3234
namespace andino {
3335

3436
/// @brief This class defines an interface for digital outputs.
@@ -43,7 +45,7 @@ class DigitalOut {
4345
/// @brief Sets the digital output value (0 or 1).
4446
///
4547
/// @param value Digital output value.
46-
virtual void write(int value) const = 0;
48+
virtual void write(uint8_t value) const = 0;
4749
};
4850

4951
} // namespace andino

andino_firmware/platformio.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ build_src_flags =
2323
-Wcast-qual
2424
-Wuseless-cast
2525
-Wnull-dereference
26+
-Wconversion
27+
-Wsign-conversion
2628
-Werror
2729
check_tool = cppcheck
2830
check_skip_packages = yes

andino_firmware/src/app/app.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void App::cmd_read_analog_gpio_cb(void*, int argc, char** argv) {
145145
return;
146146
}
147147

148-
const int pin = atoi(argv[1]);
148+
const uint8_t pin = static_cast<uint8_t>(atoi(argv[1]));
149149
Serial.println(analogRead(pin));
150150
}
151151

@@ -154,7 +154,7 @@ void App::cmd_read_digital_gpio_cb(void*, int argc, char** argv) {
154154
return;
155155
}
156156

157-
const int pin = atoi(argv[1]);
157+
const uint8_t pin = static_cast<uint8_t>(atoi(argv[1]));
158158
Serial.println(digitalRead(pin));
159159
}
160160

0 commit comments

Comments
 (0)