From 29b456ae07527e36560dd5685c7ea32f29dc6f24 Mon Sep 17 00:00:00 2001 From: Richard Wackerbarth Date: Tue, 11 Aug 2015 11:38:26 -0500 Subject: [PATCH 1/2] Suppress some compiler warnings --- Marlin/Marlin.h | 4 ++ Marlin/buzzer.cpp | 6 +-- Marlin/configuration_store.cpp | 6 +-- Marlin/planner.cpp | 84 +++++++++++++++++----------------- Marlin/stepper.cpp | 11 +++-- Marlin/ultralcd.h | 8 ++-- 6 files changed, 65 insertions(+), 54 deletions(-) diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index 88fa740319..bb5c4a9a8f 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -5,6 +5,10 @@ #define MARLIN_H #define FORCE_INLINE __attribute__((always_inline)) inline +/** + * Compiler warning on unused varable. + */ +#define UNUSED(x) (void) (x) #include #include diff --git a/Marlin/buzzer.cpp b/Marlin/buzzer.cpp index fb914c5b04..c2119e78b7 100644 --- a/Marlin/buzzer.cpp +++ b/Marlin/buzzer.cpp @@ -1,8 +1,8 @@ #include "Marlin.h" -#include "buzzer.h" -#include "ultralcd.h" - #if HAS_BUZZER + #include "buzzer.h" + #include "ultralcd.h" + void buzz(long duration, uint16_t freq) { if (freq > 0) { #if ENABLED(LCD_USE_I2C_BUZZER) diff --git a/Marlin/configuration_store.cpp b/Marlin/configuration_store.cpp index 73dae9707f..8041ab5a5b 100644 --- a/Marlin/configuration_store.cpp +++ b/Marlin/configuration_store.cpp @@ -168,7 +168,7 @@ void Config_StoreSettings() { EEPROM_WRITE_VAR(i, mesh_num_x); EEPROM_WRITE_VAR(i, mesh_num_y); dummy = 0.0f; - for (int q=0; qadvance * entry_factor * entry_factor; + volatile long initial_advance = block->advance * entry_factor * entry_factor; volatile long final_advance = block->advance * exit_factor * exit_factor; #endif // ADVANCE @@ -197,16 +197,16 @@ void calculate_trapezoid_for_block(block_t *block, float entry_factor, float exi #endif } CRITICAL_SECTION_END; -} +} -// Calculates the maximum allowable speed at this point when you must be able to reach target_velocity using the +// Calculates the maximum allowable speed at this point when you must be able to reach target_velocity using the // acceleration within the allotted distance. FORCE_INLINE float max_allowable_speed(float acceleration, float target_velocity, float distance) { return sqrt(target_velocity * target_velocity - 2 * acceleration * distance); } // "Junction jerk" in this context is the immediate change in speed at the junction of two blocks. -// This method will calculate the junction jerk as the euclidean distance between the nominal +// This method will calculate the junction jerk as the euclidean distance between the nominal // velocities of the respective blocks. //inline float junction_jerk(block_t *before, block_t *after) { // return sqrt( @@ -217,6 +217,7 @@ FORCE_INLINE float max_allowable_speed(float acceleration, float target_velocity // The kernel called by planner_recalculate() when scanning the plan from last to first entry. void planner_reverse_pass_kernel(block_t *previous, block_t *current, block_t *next) { if (!current) return; + UNUSED(previous); if (next) { // If entry speed is already at the maximum entry speed, no need to recheck. Block is cruising. @@ -229,7 +230,7 @@ void planner_reverse_pass_kernel(block_t *previous, block_t *current, block_t *n if (!current->nominal_length_flag && current->max_entry_speed > next->entry_speed) { current->entry_speed = min(current->max_entry_speed, max_allowable_speed(-current->acceleration, next->entry_speed, current->millimeters)); - } + } else { current->entry_speed = current->max_entry_speed; } @@ -239,16 +240,16 @@ void planner_reverse_pass_kernel(block_t *previous, block_t *current, block_t *n } // Skip last block. Already initialized and set for recalculation. } -// planner_recalculate() needs to go over the current plan twice. Once in reverse and once forward. This +// planner_recalculate() needs to go over the current plan twice. Once in reverse and once forward. This // implements the reverse pass. void planner_reverse_pass() { uint8_t block_index = block_buffer_head; - + //Make a local copy of block_buffer_tail, because the interrupt can alter it CRITICAL_SECTION_START; unsigned char tail = block_buffer_tail; CRITICAL_SECTION_END - + if (BLOCK_MOD(block_buffer_head - tail + BLOCK_BUFFER_SIZE) > 3) { // moves queued block_index = BLOCK_MOD(block_buffer_head - 3); block_t *block[3] = { NULL, NULL, NULL }; @@ -265,6 +266,7 @@ void planner_reverse_pass() { // The kernel called by planner_recalculate() when scanning the plan from first to last entry. void planner_forward_pass_kernel(block_t *previous, block_t *current, block_t *next) { if (!previous) return; + UNUSED(next); // If the previous block is an acceleration block, but it is not long enough to complete the // full speed change within the block, we need to adjust the entry speed accordingly. Entry @@ -300,8 +302,8 @@ void planner_forward_pass() { planner_forward_pass_kernel(block[1], block[2], NULL); } -// Recalculates the trapezoid speed profiles for all blocks in the plan according to the -// entry_factor for each junction. Must be called by planner_recalculate() after +// Recalculates the trapezoid speed profiles for all blocks in the plan according to the +// entry_factor for each junction. Must be called by planner_recalculate() after // updating the blocks. void planner_recalculate_trapezoids() { int8_t block_index = block_buffer_tail; @@ -332,22 +334,22 @@ void planner_recalculate_trapezoids() { // Recalculates the motion plan according to the following algorithm: // -// 1. Go over every block in reverse order and calculate a junction speed reduction (i.e. block_t.entry_factor) +// 1. Go over every block in reverse order and calculate a junction speed reduction (i.e. block_t.entry_factor) // so that: // a. The junction jerk is within the set limit -// b. No speed reduction within one block requires faster deceleration than the one, true constant +// b. No speed reduction within one block requires faster deceleration than the one, true constant // acceleration. -// 2. Go over every block in chronological order and dial down junction speed reduction values if -// a. The speed increase within one block would require faster acceleration than the one, true +// 2. Go over every block in chronological order and dial down junction speed reduction values if +// a. The speed increase within one block would require faster acceleration than the one, true // constant acceleration. // -// When these stages are complete all blocks have an entry_factor that will allow all speed changes to -// be performed using only the one, true constant acceleration, and where no junction jerk is jerkier than +// When these stages are complete all blocks have an entry_factor that will allow all speed changes to +// be performed using only the one, true constant acceleration, and where no junction jerk is jerkier than // the set limit. Finally it will: // // 3. Recalculate trapezoids for all blocks. -void planner_recalculate() { +void planner_recalculate() { planner_reverse_pass(); planner_forward_pass(); planner_recalculate_trapezoids(); @@ -356,7 +358,7 @@ void planner_recalculate() { void plan_init() { block_buffer_head = block_buffer_tail = 0; memset(position, 0, sizeof(position)); // clear position - for (int i=0; ie_to_p_pressure = EtoPPressure; #endif - // Compute direction bits for this block + // Compute direction bits for this block uint8_t db = 0; #if ENABLED(COREXY) if (dx < 0) db |= BIT(X_HEAD); // Save the real Extruder (head) direction in X Axis @@ -585,10 +587,10 @@ float junction_deviation = 0.1; if (dx - dz < 0) db |= BIT(C_AXIS); // Motor B direction #else if (dx < 0) db |= BIT(X_AXIS); - if (dy < 0) db |= BIT(Y_AXIS); + if (dy < 0) db |= BIT(Y_AXIS); if (dz < 0) db |= BIT(Z_AXIS); #endif - if (de < 0) db |= BIT(E_AXIS); + if (de < 0) db |= BIT(E_AXIS); block->direction_bits = db; block->active_extruder = extruder; @@ -622,7 +624,7 @@ float junction_deviation = 0.1; for (int i=0; i 0) g_uc_extruder_last_move[i]--; - + switch(extruder) { case 0: enable_e0(); @@ -686,13 +688,13 @@ float junction_deviation = 0.1; NOLESS(feed_rate, mintravelfeedrate); /** - * This part of the code calculates the total length of the movement. + * This part of the code calculates the total length of the movement. * For cartesian bots, the X_AXIS is the real X movement and same for Y_AXIS. * But for corexy bots, that is not true. The "X_AXIS" and "Y_AXIS" motors (that should be named to A_AXIS * and B_AXIS) cannot be used for X and Y length, because A=X+Y and B=X-Y. - * So we need to create other 2 "AXIS", named X_HEAD and Y_HEAD, meaning the real displacement of the Head. + * So we need to create other 2 "AXIS", named X_HEAD and Y_HEAD, meaning the real displacement of the Head. * Having the real displacement of the head, we can calculate the total movement length and apply the desired speed. - */ + */ #if ENABLED(COREXY) float delta_mm[6]; delta_mm[X_HEAD] = dx / axis_steps_per_unit[A_AXIS]; @@ -717,7 +719,7 @@ float junction_deviation = 0.1; if (block->steps[X_AXIS] <= dropsegments && block->steps[Y_AXIS] <= dropsegments && block->steps[Z_AXIS] <= dropsegments) { block->millimeters = fabs(delta_mm[E_AXIS]); - } + } else { block->millimeters = sqrt( #if ENABLED(COREXY) @@ -729,7 +731,7 @@ float junction_deviation = 0.1; #endif ); } - float inverse_millimeters = 1.0 / block->millimeters; // Inverse millimeters to remove multiple divides + float inverse_millimeters = 1.0 / block->millimeters; // Inverse millimeters to remove multiple divides // Calculate speed in mm/second for each axis. No divide by zero due to previous checks. float inverse_second = feed_rate * inverse_millimeters; @@ -762,7 +764,7 @@ float junction_deviation = 0.1; #if ENABLED(FILAMENT_SENSOR) //FMM update ring buffer used for delay with filament measurements - + if (extruder == FILAMENT_SENSOR_EXTRUDER_NUM && delay_index2 > -1) { //only for extruder with filament sensor and if ring buffer is initialized const int MMD = MAX_MEASUREMENT_DELAY + 1, MMD10 = MMD * 10; @@ -803,7 +805,7 @@ float junction_deviation = 0.1; unsigned char direction_change = block->direction_bits ^ old_direction_bits; old_direction_bits = block->direction_bits; segment_time = lround((float)segment_time / speed_factor); - + long xs0 = axis_segment_time[X_AXIS][0], xs1 = axis_segment_time[X_AXIS][1], xs2 = axis_segment_time[X_AXIS][2], @@ -834,14 +836,14 @@ float junction_deviation = 0.1; } #endif // XY_FREQUENCY_LIMIT - // Correct the speed + // Correct the speed if (speed_factor < 1.0) { for (unsigned char i = 0; i < NUM_AXIS; i++) current_speed[i] *= speed_factor; block->nominal_speed *= speed_factor; block->nominal_rate *= speed_factor; } - // Compute and limit the acceleration rate for the trapezoid generator. + // Compute and limit the acceleration rate for the trapezoid generator. float steps_per_mm = block->step_event_count / block->millimeters; long bsx = block->steps[X_AXIS], bsy = block->steps[Y_AXIS], bsz = block->steps[Z_AXIS], bse = block->steps[E_AXIS]; if (bsx == 0 && bsy == 0 && bsz == 0) { @@ -863,7 +865,7 @@ float junction_deviation = 0.1; if ((float)acc_st * bsy / block->step_event_count > ysteps) acc_st = ysteps; if ((float)acc_st * bsz / block->step_event_count > zsteps) acc_st = zsteps; if ((float)acc_st * bse / block->step_event_count > esteps) acc_st = esteps; - + block->acceleration_st = acc_st; block->acceleration = acc_st / steps_per_mm; block->acceleration_rate = (long)(acc_st * 16777216.0 / (F_CPU / 8.0)); @@ -911,7 +913,7 @@ float junction_deviation = 0.1; // Start with a safe speed float vmax_junction = max_xy_jerk / 2; - float vmax_junction_factor = 1.0; + float vmax_junction_factor = 1.0; float mz2 = max_z_jerk / 2, me2 = max_e_jerk / 2; float csz = current_speed[Z_AXIS], cse = current_speed[E_AXIS]; if (fabs(csz) > mz2) vmax_junction = min(vmax_junction, mz2); @@ -949,7 +951,7 @@ float junction_deviation = 0.1; // block nominal speed limits both the current and next maximum junction speeds. Hence, in both // the reverse and forward planners, the corresponding block junction speed will always be at the // the maximum junction speed and may always be ignored for any speed reduction checks. - block->nominal_length_flag = (block->nominal_speed <= v_allowable); + block->nominal_length_flag = (block->nominal_speed <= v_allowable); block->recalculate_flag = true; // Always calculate trapezoid for new block // Update previous path unit_vector and nominal speed @@ -1029,7 +1031,7 @@ float junction_deviation = 0.1; } void plan_set_e_position(const float &e) { - position[E_AXIS] = lround(e * axis_steps_per_unit[E_AXIS]); + position[E_AXIS] = lround(e * axis_steps_per_unit[E_AXIS]); st_set_e_position(position[E_AXIS]); } diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 2efb5b9574..f5016a169d 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -1185,6 +1185,9 @@ void digitalPotWrite(int address, int value) { SPI.transfer(value); digitalWrite(DIGIPOTSS_PIN,HIGH); // take the SS pin high to de-select the chip: //delay(10); + #else + UNUSED(address); + UNUSED(value); #endif } @@ -1216,14 +1219,16 @@ void digipot_current(uint8_t driver, int current) { #if HAS_DIGIPOTSS const uint8_t digipot_ch[] = DIGIPOT_CHANNELS; digitalPotWrite(digipot_ch[driver], current); - #endif - #ifdef MOTOR_CURRENT_PWM_XY_PIN + #elif defined(MOTOR_CURRENT_PWM_XY_PIN) switch(driver) { case 0: analogWrite(MOTOR_CURRENT_PWM_XY_PIN, 255L * current / MOTOR_CURRENT_PWM_RANGE); break; case 1: analogWrite(MOTOR_CURRENT_PWM_Z_PIN, 255L * current / MOTOR_CURRENT_PWM_RANGE); break; case 2: analogWrite(MOTOR_CURRENT_PWM_E_PIN, 255L * current / MOTOR_CURRENT_PWM_RANGE); break; } - #endif + #else + UNUSED(driver); + UNUSED(current); +#endif } void microstep_init() { diff --git a/Marlin/ultralcd.h b/Marlin/ultralcd.h index 94a54b8b54..c8559760d7 100644 --- a/Marlin/ultralcd.h +++ b/Marlin/ultralcd.h @@ -2,9 +2,9 @@ #define ULTRALCD_H #include "Marlin.h" -#include "buzzer.h" - #if ENABLED(ULTRA_LCD) + #include "buzzer.h" + int lcd_strlen(char *s); int lcd_strlen_P(const char *s); void lcd_update(); @@ -105,8 +105,8 @@ FORCE_INLINE void lcd_update() {} FORCE_INLINE void lcd_init() {} FORCE_INLINE bool lcd_hasstatus() { return false; } - FORCE_INLINE void lcd_setstatus(const char* message, const bool persist=false) {} - FORCE_INLINE void lcd_setstatuspgm(const char* message, const uint8_t level=0) {} + FORCE_INLINE void lcd_setstatus(const char* message, const bool persist=false) {UNUSED(message); UNUSED(persist);} + FORCE_INLINE void lcd_setstatuspgm(const char* message, const uint8_t level=0) {UNUSED(message); UNUSED(level);} FORCE_INLINE void lcd_buttons_update() {} FORCE_INLINE void lcd_reset_alert_level() {} FORCE_INLINE bool lcd_detected(void) { return true; } From ad90e851b38d1cca045b2471be99193eb8b310d6 Mon Sep 17 00:00:00 2001 From: Richard Wackerbarth Date: Tue, 11 Aug 2015 15:14:32 -0500 Subject: [PATCH 2/2] Use a small unsigned integer type --- Marlin/configuration_store.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/configuration_store.cpp b/Marlin/configuration_store.cpp index 8041ab5a5b..b1f757e0a3 100644 --- a/Marlin/configuration_store.cpp +++ b/Marlin/configuration_store.cpp @@ -168,7 +168,7 @@ void Config_StoreSettings() { EEPROM_WRITE_VAR(i, mesh_num_x); EEPROM_WRITE_VAR(i, mesh_num_y); dummy = 0.0f; - for (uint q=0; q