Bladeren bron

- Rename WRITE_E_STEP for consistency

- Add BIT and TEST macros
- Add _APPLY_ macros to stepper.cpp to help with consolidation
- Consolidate code in stepper.cpp using macros
- Apply standards in stepper.cpp
- Use >= 0 instead of > -1 as a better semantic
- Replace DUAL_Y_CARRIAGE with Y_DUAL_STEPPER_DRIVERS
Scott Lahteine 9 jaren geleden
bovenliggende
commit
c37f7d15c9

+ 3
- 0
Marlin/Marlin.h Bestand weergeven

@@ -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)

+ 2
- 2
Marlin/Marlin.ino Bestand weergeven

@@ -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 Bestand weergeven

@@ -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 Bestand weergeven

@@ -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 Bestand weergeven

@@ -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
 

+ 6
- 6
Marlin/Marlin_main.cpp Bestand weergeven

@@ -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
 
@@ -4190,7 +4190,7 @@ inline void gcode_M503() {
4190 4190
  * M907: Set digital trimpot motor current using axis codes X, Y, Z, E, B, S
4191 4191
  */
4192 4192
 inline void gcode_M907() {
4193
-  #if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
4193
+  #if HAS_DIGIPOTSS
4194 4194
     for (int i=0;i<NUM_AXIS;i++)
4195 4195
       if (code_seen(axis_codes[i])) digipot_current(i, code_value());
4196 4196
     if (code_seen('B')) digipot_current(4, code_value());
@@ -4213,7 +4213,7 @@ inline void gcode_M907() {
4213 4213
   #endif
4214 4214
 }
4215 4215
 
4216
-#if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
4216
+#if HAS_DIGIPOTSS
4217 4217
 
4218 4218
   /**
4219 4219
    * M908: Control digital trimpot directly (M908 P<pin> S<current>)
@@ -4225,7 +4225,7 @@ inline void gcode_M907() {
4225 4225
       );
4226 4226
   }
4227 4227
 
4228
-#endif // DIGIPOTSS_PIN
4228
+#endif // HAS_DIGIPOTSS
4229 4229
 
4230 4230
 // M350 Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers.
4231 4231
 inline void gcode_M350() {
@@ -4812,11 +4812,11 @@ void process_commands() {
4812 4812
         gcode_M907();
4813 4813
         break;
4814 4814
 
4815
-      #if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
4815
+      #if HAS_DIGIPOTSS
4816 4816
         case 908: // M908 Control digital trimpot directly.
4817 4817
           gcode_M908();
4818 4818
           break;
4819
-      #endif // DIGIPOTSS_PIN
4819
+      #endif // HAS_DIGIPOTSS
4820 4820
 
4821 4821
       case 350: // M350 Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers.
4822 4822
         gcode_M350();

+ 9
- 9
Marlin/Sd2Card.cpp Bestand weergeven

@@ -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 Bestand weergeven

@@ -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 Bestand weergeven

@@ -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 Bestand weergeven

@@ -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 Bestand weergeven

@@ -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 Bestand weergeven

@@ -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 Bestand weergeven

@@ -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

+ 11
- 11
Marlin/planner.cpp Bestand weergeven

@@ -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
Diff onderdrukt omdat het te groot bestand
Bestand weergeven


+ 5
- 5
Marlin/stepper.h Bestand weergeven

@@ -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

+ 16
- 16
Marlin/temperature.cpp Bestand weergeven

@@ -878,8 +878,8 @@ void tp_init()
878 878
 {
879 879
   #if MB(RUMBA) && ((TEMP_SENSOR_0==-1)||(TEMP_SENSOR_1==-1)||(TEMP_SENSOR_2==-1)||(TEMP_SENSOR_BED==-1))
880 880
     //disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector
881
-    MCUCR=(1<<JTD);
882
-    MCUCR=(1<<JTD);
881
+    MCUCR=BIT(JTD);
882
+    MCUCR=BIT(JTD);
883 883
   #endif
884 884
   
885 885
   // Finish init of mult extruder arrays 
@@ -937,13 +937,13 @@ void tp_init()
937 937
   #endif //HEATER_0_USES_MAX6675
938 938
 
939 939
   #ifdef DIDR2
940
-    #define ANALOG_SELECT(pin) do{ if (pin < 8) DIDR0 |= 1 << pin; else DIDR2 |= 1 << (pin - 8); }while(0)
940
+    #define ANALOG_SELECT(pin) do{ if (pin < 8) DIDR0 |= BIT(pin); else DIDR2 |= BIT(pin - 8); }while(0)
941 941
   #else
942
-    #define ANALOG_SELECT(pin) do{ DIDR0 |= 1 << pin; }while(0)
942
+    #define ANALOG_SELECT(pin) do{ DIDR0 |= BIT(pin); }while(0)
943 943
   #endif
944 944
 
945 945
   // Set analog inputs
946
-  ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
946
+  ADCSRA = BIT(ADEN) | BIT(ADSC) | BIT(ADIF) | 0x07;
947 947
   DIDR0 = 0;
948 948
   #ifdef DIDR2
949 949
     DIDR2 = 0;
@@ -970,7 +970,7 @@ void tp_init()
970 970
   // Use timer0 for temperature measurement
971 971
   // Interleave temperature interrupt with millies interrupt
972 972
   OCR0B = 128;
973
-  TIMSK0 |= (1<<OCIE0B);  
973
+  TIMSK0 |= BIT(OCIE0B);  
974 974
   
975 975
   // Wait for temperature measurement to settle
976 976
   delay(250);
@@ -1174,12 +1174,12 @@ void disable_heater() {
1174 1174
     max6675_temp = 0;
1175 1175
 
1176 1176
     #ifdef PRR
1177
-      PRR &= ~(1<<PRSPI);
1177
+      PRR &= ~BIT(PRSPI);
1178 1178
     #elif defined(PRR0)
1179
-      PRR0 &= ~(1<<PRSPI);
1179
+      PRR0 &= ~BIT(PRSPI);
1180 1180
     #endif
1181 1181
 
1182
-    SPCR = (1<<MSTR) | (1<<SPE) | (1<<SPR0);
1182
+    SPCR = BIT(MSTR) | BIT(SPE) | BIT(SPR0);
1183 1183
 
1184 1184
     // enable TT_MAX6675
1185 1185
     WRITE(MAX6675_SS, 0);
@@ -1190,13 +1190,13 @@ void disable_heater() {
1190 1190
 
1191 1191
     // read MSB
1192 1192
     SPDR = 0;
1193
-    for (;(SPSR & (1<<SPIF)) == 0;);
1193
+    for (;(SPSR & BIT(SPIF)) == 0;);
1194 1194
     max6675_temp = SPDR;
1195 1195
     max6675_temp <<= 8;
1196 1196
 
1197 1197
     // read LSB
1198 1198
     SPDR = 0;
1199
-    for (;(SPSR & (1<<SPIF)) == 0;);
1199
+    for (;(SPSR & BIT(SPIF)) == 0;);
1200 1200
     max6675_temp |= SPDR;
1201 1201
 
1202 1202
     // disable TT_MAX6675
@@ -1246,7 +1246,7 @@ ISR(TIMER0_COMPB_vect) {
1246 1246
   static unsigned long raw_temp_3_value = 0;
1247 1247
   static unsigned long raw_temp_bed_value = 0;
1248 1248
   static TempState temp_state = StartupDelay;
1249
-  static unsigned char pwm_count = (1 << SOFT_PWM_SCALE);
1249
+  static unsigned char pwm_count = BIT(SOFT_PWM_SCALE);
1250 1250
 
1251 1251
   // Static members for each heater
1252 1252
   #ifdef SLOW_PWM_HEATERS
@@ -1331,7 +1331,7 @@ ISR(TIMER0_COMPB_vect) {
1331 1331
       if (soft_pwm_fan < pwm_count) WRITE_FAN(0);
1332 1332
     #endif
1333 1333
     
1334
-    pwm_count += (1 << SOFT_PWM_SCALE);
1334
+    pwm_count += BIT(SOFT_PWM_SCALE);
1335 1335
     pwm_count &= 0x7f;
1336 1336
   
1337 1337
   #else // SLOW_PWM_HEATERS
@@ -1412,7 +1412,7 @@ ISR(TIMER0_COMPB_vect) {
1412 1412
       if (soft_pwm_fan < pwm_count) WRITE_FAN(0);
1413 1413
     #endif //FAN_SOFT_PWM
1414 1414
 
1415
-    pwm_count += (1 << SOFT_PWM_SCALE);
1415
+    pwm_count += BIT(SOFT_PWM_SCALE);
1416 1416
     pwm_count &= 0x7f;
1417 1417
 
1418 1418
     // increment slow_pwm_count only every 64 pwm_count circa 65.5ms
@@ -1438,9 +1438,9 @@ ISR(TIMER0_COMPB_vect) {
1438 1438
   
1439 1439
   #endif // SLOW_PWM_HEATERS
1440 1440
 
1441
-  #define SET_ADMUX_ADCSRA(pin) ADMUX = (1 << REFS0) | (pin & 0x07); ADCSRA |= 1<<ADSC
1441
+  #define SET_ADMUX_ADCSRA(pin) ADMUX = BIT(REFS0) | (pin & 0x07); ADCSRA |= BIT(ADSC)
1442 1442
   #ifdef MUX5
1443
-    #define START_ADC(pin) if (pin > 7) ADCSRB = 1 << MUX5; else ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
1443
+    #define START_ADC(pin) if (pin > 7) ADCSRB = BIT(MUX5); else ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
1444 1444
   #else
1445 1445
     #define START_ADC(pin) ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
1446 1446
   #endif

+ 2
- 2
Marlin/ultralcd.cpp Bestand weergeven

@@ -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 Bestand weergeven

@@ -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 Bestand weergeven

@@ -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

Laden…
Annuleren
Opslaan