diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index ac83b81a..f73e99e0 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3351,8 +3351,8 @@ void process_commands() if(code_seen("CRASH_DETECTED")) { uint8_t mask = 0; - if (code_seen("X")) mask |= X_AXIS_MASK; - if (code_seen("Y")) mask |= Y_AXIS_MASK; + if (code_seen('X')) mask |= X_AXIS_MASK; + if (code_seen('Y')) mask |= Y_AXIS_MASK; crashdet_detected(mask); } else if(code_seen("CRASH_RECOVER")) @@ -4281,10 +4281,10 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) if (code_seen('X')) dimension_x = code_value(); if (code_seen('Y')) dimension_y = code_value(); - if (code_seen('XP')) points_x = code_value(); - if (code_seen('YP')) points_y = code_value(); - if (code_seen('XO')) offset_x = code_value(); - if (code_seen('YO')) offset_y = code_value(); + if (code_seen("XP")) { strchr_pointer+=1; points_x = code_value(); } + if (code_seen("YP")) { strchr_pointer+=1; points_y = code_value(); } + if (code_seen("XO")) { strchr_pointer+=1; offset_x = code_value(); } + if (code_seen("YO")) { strchr_pointer+=1; offset_y = code_value(); } bed_analysis(dimension_x,dimension_y,points_x,points_y,offset_x,offset_y); @@ -7775,7 +7775,7 @@ void bed_analysis(float x_dimension, float y_dimension, int x_points_num, int y_ int ix = 0; int iy = 0; - char* filename_wldsd = "wldsd.txt"; + const char* filename_wldsd = "wldsd.txt"; char data_wldsd[70]; char numb_wldsd[10]; diff --git a/Firmware/adc.h b/Firmware/adc.h index 1d286917..9ff137df 100644 --- a/Firmware/adc.h +++ b/Firmware/adc.h @@ -10,6 +10,17 @@ extern "C" { #endif //defined(__cplusplus) +/* +http://resnet.uoregon.edu/~gurney_j/jmpc/bitwise.html +*/ +#define BITCOUNT(x) (((BX_(x)+(BX_(x)>>4)) & 0x0F0F0F0F) % 255) +#define BX_(x) ((x) - (((x)>>1)&0x77777777) - (((x)>>2)&0x33333333) - (((x)>>3)&0x11111111)) + +#define ADC_PIN_IDX(pin) BITCOUNT(ADC_CHAN_MSK & ((1 << (pin)) - 1)) + +#if BITCOUNT(ADC_CHAN_MSK) != ADC_CHAN_CNT +# error "ADC_CHAN_MSK oes not match ADC_CHAN_CNT" +#endif extern uint8_t adc_state; extern uint8_t adc_count; diff --git a/Firmware/cardreader.cpp b/Firmware/cardreader.cpp index 82312efb..fe181362 100644 --- a/Firmware/cardreader.cpp +++ b/Firmware/cardreader.cpp @@ -258,7 +258,7 @@ void CardReader::pauseSDPrint() } -void CardReader::openLogFile(char* name) +void CardReader::openLogFile(const char* name) { logging = true; openFile(name, false); @@ -289,7 +289,7 @@ void CardReader::getAbsFilename(char *t) t[0]=0; } -void CardReader::openFile(char* name,bool read, bool replace_current/*=true*/) +void CardReader::openFile(const char* name,bool read, bool replace_current/*=true*/) { if(!cardOK) return; @@ -341,7 +341,7 @@ void CardReader::openFile(char* name,bool read, bool replace_current/*=true*/) SdFile myDir; curDir=&root; - char *fname=name; + const char *fname=name; char *dirname_start,*dirname_end; if(name[0]=='/') @@ -429,7 +429,7 @@ void CardReader::openFile(char* name,bool read, bool replace_current/*=true*/) } -void CardReader::removeFile(char* name) +void CardReader::removeFile(const char* name) { if(!cardOK) return; @@ -439,7 +439,7 @@ void CardReader::removeFile(char* name) SdFile myDir; curDir=&root; - char *fname=name; + const char *fname=name; char *dirname_start,*dirname_end; if(name[0]=='/') diff --git a/Firmware/cardreader.h b/Firmware/cardreader.h index 073325e3..4acc9376 100644 --- a/Firmware/cardreader.h +++ b/Firmware/cardreader.h @@ -19,9 +19,9 @@ public: //this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset void checkautostart(bool x); - void openFile(char* name,bool read,bool replace_current=true); - void openLogFile(char* name); - void removeFile(char* name); + void openFile(const char* name,bool read,bool replace_current=true); + void openLogFile(const char* name); + void removeFile(const char* name); void closefile(bool store_location=false); void release(); void startFileprint(); diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index 04b541e9..865c8492 100644 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -75,7 +75,10 @@ void menu_end(void) void menu_back(void) { - if (menu_depth > 0) menu_goto(menu_stack[--menu_depth].menu, menu_stack[menu_depth].position, true, true); + if (menu_depth > 0) { + menu_depth--; + menu_goto(menu_stack[menu_depth].menu, menu_stack[menu_depth].position, true, true); + } } void menu_back_if_clicked(void) diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index e281303f..6a21b825 100644 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -1552,17 +1552,17 @@ extern "C" { void adc_ready(void) //callback from adc when sampling finished { - current_temperature_raw[0] = adc_values[TEMP_0_PIN]; //heater - current_temperature_raw_pinda = adc_values[TEMP_PINDA_PIN]; - current_temperature_bed_raw = adc_values[TEMP_BED_PIN]; + current_temperature_raw[0] = adc_values[ADC_PIN_IDX(TEMP_0_PIN)]; //heater + current_temperature_raw_pinda = adc_values[ADC_PIN_IDX(TEMP_PINDA_PIN)]; + current_temperature_bed_raw = adc_values[ADC_PIN_IDX(TEMP_BED_PIN)]; #ifdef VOLT_PWR_PIN - current_voltage_raw_pwr = adc_values[VOLT_PWR_PIN]; + current_voltage_raw_pwr = adc_values[ADC_PIN_IDX(VOLT_PWR_PIN)]; #endif #ifdef AMBIENT_THERMISTOR - current_temperature_raw_ambient = adc_values[TEMP_AMBIENT_PIN]; + current_temperature_raw_ambient = adc_values[ADC_PIN_IDX(TEMP_AMBIENT_PIN)]; #endif //AMBIENT_THERMISTOR #ifdef VOLT_BED_PIN - current_voltage_raw_bed = adc_values[VOLT_BED_PIN]; // 6->9 + current_voltage_raw_bed = adc_values[ADC_PIN_IDX(VOLT_BED_PIN)]; // 6->9 #endif temp_meas_ready = true; } diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index 1c219cc7..d4295701 100644 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -129,10 +129,10 @@ void tmc2130_wr_TPWMTHRS(uint8_t axis, uint32_t val32); void tmc2130_wr_THIGH(uint8_t axis, uint32_t val32); #define tmc2130_rd(axis, addr, rval) tmc2130_rx(axis, addr, rval) -#define tmc2130_wr(axis, addr, wval) tmc2130_tx(axis, addr | 0x80, wval) +#define tmc2130_wr(axis, addr, wval) tmc2130_tx(axis, (addr) | 0x80, wval) -uint8_t tmc2130_tx(uint8_t axis, uint8_t addr, uint32_t wval); -uint8_t tmc2130_rx(uint8_t axis, uint8_t addr, uint32_t* rval); +static void tmc2130_tx(uint8_t axis, uint8_t addr, uint32_t wval); +static uint8_t tmc2130_rx(uint8_t axis, uint8_t addr, uint32_t* rval); void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_t current_r); @@ -627,7 +627,7 @@ inline void tmc2130_cs_high(uint8_t axis) #define TMC2130_SPI_TXRX spi_txrx #define TMC2130_SPI_LEAVE() -uint8_t tmc2130_tx(uint8_t axis, uint8_t addr, uint32_t wval) +static void tmc2130_tx(uint8_t axis, uint8_t addr, uint32_t wval) { //datagram1 - request TMC2130_SPI_ENTER(); @@ -641,7 +641,7 @@ uint8_t tmc2130_tx(uint8_t axis, uint8_t addr, uint32_t wval) TMC2130_SPI_LEAVE(); } -uint8_t tmc2130_rx(uint8_t axis, uint8_t addr, uint32_t* rval) +static uint8_t tmc2130_rx(uint8_t axis, uint8_t addr, uint32_t* rval) { //datagram1 - request TMC2130_SPI_ENTER(); @@ -860,8 +860,8 @@ void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000) printf_P(PSTR(" factor: %s\n"), ftostr43(fac)); uint8_t vA = 0; //value of currentA uint8_t va = 0; //previous vA - uint8_t d0 = 0; //delta0 - uint8_t d1 = 1; //delta1 + int8_t d0 = 0; //delta0 + int8_t d1 = 1; //delta1 uint8_t w[4] = {1,1,1,1}; //W bits (MSLUTSEL) uint8_t x[3] = {255,255,255}; //X segment bounds (MSLUTSEL) uint8_t s = 0; //current segment @@ -872,7 +872,7 @@ void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000) tmc2130_wr_MSLUTSTART(axis, 0, amp); for (i = 0; i < 256; i++) { - if ((i & 31) == 0) + if ((i & 0x1f) == 0) reg = 0; // calculate value if (fac == 0) // default TMC wave diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index a30d1520..b95d14b3 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -3573,7 +3573,7 @@ void lcd_bed_calibration_show_result(uint8_t result, uint8_t point_too_far_mask) else if (point_too_far_mask == 2 || point_too_far_mask == 7) // Only the center point or all the three front points. msg = _i("XYZ calibration failed. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR c=20 r=8 - else if (point_too_far_mask & 1 == 0) + else if ((point_too_far_mask & 1) == 0) // The right and maybe the center point out of reach. msg = _i("XYZ calibration failed. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR c=20 r=8 else @@ -3585,7 +3585,7 @@ void lcd_bed_calibration_show_result(uint8_t result, uint8_t point_too_far_mask) if (point_too_far_mask == 2 || point_too_far_mask == 7) // Only the center point or all the three front points. msg = _i("XYZ calibration compromised. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR c=20 r=8 - else if (point_too_far_mask & 1 == 0) + else if ((point_too_far_mask & 1) == 0) // The right and maybe the center point out of reach. msg = _i("XYZ calibration compromised. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR c=20 r=8 else @@ -3648,11 +3648,11 @@ static void lcd_show_end_stops() { lcd_set_cursor(0, 0); lcd_puts_P((PSTR("End stops diag"))); lcd_set_cursor(0, 1); - lcd_puts_P((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("X1")) : (PSTR("X0"))); + lcd_puts_P((READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ? (PSTR("X1")) : (PSTR("X0"))); lcd_set_cursor(0, 2); - lcd_puts_P((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Y1")) : (PSTR("Y0"))); + lcd_puts_P((READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ? (PSTR("Y1")) : (PSTR("Y0"))); lcd_set_cursor(0, 3); - lcd_puts_P((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Z1")) : (PSTR("Z0"))); + lcd_puts_P((READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING) ? (PSTR("Z1")) : (PSTR("Z0"))); } static void menu_show_end_stops() { @@ -6685,13 +6685,12 @@ static bool lcd_selfcheck_axis_sg(char axis) { enable_endstops(false); const char *_error_1; - const char *_error_2; if (axis == X_AXIS) _error_1 = "X"; if (axis == Y_AXIS) _error_1 = "Y"; if (axis == Z_AXIS) _error_1 = "Z"; - lcd_selftest_error(9, _error_1, _error_2); + lcd_selftest_error(9, _error_1, NULL); current_position[axis] = 0; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); reset_crash_det(axis); @@ -6704,13 +6703,12 @@ static bool lcd_selfcheck_axis_sg(char axis) { if (abs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low //loose pulleys const char *_error_1; - const char *_error_2; if (axis == X_AXIS) _error_1 = "X"; if (axis == Y_AXIS) _error_1 = "Y"; if (axis == Z_AXIS) _error_1 = "Z"; - lcd_selftest_error(8, _error_1, _error_2); + lcd_selftest_error(8, _error_1, NULL); current_position[axis] = 0; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); reset_crash_det(axis); @@ -6748,11 +6746,11 @@ static bool lcd_selfcheck_axis(int _axis, int _travel) plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder); st_synchronize(); #ifdef TMC2130 - if (((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1)) + if ((READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING)) #else //TMC2130 - if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) || - ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) || - ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1)) + if ((READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) || + (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) || + (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING)) #endif //TMC2130 { if (_axis == 0) @@ -7125,8 +7123,7 @@ static bool lcd_selftest_fsensor(void) fsensor_init(); if (fsensor_not_responding) { - const char *_err; - lcd_selftest_error(11, _err, _err); + lcd_selftest_error(11, NULL, NULL); } return (!fsensor_not_responding); } @@ -7281,8 +7278,7 @@ static bool lcd_selftest_fan_dialog(int _fan) } if (!_result) { - const char *_err; - lcd_selftest_error(_errno, _err, _err); + lcd_selftest_error(_errno, NULL, NULL); } return _result; } diff --git a/Firmware/xyzcal.cpp b/Firmware/xyzcal.cpp index ed3d3210..027cfdfb 100644 --- a/Firmware/xyzcal.cpp +++ b/Firmware/xyzcal.cpp @@ -210,16 +210,16 @@ bool xyzcal_spiral8(int16_t cx, int16_t cy, int16_t z0, int16_t dz, int16_t radi if (pad) ad = *pad; DBG(_n("xyzcal_spiral8 cx=%d cy=%d z0=%d dz=%d radius=%d ad=%d\n"), cx, cy, z0, dz, radius, ad); if (!ret && (ad < 720)) - if (ret = xyzcal_spiral2(cx, cy, z0 - 0*dz, dz, radius, 0, delay_us, check_pinda, &ad)) + if ((ret = xyzcal_spiral2(cx, cy, z0 - 0*dz, dz, radius, 0, delay_us, check_pinda, &ad)) != 0) ad += 0; if (!ret && (ad < 1440)) - if (ret = xyzcal_spiral2(cx, cy, z0 - 1*dz, dz, -radius, 0, delay_us, check_pinda, &ad)) + if ((ret = xyzcal_spiral2(cx, cy, z0 - 1*dz, dz, -radius, 0, delay_us, check_pinda, &ad)) != 0) ad += 720; if (!ret && (ad < 2160)) - if (ret = xyzcal_spiral2(cx, cy, z0 - 2*dz, dz, radius, 180, delay_us, check_pinda, &ad)) + if ((ret = xyzcal_spiral2(cx, cy, z0 - 2*dz, dz, radius, 180, delay_us, check_pinda, &ad)) != 0) ad += 1440; if (!ret && (ad < 2880)) - if (ret = xyzcal_spiral2(cx, cy, z0 - 3*dz, dz, -radius, 180, delay_us, check_pinda, &ad)) + if ((ret = xyzcal_spiral2(cx, cy, z0 - 3*dz, dz, -radius, 180, delay_us, check_pinda, &ad)) != 0) ad += 2160; if (pad) *pad = ad; return ret;