Browse Source

Various cleanups ahead of digipot save

Scott Lahteine 8 years ago
parent
commit
3c7bfe798d
5 changed files with 36 additions and 27 deletions
  1. 3
    3
      .travis.yml
  2. 2
    2
      Marlin/Makefile
  3. 6
    0
      Marlin/Marlin_main.cpp
  4. 16
    13
      Marlin/stepper.cpp
  5. 9
    9
      Marlin/stepper.h

+ 3
- 3
.travis.yml View File

202
   #
202
   #
203
   # Enable COREYX (swapped)
203
   # Enable COREYX (swapped)
204
   #
204
   #
205
-  - restore_configs
206
-  - opt_enable COREYX
207
-  - build_marlin
205
+  #- restore_configs
206
+  #- opt_enable COREYX
207
+  #- build_marlin
208
   #
208
   #
209
   #
209
   #
210
   ######## Other Standard LCD/Panels ##############
210
   ######## Other Standard LCD/Panels ##############

+ 2
- 2
Marlin/Makefile View File

290
 SRC = wiring.c
290
 SRC = wiring.c
291
 VPATH += $(ARDUINO_INSTALL_DIR)/hardware/teensy/cores/teensy
291
 VPATH += $(ARDUINO_INSTALL_DIR)/hardware/teensy/cores/teensy
292
 endif
292
 endif
293
-CXXSRC = WMath.cpp WString.cpp Print.cpp Marlin_main.cpp	\
294
-	MarlinSerial.cpp Sd2Card.cpp SdBaseFile.cpp SdFatUtil.cpp	\
293
+CXXSRC = WMath.cpp WString.cpp Print.cpp Marlin_main.cpp \
294
+	MarlinSerial.cpp Sd2Card.cpp SdBaseFile.cpp SdFatUtil.cpp \
295
 	SdFile.cpp SdVolume.cpp planner.cpp stepper.cpp \
295
 	SdFile.cpp SdVolume.cpp planner.cpp stepper.cpp \
296
 	temperature.cpp cardreader.cpp configuration_store.cpp \
296
 	temperature.cpp cardreader.cpp configuration_store.cpp \
297
 	watchdog.cpp SPI.cpp servo.cpp Tone.cpp ultralcd.cpp digipot_mcp4451.cpp \
297
 	watchdog.cpp SPI.cpp servo.cpp Tone.cpp ultralcd.cpp digipot_mcp4451.cpp \

+ 6
- 0
Marlin/Marlin_main.cpp View File

9677
  */
9677
  */
