ソースを参照

Various cleanups ahead of digipot save

Scott Lahteine 7年前
コミット
3c7bfe798d
5個のファイルの変更36行の追加27行の削除
  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 ファイルの表示

@@ -202,9 +202,9 @@ script:
202 202
   #
203 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 210
   ######## Other Standard LCD/Panels ##############

+ 2
- 2
Marlin/Makefile ファイルの表示

@@ -290,8 +290,8 @@ ifeq ($(HARDWARE_VARIANT), Teensy)
290 290
 SRC = wiring.c
291 291
 VPATH += $(ARDUINO_INSTALL_DIR)/hardware/teensy/cores/teensy
292 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 295
 	SdFile.cpp SdVolume.cpp planner.cpp stepper.cpp \
296 296
 	temperature.cpp cardreader.cpp configuration_store.cpp \
297 297
 	watchdog.cpp SPI.cpp servo.cpp Tone.cpp ultralcd.cpp digipot_mcp4451.cpp \

+ 6
- 0
Marlin/Marlin_main.cpp ファイルの表示

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

+ 16
- 13
Marlin/stepper.cpp ファイルの表示

@@ -74,8 +74,8 @@ block_t* Stepper::current_block = NULL;  // A pointer to the block currently bei
74 74
 
75 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 80
 #if ENABLED(Z_DUAL_ENDSTOPS)
81 81
   bool Stepper::locked_z_motor = false;
@@ -1447,11 +1447,11 @@ void Stepper::report_positions() {
1447 1447
 #if HAS_DIGIPOTSS
1448 1448
 
1449 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 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 1455
     //delay(10);
1456 1456
   }
1457 1457
 
@@ -1486,21 +1486,24 @@ void Stepper::report_positions() {
1486 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 1491
     #if HAS_DIGIPOTSS
1492
+
1491 1493
       const uint8_t digipot_ch[] = DIGIPOT_CHANNELS;
1492 1494
       digitalPotWrite(digipot_ch[driver], current);
1495
+
1493 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 1498
       switch (driver) {
1496 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 1501
         #endif
1499 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 1504
         #endif
1502 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 1507
         #endif
1505 1508
       }
1506 1509
     #endif
@@ -1550,7 +1553,7 @@ void Stepper::report_positions() {
1550 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 1557
     if (ms1 >= 0) switch (driver) {
1555 1558
       case 0: WRITE(X_MS1_PIN, ms1); break;
1556 1559
       #if HAS_Y_MICROSTEPS
@@ -1601,7 +1604,7 @@ void Stepper::report_positions() {
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 1608
     switch (stepping_mode) {
1606 1609
       case 1: microstep_ms(driver, MICROSTEP1); break;
1607 1610
       case 2: microstep_ms(driver, MICROSTEP2); break;

+ 9
- 9
Marlin/stepper.h ファイルの表示

@@ -93,8 +93,8 @@ class Stepper {
93 93
 
94 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 99
     #if ENABLED(Z_DUAL_ENDSTOPS)
100 100
       static bool locked_z_motor, locked_z2_motor;
@@ -243,20 +243,20 @@ class Stepper {
243 243
     static FORCE_INLINE bool motor_direction(AxisEnum axis) { return TEST(last_direction_bits, axis); }
244 244
 
245 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 248
     #endif
249 249
 
250 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 253
       static void microstep_readings();
254 254
     #endif
255 255
 
256 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 260
     #endif
261 261
 
262 262
     #if ENABLED(BABYSTEPPING)

読み込み中…
キャンセル
保存