Skip to content

Commit

Permalink
Fix the majority of conversion warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoantoniocardoso committed Feb 26, 2022
1 parent e0e7e1b commit c42bfba
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 27 deletions.
8 changes: 6 additions & 2 deletions firmware/src/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ uint8_t ma_adc0(void)
for(uint8_t i = cbuf_adc0_SIZE; i; i--){
sum += CBUF_Get(cbuf_adc0, i);
}
avg_adc0 = sum >> cbuf_adc0_SIZE_2;
// Here it is matematically safe to expect sum to fit into uint8_t only because
// cbuf_adc0_SIZE and cbuf_adc0_SIZE_2 are coherently defined.
avg_adc0 = (uint8_t) (sum >> cbuf_adc0_SIZE_2);
return avg_adc0;
}

Expand All @@ -35,7 +37,9 @@ uint8_t ma_adc0(void)
void adc_select_channel(adc_channels_t __ch)
{
ADC_CHANNEL = __ch;
ADMUX = (ADMUX & 0xF8) | ADC_CHANNEL; // clears the bottom 3 bits before ORing
#pragma GCC diagnostic ignored "-Wconversion"
ADMUX =(ADMUX & 0xF8) | ADC_CHANNEL; // clears the bottom 3 bits before ORing
#pragma GCC diagnostic pop
}

/**
Expand Down
3 changes: 1 addition & 2 deletions firmware/src/can_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ inline void can_app_send_motor(void)
msg.flags.rtr = 0;

msg.data[CAN_MSG_GENERIC_STATE_SIGNATURE_BYTE] = CAN_SIGNATURE_SELF;
msg.data[CAN_MSG_MAM19_MOTOR_D_BYTE] = control.D;
msg.data[CAN_MSG_MAM19_MOTOR_I_BYTE] = control.I;
msg.data[CAN_MSG_MAM19_MOTOR_D_BYTE] = (uint8_t) control.D >> 8;

can_send_message(&msg);
}
Expand Down
28 changes: 14 additions & 14 deletions firmware/src/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@


// PWM DEFINITIONS
#define INITIAL_D 0 //!< float value from 0 to 1
#define PWM_D_DELTA 1 //!< amount to increase (may interfer on threshholds)
#define PWM_D_MAX_DELTA 1 //!< clock divisor
#define PWM_D_MIN 0 //!< minimum D
#define PWM_D_MAX 640 //!< maximum D
#define PWM_D_MIN_THRESHHOLD 6 //!< minimum D threshhold
#define PWM_D_MAX_THRESHHOLD 634 //!< maximum D threshhold
#define PWM_D_LIN_MULT 5 //!< this is A for D = (D*A) >> B
#define PWM_D_LIN_DIV 1 //!< this is B for D = (D*A) >> B

// tempo em que o potenciometro deve ficar zerado para que seja permitido ligar
#define MIN_ZERO_WIDTH_TIMES 10
#define INITIAL_D (uint8_t)0 //!< float value from 0 to 1
#define PWM_D_DELTA (uint8_t)1 //!< amount to increase (may interfer on threshholds)
#define PWM_D_MAX_DELTA (uint8_t)1 //!< clock divisor
#define PWM_D_MIN (uint16_t)0 //!< minimum D
#define PWM_D_MAX (uint16_t)640 //!< maximum D
#define PWM_D_MIN_THRESHHOLD (uint16_t)6 //!< minimum D threshhold
#define PWM_D_MAX_THRESHHOLD (uint16_t)634 //!< maximum D threshhold
#define PWM_D_LIN_MULT (uint8_t)5 //!< this is A for D = (D*A) >> B
#define PWM_D_LIN_DIV (uint8_t)1 //!< this is B for D = (D*A) >> B

// tempo em que o potenciometro deve ficar zerado para que seja permitido ligar
#define MIN_ZERO_WIDTH_TIMES (uint8_t)10
// number of checks before reset the pwm fault counter.
#define CHECKS_BEFORE_RESET_FAULT_COUNTER 100
#define CHECKS_BEFORE_RESET_FAULT_COUNTER (uint8_t)100
// maximum of consecutive faults before state an error
#define FAULT_COUNT_LIMIT 50
#define FAULT_COUNT_LIMIT (uint8_t)50


// INPUT PINS DEFINITIONS
Expand Down
6 changes: 3 additions & 3 deletions firmware/src/machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void machine_init(void)
*/
inline void check_idle_zero_pot(void)
{
system_flags.pot_zero_width = pwm_zero_width(control.D_raw_target);
system_flags.pot_zero_width = pwm_zero_width(control.D_raw_target)? 1 : 0;
}


Expand Down Expand Up @@ -308,9 +308,9 @@ void set_initial_state(void)
system_flags.all__ = 0;
error_flags.all = 0;

control.D_raw = control.D_raw_target = control. D = 0;
control. D = control.D_raw = control.D_raw_target = 0;

control.I_raw = control.I_raw_target = control.I = 0;
control.I = control.I_raw = control.I_raw_target = 0;
control.V = control.R = control.T = control.fault = 0;
}

Expand Down
6 changes: 3 additions & 3 deletions firmware/src/pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ void pwm_init(void)
inline void pwm_reset(void)
{
set_pwm_off();
control.D_raw = control.D_raw_target = control.D = 0;
control.I_raw = control.I_raw_target = control.I = 0;
control.D = control.D_raw = control.D_raw_target = 0;
control.I = control.I_raw = control.I_raw_target = 0;
VERBOSE_MSG_PWM(usart_send_string("PWM turned off!\n"));
}

Expand Down Expand Up @@ -75,7 +75,7 @@ inline void pwm_compute(void)
}

// converts to OCR1A range.
control.D = (control.D_raw*PWM_D_LIN_MULT) >> PWM_D_LIN_DIV;
control.D = (((uint16_t)control.D_raw)*PWM_D_LIN_MULT) >> PWM_D_LIN_DIV;

// apply some threshhold saturation limits
if(control.D > PWM_D_MAX_THRESHHOLD) control.D = PWM_D_MAX;
Expand Down
4 changes: 3 additions & 1 deletion firmware/src/sleep.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ void sleep_init(void);

void sleep_init(void)
{
set_sleep_mode(SLEEP_MODE_IDLE);
#pragma GCC diagnostic ignored "-Wconversion"
set_sleep_mode(SLEEP_MODE_IDLE);
#pragma GCC diagnostic pop
}

#endif /* ifndef SLEEP_H */
8 changes: 6 additions & 2 deletions firmware/src/usart.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ inline void usart_send_uint16(uint16_t num)
char str[LEN] = {FILL}; // ascii zero filled array
str[i] = '\0'; // adds string null terminator
while(i--){
str[i] = FILL + (num % BASE);// gets each algarism}
#pragma GCC diagnostic ignored "-Wconversion"
str[i] = FILL + (num % BASE);// gets each algarism}
#pragma GCC diagnostic pop
num /= BASE; // prepare the next
}
usart_send_string(str); // sends the string
Expand Down Expand Up @@ -83,6 +85,8 @@ inline void usart_init(uint16_t ubrr, uint8_t rx, uint8_t tx)
UBRR0L = (uint8_t)ubrr;

// Enable RX and TX
UCSR0B = ((rx&1)<<RXEN0) | ((tx&1)<<TXEN0);
#pragma GCC diagnostic ignored "-Wconversion"
UCSR0B = ((rx&1)<<RXEN0) | ((tx&1)<<TXEN0);
#pragma GCC diagnostic pop
}

0 comments on commit c42bfba

Please sign in to comment.