9678
 inline void gcode_M907() {
9678
 inline void gcode_M907() {
9679
   #if HAS_DIGIPOTSS
9679
   #if HAS_DIGIPOTSS
9680
+
9680
     LOOP_XYZE(i) if (parser.seen(axis_codes[i])) stepper.digipot_current(i, parser.value_int());
9681
     LOOP_XYZE(i) if (parser.seen(axis_codes[i])) stepper.digipot_current(i, parser.value_int());
9681
     if (parser.seen('B')) stepper.digipot_current(4, parser.value_int());
9682
     if (parser.seen('B')) stepper.digipot_current(4, parser.value_int());
9682
     if (parser.seen('S')) for (uint8_t i = 0; i <= 4; i++) stepper.digipot_current(i, parser.value_int());
9683
     if (parser.seen('S')) for (uint8_t i = 0; i <= 4; i++) stepper.digipot_current(i, parser.value_int());
9684
+
9683
   #elif HAS_MOTOR_CURRENT_PWM
9685
   #elif HAS_MOTOR_CURRENT_PWM
9686
+
9684
     #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
9687
     #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
9685
       if (parser.seen('X')) stepper.digipot_current(0, parser.value_int());
9688
       if (parser.seen('X')) stepper.digipot_current(0, parser.value_int());
9686
     #endif
9689
     #endif
9690
     #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
9693
     #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
9691
       if (parser.seen('E')) stepper.digipot_current(2, parser.value_int());
9694
       if (parser.seen('E')) stepper.digipot_current(2, parser.value_int());
9692
     #endif
9695
     #endif
9696
+
9693
   #endif
9697
   #endif
9698
+
9694
   #if ENABLED(DIGIPOT_I2C)
9699
   #if ENABLED(DIGIPOT_I2C)
9695
     // this one uses actual amps in floating point
9700
     // this one uses actual amps in floating point
9696
     LOOP_XYZE(i) if (parser.seen(axis_codes[i])) digipot_i2c_set_current(i, parser.value_float());
9701
     LOOP_XYZE(i) if (parser.seen(axis_codes[i])) digipot_i2c_set_current(i, parser.value_float());
9697
     // for each additional extruder (named B,C,D,E..., channels 4,5,6,7...)
9702
     // for each additional extruder (named B,C,D,E..., channels 4,5,6,7...)
9698
     for (uint8_t i = NUM_AXIS; i < DIGIPOT_I2C_NUM_CHANNELS; i++) if (parser.seen('B' + i - (NUM_AXIS))) digipot_i2c_set_current(i, parser.value_float());
9703
     for (uint8_t i = NUM_AXIS; i < DIGIPOT_I2C_NUM_CHANNELS; i++) if (parser.seen('B' + i - (NUM_AXIS))) digipot_i2c_set_current(i, parser.value_float());
9699
   #endif
9704
   #endif
9705
+
9700
   #if ENABLED(DAC_STEPPER_CURRENT)
9706
   #if ENABLED(DAC_STEPPER_CURRENT)
9701
     if (parser.seen('S')) {
9707
     if (parser.seen('S')) {
9702
       const float dac_percent = parser.value_float();
9708
       const float dac_percent = parser.value_float();

+ 16
- 13
Marlin/stepper.cpp View File

74
 
74
 
75
 // private:
75
 // private:
76
 
76
 
77
-unsigned char Stepper::last_direction_bits = 0;        // The next stepping-bits to be output
78
-unsigned int Stepper::cleaning_buffer_counter = 0;
77
+uint8_t Stepper::last_direction_bits = 0;        // The next stepping-bits to be output
78
+uint16_t Stepper::cleaning_buffer_counter = 0;
79
 
79
 
80
 #if ENABLED(Z_DUAL_ENDSTOPS)
80
 #if ENABLED(Z_DUAL_ENDSTOPS)
81
   bool Stepper::locked_z_motor = false;
81
   bool Stepper::locked_z_motor = false;
1447
 #if HAS_DIGIPOTSS
1447
 #if HAS_DIGIPOTSS
1448
 
1448
 
1449
   // From Arduino DigitalPotControl example
1449
   // From Arduino DigitalPotControl example
1450
-  void Stepper::digitalPotWrite(int address, int value) {
1451
-    WRITE(DIGIPOTSS_PIN, LOW); // take the SS pin low to select the chip
1452
-    SPI.transfer(address); //  send in the address and value via SPI:
1450
+  void Stepper::digitalPotWrite(const int16_t address, const int16_t value) {
1451
+    WRITE(DIGIPOTSS_PIN, LOW);  // Take the SS pin low to select the chip
1452
+    SPI.transfer(address);      // Send the address and value via SPI
1453
     SPI.transfer(value);
1453
     SPI.transfer(value);
1454
-    WRITE(DIGIPOTSS_PIN, HIGH); // take the SS pin high to de-select the chip:
1454
+    WRITE(DIGIPOTSS_PIN, HIGH); // Take the SS pin high to de-select the chip
1455
     //delay(10);
1455
     //delay(10);
1456
   }
1456
   }
1457
 
1457
 
1486
     #endif
1486
     #endif
1487
   }
1487
   }
1488
 
1488
 
1489
-  void Stepper::digipot_current(uint8_t driver, int current) {
1489
+  void Stepper::digipot_current(const uint8_t driver, const int current) {
1490
+
1490
     #if HAS_DIGIPOTSS
1491
     #if HAS_DIGIPOTSS
1492
+
1491
       const uint8_t digipot_ch[] = DIGIPOT_CHANNELS;
1493
       const uint8_t digipot_ch[] = DIGIPOT_CHANNELS;
1492
       digitalPotWrite(digipot_ch[driver], current);
1494
       digitalPotWrite(digipot_ch[driver], current);
1495
+
1493
     #elif HAS_MOTOR_CURRENT_PWM
1496
     #elif HAS_MOTOR_CURRENT_PWM
1494
-      #define _WRITE_CURRENT_PWM(P) analogWrite(P, 255L * current / (MOTOR_CURRENT_PWM_RANGE))
1497
+      #define _WRITE_CURRENT_PWM(P) analogWrite(MOTOR_CURRENT_PWM_## P ##_PIN, 255L * current / (MOTOR_CURRENT_PWM_RANGE))
1495
       switch (driver) {
1498
       switch (driver) {
1496
         #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
1499
         #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
1497
-          case 0: _WRITE_CURRENT_PWM(MOTOR_CURRENT_PWM_XY_PIN); break;
1500
+          case 0: _WRITE_CURRENT_PWM(XY); break;
1498
         #endif
1501
         #endif
1499
         #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
1502
         #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
1500
-          case 1: _WRITE_CURRENT_PWM(MOTOR_CURRENT_PWM_Z_PIN); break;
1503
+          case 1: _WRITE_CURRENT_PWM(Z); break;
1501
         #endif
1504
         #endif
1502
         #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
1505
         #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
1503
-          case 2: _WRITE_CURRENT_PWM(MOTOR_CURRENT_PWM_E_PIN); break;
1506
+          case 2: _WRITE_CURRENT_PWM(E); break;
1504
         #endif
1507
         #endif
1505
       }
1508
       }
1506
     #endif
1509
     #endif
1550
       microstep_mode(i, microstep_modes[i]);
1553
       microstep_mode(i, microstep_modes[i]);
1551
   }
1554
   }
1552
 
1555
 
1553
-  void Stepper::microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2) {
1556
+  void Stepper::microstep_ms(const uint8_t driver, const int8_t ms1, const int8_t ms2) {
1554
     if (ms1 >= 0) switch (driver) {
1557
     if (ms1 >= 0) switch (driver) {
1555
       case 0: WRITE(X_MS1_PIN, ms1); break;
1558
       case 0: WRITE(X_MS1_PIN, ms1); break;
1556
       #if HAS_Y_MICROSTEPS
1559
       #if HAS_Y_MICROSTEPS
1601
     }
1604
     }
1602
   }
1605
   }
1603
 
1606
 
1604
-  void Stepper::microstep_mode(uint8_t driver, uint8_t stepping_mode) {
1607
+  void Stepper::microstep_mode(const uint8_t driver, const uint8_t stepping_mode) {
1605
     switch (stepping_mode) {
1608
     switch (stepping_mode) {
1606
       case 1: microstep_ms(driver, MICROSTEP1); break;
1609
       case 1: microstep_ms(driver, MICROSTEP1); break;
1607
       case 2: microstep_ms(driver, MICROSTEP2); break;
1610
       case 2: microstep_ms(driver, MICROSTEP2); break;

+ 9
- 9
Marlin/stepper.h View File

93
 
93
 
94
   private:
94
   private:
95
 
95
 
96
-    static unsigned char last_direction_bits;        // The next stepping-bits to be output
97
-    static unsigned int cleaning_buffer_counter;
96
+    static uint8_t last_direction_bits;        // The next stepping-bits to be output
97
+    static uint16_t cleaning_buffer_counter;
98
 
98
 
99
     #if ENABLED(Z_DUAL_ENDSTOPS)
99
     #if ENABLED(Z_DUAL_ENDSTOPS)
100
       static bool locked_z_motor, locked_z2_motor;
100
       static bool locked_z_motor, locked_z2_motor;
243
     static FORCE_INLINE bool motor_direction(AxisEnum axis) { return TEST(last_direction_bits, axis); }
243
     static FORCE_INLINE bool motor_direction(AxisEnum axis) { return TEST(last_direction_bits, axis); }
244
 
244
 
245
     #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
245
     #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
246
-      static void digitalPotWrite(int address, int value);
247
-      static void digipot_current(uint8_t driver, int current);
246
+      static void digitalPotWrite(const int16_t address, const int16_t value);
247
+      static void digipot_current(const uint8_t driver, const int16_t current);
248
     #endif
248
     #endif
249
 
249
 
250
     #if HAS_MICROSTEPS
250
     #if HAS_MICROSTEPS
251
-      static void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2);
252
-      static void microstep_mode(uint8_t driver, uint8_t stepping);
251
+      static void microstep_ms(const uint8_t driver, const int8_t ms1, const int8_t ms2);
252
+      static void microstep_mode(const uint8_t driver, const uint8_t stepping);
253
       static void microstep_readings();
253
       static void microstep_readings();
254
     #endif
254
     #endif
255
 
255
 
256
     #if ENABLED(Z_DUAL_ENDSTOPS)
256
     #if ENABLED(Z_DUAL_ENDSTOPS)
257
-      static FORCE_INLINE void set_homing_flag(bool state) { performing_homing = state; }
258
-      static FORCE_INLINE void set_z_lock(bool state) { locked_z_motor = state; }
259
-      static FORCE_INLINE void set_z2_lock(bool state) { locked_z2_motor = state; }
257
+      static FORCE_INLINE void set_homing_flag(const bool state) { performing_homing = state; }
258
+      static FORCE_INLINE void set_z_lock(const bool state) { locked_z_motor = state; }
259
+      static FORCE_INLINE void set_z2_lock(const bool state) { locked_z2_motor = state; }
260
     #endif
260
     #endif
261
 
261
 
262
     #if ENABLED(BABYSTEPPING)
262
     #if ENABLED(BABYSTEPPING)

Loading…
Cancel
Save