Kaynağa Gözat

Code cleanup around MOTOR_CURRENT_PWM options

Scott Lahteine 8 yıl önce
ebeveyn
işleme
5d8036e554
4 değiştirilmiş dosya ile 51 ekleme ve 40 silme
  1. 2
    0
      Marlin/Conditionals.h
  2. 3
    3
      Marlin/Marlin_main.cpp
  3. 21
    25
      Marlin/servo.h
  4. 25
    12
      Marlin/stepper.cpp

+ 2
- 0
Marlin/Conditionals.h Dosyayı Görüntüle

@@ -570,6 +570,8 @@
570 570
   #define HAS_E3_STEP (PIN_EXISTS(E3_STEP))
571 571
   #define HAS_E4_STEP (PIN_EXISTS(E4_STEP))
572 572
 
573
+  #define HAS_MOTOR_CURRENT_PWM (PIN_EXISTS(MOTOR_CURRENT_PWM_XY) || PIN_EXISTS(MOTOR_CURRENT_PWM_Z) || PIN_EXISTS(MOTOR_CURRENT_PWM_E))
574
+
573 575
   /**
574 576
    * Helper Macros for heaters and extruder fan
575 577
    */

+ 3
- 3
Marlin/Marlin_main.cpp Dosyayı Görüntüle

