Sfoglia il codice sorgente

Merge branch 'Development' into marlin_configurator

Latest upstream changes
Scott Lahteine 10 anni fa
parent
commit
4b50205f11

+ 9
- 0
Marlin/Configuration.h Vedi File

@@ -362,6 +362,15 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o
362 362
 #define Y_MAX_LENGTH (Y_MAX_POS - Y_MIN_POS)
363 363
 #define Z_MAX_LENGTH (Z_MAX_POS - Z_MIN_POS)
364 364
 
365
+//===========================================================================
366
+//============================= Filament Runout Sensor ======================
367
+//===========================================================================
368
+//#define FILAMENT_RUNOUT_SENSOR // Uncomment for defining a filament runout sensor such as a mechanical or opto endstop to check the existence of filament
369
+                                 // In RAMPS uses servo pin 2. Can be changed in pins file. For other boards pin definition should be made.
370
+                                 // It is assumed that when logic high = filament available
371
+                                 //                    when logic  low = filament ran out
372
+//const bool FIL_RUNOUT_INVERTING = true;  // Should be uncommented and true or false should assigned
373
+//#define ENDSTOPPULLUP_FIL_RUNOUT // Uncomment to use internal pullup for filament runout pins if the sensor is defined.
365 374
 
366 375
 //===========================================================================
367 376
 //============================= Bed Auto Leveling ===========================

+ 7
- 0
Marlin/Marlin.h Vedi File

@@ -32,6 +32,9 @@
32 32
   #include "WProgram.h"
33 33
 #endif
34 34
 
35
+#define BIT(b) (1<<(b))
36
+#define TEST(n,b) ((n)&BIT(b)!=0)
37
+
35 38
 // Arduino < 1.0.0 does not define this, so we need to do it ourselves
36 39
 #ifndef analogInputToDigitalPin
37 40
   #define analogInputToDigitalPin(p) ((p) + 0xA0)
@@ -199,6 +202,10 @@ void prepare_move();
199 202
 void kill();
200 203
 void Stop();
201 204
 
205
+#ifdef FILAMENT_RUNOUT_SENSOR
206
+void filrunout();
207
+#endif
208
+
202 209
 bool IsStopped();
203 210
 
204 211
 bool enquecommand(const char *cmd); //put a single ASCII command at the end of the current buffer or return false when it is full

+ 2
- 2
Marlin/Marlin.ino Vedi File

@@ -47,8 +47,8 @@
47 47
   #endif
48 48
 #endif
49 49
 
50
-#if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
51
-#include <SPI.h>
50
+#if HAS_DIGIPOTSS
51
+  #include <SPI.h>
52 52
 #endif
53 53
 
54 54
 #if defined(DIGIPOT_I2C)

+ 2
- 2
Marlin/Marlin.pde Vedi File

@@ -47,8 +47,8 @@
47 47
   #endif
48 48
 #endif
49 49
 
50
-#if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
51
-#include <SPI.h>
50
+#if HAS_DIGIPOTSS
51
+  #include <SPI.h>
52 52
 #endif
53 53
 
54 54
 #if defined(DIGIPOT_I2C)

+ 1
- 1
Marlin/MarlinSerial.cpp Vedi File

