浏览代码

Use TEST macro where possible

Scott Lahteine 5 年前
父节点
当前提交
dfdbd1e75f
共有 1 个文件被更改,包括 37 次插入37 次删除
  1. 37
    37
      Marlin/src/feature/tmc_util.cpp

+ 37
- 37
Marlin/src/feature/tmc_util.cpp 查看文件

@@ -95,38 +95,38 @@
95 95
         constexpr uint8_t STST_bp = 31;
96 96
       #endif
97 97
       TMC_driver_data data;
98
-      data.drv_status = st.DRV_STATUS();
98
+      const auto ds = data.drv_status = st.DRV_STATUS();
99 99
       #ifdef __AVR__
100 100
         // 8-bit optimization saves up to 70 bytes of PROGMEM per axis
101 101
         uint8_t spart;
102 102
         #if ENABLED(TMC_DEBUG)
103
-          data.sg_result = data.drv_status & SG_RESULT_bm;
104
-          spart = data.drv_status >> 8;
105
-          data.is_stealth = !!(spart & _BV(STEALTH_bp - 8));
106
-          spart = data.drv_status >> 16;
103
+          data.sg_result = ds & SG_RESULT_bm;
104
+          spart = ds >> 8;
105
+          data.is_stealth = TEST(spart, STEALTH_bp - 8);
106
+          spart = ds >> 16;
107 107
           data.cs_actual = spart & (CS_ACTUAL_bm >> 16);
108 108
         #endif
109
-        spart = data.drv_status >> 24;
110
-        data.is_ot = !!(spart & _BV(OT_bp - 24));
111
-        data.is_otpw = !!(spart & _BV(OTPW_bp - 24));
109
+        spart = ds >> 24;
110
+        data.is_ot = TEST(spart, OT_bp - 24);
111
+        data.is_otpw = TEST(spart, OTPW_bp - 24);
112 112
         data.is_s2g = !!(spart & (S2G_bm >> 24));
113 113
         #if ENABLED(TMC_DEBUG)
114
-          data.is_stall = !!(spart & _BV(STALL_GUARD_bp - 24));
115
-          data.is_standstill = !!(spart & _BV(STST_bp - 24));
114
+          data.is_stall = TEST(spart, STALL_GUARD_bp - 24);
115
+          data.is_standstill = TEST(spart, STST_bp - 24);
116 116
           data.sg_result_reasonable = !data.is_standstill; // sg_result has no reasonable meaning while standstill
117 117
         #endif
118 118
       #else // !__AVR__
119 119
 
120
-        data.is_ot = !!(data.drv_status & _BV(OT_bp));
121
-        data.is_otpw = !!(data.drv_status & _BV(OTPW_bp));
122
-        data.is_s2g = !!(data.drv_status & S2G_bm);
120
+        data.is_ot = TEST(ds, OT_bp);
121
+        data.is_otpw = TEST(ds, OTPW_bp);
122
+        data.is_s2g = !!(ds & S2G_bm);
123 123
         #if ENABLED(TMC_DEBUG)
124 124
           constexpr uint8_t CS_ACTUAL_sb = 16;
125
-          data.sg_result = data.drv_status & SG_RESULT_bm;
126
-          data.is_stealth = !!(data.drv_status & _BV(STEALTH_bp));
127
-          data.cs_actual = (data.drv_status & CS_ACTUAL_bm) >> CS_ACTUAL_sb;
128
-          data.is_stall = !!(data.drv_status & _BV(STALL_GUARD_bp));
129
-          data.is_standstill = !!(data.drv_status & _BV(STST_bp));
125
+          data.sg_result = ds & SG_RESULT_bm;
126
+          data.is_stealth = TEST(ds, STEALTH_bp);
127
+          data.cs_actual = (ds & CS_ACTUAL_bm) >> CS_ACTUAL_sb;
128
+          data.is_stall = TEST(ds, STALL_GUARD_bp);
129
+          data.is_standstill = TEST(ds, STST_bp);
130 130
           data.sg_result_reasonable = !data.is_standstill; // sg_result has no reasonable meaning while standstill
131 131
         #endif
132 132
 
@@ -147,25 +147,25 @@
147 147
       constexpr uint8_t OTPW_bp = 0, OT_bp = 1;
148 148
       constexpr uint8_t S2G_bm = 0b11110; // 2..5