@@ -5729,13 +5729,13 @@ inline void gcode_M907() {
5729 5729
     if (code_seen('B')) digipot_current(4, code_value());
5730 5730
     if (code_seen('S')) for (int i = 0; i <= 4; i++) digipot_current(i, code_value());
5731 5731
   #endif
5732
-  #ifdef MOTOR_CURRENT_PWM_XY_PIN
5732
+  #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
5733 5733
     if (code_seen('X')) digipot_current(0, code_value());
5734 5734
   #endif
5735
-  #ifdef MOTOR_CURRENT_PWM_Z_PIN
5735
+  #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
5736 5736
     if (code_seen('Z')) digipot_current(1, code_value());
5737 5737
   #endif
5738
-  #ifdef MOTOR_CURRENT_PWM_E_PIN
5738
+  #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
5739 5739
     if (code_seen('E')) digipot_current(2, code_value());
5740 5740
   #endif
5741 5741
   #if ENABLED(DIGIPOT_I2C)

+ 21
- 25
Marlin/servo.h Dosyayı Görüntüle

@@ -85,39 +85,35 @@
85 85
   //#define _useTimer1
86 86
   #define _useTimer3
87 87
   #define _useTimer4
88
-  #ifndef MOTOR_CURRENT_PWM_XY_PIN
89
-    //Timer 5 is used for motor current PWM and can't be used for servos.
90
-    #define _useTimer5
91
-    //typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ;
92
-    typedef enum { _timer5, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ;
93
-  #else
94
-    typedef enum {_timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ;
88
+  #if !HAS_MOTOR_CURRENT_PWM
89
+    #define _useTimer5 // Timer 5 is used for motor current PWM and can't be used for servos.
95 90
   #endif
96
-
97 91
 #elif defined(__AVR_ATmega32U4__)
98
-  //#define _useTimer1
99 92
   #define _useTimer3
100
-  //typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;
101
-  typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t ;
102
-
103 93
 #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
104 94
   #define _useTimer3
105
-  //#define _useTimer1
106
-  //typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;
107
-  typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t ;
108
-
109
-#elif defined(__AVR_ATmega128__) ||defined(__AVR_ATmega1281__) || defined(__AVR_ATmega1284P__) ||defined(__AVR_ATmega2561__)
95
+#elif defined(__AVR_ATmega128__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega2561__)
110 96
   #define _useTimer3
111
-  //#define _useTimer1
112
-  //typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;
113
-  typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t ;
97
+#else
98
+  // everything else
99
+#endif
114 100
 
115
-#else  // everything else
116
-  //#define _useTimer1
117
-  //typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;
118
-  typedef enum { _Nbr_16timers } timer16_Sequence_t ;
101
+typedef enum {
102
+  #if ENABLED(_useTimer1)
103
+    _timer1,
104
+  #endif
105
+  #if ENABLED(_useTimer3)
106
+    _timer3,
107
+  #endif
108
+  #if ENABLED(_useTimer4)
109
+    _timer4,
110
+  #endif
111
+  #if ENABLED(_useTimer5)
112
+    _timer5,
113
+  #endif
114
+  _Nbr_16timers
115
+} timer16_Sequence_t;
119 116
 
120
-#endif
121 117
 
122 118
 #define Servo_VERSION           2     // software version of this library
123 119
 

+ 25
- 12
Marlin/stepper.cpp Dosyayı Görüntüle

@@ -113,7 +113,7 @@ static volatile char endstop_hit_bits = 0; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_
113 113
   bool abort_on_endstop_hit = false;
114 114
 #endif
115 115
 
116
-#if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
116
+#if HAS_MOTOR_CURRENT_PWM
117 117
   #ifndef PWM_MOTOR_CURRENT
118 118
     #define PWM_MOTOR_CURRENT DEFAULT_PWM_MOTOR_CURRENT
119 119
   #endif
@@ -1238,13 +1238,19 @@ void digipot_init() {
1238 1238
       digipot_current(i, digipot_motor_current[i]);
1239 1239
     }
1240 1240
   #endif
1241
-  #ifdef MOTOR_CURRENT_PWM_XY_PIN
1242
-    pinMode(MOTOR_CURRENT_PWM_XY_PIN, OUTPUT);
1243
-    pinMode(MOTOR_CURRENT_PWM_Z_PIN, OUTPUT);
1244
-    pinMode(MOTOR_CURRENT_PWM_E_PIN, OUTPUT);
1245
-    digipot_current(0, motor_current_setting[0]);
1246
-    digipot_current(1, motor_current_setting[1]);
1247
-    digipot_current(2, motor_current_setting[2]);
1241
+  #if HAS_MOTOR_CURRENT_PWM
1242
+    #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
1243
+      pinMode(MOTOR_CURRENT_PWM_XY_PIN, OUTPUT);
1244
+      digipot_current(0, motor_current_setting[0]);
1245
+    #endif
1246
+    #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
1247
+      pinMode(MOTOR_CURRENT_PWM_Z_PIN, OUTPUT);
1248
+      digipot_current(1, motor_current_setting[1]);
1249
+    #endif
1250
+    #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
1251
+      pinMode(MOTOR_CURRENT_PWM_E_PIN, OUTPUT);
1252
+      digipot_current(2, motor_current_setting[2]);
1253
+    #endif
1248 1254
     //Set timer5 to 31khz so the PWM of the motor power is as constant as possible. (removes a buzzing noise)
1249 1255
     TCCR5B = (TCCR5B & ~(_BV(CS50) | _BV(CS51) | _BV(CS52))) | _BV(CS50);
1250 1256
   #endif
@@ -1254,11 +1260,18 @@ void digipot_current(uint8_t driver, int current) {
1254 1260
   #if HAS_DIGIPOTSS
1255 1261
     const uint8_t digipot_ch[] = DIGIPOT_CHANNELS;
1256 1262
     digitalPotWrite(digipot_ch[driver], current);
1257
-  #elif defined(MOTOR_CURRENT_PWM_XY_PIN)
1263
+  #elif HAS_MOTOR_CURRENT_PWM
1264
+    #define _WRITE_CURRENT_PWM(P) analogWrite(P, 255L * current / (MOTOR_CURRENT_PWM_RANGE))
1258 1265
     switch (driver) {
1259
-      case 0: analogWrite(MOTOR_CURRENT_PWM_XY_PIN, 255L * current / (MOTOR_CURRENT_PWM_RANGE)); break;
1260
-      case 1: analogWrite(MOTOR_CURRENT_PWM_Z_PIN, 255L * current / (MOTOR_CURRENT_PWM_RANGE)); break;
1261
-      case 2: analogWrite(MOTOR_CURRENT_PWM_E_PIN, 255L * current / (MOTOR_CURRENT_PWM_RANGE)); break;
1266
+      #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
1267
+        case 0: _WRITE_CURRENT_PWM(MOTOR_CURRENT_PWM_XY_PIN); break;
1268
+      #endif
1269
+      #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
1270
+        case 1: _WRITE_CURRENT_PWM(MOTOR_CURRENT_PWM_Z_PIN); break;
1271
+      #endif
1272
+      #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
1273
+        case 2: _WRITE_CURRENT_PWM(MOTOR_CURRENT_PWM_E_PIN); break;
1274
+      #endif
1262 1275
     }
1263 1276
   #else
1264 1277
     UNUSED(driver);

Loading…
İptal
Kaydet