@@ -76,7 +76,7 @@ void MarlinSerial::begin(long baud) {
76 76
   #endif
77 77
   
78 78
   if (useU2X) {
79
-    M_UCSRxA = 1 << M_U2Xx;
79
+    M_UCSRxA = BIT(M_U2Xx);
80 80
     baud_setting = (F_CPU / 4 / baud - 1) / 2;
81 81
   } else {
82 82
     M_UCSRxA = 0;

+ 2
- 2
Marlin/MarlinSerial.h Vedi File

@@ -97,14 +97,14 @@ class MarlinSerial { //: public Stream
97 97
     }
98 98
 
99 99
     FORCE_INLINE void write(uint8_t c) {
100
-      while (!((M_UCSRxA) & (1 << M_UDREx)))
100
+      while (!TEST(M_UCSRxA, M_UDREx))
101 101
         ;
102 102
 
103 103
       M_UDRx = c;
104 104
     }
105 105
 
106 106
     FORCE_INLINE void checkRx(void) {
107
-      if ((M_UCSRxA & (1<<M_RXCx)) != 0) {
107
+      if (TEST(M_UCSRxA, M_RXCx)) {
108 108
         unsigned char c  =  M_UDRx;
109 109
         int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
110 110
 

+ 54
- 12
Marlin/Marlin_main.cpp Vedi File

@@ -62,7 +62,7 @@
62 62
   #include "Servo.h"
63 63
 #endif
64 64
 
65
-#if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
65
+#if HAS_DIGIPOTSS
66 66
   #include <SPI.h>
67 67
 #endif
68 68
 
@@ -370,6 +370,10 @@ bool cancel_heatup = false;
370 370
   int meas_delay_cm = MEASUREMENT_DELAY_CM;  //distance delay setting
371 371
 #endif
372 372
 
373
+#ifdef FILAMENT_RUNOUT_SENSOR
374
+   static bool filrunoutEnqued = false;
375
+#endif
376
+
373 377
 const char errormagic[] PROGMEM = "Error:";
374 378
 const char echomagic[] PROGMEM = "echo:";
375 379
 
@@ -529,6 +533,16 @@ void setup_killpin()
529 533
   #endif
530 534
 }
531 535
 
536
+void setup_filrunoutpin()
537
+{
538
+#if defined(FILRUNOUT_PIN) && FILRUNOUT_PIN > -1
539
+   pinMode(FILRUNOUT_PIN,INPUT);
540
+   #if defined(ENDSTOPPULLUP_FIL_RUNOUT)
541
+      WRITE(FILLRUNOUT_PIN,HIGH);
542
+   #endif
543
+#endif
544
+}
545
+
532 546
 // Set home pin
533 547
 void setup_homepin(void)
534 548
 {
@@ -605,6 +619,7 @@ void servo_init()
605 619
 void setup()
606 620
 {
607 621
   setup_killpin();
622
+  setup_filrunoutpin();
608 623
   setup_powerhold();
609 624
   MYSERIAL.begin(BAUDRATE);
610 625
   SERIAL_PROTOCOLLNPGM("start");
@@ -2015,14 +2030,15 @@ inline void gcode_G28() {
2015 2030
 
2016 2031
       if (verbose_level) {
2017 2032
         SERIAL_PROTOCOLPGM("Eqn coefficients: a: ");
2018
-        SERIAL_PROTOCOL(plane_equation_coefficients[0] + 0.0001);
2033
+        SERIAL_PROTOCOL_F(plane_equation_coefficients[0], 8);
2019 2034
         SERIAL_PROTOCOLPGM(" b: ");
2020
-        SERIAL_PROTOCOL(plane_equation_coefficients[1] + 0.0001);
2035
+        SERIAL_PROTOCOL_F(plane_equation_coefficients[1], 8);
2021 2036
         SERIAL_PROTOCOLPGM(" d: ");
2022
-        SERIAL_PROTOCOLLN(plane_equation_coefficients[2] + 0.0001);
2037
+        SERIAL_PROTOCOL_F(plane_equation_coefficients[2], 8);
2038
+        SERIAL_EOL;
2023 2039
         if (verbose_level > 2) {
2024 2040
           SERIAL_PROTOCOLPGM("Mean of sampled points: ");
2025
-          SERIAL_PROTOCOL_F(mean, 6);
2041
+          SERIAL_PROTOCOL_F(mean, 8);
2026 2042
           SERIAL_EOL;
2027 2043
         }
2028 2044
       }
@@ -2033,15 +2049,20 @@ inline void gcode_G28() {
2033 2049
 
2034 2050
         SERIAL_PROTOCOLPGM(" \nBed Height Topography: \n");
2035 2051
         #if TOPO_ORIGIN == OriginFrontLeft
2052
+          SERIAL_PROTOCOLPGM("+-----------+\n");
2053
+          SERIAL_PROTOCOLPGM("|...Back....|\n");
2054
+          SERIAL_PROTOCOLPGM("|Left..Right|\n");
2055
+          SERIAL_PROTOCOLPGM("|...Front...|\n");
2056
+          SERIAL_PROTOCOLPGM("+-----------+\n");
2036 2057
           for (yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--)
2037 2058
         #else
2038 2059
           for (yy = 0; yy < auto_bed_leveling_grid_points; yy++)
2039 2060
         #endif
2040 2061
           {
2041 2062
             #if TOPO_ORIGIN == OriginBackRight
2042
-              for (xx = auto_bed_leveling_grid_points - 1; xx >= 0; xx--)
2043
-            #else
2044 2063
               for (xx = 0; xx < auto_bed_leveling_grid_points; xx++)
2064
+            #else
2065
+              for (xx = auto_bed_leveling_grid_points - 1; xx >= 0; xx--)
2045 2066
             #endif
2046 2067
               {
2047 2068
                 int ind =
@@ -4130,6 +4151,11 @@ inline void gcode_M503() {
4130 4151
       plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], lastpos[Z_AXIS], target[E_AXIS], fr60, active_extruder); //move z back
4131 4152
       plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], lastpos[Z_AXIS], lastpos[E_AXIS], fr60, active_extruder); //final untretract
4132 4153
     #endif        
4154
+
4155
+    #ifdef FILAMENT_RUNOUT_SENSOR
4156
+      filrunoutEnqued = false;
4157
+    #endif
4158
+    
4133 4159
   }
4134 4160
 
4135 4161
 #endif // FILAMENTCHANGEENABLE
@@ -4184,7 +4210,7 @@ inline void gcode_M503() {
4184 4210
  * M907: Set digital trimpot motor current using axis codes X, Y, Z, E, B, S
4185 4211
  */
4186 4212
 inline void gcode_M907() {
4187
-  #if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
4213
+  #if HAS_DIGIPOTSS
4188 4214
     for (int i=0;i<NUM_AXIS;i++)
4189 4215
       if (code_seen(axis_codes[i])) digipot_current(i, code_value());
4190 4216
     if (code_seen('B')) digipot_current(4, code_value());
@@ -4207,7 +4233,7 @@ inline void gcode_M907() {
4207 4233
   #endif
4208 4234
 }
4209 4235
 
4210
-#if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
4236
+#if HAS_DIGIPOTSS
4211 4237
 
4212 4238
   /**
4213 4239
    * M908: Control digital trimpot directly (M908 P<pin> S<current>)
@@ -4219,7 +4245,7 @@ inline void gcode_M907() {
4219 4245
       );
4220 4246
   }
4221 4247
 
4222
-#endif // DIGIPOTSS_PIN
4248
+#endif // HAS_DIGIPOTSS
4223 4249
 
4224 4250
 // M350 Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers.
4225 4251
 inline void gcode_M350() {
@@ -4806,11 +4832,11 @@ void process_commands() {
4806 4832
         gcode_M907();
4807 4833
         break;
4808 4834
 
4809
-      #if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
4835
+      #if HAS_DIGIPOTSS
4810 4836
         case 908: // M908 Control digital trimpot directly.
4811 4837
           gcode_M908();
4812 4838
           break;
4813
-      #endif // DIGIPOTSS_PIN
4839
+      #endif // HAS_DIGIPOTSS
4814 4840
 
4815 4841
       case 350: // M350 Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers.
4816 4842
         gcode_M350();
@@ -5269,6 +5295,12 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s
5269 5295
    const int KILL_DELAY = 10000;
5270 5296
 #endif
5271 5297
 
5298
+#if defined(FILRUNOUT_PIN) && FILRUNOUT_PIN > -1
5299
+    if(card.sdprinting) {
5300
+      if(!(READ(FILRUNOUT_PIN))^FIL_RUNOUT_INVERTING)
5301
+      filrunout();        }
5302
+#endif
5303
+
5272 5304
 #if defined(HOME_PIN) && HOME_PIN > -1
5273 5305
    static int homeDebounceCount = 0;   // poor man's debouncing count
5274 5306
    const int HOME_DEBOUNCE_DELAY = 10000;
@@ -5417,6 +5449,16 @@ void kill()
5417 5449
   while(1) { /* Intentionally left empty */ } // Wait for reset
5418 5450
 }
5419 5451
 
5452
+#ifdef FILAMENT_RUNOUT_SENSOR
5453
+   void filrunout()
5454
+   {
5455
+      if filrunoutEnqued == false {
5456
+         filrunoutEnqued = true;
5457
+         enquecommand("M600");
5458
+      }
5459
+   }
5460
+#endif
5461
+
5420 5462
 void Stop()
5421 5463
 {
5422 5464
   disable_heater();

+ 9
- 9
Marlin/Sd2Card.cpp Vedi File

@@ -35,14 +35,14 @@
35 35
  */
36 36
 static void spiInit(uint8_t spiRate) {
37 37
   // See avr processor documentation
38
-  SPCR = (1 << SPE) | (1 << MSTR) | (spiRate >> 1);
39
-  SPSR = spiRate & 1 || spiRate == 6 ? 0 : 1 << SPI2X;
38
+  SPCR = BIT(SPE) | BIT(MSTR) | (spiRate >> 1);
39
+  SPSR = spiRate & 1 || spiRate == 6 ? 0 : BIT(SPI2X);
40 40
 }
41 41
 //------------------------------------------------------------------------------
42 42
 /** SPI receive a byte */
43 43
 static uint8_t spiRec() {
44 44
   SPDR = 0XFF;
45
-  while (!(SPSR & (1 << SPIF))) { /* Intentionally left empty */ }
45
+  while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
46 46
   return SPDR;
47 47
 }
48 48
 //------------------------------------------------------------------------------
@@ -52,18 +52,18 @@ void spiRead(uint8_t* buf, uint16_t nbyte) {
52 52
   if (nbyte-- == 0) return;
53 53
   SPDR = 0XFF;
54 54
   for (uint16_t i = 0; i < nbyte; i++) {
55
-    while (!(SPSR & (1 << SPIF))) { /* Intentionally left empty */ }
55
+    while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
56 56
     buf[i] = SPDR;
57 57
     SPDR = 0XFF;
58 58
   }
59
-  while (!(SPSR & (1 << SPIF))) { /* Intentionally left empty */ }
59
+  while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
60 60
   buf[nbyte] = SPDR;
61 61
 }
62 62
 //------------------------------------------------------------------------------
63 63
 /** SPI send a byte */
64 64
 static void spiSend(uint8_t b) {
65 65
   SPDR = b;
66
-  while (!(SPSR & (1 << SPIF))) { /* Intentionally left empty */ }
66
+  while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
67 67
 }
68 68
 //------------------------------------------------------------------------------
69 69
 /** SPI send block - only one call so force inline */
@@ -71,12 +71,12 @@ static inline __attribute__((always_inline))
71 71
   void spiSendBlock(uint8_t token, const uint8_t* buf) {
72 72
   SPDR = token;
73 73
   for (uint16_t i = 0; i < 512; i += 2) {
74
-    while (!(SPSR & (1 << SPIF))) { /* Intentionally left empty */ }
74
+    while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
75 75
     SPDR = buf[i];
76
-    while (!(SPSR & (1 << SPIF))) { /* Intentionally left empty */ }
76
+    while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
77 77
     SPDR = buf[i + 1];
78 78
   }
79
-  while (!(SPSR & (1 << SPIF))) { /* Intentionally left empty */ }
79
+  while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
80 80
 }
81 81
 //------------------------------------------------------------------------------
82 82
 #else  // SOFTWARE_SPI

+ 4
- 4
Marlin/Sd2PinMap.h Vedi File

@@ -334,9 +334,9 @@ static inline __attribute__((always_inline))
334 334
   void setPinMode(uint8_t pin, uint8_t mode) {
335 335
   if (__builtin_constant_p(pin) && pin < digitalPinCount) {
336 336
     if (mode) {
337
-      *digitalPinMap[pin].ddr |= 1 << digitalPinMap[pin].bit;
337
+      *digitalPinMap[pin].ddr |= BIT(digitalPinMap[pin].bit);
338 338
     } else {
339
-      *digitalPinMap[pin].ddr &= ~(1 << digitalPinMap[pin].bit);
339
+      *digitalPinMap[pin].ddr &= ~BIT(digitalPinMap[pin].bit);
340 340
     }
341 341
   } else {
342 342
     badPinNumber();
@@ -354,9 +354,9 @@ static inline __attribute__((always_inline))
354 354
   void fastDigitalWrite(uint8_t pin, uint8_t value) {
355 355
   if (__builtin_constant_p(pin) && pin < digitalPinCount) {
356 356
     if (value) {
357
-      *digitalPinMap[pin].port |= 1 << digitalPinMap[pin].bit;
357
+      *digitalPinMap[pin].port |= BIT(digitalPinMap[pin].bit);
358 358
     } else {
359
-      *digitalPinMap[pin].port &= ~(1 << digitalPinMap[pin].bit);
359
+      *digitalPinMap[pin].port &= ~BIT(digitalPinMap[pin].bit);
360 360
     }
361 361
   } else {
362 362
     badPinNumber();

+ 2
- 2
Marlin/SdBaseFile.h Vedi File

@@ -171,9 +171,9 @@ static inline uint8_t FAT_SECOND(uint16_t fatTime) {
171 171
   return 2*(fatTime & 0X1F);
172 172
 }
173 173
 /** Default date for file timestamps is 1 Jan 2000 */
174
-uint16_t const FAT_DEFAULT_DATE = ((2000 - 1980) << 9) | (1 << 5) | 1;
174
+uint16_t const FAT_DEFAULT_DATE = ((2000 - 1980) << 9) | BIT(5) | 1;
175 175
 /** Default time for file timestamp is 1 am */
176
-uint16_t const FAT_DEFAULT_TIME = (1 << 11);
176
+uint16_t const FAT_DEFAULT_TIME = BIT(11);
177 177
 //------------------------------------------------------------------------------
178 178
 /**
179 179
  * \class SdBaseFile

+ 1
- 1
Marlin/SdVolume.cpp Vedi File

@@ -360,7 +360,7 @@ bool SdVolume::init(Sd2Card* dev, uint8_t part) {
360 360
   blocksPerCluster_ = fbs->sectorsPerCluster;
361 361
   // determine shift that is same as multiply by blocksPerCluster_
362 362
   clusterSizeShift_ = 0;
363
-  while (blocksPerCluster_ != (1 << clusterSizeShift_)) {
363
+  while (blocksPerCluster_ != BIT(clusterSizeShift_)) {
364 364
     // error if not power of 2
365 365
     if (clusterSizeShift_++ > 7) goto fail;
366 366
   }

+ 3
- 3
Marlin/dogm_lcd_implementation.h Vedi File

@@ -24,9 +24,9 @@
24 24
   #define BLEN_A 0
25 25
   #define BLEN_B 1
26 26
   #define BLEN_C 2
27
-  #define EN_A (1<<BLEN_A)
28
-  #define EN_B (1<<BLEN_B)
29
-  #define EN_C (1<<BLEN_C)
27
+  #define EN_A BIT(BLEN_A)
28
+  #define EN_B BIT(BLEN_B)
29
+  #define EN_C BIT(BLEN_C)
30 30
   #define LCD_CLICKED (buttons&EN_C)
31 31
 #endif
32 32
 

+ 1
- 2
Marlin/fastio.h Vedi File

@@ -13,8 +13,7 @@
13 13
 */
14 14
 
15 15
 #ifndef MASK
16
-/// MASKING- returns \f$2^PIN\f$
17
-#define MASK(PIN)  (1 << PIN)
16
+  #define MASK(PIN)  (1 << PIN)
18 17
 #endif
19 18
 
20 19
 /*

+ 2
- 0
Marlin/pins.h Vedi File

@@ -184,4 +184,6 @@
184 184
                         analogInputToDigitalPin(TEMP_BED_PIN) \
185 185
                        }
186 186
 
187
+#define HAS_DIGIPOTSS (DIGIPOTSS_PIN >= 0)
188
+
187 189
 #endif //__PINS_H

+ 5
- 0
Marlin/pins_RAMPS_13.h Vedi File

@@ -61,6 +61,11 @@
61 61
   #define FILWIDTH_PIN        5
62 62
 #endif
63 63
 
64
+#if defined(FILAMENT_RUNOUT_SENSOR)
65
+  // define digital pin 4 for the filament runout sensor. Use the RAMPS 1.4 digital input 4 on the servos connector
66
+  #define FILRUNOUT_PIN        4
67
+#endif
68
+
64 69
 #if MB(RAMPS_13_EFB) || MB(RAMPS_13_EFF)
65 70
   #define FAN_PIN            9 // (Sprinter config)
66 71
   #if MB(RAMPS_13_EFF)

+ 11
- 11
Marlin/planner.cpp Vedi File

@@ -59,7 +59,7 @@
59 59
 #include "language.h"
60 60
 
61 61
 //===========================================================================
62
-//=============================public variables ============================
62
+//============================= public variables ============================
63 63
 //===========================================================================
64 64
 
65 65
 unsigned long minsegmenttime;
@@ -623,37 +623,37 @@ block->steps_y = labs((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-positi
623 623
 #ifndef COREXY
624 624
   if (target[X_AXIS] < position[X_AXIS])
625 625
   {
626
-    block->direction_bits |= (1<<X_AXIS); 
626
+    block->direction_bits |= BIT(X_AXIS); 
627 627
   }
628 628
   if (target[Y_AXIS] < position[Y_AXIS])
629 629
   {
630
-    block->direction_bits |= (1<<Y_AXIS); 
630
+    block->direction_bits |= BIT(Y_AXIS); 
631 631
   }
632 632
 #else
633 633
   if (target[X_AXIS] < position[X_AXIS])
634 634
   {
635
-    block->direction_bits |= (1<<X_HEAD); //AlexBorro: Save the real Extruder (head) direction in X Axis
635
+    block->direction_bits |= BIT(X_HEAD); //AlexBorro: Save the real Extruder (head) direction in X Axis
636 636
   }
637 637
   if (target[Y_AXIS] < position[Y_AXIS])
638 638
   {
639
-    block->direction_bits |= (1<<Y_HEAD); //AlexBorro: Save the real Extruder (head) direction in Y Axis
639
+    block->direction_bits |= BIT(Y_HEAD); //AlexBorro: Save the real Extruder (head) direction in Y Axis
640 640
   }
641 641
   if ((target[X_AXIS]-position[X_AXIS]) + (target[Y_AXIS]-position[Y_AXIS]) < 0)
642 642
   {
643
-    block->direction_bits |= (1<<X_AXIS); //AlexBorro: Motor A direction (Incorrectly implemented as X_AXIS)
643
+    block->direction_bits |= BIT(X_AXIS); //AlexBorro: Motor A direction (Incorrectly implemented as X_AXIS)
644 644
   }
645 645
   if ((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-position[Y_AXIS]) < 0)
646 646
   {
647
-    block->direction_bits |= (1<<Y_AXIS); //AlexBorro: Motor B direction (Incorrectly implemented as Y_AXIS)
647
+    block->direction_bits |= BIT(Y_AXIS); //AlexBorro: Motor B direction (Incorrectly implemented as Y_AXIS)
648 648
   }
649 649
 #endif
650 650
   if (target[Z_AXIS] < position[Z_AXIS])
651 651
   {
652
-    block->direction_bits |= (1<<Z_AXIS); 
652
+    block->direction_bits |= BIT(Z_AXIS); 
653 653
   }
654 654
   if (target[E_AXIS] < position[E_AXIS])
655 655
   {
656
-    block->direction_bits |= (1<<E_AXIS); 
656
+    block->direction_bits |= BIT(E_AXIS); 
657 657
   }
658 658
 
659 659
   block->active_extruder = extruder;
@@ -864,7 +864,7 @@ Having the real displacement of the head, we can calculate the total movement le
864 864
   old_direction_bits = block->direction_bits;
865 865
   segment_time = lround((float)segment_time / speed_factor);
866 866
   
867
-  if((direction_change & (1<<X_AXIS)) == 0)
867
+  if((direction_change & BIT(X_AXIS)) == 0)
868 868
   {
869 869
     x_segment_time[0] += segment_time;
870 870
   }
@@ -874,7 +874,7 @@ Having the real displacement of the head, we can calculate the total movement le
874 874
     x_segment_time[1] = x_segment_time[0];
875 875
     x_segment_time[0] = segment_time;
876 876
   }
877
-  if((direction_change & (1<<Y_AXIS)) == 0)
877
+  if((direction_change & BIT(Y_AXIS)) == 0)
878 878
   {
879 879
     y_segment_time[0] += segment_time;
880 880
   }

+ 523
- 739
Marlin/stepper.cpp
File diff soppresso perché troppo grande
Vedi File


+ 5
- 5
Marlin/stepper.h Vedi File

@@ -25,26 +25,26 @@
25 25
 #include "stepper_indirection.h"
26 26
 
27 27
 #if EXTRUDERS > 3
28
-  #define WRITE_E_STEP(v) { if(current_block->active_extruder == 3) { E3_STEP_WRITE(v); } else { if(current_block->active_extruder == 2) { E2_STEP_WRITE(v); } else { if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }}}}
28
+  #define E_STEP_WRITE(v) { if(current_block->active_extruder == 3) { E3_STEP_WRITE(v); } else { if(current_block->active_extruder == 2) { E2_STEP_WRITE(v); } else { if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }}}}
29 29
   #define NORM_E_DIR() { if(current_block->active_extruder == 3) { E3_DIR_WRITE( !INVERT_E3_DIR); } else { if(current_block->active_extruder == 2) { E2_DIR_WRITE(!INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { E1_DIR_WRITE(!INVERT_E1_DIR); } else { E0_DIR_WRITE(!INVERT_E0_DIR); }}}}
30 30
   #define REV_E_DIR() { if(current_block->active_extruder == 3) { E3_DIR_WRITE(INVERT_E3_DIR); } else { if(current_block->active_extruder == 2) { E2_DIR_WRITE(INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { E1_DIR_WRITE(INVERT_E1_DIR); } else { E0_DIR_WRITE(INVERT_E0_DIR); }}}}
31 31
 #elif EXTRUDERS > 2
32
-  #define WRITE_E_STEP(v) { if(current_block->active_extruder == 2) { E2_STEP_WRITE(v); } else { if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }}}
32
+  #define E_STEP_WRITE(v) { if(current_block->active_extruder == 2) { E2_STEP_WRITE(v); } else { if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }}}
33 33
   #define NORM_E_DIR() { if(current_block->active_extruder == 2) { E2_DIR_WRITE(!INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { E1_DIR_WRITE(!INVERT_E1_DIR); } else { E0_DIR_WRITE(!INVERT_E0_DIR); }}}
34 34
   #define REV_E_DIR() { if(current_block->active_extruder == 2) { E2_DIR_WRITE(INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { E1_DIR_WRITE(INVERT_E1_DIR); } else { E0_DIR_WRITE(INVERT_E0_DIR); }}}
35 35
 #elif EXTRUDERS > 1
36 36
   #ifndef DUAL_X_CARRIAGE
37
-    #define WRITE_E_STEP(v) { if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }}
37
+    #define E_STEP_WRITE(v) { if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }}
38 38
     #define NORM_E_DIR() { if(current_block->active_extruder == 1) { E1_DIR_WRITE(!INVERT_E1_DIR); } else { E0_DIR_WRITE(!INVERT_E0_DIR); }}
39 39
     #define REV_E_DIR() { if(current_block->active_extruder == 1) { E1_DIR_WRITE(INVERT_E1_DIR); } else { E0_DIR_WRITE(INVERT_E0_DIR); }}
40 40
   #else
41 41
     extern bool extruder_duplication_enabled;
42
-    #define WRITE_E_STEP(v) { if(extruder_duplication_enabled) { E0_STEP_WRITE(v); E1_STEP_WRITE(v); } else if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }}
42
+    #define E_STEP_WRITE(v) { if(extruder_duplication_enabled) { E0_STEP_WRITE(v); E1_STEP_WRITE(v); } else if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }}
43 43
     #define NORM_E_DIR() { if(extruder_duplication_enabled) { E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); } else if(current_block->active_extruder == 1) { E1_DIR_WRITE(!INVERT_E1_DIR); } else { E0_DIR_WRITE(!INVERT_E0_DIR); }}
44 44
     #define REV_E_DIR() { if(extruder_duplication_enabled) { E0_DIR_WRITE(INVERT_E0_DIR); E1_DIR_WRITE(INVERT_E1_DIR); } else if(current_block->active_extruder == 1) { E1_DIR_WRITE(INVERT_E1_DIR); } else { E0_DIR_WRITE(INVERT_E0_DIR); }}
45 45
   #endif  
46 46
 #else
47
-  #define WRITE_E_STEP(v) E0_STEP_WRITE(v)
47
+  #define E_STEP_WRITE(v) E0_STEP_WRITE(v)
48 48
   #define NORM_E_DIR() E0_DIR_WRITE(!INVERT_E0_DIR)
49 49
   #define REV_E_DIR() E0_DIR_WRITE(INVERT_E0_DIR)
50 50
 #endif

+ 114
- 110
Marlin/temperature.cpp Vedi File

@@ -75,6 +75,10 @@
75 75
 //============================= public variables ============================
76 76
 //===========================================================================
77 77
 
78
+#ifdef K1 // Defined in Configuration.h in the PID settings
79
+  #define K2 (1.0-K1)
80
+#endif
81
+
78 82
 // Sampling period of the temperature routine
79 83
 #ifdef PID_dT
80 84
   #undef PID_dT
@@ -127,8 +131,6 @@ static volatile bool temp_meas_ready = false;
127 131
   static float pid_error[EXTRUDERS];
128 132
   static float temp_iState_min[EXTRUDERS];
129 133
   static float temp_iState_max[EXTRUDERS];
130
-  // static float pid_input[EXTRUDERS];
131
-  // static float pid_output[EXTRUDERS];
132 134
   static bool pid_reset[EXTRUDERS];
133 135
 #endif //PIDTEMP
134 136
 #ifdef PIDTEMPBED
@@ -546,12 +548,102 @@ void bed_max_temp_error(void) {
546 548
   _temp_error(-1, MSG_MAXTEMP_BED_OFF, MSG_ERR_MAXTEMP_BED);
547 549
 }
548 550
 
551
+float get_pid_output(int e) {
552
+  float pid_output;
553
+  #ifdef PIDTEMP
554
+    #ifndef PID_OPENLOOP
555
+      pid_error[e] = target_temperature[e] - current_temperature[e];
556
+      if (pid_error[e] > PID_FUNCTIONAL_RANGE) {
557
+        pid_output = BANG_MAX;
558
+        pid_reset[e] = true;
559
+      }
560
+      else if (pid_error[e] < -PID_FUNCTIONAL_RANGE || target_temperature[e] == 0) {
561
+        pid_output = 0;
562
+        pid_reset[e] = true;
563
+      }
564
+      else {
565
+        if (pid_reset[e]) {
566
+          temp_iState[e] = 0.0;
567
+          pid_reset[e] = false;
568
+        }
569
+        pTerm[e] = PID_PARAM(Kp,e) * pid_error[e];
570
+        temp_iState[e] += pid_error[e];
571
+        temp_iState[e] = constrain(temp_iState[e], temp_iState_min[e], temp_iState_max[e]);
572
+        iTerm[e] = PID_PARAM(Ki,e) * temp_iState[e];
573
+
574
+        dTerm[e] = K2 * PID_PARAM(Kd,e) * (current_temperature[e] - temp_dState[e]) + K1 * dTerm[e];
575
+        pid_output = pTerm[e] + iTerm[e] - dTerm[e];
576
+        if (pid_output > PID_MAX) {
577
+          if (pid_error[e] > 0) temp_iState[e] -= pid_error[e]; // conditional un-integration
578
+          pid_output = PID_MAX;
579
+        }
580
+        else if (pid_output < 0) {
581
+          if (pid_error[e] < 0) temp_iState[e] -= pid_error[e]; // conditional un-integration
582
+          pid_output = 0;
583
+        }
584
+      }
585
+      temp_dState[e] = current_temperature[e];
586
+    #else
587
+      pid_output = constrain(target_temperature[e], 0, PID_MAX);
588
+    #endif //PID_OPENLOOP
589
+
590
+    #ifdef PID_DEBUG
591
+      SERIAL_ECHO_START;
592
+      SERIAL_ECHO(MSG_PID_DEBUG);
593
+      SERIAL_ECHO(e);
594
+      SERIAL_ECHO(MSG_PID_DEBUG_INPUT);
595
+      SERIAL_ECHO(current_temperature[e]);
596
+      SERIAL_ECHO(MSG_PID_DEBUG_OUTPUT);
597
+      SERIAL_ECHO(pid_output);
598
+      SERIAL_ECHO(MSG_PID_DEBUG_PTERM);
599
+      SERIAL_ECHO(pTerm[e]);
600
+      SERIAL_ECHO(MSG_PID_DEBUG_ITERM);
601
+      SERIAL_ECHO(iTerm[e]);
602
+      SERIAL_ECHO(MSG_PID_DEBUG_DTERM);
603
+      SERIAL_ECHOLN(dTerm[e]);
604
+    #endif //PID_DEBUG
605
+
606
+  #else /* PID off */
607
+    pid_output = (current_temperature[e] < target_temperature[e]) ? PID_MAX : 0;
608
+  #endif
609
+
610
+  return pid_output;
611
+}
612
+
613
+#ifdef PIDTEMPBED
614
+  float get_pid_output_bed() {
615
+    float pid_output;
616
+    #ifndef PID_OPENLOOP
617
+      pid_error_bed = target_temperature_bed - current_temperature_bed;
618
+      pTerm_bed = bedKp * pid_error_bed;
619
+      temp_iState_bed += pid_error_bed;
620
+      temp_iState_bed = constrain(temp_iState_bed, temp_iState_min_bed, temp_iState_max_bed);
621
+      iTerm_bed = bedKi * temp_iState_bed;
622
+
623
+      dTerm_bed = K2 * bedKd * (current_temperature_bed - temp_dState_bed) + K1 * dTerm_bed;
624
+      temp_dState_bed = current_temperature_bed;
625
+
626
+      pid_output = pTerm_bed + iTerm_bed - dTerm_bed;
627
+      if (pid_output > MAX_BED_POWER) {
628
+        if (pid_error_bed > 0) temp_iState_bed -= pid_error_bed; // conditional un-integration
629
+        pid_output = MAX_BED_POWER;
630
+      }
631
+      else if (pid_output < 0) {
632
+        if (pid_error_bed < 0) temp_iState_bed -= pid_error_bed; // conditional un-integration
633
+        pid_output = 0;
634
+      }
635
+    #else
636
+      pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER);
637
+    #endif // PID_OPENLOOP
638
+
639
+    return pid_output;
640
+  }
641
+#endif
642
+
549 643
 void manage_heater() {
550 644
 
551 645
   if (!temp_meas_ready) return;
552 646
 
553
-  float pid_input, pid_output;
554
-
555 647
   updateTemperaturesFromRawValues();
556 648
 
557 649
   #ifdef HEATER_0_USES_MAX6675
@@ -569,69 +661,7 @@ void manage_heater() {
569 661
       thermal_runaway_protection(&thermal_runaway_state_machine[e], &thermal_runaway_timer[e], current_temperature[e], target_temperature[e], e, THERMAL_RUNAWAY_PROTECTION_PERIOD, THERMAL_RUNAWAY_PROTECTION_HYSTERESIS);
570 662
     #endif
571 663
 
572
-    #ifdef PIDTEMP
573
-      pid_input = current_temperature[e];
574
-
575
-      #ifndef PID_OPENLOOP
576
-        pid_error[e] = target_temperature[e] - pid_input;
577
-        if (pid_error[e] > PID_FUNCTIONAL_RANGE) {
578
-          pid_output = BANG_MAX;
579
-          pid_reset[e] = true;
580
-        }
581
-        else if (pid_error[e] < -PID_FUNCTIONAL_RANGE || target_temperature[e] == 0) {
582
-          pid_output = 0;
583
-          pid_reset[e] = true;
584
-        }
585
-        else {
586
-          if (pid_reset[e] == true) {
587
-            temp_iState[e] = 0.0;
588
-            pid_reset[e] = false;
589
-          }
590
-          pTerm[e] = PID_PARAM(Kp,e) * pid_error[e];
591
-          temp_iState[e] += pid_error[e];
592
-          temp_iState[e] = constrain(temp_iState[e], temp_iState_min[e], temp_iState_max[e]);
593
-          iTerm[e] = PID_PARAM(Ki,e) * temp_iState[e];
594
-
595
-          //K1 defined in Configuration.h in the PID settings
596
-          #define K2 (1.0-K1)
597
-          dTerm[e] = (PID_PARAM(Kd,e) * (pid_input - temp_dState[e])) * K2 + (K1 * dTerm[e]);
598
-          pid_output = pTerm[e] + iTerm[e] - dTerm[e];
599
-          if (pid_output > PID_MAX) {
600
-            if (pid_error[e] > 0) temp_iState[e] -= pid_error[e]; // conditional un-integration
601
-            pid_output = PID_MAX;
602
-          }
603
-          else if (pid_output < 0) {
604
-            if (pid_error[e] < 0) temp_iState[e] -= pid_error[e]; // conditional un-integration
605
-            pid_output = 0;
606
-          }
607
-        }
608
-        temp_dState[e] = pid_input;
609
-      #else
610
-        pid_output = constrain(target_temperature[e], 0, PID_MAX);
611
-      #endif //PID_OPENLOOP
612
-
613
-      #ifdef PID_DEBUG
614
-        SERIAL_ECHO_START;
615
-        SERIAL_ECHO(MSG_PID_DEBUG);
616
-        SERIAL_ECHO(e);
617
-        SERIAL_ECHO(MSG_PID_DEBUG_INPUT);
618
-        SERIAL_ECHO(pid_input);
619
-        SERIAL_ECHO(MSG_PID_DEBUG_OUTPUT);
620
-        SERIAL_ECHO(pid_output);
621
-        SERIAL_ECHO(MSG_PID_DEBUG_PTERM);
622
-        SERIAL_ECHO(pTerm[e]);
623
-        SERIAL_ECHO(MSG_PID_DEBUG_ITERM);
624
-        SERIAL_ECHO(iTerm[e]);
625
-        SERIAL_ECHO(MSG_PID_DEBUG_DTERM);
626
-        SERIAL_ECHOLN(dTerm[e]);
627
-      #endif //PID_DEBUG
628
-
629
-    #else /* PID off */
630
-
631
-      pid_output = 0;
632
-      if (current_temperature[e] < target_temperature[e]) pid_output = PID_MAX;
633
-
634
-    #endif
664
+    float pid_output = get_pid_output(e);
635 665
 
636 666
     // Check if temperature is within the correct range
637 667
     soft_pwm[e] = current_temperature[e] > minttemp[e] && current_temperature[e] < maxttemp[e] ? (int)pid_output >> 1 : 0;
@@ -678,33 +708,7 @@ void manage_heater() {
678 708
     #endif
679 709
 
680 710
     #ifdef PIDTEMPBED
681
-      pid_input = current_temperature_bed;
682
-
683
-      #ifndef PID_OPENLOOP
684
-        pid_error_bed = target_temperature_bed - pid_input;
685
-        pTerm_bed = bedKp * pid_error_bed;
686
-        temp_iState_bed += pid_error_bed;
687
-        temp_iState_bed = constrain(temp_iState_bed, temp_iState_min_bed, temp_iState_max_bed);
688
-        iTerm_bed = bedKi * temp_iState_bed;
689
-
690
-        //K1 defined in Configuration.h in the PID settings
691
-  		  #define K2 (1.0-K1)
692
-  		  dTerm_bed = (bedKd * (pid_input - temp_dState_bed))*K2 + (K1 * dTerm_bed);
693
-        temp_dState_bed = pid_input;
694
-
695
-        pid_output = pTerm_bed + iTerm_bed - dTerm_bed;
696
-        if (pid_output > MAX_BED_POWER) {
697
-          if (pid_error_bed > 0) temp_iState_bed -= pid_error_bed; // conditional un-integration
698
-          pid_output = MAX_BED_POWER;
699
-        }
700
-        else if (pid_output < 0) {
701
-          if (pid_error_bed < 0) temp_iState_bed -= pid_error_bed; // conditional un-integration
702
-          pid_output = 0;
703
-        }
704
-
705
-      #else
706
-        pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER);
707
-      #endif //PID_OPENLOOP
711
+      float pid_output = get_pid_output_bed();
708 712
 
709 713
       soft_pwm_bed = current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP ? (int)pid_output >> 1 : 0;
710 714
 
@@ -878,8 +882,8 @@ void tp_init()
878 882
 {
879 883
   #if MB(RUMBA) && ((TEMP_SENSOR_0==-1)||(TEMP_SENSOR_1==-1)||(TEMP_SENSOR_2==-1)||(TEMP_SENSOR_BED==-1))
880 884
     //disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector
881
-    MCUCR=(1<<JTD);
882
-    MCUCR=(1<<JTD);
885
+    MCUCR=BIT(JTD);
886
+    MCUCR=BIT(JTD);
883 887
   #endif
884 888
   
885 889
   // Finish init of mult extruder arrays 
@@ -937,13 +941,13 @@ void tp_init()
937 941
   #endif //HEATER_0_USES_MAX6675
938 942
 
939 943
   #ifdef DIDR2
940
-    #define ANALOG_SELECT(pin) do{ if (pin < 8) DIDR0 |= 1 << pin; else DIDR2 |= 1 << (pin - 8); }while(0)
944
+    #define ANALOG_SELECT(pin) do{ if (pin < 8) DIDR0 |= BIT(pin); else DIDR2 |= BIT(pin - 8); }while(0)
941 945
   #else
942
-    #define ANALOG_SELECT(pin) do{ DIDR0 |= 1 << pin; }while(0)
946
+    #define ANALOG_SELECT(pin) do{ DIDR0 |= BIT(pin); }while(0)
943 947
   #endif
944 948
 
945 949
   // Set analog inputs
946
-  ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
950
+  ADCSRA = BIT(ADEN) | BIT(ADSC) | BIT(ADIF) | 0x07;
947 951
   DIDR0 = 0;
948 952
   #ifdef DIDR2
949 953
     DIDR2 = 0;
@@ -970,7 +974,7 @@ void tp_init()
970 974
   // Use timer0 for temperature measurement
971 975
   // Interleave temperature interrupt with millies interrupt
972 976
   OCR0B = 128;
973
-  TIMSK0 |= (1<<OCIE0B);  
977
+  TIMSK0 |= BIT(OCIE0B);  
974 978
   
975 979
   // Wait for temperature measurement to settle
976 980
   delay(250);
@@ -1174,12 +1178,12 @@ void disable_heater() {
1174 1178
     max6675_temp = 0;
1175 1179
 
1176 1180
     #ifdef PRR
1177
-      PRR &= ~(1<<PRSPI);
1181
+      PRR &= ~BIT(PRSPI);
1178 1182
     #elif defined(PRR0)
1179
-      PRR0 &= ~(1<<PRSPI);
1183
+      PRR0 &= ~BIT(PRSPI);
1180 1184
     #endif
1181 1185
 
1182
-    SPCR = (1<<MSTR) | (1<<SPE) | (1<<SPR0);
1186
+    SPCR = BIT(MSTR) | BIT(SPE) | BIT(SPR0);
1183 1187
 
1184 1188
     // enable TT_MAX6675
1185 1189
     WRITE(MAX6675_SS, 0);
@@ -1190,13 +1194,13 @@ void disable_heater() {
1190 1194
 
1191 1195
     // read MSB
1192 1196
     SPDR = 0;
1193
-    for (;(SPSR & (1<<SPIF)) == 0;);
1197
+    for (;(SPSR & BIT(SPIF)) == 0;);
1194 1198
     max6675_temp = SPDR;
1195 1199
     max6675_temp <<= 8;
1196 1200
 
1197 1201
     // read LSB
1198 1202
     SPDR = 0;
1199
-    for (;(SPSR & (1<<SPIF)) == 0;);
1203
+    for (;(SPSR & BIT(SPIF)) == 0;);
1200 1204
     max6675_temp |= SPDR;
1201 1205
 
1202 1206
     // disable TT_MAX6675
@@ -1246,7 +1250,7 @@ ISR(TIMER0_COMPB_vect) {
1246 1250
   static unsigned long raw_temp_3_value = 0;
1247 1251
   static unsigned long raw_temp_bed_value = 0;
1248 1252
   static TempState temp_state = StartupDelay;
1249
-  static unsigned char pwm_count = (1 << SOFT_PWM_SCALE);
1253
+  static unsigned char pwm_count = BIT(SOFT_PWM_SCALE);
1250 1254
 
1251 1255
   // Static members for each heater
1252 1256
   #ifdef SLOW_PWM_HEATERS
@@ -1331,7 +1335,7 @@ ISR(TIMER0_COMPB_vect) {
1331 1335
       if (soft_pwm_fan < pwm_count) WRITE_FAN(0);
1332 1336
     #endif
1333 1337
     
1334
-    pwm_count += (1 << SOFT_PWM_SCALE);
1338
+    pwm_count += BIT(SOFT_PWM_SCALE);
1335 1339
     pwm_count &= 0x7f;
1336 1340
   
1337 1341
   #else // SLOW_PWM_HEATERS
@@ -1412,7 +1416,7 @@ ISR(TIMER0_COMPB_vect) {
1412 1416
       if (soft_pwm_fan < pwm_count) WRITE_FAN(0);
1413 1417
     #endif //FAN_SOFT_PWM
1414 1418
 
1415
-    pwm_count += (1 << SOFT_PWM_SCALE);
1419
+    pwm_count += BIT(SOFT_PWM_SCALE);
1416 1420
     pwm_count &= 0x7f;
1417 1421
 
1418 1422
     // increment slow_pwm_count only every 64 pwm_count circa 65.5ms
@@ -1438,9 +1442,9 @@ ISR(TIMER0_COMPB_vect) {
1438 1442
   
1439 1443
   #endif // SLOW_PWM_HEATERS
1440 1444
 
1441
-  #define SET_ADMUX_ADCSRA(pin) ADMUX = (1 << REFS0) | (pin & 0x07); ADCSRA |= 1<<ADSC
1445
+  #define SET_ADMUX_ADCSRA(pin) ADMUX = BIT(REFS0) | (pin & 0x07); ADCSRA |= BIT(ADSC)
1442 1446
   #ifdef MUX5
1443
-    #define START_ADC(pin) if (pin > 7) ADCSRB = 1 << MUX5; else ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
1447
+    #define START_ADC(pin) if (pin > 7) ADCSRB = BIT(MUX5); else ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
1444 1448
   #else
1445 1449
     #define START_ADC(pin) ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
1446 1450
   #endif

+ 2
- 2
Marlin/ultralcd.cpp Vedi File

@@ -1426,7 +1426,7 @@ void lcd_buttons_update() {
1426 1426
       WRITE(SHIFT_LD, HIGH);
1427 1427
       for(int8_t i = 0; i < 8; i++) {
1428 1428
         newbutton_reprapworld_keypad >>= 1;
1429
-        if (READ(SHIFT_OUT)) newbutton_reprapworld_keypad |= (1 << 7);
1429
+        if (READ(SHIFT_OUT)) newbutton_reprapworld_keypad |= BIT(7);
1430 1430
         WRITE(SHIFT_CLK, HIGH);
1431 1431
         WRITE(SHIFT_CLK, LOW);
1432 1432
       }
@@ -1439,7 +1439,7 @@ void lcd_buttons_update() {
1439 1439
     unsigned char tmp_buttons = 0;
1440 1440
     for(int8_t i=0; i<8; i++) {
1441 1441
       newbutton >>= 1;
1442
-      if (READ(SHIFT_OUT)) newbutton |= (1 << 7);
1442
+      if (READ(SHIFT_OUT)) newbutton |= BIT(7);
1443 1443
       WRITE(SHIFT_CLK, HIGH);
1444 1444
       WRITE(SHIFT_CLK, LOW);
1445 1445
     }

+ 19
- 19
Marlin/ultralcd.h Vedi File

@@ -57,20 +57,20 @@
57 57
   void lcd_ignore_click(bool b=true);
58 58
 
59 59
   #ifdef NEWPANEL
60
-    #define EN_C (1<<BLEN_C)
61
-    #define EN_B (1<<BLEN_B)
62
-    #define EN_A (1<<BLEN_A)
60
+    #define EN_C BIT(BLEN_C)
61
+    #define EN_B BIT(BLEN_B)
62
+    #define EN_A BIT(BLEN_A)
63 63
 
64 64
     #define LCD_CLICKED (buttons&EN_C)
65 65
     #ifdef REPRAPWORLD_KEYPAD
66
-  	  #define EN_REPRAPWORLD_KEYPAD_F3 (1<<BLEN_REPRAPWORLD_KEYPAD_F3)
67
-  	  #define EN_REPRAPWORLD_KEYPAD_F2 (1<<BLEN_REPRAPWORLD_KEYPAD_F2)
68
-  	  #define EN_REPRAPWORLD_KEYPAD_F1 (1<<BLEN_REPRAPWORLD_KEYPAD_F1)
69
-  	  #define EN_REPRAPWORLD_KEYPAD_UP (1<<BLEN_REPRAPWORLD_KEYPAD_UP)
70
-  	  #define EN_REPRAPWORLD_KEYPAD_RIGHT (1<<BLEN_REPRAPWORLD_KEYPAD_RIGHT)
71
-  	  #define EN_REPRAPWORLD_KEYPAD_MIDDLE (1<<BLEN_REPRAPWORLD_KEYPAD_MIDDLE)
72
-  	  #define EN_REPRAPWORLD_KEYPAD_DOWN (1<<BLEN_REPRAPWORLD_KEYPAD_DOWN)
73
-  	  #define EN_REPRAPWORLD_KEYPAD_LEFT (1<<BLEN_REPRAPWORLD_KEYPAD_LEFT)
66
+  	  #define EN_REPRAPWORLD_KEYPAD_F3 BIT(BLEN_REPRAPWORLD_KEYPAD_F3)
67
+  	  #define EN_REPRAPWORLD_KEYPAD_F2 BIT(BLEN_REPRAPWORLD_KEYPAD_F2)
68
+  	  #define EN_REPRAPWORLD_KEYPAD_F1 BIT(BLEN_REPRAPWORLD_KEYPAD_F1)
69
+  	  #define EN_REPRAPWORLD_KEYPAD_UP BIT(BLEN_REPRAPWORLD_KEYPAD_UP)
70
+  	  #define EN_REPRAPWORLD_KEYPAD_RIGHT BIT(BLEN_REPRAPWORLD_KEYPAD_RIGHT)
71
+  	  #define EN_REPRAPWORLD_KEYPAD_MIDDLE BIT(BLEN_REPRAPWORLD_KEYPAD_MIDDLE)
72
+  	  #define EN_REPRAPWORLD_KEYPAD_DOWN BIT(BLEN_REPRAPWORLD_KEYPAD_DOWN)
73
+  	  #define EN_REPRAPWORLD_KEYPAD_LEFT BIT(BLEN_REPRAPWORLD_KEYPAD_LEFT)
74 74
 
75 75
   	  #define LCD_CLICKED ((buttons&EN_C) || (buttons_reprapworld_keypad&EN_REPRAPWORLD_KEYPAD_F1))
76 76
   	  #define REPRAPWORLD_KEYPAD_MOVE_Z_UP (buttons_reprapworld_keypad&EN_REPRAPWORLD_KEYPAD_F2)
@@ -83,14 +83,14 @@
83 83
     #endif //REPRAPWORLD_KEYPAD
84 84
   #else
85 85
     //atomic, do not change
86
-    #define B_LE (1<<BL_LE)
87
-    #define B_UP (1<<BL_UP)
88
-    #define B_MI (1<<BL_MI)
89
-    #define B_DW (1<<BL_DW)
90
-    #define B_RI (1<<BL_RI)
91
-    #define B_ST (1<<BL_ST)
92
-    #define EN_B (1<<BLEN_B)
93
-    #define EN_A (1<<BLEN_A)
86
+    #define B_LE BIT(BL_LE)
87
+    #define B_UP BIT(BL_UP)
88
+    #define B_MI BIT(BL_MI)
89
+    #define B_DW BIT(BL_DW)
90
+    #define B_RI BIT(BL_RI)
91
+    #define B_ST BIT(BL_ST)
92
+    #define EN_B BIT(BLEN_B)
93
+    #define EN_A BIT(BLEN_A)
94 94
     
95 95
     #define LCD_CLICKED ((buttons&B_MI)||(buttons&B_ST))
96 96
   #endif//NEWPANEL

+ 17
- 17
Marlin/ultralcd_implementation_hitachi_HD44780.h Vedi File

@@ -24,13 +24,13 @@
24 24
 #define BLEN_B 1
25 25
 #define BLEN_A 0
26 26
 
27
-#define EN_B (1<<BLEN_B) // The two encoder pins are connected through BTN_EN1 and BTN_EN2
28
-#define EN_A (1<<BLEN_A)
27
+#define EN_B BIT(BLEN_B) // The two encoder pins are connected through BTN_EN1 and BTN_EN2
28
+#define EN_A BIT(BLEN_A)
29 29
 
30 30
 #if defined(BTN_ENC) && BTN_ENC > -1
31 31
   // encoder click is directly connected
32 32
   #define BLEN_C 2 
33
-  #define EN_C (1<<BLEN_C) 
33
+  #define EN_C BIT(BLEN_C) 
34 34
 #endif 
35 35
   
36 36
 //
@@ -85,14 +85,14 @@
85 85
     
86 86
     #define REPRAPWORLD_BTN_OFFSET 3 // bit offset into buttons for shift register values
87 87
 
88
-    #define EN_REPRAPWORLD_KEYPAD_F3 (1<<(BLEN_REPRAPWORLD_KEYPAD_F3+REPRAPWORLD_BTN_OFFSET))
89
-    #define EN_REPRAPWORLD_KEYPAD_F2 (1<<(BLEN_REPRAPWORLD_KEYPAD_F2+REPRAPWORLD_BTN_OFFSET))
90
-    #define EN_REPRAPWORLD_KEYPAD_F1 (1<<(BLEN_REPRAPWORLD_KEYPAD_F1+REPRAPWORLD_BTN_OFFSET))
91
-    #define EN_REPRAPWORLD_KEYPAD_UP (1<<(BLEN_REPRAPWORLD_KEYPAD_UP+REPRAPWORLD_BTN_OFFSET))
92
-    #define EN_REPRAPWORLD_KEYPAD_RIGHT (1<<(BLEN_REPRAPWORLD_KEYPAD_RIGHT+REPRAPWORLD_BTN_OFFSET))
93
-    #define EN_REPRAPWORLD_KEYPAD_MIDDLE (1<<(BLEN_REPRAPWORLD_KEYPAD_MIDDLE+REPRAPWORLD_BTN_OFFSET))
94
-    #define EN_REPRAPWORLD_KEYPAD_DOWN (1<<(BLEN_REPRAPWORLD_KEYPAD_DOWN+REPRAPWORLD_BTN_OFFSET))
95
-    #define EN_REPRAPWORLD_KEYPAD_LEFT (1<<(BLEN_REPRAPWORLD_KEYPAD_LEFT+REPRAPWORLD_BTN_OFFSET))
88
+    #define EN_REPRAPWORLD_KEYPAD_F3 BIT((BLEN_REPRAPWORLD_KEYPAD_F3+REPRAPWORLD_BTN_OFFSET))
89
+    #define EN_REPRAPWORLD_KEYPAD_F2 BIT((BLEN_REPRAPWORLD_KEYPAD_F2+REPRAPWORLD_BTN_OFFSET))
90
+    #define EN_REPRAPWORLD_KEYPAD_F1 BIT((BLEN_REPRAPWORLD_KEYPAD_F1+REPRAPWORLD_BTN_OFFSET))
91
+    #define EN_REPRAPWORLD_KEYPAD_UP BIT((BLEN_REPRAPWORLD_KEYPAD_UP+REPRAPWORLD_BTN_OFFSET))
92
+    #define EN_REPRAPWORLD_KEYPAD_RIGHT BIT((BLEN_REPRAPWORLD_KEYPAD_RIGHT+REPRAPWORLD_BTN_OFFSET))
93
+    #define EN_REPRAPWORLD_KEYPAD_MIDDLE BIT((BLEN_REPRAPWORLD_KEYPAD_MIDDLE+REPRAPWORLD_BTN_OFFSET))
94
+    #define EN_REPRAPWORLD_KEYPAD_DOWN BIT((BLEN_REPRAPWORLD_KEYPAD_DOWN+REPRAPWORLD_BTN_OFFSET))
95
+    #define EN_REPRAPWORLD_KEYPAD_LEFT BIT((BLEN_REPRAPWORLD_KEYPAD_LEFT+REPRAPWORLD_BTN_OFFSET))
96 96
 
97 97
     #define LCD_CLICKED ((buttons&EN_C) || (buttons&EN_REPRAPWORLD_KEYPAD_F1))
98 98
     #define REPRAPWORLD_KEYPAD_MOVE_Y_DOWN (buttons&EN_REPRAPWORLD_KEYPAD_DOWN)
@@ -113,12 +113,12 @@
113 113
   #define BL_ST 2
114 114
 
115 115
   //automatic, do not change
116
-  #define B_LE (1<<BL_LE)
117
-  #define B_UP (1<<BL_UP)
118
-  #define B_MI (1<<BL_MI)
119
-  #define B_DW (1<<BL_DW)
120
-  #define B_RI (1<<BL_RI)
121
-  #define B_ST (1<<BL_ST)
116
+  #define B_LE BIT(BL_LE)
117
+  #define B_UP BIT(BL_UP)
118
+  #define B_MI BIT(BL_MI)
119
+  #define B_DW BIT(BL_DW)
120
+  #define B_RI BIT(BL_RI)
121
+  #define B_ST BIT(BL_ST)
122 122
   
123 123
   #define LCD_CLICKED (buttons&(B_MI|B_ST))
124 124
 #endif

+ 6
- 0
Marlin/ultralcd_st7920_u8glib_rrd.h Vedi File

@@ -27,9 +27,15 @@ static void ST7920_SWSPI_SND_8BIT(uint8_t val)
27 27
   for( i=0; i<8; i++ )
28 28
   {
29 29
     WRITE(ST7920_CLK_PIN,0);
30
+    #if F_CPU == 20000000
31
+      __asm__("nop\n\t"); 
32
+    #endif
30 33
     WRITE(ST7920_DAT_PIN,val&0x80); 
31 34
     val<<=1;
32 35
     WRITE(ST7920_CLK_PIN,1);
36
+    #if F_CPU == 20000000
37
+      __asm__("nop\n\t""nop\n\t"); 
38
+    #endif
33 39
   }
34 40
 }
35 41
 

+ 4
- 4
Marlin/vector_3.cpp Vedi File

@@ -79,11 +79,11 @@ void vector_3::debug(char* title)
79 79
 {
80 80
 	SERIAL_PROTOCOL(title);
81 81
 	SERIAL_PROTOCOLPGM(" x: ");
82
-	SERIAL_PROTOCOL(x);
82
+	SERIAL_PROTOCOL_F(x, 6);
83 83
 	SERIAL_PROTOCOLPGM(" y: ");
84
-	SERIAL_PROTOCOL(y);
84
+	SERIAL_PROTOCOL_F(y, 6);
85 85
 	SERIAL_PROTOCOLPGM(" z: ");
86
-	SERIAL_PROTOCOL(z);
86
+	SERIAL_PROTOCOL_F(z, 6);
87 87
 	SERIAL_EOL;
88 88
 }
89 89
 
@@ -150,7 +150,7 @@ void matrix_3x3::debug(char* title) {
150 150
   int count = 0;
151 151
   for(int i=0; i<3; i++) {
152 152
     for(int j=0; j<3; j++) {
153
-      SERIAL_PROTOCOL(matrix[count] + 0.0001);
153
+      SERIAL_PROTOCOL_F(matrix[count], 6);
154 154
       SERIAL_PROTOCOLPGM(" ");
155 155
       count++;
156 156
     }

Loading…
Annulla
Salva