149 149
       TMC_driver_data data;
150
-      data.drv_status = st.DRV_STATUS();
151
-      data.is_otpw = !!(data.drv_status & _BV(OTPW_bp));
152
-      data.is_ot = !!(data.drv_status & _BV(OT_bp));
153
-      data.is_s2g = !!(data.drv_status & S2G_bm);
150
+      const auto ds = data.drv_status = st.DRV_STATUS();
151
+      data.is_otpw = TEST(ds, OTPW_bp);
152
+      data.is_ot = TEST(ds, OT_bp);
153
+      data.is_s2g = !!(ds & S2G_bm);
154 154
       #if ENABLED(TMC_DEBUG)
155 155
         constexpr uint32_t CS_ACTUAL_bm = 0x1F0000; // 16:20
156 156
         constexpr uint8_t STEALTH_bp = 30, STST_bp = 31;
157 157
         #ifdef __AVR__
158 158
           // 8-bit optimization saves up to 12 bytes of PROGMEM per axis
159
-          uint8_t spart = data.drv_status >> 16;
159
+          uint8_t spart = ds >> 16;
160 160
           data.cs_actual = spart & (CS_ACTUAL_bm >> 16);
161
-          spart = data.drv_status >> 24;
162
-          data.is_stealth = !!(spart & _BV(STEALTH_bp - 24));
163
-          data.is_standstill = !!(spart & _BV(STST_bp - 24));
161
+          spart = ds >> 24;
162
+          data.is_stealth = TEST(spart, STEALTH_bp - 24);
163
+          data.is_standstill = TEST(spart, STST_bp - 24);
164 164
         #else
165 165
           constexpr uint8_t CS_ACTUAL_sb = 16;
166
-          data.cs_actual = (data.drv_status & CS_ACTUAL_bm) >> CS_ACTUAL_sb;
167
-          data.is_stealth = !!(data.drv_status & _BV(STEALTH_bp));
168
-          data.is_standstill = !!(data.drv_status & _BV(STST_bp));
166
+          data.cs_actual = (ds & CS_ACTUAL_bm) >> CS_ACTUAL_sb;
167
+          data.is_stealth = TEST(ds, STEALTH_bp);
168
+          data.is_standstill = TEST(ds, STST_bp);
169 169
         #endif
170 170
         #if HAS_STALLGUARD
171 171
           data.sg_result_reasonable = false;
@@ -186,18 +186,18 @@
186 186
       constexpr uint8_t OT_bp = 1, OTPW_bp = 2;
187 187
       constexpr uint8_t S2G_bm = 0b11000;
188 188
       TMC_driver_data data;
189
-      data.drv_status = st.DRVSTATUS();
190
-      uint8_t spart = data.drv_status & 0xFF;
191
-      data.is_otpw = !!(spart & _BV(OTPW_bp));
192
-      data.is_ot = !!(spart & _BV(OT_bp));
193
-      data.is_s2g = !!(data.drv_status & S2G_bm);
189
+      const auto ds = data.drv_status = st.DRVSTATUS();
190
+      uint8_t spart = ds & 0xFF;
191
+      data.is_otpw = TEST(spart, OTPW_bp);
192
+      data.is_ot = TEST(spart, OT_bp);
193
+      data.is_s2g = !!(ds & S2G_bm);
194 194
       #if ENABLED(TMC_DEBUG)
195 195
         constexpr uint8_t STALL_GUARD_bp = 0;
196 196
         constexpr uint8_t STST_bp = 7, SG_RESULT_sp = 10;
197 197
         constexpr uint32_t SG_RESULT_bm = 0xFFC00; // 10:19
198
-        data.is_stall = !!(spart & _BV(STALL_GUARD_bp));
199
-        data.is_standstill = !!(spart & _BV(STST_bp));
200
-        data.sg_result = (data.drv_status & SG_RESULT_bm) >> SG_RESULT_sp;
198
+        data.is_stall = TEST(spart, STALL_GUARD_bp);
199
+        data.is_standstill = TEST(spart, STST_bp);
200
+        data.sg_result = (ds & SG_RESULT_bm) >> SG_RESULT_sp;
201 201
         data.sg_result_reasonable = true;
202 202
       #endif
203 203
       return data;

正在加载...
取消
保存