Browse Source

Less use of "this"

Scott Lahteine 4 years ago
parent
commit
0b4aedf13e

+ 14
- 14
Marlin/src/HAL/HAL_ESP32/Servo.cpp View File

@@ -32,25 +32,25 @@
32 32
 int Servo::channel_next_free = 12;
33 33
 
34 34
 Servo::Servo() {
35
-  this->channel = channel_next_free++;
35
+  channel = channel_next_free++;
36 36
 }
37 37
 
38
-int8_t Servo::attach(const int pin) {
39
-  if (this->channel >= CHANNEL_MAX_NUM) return -1;
40
-  if (pin > 0) this->pin = pin;
38
+int8_t Servo::attach(const int inPin) {
39
+  if (channel >= CHANNEL_MAX_NUM) return -1;
40
+  if (pin > 0) pin = inPin;
41 41
 
42
-  ledcSetup(this->channel, 50, 16); // channel X, 50 Hz, 16-bit depth
43
-  ledcAttachPin(this->pin, this->channel);
42
+  ledcSetup(channel, 50, 16); // channel X, 50 Hz, 16-bit depth
43
+  ledcAttachPin(pin, channel);
44 44
   return true;
45 45
 }
46 46
 
47
-void Servo::detach() { ledcDetachPin(this->pin); }
47
+void Servo::detach() { ledcDetachPin(pin); }
48 48
 
49
-int Servo::read() { return this->degrees; }
49
+int Servo::read() { return degrees; }
50 50
 
51 51
 void Servo::write(int inDegrees) {
52
-  this->degrees = constrain(inDegrees, MIN_ANGLE, MAX_ANGLE);
53
-  int us = map(this->degrees, MIN_ANGLE, MAX_ANGLE, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
52
+  degrees = constrain(inDegrees, MIN_ANGLE, MAX_ANGLE);
53
+  int us = map(degrees, MIN_ANGLE, MAX_ANGLE, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
54 54
   int duty = map(us, 0, TAU_USEC, 0, MAX_COMPARE);
55 55
   ledcWrite(channel, duty);
56 56
 }
@@ -58,11 +58,11 @@ void Servo::write(int inDegrees) {
58 58
 void Servo::move(const int value) {
59 59
   constexpr uint16_t servo_delay[] = SERVO_DELAY;
60 60
   static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
61
-  if (this->attach(0) >= 0) {
62
-    this->write(value);
63
-    safe_delay(servo_delay[this->channel]);
61
+  if (attach(0) >= 0) {
62
+    write(value);
63
+    safe_delay(servo_delay[channel]);
64 64
     #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
65
-      this->detach();
65
+      detach();
66 66
     #endif
67 67
   }
68 68
 }

+ 4
- 4
Marlin/src/HAL/HAL_LPC1768/Servo.h View File

@@ -57,11 +57,11 @@ class libServo: public Servo {
57 57
     constexpr uint16_t servo_delay[] = SERVO_DELAY;
58 58
     static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
59 59
 
60
-    if (this->attach(servo_info[this->servoIndex].Pin.nbr) >= 0) {    // try to reattach
61
-      this->write(value);
62
-      safe_delay(servo_delay[this->servoIndex]); // delay to allow servo to reach position
60
+    if (attach(servo_info[servoIndex].Pin.nbr) >= 0) {    // try to reattach
61
+      write(value);
62
+      safe_delay(servo_delay[servoIndex]); // delay to allow servo to reach position
63 63
       #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
64
-        this->detach();
64
+        detach();
65 65
       #endif
66 66
     }
67 67
 

+ 9
- 9
Marlin/src/HAL/HAL_STM32/Servo.cpp View File

@@ -31,24 +31,24 @@
31 31
 uint8_t servoPin[MAX_SERVOS] = { 0 };
32 32
 
33 33
 int8_t libServo::attach(const int pin) {
34
-  if (this->servoIndex >= MAX_SERVOS) return -1;
35
-  if (pin > 0) servoPin[this->servoIndex] = pin;
36
-  return Servo::attach(servoPin[this->servoIndex]);
34
+  if (servoIndex >= MAX_SERVOS) return -1;
35
+  if (pin > 0) servoPin[servoIndex] = pin;
36
+  return super::attach(servoPin[servoIndex]);
37 37
 }
38 38
 
39 39
 int8_t libServo::attach(const int pin, const int min, const int max) {
40
-  if (pin > 0) servoPin[this->servoIndex] = pin;
41
-  return Servo::attach(servoPin[this->servoIndex], min, max);
40
+  if (pin > 0) servoPin[servoIndex] = pin;
41
+  return super::attach(servoPin[servoIndex], min, max);
42 42
 }
43 43
 
44 44
 void libServo::move(const int value) {
45 45
   constexpr uint16_t servo_delay[] = SERVO_DELAY;
46 46
   static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
47
-  if (this->attach(0) >= 0) {
48
-    this->write(value);
49
-    safe_delay(servo_delay[this->servoIndex]);
47
+  if (attach(0) >= 0) {
48
+    write(value);
49
+    safe_delay(servo_delay[servoIndex]);
50 50
     #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
51
-      this->detach();
51
+      detach();
52 52
     #endif
53 53
   }
54 54
 }

+ 32
- 43
Marlin/src/HAL/HAL_STM32F1/SPI.cpp View File

@@ -213,31 +213,31 @@ void SPIClass::setDataSize(uint32_t datasize) {
213 213
 }
214 214
 
215 215
 void SPIClass::setDataMode(uint8_t dataMode) {
216
-  /*
217
-  Notes:
218
-  As far as we know the AVR numbers for dataMode match the numbers required by the STM32.
219
-  From the AVR doc http://www.atmel.com/images/doc2585.pdf section 2.4
220
-
221
-  SPI Mode  CPOL  CPHA  Shift SCK-edge  Capture SCK-edge
222
-  0       0     0     Falling     Rising
223
-  1       0     1     Rising      Falling
224
-  2       1     0     Rising      Falling
225
-  3       1     1     Falling     Rising
226
-
227
-  On the STM32 it appears to be
228
-
229
-  bit 1 - CPOL : Clock polarity
230
-    (This bit should not be changed when communication is ongoing)
231
-    0 : CLK to 0 when idle
232
-    1 : CLK to 1 when idle
233
-
234
-  bit 0 - CPHA : Clock phase
235
-    (This bit should not be changed when communication is ongoing)
236
-    0 : The first clock transition is the first data capture edge
237
-    1 : The second clock transition is the first data capture edge
238
-
239
-  If someone finds this is not the case or sees a logic error with this let me know ;-)
240
-  */
216
+  /**
217
+   * Notes:
218
+   * As far as we know the AVR numbers for dataMode match the numbers required by the STM32.
219
+   * From the AVR doc http://www.atmel.com/images/doc2585.pdf section 2.4
220
+   *
221
+   * SPI Mode  CPOL  CPHA  Shift SCK-edge  Capture SCK-edge
222
+   * 0       0     0     Falling     Rising
223
+   * 1       0     1     Rising      Falling
224
+   * 2       1     0     Rising      Falling
225
+   * 3       1     1     Falling     Rising
226
+   *
227
+   * On the STM32 it appears to be
228
+   *
229
+   * bit 1 - CPOL : Clock polarity
230
+   *   (This bit should not be changed when communication is ongoing)
231
+   *   0 : CLK to 0 when idle
232
+   *   1 : CLK to 1 when idle
233
+   *
234
+   * bit 0 - CPHA : Clock phase
235
+   *   (This bit should not be changed when communication is ongoing)
236
+   *   0 : The first clock transition is the first data capture edge
237
+   *   1 : The second clock transition is the first data capture edge
238
+   *
239
+   * If someone finds this is not the case or sees a logic error with this let me know ;-)
240
+   */
241 241
   _currentSetting->dataMode = dataMode;
242 242
   uint32_t cr1 = _currentSetting->spi_d->regs->CR1 & ~(SPI_CR1_CPOL|SPI_CR1_CPHA);
243 243
   _currentSetting->spi_d->regs->CR1 = cr1 | (dataMode & (SPI_CR1_CPOL|SPI_CR1_CPHA));
@@ -593,7 +593,7 @@ void SPIClass::detachInterrupt() {
593 593
   // Should be disableInterrupt()
594 594
 }
595 595
 
596
-/*
596
+/**
597 597
  * Pin accessors
598 598
  */
599 599
 
@@ -613,25 +613,14 @@ uint8_t SPIClass::nssPin() {
613 613
   return dev_to_spi_pins(_currentSetting->spi_d)->nss;
614 614
 }
615 615
 
616
-/*
616
+/**
617 617
  * Deprecated functions
618 618
  */
619
+uint8_t SPIClass::send(uint8_t data)               { write(data); return 1; }
620
+uint8_t SPIClass::send(uint8_t *buf, uint32_t len) { write(buf, len); return len; }
621
+uint8_t SPIClass::recv()                           { return read(); }
619 622
 
620
-uint8_t SPIClass::send(uint8_t data) {
621
-  this->write(data);
622
-  return 1;
623
-}
624
-
625
-uint8_t SPIClass::send(uint8_t *buf, uint32_t len) {
626
-  this->write(buf, len);
627
-  return len;
628
-}
629
-
630
-uint8_t SPIClass::recv() {
631
-  return this->read();
632
-}
633
-
634
-/*
623
+/**
635 624
  * DMA call back functions, one per port.
636 625
  */
637 626
 #if BOARD_NR_SPI >= 1
@@ -650,7 +639,7 @@ uint8_t SPIClass::recv() {
650 639
   }
651 640
 #endif
652 641
 
653
-/*
642
+/**
654 643
  * Auxiliary functions
655 644
  */
656 645
 static const spi_pins* dev_to_spi_pins(spi_dev *dev) {

+ 20
- 20
Marlin/src/HAL/HAL_STM32F1/SPI.h View File

@@ -96,36 +96,36 @@ typedef enum {
96 96
 
97 97
 class SPISettings {
98 98
 public:
99
-  SPISettings(uint32_t clock, BitOrder bitOrder, uint8_t dataMode) {
100
-    if (__builtin_constant_p(clock))
101
-      init_AlwaysInline(clock, bitOrder, dataMode, DATA_SIZE_8BIT);
99
+  SPISettings(uint32_t inClock, BitOrder inBitOrder, uint8_t inDataMode) {
100
+    if (__builtin_constant_p(inClock))
101
+      init_AlwaysInline(inClock, inBitOrder, inDataMode, DATA_SIZE_8BIT);
102 102
     else
103
-      init_MightInline(clock, bitOrder, dataMode, DATA_SIZE_8BIT);
103
+      init_MightInline(inClock, inBitOrder, inDataMode, DATA_SIZE_8BIT);
104 104
   }
105
-  SPISettings(uint32_t clock, BitOrder bitOrder, uint8_t dataMode, uint32_t dataSize) {
106
-    if (__builtin_constant_p(clock))
107
-      init_AlwaysInline(clock, bitOrder, dataMode, dataSize);
105
+  SPISettings(uint32_t inClock, BitOrder inBitOrder, uint8_t inDataMode, uint32_t inDataSize) {
106
+    if (__builtin_constant_p(inClock))
107
+      init_AlwaysInline(inClock, inBitOrder, inDataMode, inDataSize);
108 108
     else
109
-      init_MightInline(clock, bitOrder, dataMode, dataSize);
109
+      init_MightInline(inClock, inBitOrder, inDataMode, inDataSize);
110 110
   }
111
-  SPISettings(uint32_t clock) {
112
-    if (__builtin_constant_p(clock))
113
-      init_AlwaysInline(clock, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
111
+  SPISettings(uint32_t inClock) {
112
+    if (__builtin_constant_p(inClock))
113
+      init_AlwaysInline(inClock, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
114 114
     else
115
-      init_MightInline(clock, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
115
+      init_MightInline(inClock, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
116 116
   }
117 117
   SPISettings() {
118 118
     init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
119 119
   }
120 120
 private:
121
-  void init_MightInline(uint32_t clock, BitOrder bitOrder, uint8_t dataMode, uint32_t dataSize) {
122
-    init_AlwaysInline(clock, bitOrder, dataMode, dataSize);
121
+  void init_MightInline(uint32_t inClock, BitOrder inBitOrder, uint8_t inDataMode, uint32_t inDataSize) {
122
+    init_AlwaysInline(inClock, inBitOrder, inDataMode, inDataSize);
123 123
   }
124
-  void init_AlwaysInline(uint32_t clock, BitOrder bitOrder, uint8_t dataMode, uint32_t dataSize) __attribute__((__always_inline__)) {
125
-    this->clock = clock;
126
-    this->bitOrder = bitOrder;
127
-    this->dataMode = dataMode;
128
-    this->dataSize = dataSize;
124
+  void init_AlwaysInline(uint32_t inClock, BitOrder inBitOrder, uint8_t inDataMode, uint32_t inDataSize) __attribute__((__always_inline__)) {
125
+    clock    = inClock;
126
+    bitOrder = inBitOrder;
127
+    dataMode = inDataMode;
128
+    dataSize = inDataSize;
129 129
   }
130 130
   uint32_t clock;
131 131
   uint32_t dataSize;
@@ -339,7 +339,7 @@ public:
339 339
    *     or 1-3 in high density devices.
340 340
    */
341 341
   void setModule(int spi_num) {
342
-    _currentSetting=&_settings[spi_num-1];// SPI channels are called 1 2 and 3 but the array is zero indexed
342
+    _currentSetting = &_settings[spi_num - 1];// SPI channels are called 1 2 and 3 but the array is zero indexed
343 343
   }
344 344
 
345 345
   /* -- The following methods are deprecated --------------------------- */

+ 43
- 46
Marlin/src/HAL/HAL_STM32F1/Servo.cpp View File

@@ -56,52 +56,50 @@ uint8_t ServoCount = 0;
56 56
 #define SERVO_OVERFLOW  ((uint16_t)round((double)TAU_CYC / SERVO_PRESCALER))
57 57
 
58 58
 // Unit conversions
59
-#define US_TO_COMPARE(us) ((uint16_t)map((us), 0, TAU_USEC, 0, SERVO_OVERFLOW))
60
-#define COMPARE_TO_US(c)  ((uint32_t)map((c), 0, SERVO_OVERFLOW, 0, TAU_USEC))
61
-#define ANGLE_TO_US(a)    ((uint16_t)(map((a), this->minAngle, this->maxAngle, \
62
-                                        SERVO_DEFAULT_MIN_PW, SERVO_DEFAULT_MAX_PW)))
63
-#define US_TO_ANGLE(us)   ((int16_t)(map((us), SERVO_DEFAULT_MIN_PW, SERVO_DEFAULT_MAX_PW,  \
64
-                                       this->minAngle, this->maxAngle)))
65
-
66
-void libServo::servoWrite(uint8_t pin, uint16_t duty_cycle) {
59
+#define US_TO_COMPARE(us) uint16_t(map((us), 0, TAU_USEC, 0, SERVO_OVERFLOW))
60
+#define COMPARE_TO_US(c)  uint32_t(map((c),  0, SERVO_OVERFLOW, 0, TAU_USEC))
61
+#define ANGLE_TO_US(a)    uint16_t(map((a),  minAngle, maxAngle, SERVO_DEFAULT_MIN_PW, SERVO_DEFAULT_MAX_PW))
62
+#define US_TO_ANGLE(us)    int16_t(map((us), SERVO_DEFAULT_MIN_PW, SERVO_DEFAULT_MAX_PW, minAngle, maxAngle))
63
+
64
+void libServo::servoWrite(uint8_t inPin, uint16_t duty_cycle) {
67 65
   #ifdef SERVO0_TIMER_NUM
68
-    if (this->servoIndex == 0) {
69
-      this->pwmSetDuty(duty_cycle);
66
+    if (servoIndex == 0) {
67
+      pwmSetDuty(duty_cycle);
70 68
       return;
71 69
     }
72 70
   #endif
73 71
 
74
-  timer_dev *tdev = PIN_MAP[pin].timer_device;
75
-  uint8_t tchan = PIN_MAP[pin].timer_channel;
72
+  timer_dev *tdev = PIN_MAP[inPin].timer_device;
73
+  uint8_t tchan = PIN_MAP[inPin].timer_channel;
76 74
   if (tdev) timer_set_compare(tdev, tchan, duty_cycle);
77 75
 }
78 76
 
79 77
 libServo::libServo() {
80
-  this->servoIndex = ServoCount < MAX_SERVOS ? ServoCount++ : INVALID_SERVO;
78
+  servoIndex = ServoCount < MAX_SERVOS ? ServoCount++ : INVALID_SERVO;
81 79
 }
82 80
 
83
-bool libServo::attach(const int32_t pin, const int32_t minAngle, const int32_t maxAngle) {
84
-  if (this->servoIndex >= MAX_SERVOS) return false;
85
-  if (pin >= BOARD_NR_GPIO_PINS) return false;
81
+bool libServo::attach(const int32_t inPin, const int32_t inMinAngle, const int32_t inMaxAngle) {
82
+  if (servoIndex >= MAX_SERVOS) return false;
83
+  if (inPin >= BOARD_NR_GPIO_PINS) return false;
86 84
 
87
-  this->minAngle = minAngle;
88
-  this->maxAngle = maxAngle;
89
-  this->angle = -1;
85
+  minAngle = inMinAngle;
86
+  maxAngle = inMaxAngle;
87
+  angle = -1;
90 88
 
91 89
   #ifdef SERVO0_TIMER_NUM
92
-    if (this->servoIndex == 0 && this->setupSoftPWM(pin)) {
93
-      this->pin = pin; // set attached()
90
+    if (servoIndex == 0 && setupSoftPWM(inPin)) {
91
+      pin = inPin; // set attached()
94 92
       return true;
95 93
     }
96 94
   #endif
97 95
 
98
-  if (!PWM_PIN(pin)) return false;
96
+  if (!PWM_PIN(inPin)) return false;
99 97
 
100
-  timer_dev *tdev = PIN_MAP[pin].timer_device;
101
-  //uint8_t tchan = PIN_MAP[pin].timer_channel;
98
+  timer_dev *tdev = PIN_MAP[inPin].timer_device;
99
+  //uint8_t tchan = PIN_MAP[inPin].timer_channel;
102 100
 
103
-  SET_PWM(pin);
104
-  servoWrite(pin, 0);
101
+  SET_PWM(inPin);
102
+  servoWrite(inPin, 0);
105 103
 
106 104
   timer_pause(tdev);
107 105
   timer_set_prescaler(tdev, SERVO_PRESCALER - 1); // prescaler is 1-based
@@ -109,25 +107,24 @@ bool libServo::attach(const int32_t pin, const int32_t minAngle, const int32_t m
109 107
   timer_generate_update(tdev);
110 108
   timer_resume(tdev);
111 109
 
112
-  this->pin = pin; // set attached()
113
-
110
+  pin = inPin; // set attached()
114 111
   return true;
115 112
 }
116 113
 
117 114
 bool libServo::detach() {
118
-  if (!this->attached()) return false;
119
-  this->angle = -1;
120
-  servoWrite(this->pin, 0);
115
+  if (!attached()) return false;
116
+  angle = -1;
117
+  servoWrite(pin, 0);
121 118
   return true;
122 119
 }
123 120
 
124 121
 int32_t libServo::read() const {
125
-  if (this->attached()) {
122
+  if (attached()) {
126 123
     #ifdef SERVO0_TIMER_NUM
127
-      if (this->servoIndex == 0) return this->angle;
124
+      if (servoIndex == 0) return angle;
128 125
     #endif
129
-    timer_dev *tdev = PIN_MAP[this->pin].timer_device;
130
-    uint8_t tchan = PIN_MAP[this->pin].timer_channel;
126
+    timer_dev *tdev = PIN_MAP[pin].timer_device;
127
+    uint8_t tchan = PIN_MAP[pin].timer_channel;
131 128
     return US_TO_ANGLE(COMPARE_TO_US(timer_get_compare(tdev, tchan)));
132 129
   }
133 130
   return 0;
@@ -137,12 +134,12 @@ void libServo::move(const int32_t value) {
137 134
   constexpr uint16_t servo_delay[] = SERVO_DELAY;
138 135
   static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
139 136
 
140
-  if (this->attached()) {
141
-    this->angle = constrain(value, this->minAngle, this->maxAngle);
142
-    servoWrite(this->pin, US_TO_COMPARE(ANGLE_TO_US(this->angle)));
143
-    safe_delay(servo_delay[this->servoIndex]);
137
+  if (attached()) {
138
+    angle = constrain(value, minAngle, maxAngle);
139
+    servoWrite(pin, US_TO_COMPARE(ANGLE_TO_US(angle)));
140
+    safe_delay(servo_delay[servoIndex]);
144 141
     #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
145
-      this->detach();
142
+      detach();
146 143
     #endif
147 144
   }
148 145
 }
@@ -169,13 +166,13 @@ void libServo::move(const int32_t value) {
169 166
     }
170 167
   }
171 168
 
172
-  bool libServo::setupSoftPWM(const int32_t pin) {
169
+  bool libServo::setupSoftPWM(const int32_t inPin) {
173 170
     timer_dev *tdev = get_timer_dev(SERVO0_TIMER_NUM);
174 171
     if (!tdev) return false;
175 172
     #ifdef SERVO0_PWM_OD
176
-      OUT_WRITE_OD(pin, 1);
173
+      OUT_WRITE_OD(inPin, 1);
177 174
     #else
178
-      OUT_WRITE(pin, 0);
175
+      OUT_WRITE(inPin, 0);
179 176
     #endif
180 177
 
181 178
     timer_pause(tdev);
@@ -206,9 +203,9 @@ void libServo::move(const int32_t value) {
206 203
       timer_disable_irq(tdev, 1);
207 204
       timer_disable_irq(tdev, 2);
208 205
       #ifdef SERVO0_PWM_OD
209
-        OUT_WRITE_OD(this->pin, 1); // off
206
+        OUT_WRITE_OD(pin, 1); // off
210 207
       #else
211
-        OUT_WRITE(this->pin, 0);
208
+        OUT_WRITE(pin, 0);
212 209
       #endif
213 210
     }
214 211
   }
@@ -221,7 +218,7 @@ void libServo::move(const int32_t value) {
221 218
 
222 219
 #else
223 220
 
224
-  bool libServo::setupSoftPWM(const int32_t pin) { return false; }
221
+  bool libServo::setupSoftPWM(const int32_t inPin) { return false; }
225 222
   void libServo::pwmSetDuty(const uint16_t duty_cycle) {}
226 223
   void libServo::pauseSoftPWM() {}
227 224
 

+ 1
- 1
Marlin/src/HAL/HAL_STM32F1/Servo.h View File

@@ -41,7 +41,7 @@ class libServo {
41 41
   public:
42 42
     libServo();
43 43
     bool attach(const int32_t pin, const int32_t minAngle=SERVO_DEFAULT_MIN_ANGLE, const int32_t maxAngle=SERVO_DEFAULT_MAX_ANGLE);
44
-    bool attached() const { return this->pin != NOT_ATTACHED; }
44
+    bool attached() const { return pin != NOT_ATTACHED; }
45 45
     bool detach();
46 46
     void move(const int32_t value);
47 47
     int32_t read() const;

+ 7
- 7
Marlin/src/HAL/HAL_STM32_F4_F7/Servo.cpp View File

@@ -30,22 +30,22 @@
30 30
 #include "Servo.h"
31 31
 
32 32
 int8_t libServo::attach(const int pin) {
33
-  if (this->servoIndex >= MAX_SERVOS) return -1;
34
-  return Servo::attach(pin);
33
+  if (servoIndex >= MAX_SERVOS) return -1;
34
+  return super::attach(pin);
35 35
 }
36 36
 
37 37
 int8_t libServo::attach(const int pin, const int min, const int max) {
38
-  return Servo::attach(pin, min, max);
38
+  return super::attach(pin, min, max);
39 39
 }
40 40
 
41 41
 void libServo::move(const int value) {
42 42
   constexpr uint16_t servo_delay[] = SERVO_DELAY;
43 43
   static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
44
-  if (this->attach(0) >= 0) {
45
-    this->write(value);
46
-    safe_delay(servo_delay[this->servoIndex]);
44
+  if (attach(0) >= 0) {
45
+    write(value);
46
+    safe_delay(servo_delay[servoIndex]);
47 47
     #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
48
-      this->detach();
48
+      detach();
49 49
     #endif
50 50
   }
51 51
 }

+ 11
- 11
Marlin/src/HAL/HAL_TEENSY31_32/Servo.cpp View File

@@ -29,25 +29,25 @@
29 29
 
30 30
 uint8_t servoPin[MAX_SERVOS] = { 0 };
31 31
 
32
-int8_t libServo::attach(const int pin) {
33
-  if (this->servoIndex >= MAX_SERVOS) return -1;
34
-  if (pin > 0) servoPin[this->servoIndex] = pin;
35
-  return Servo::attach(servoPin[this->servoIndex]);
32
+int8_t libServo::attach(const int inPin) {
33
+  if (servoIndex >= MAX_SERVOS) return -1;
34
+  if (inPin > 0) servoPin[servoIndex] = inPin;
35
+  return super::attach(servoPin[servoIndex]);
36 36
 }
37 37
 
38
-int8_t libServo::attach(const int pin, const int min, const int max) {
39
-  if (pin > 0) servoPin[this->servoIndex] = pin;
40
-  return Servo::attach(servoPin[this->servoIndex], min, max);
38
+int8_t libServo::attach(const int inPin, const int inMin, const int inMax) {
39
+  if (inPin > 0) servoPin[servoIndex] = inPin;
40
+  return super::attach(servoPin[servoIndex], inMin, inMax);
41 41
 }
42 42
 
43 43
 void libServo::move(const int value) {
44 44
   constexpr uint16_t servo_delay[] = SERVO_DELAY;
45 45
   static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
46
-  if (this->attach(0) >= 0) {
47
-    this->write(value);
48
-    safe_delay(servo_delay[this->servoIndex]);
46
+  if (attach(0) >= 0) {
47
+    write(value);
48
+    safe_delay(servo_delay[servoIndex]);
49 49
     #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
50
-      this->detach();
50
+      detach();
51 51
     #endif
52 52
   }
53 53
 }

+ 32
- 11
Marlin/src/HAL/HAL_TEENSY35_36/Servo.cpp View File

@@ -1,3 +1,24 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
1 22
 #if defined(__MK64FX512__) || defined(__MK66FX1M0__)
2 23
 
3 24
 #include "../../inc/MarlinConfig.h"
@@ -8,25 +29,25 @@
8 29
 
9 30
 uint8_t servoPin[MAX_SERVOS] = { 0 };
10 31
 
11
-int8_t libServo::attach(const int pin) {
12
-  if (this->servoIndex >= MAX_SERVOS) return -1;
13
-  if (pin > 0) servoPin[this->servoIndex] = pin;
14
-  return Servo::attach(servoPin[this->servoIndex]);
32
+int8_t libServo::attach(const int inPin) {
33
+  if (servoIndex >= MAX_SERVOS) return -1;
34
+  if (inPin > 0) servoPin[servoIndex] = inPin;
35
+  return super::attach(servoPin[servoIndex]);
15 36
 }
16 37
 
17
-int8_t libServo::attach(const int pin, const int min, const int max) {
18
-  if (pin > 0) servoPin[this->servoIndex] = pin;
19
-  return Servo::attach(servoPin[this->servoIndex], min, max);
38
+int8_t libServo::attach(const int inPin, const int inMin, const int inMax) {
39
+  if (inPin > 0) servoPin[servoIndex] = inPin;
40
+  return super::attach(servoPin[servoIndex], inMin, inMax);
20 41
 }
21 42
 
22 43
 void libServo::move(const int value) {
23 44
   constexpr uint16_t servo_delay[] = SERVO_DELAY;
24 45
   static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
25
-  if (this->attach(0) >= 0) {
26
-    this->write(value);
27
-    safe_delay(servo_delay[this->servoIndex]);
46
+  if (attach(0) >= 0) {
47
+    write(value);
48
+    safe_delay(servo_delay[servoIndex]);
28 49
     #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
29
-      this->detach();
50
+      detach();
30 51
     #endif
31 52
   }
32 53
 }

+ 30
- 30
Marlin/src/HAL/shared/servo.cpp View File

@@ -58,11 +58,11 @@
58 58
 #include "servo.h"
59 59
 #include "servo_private.h"
60 60
 
61
-ServoInfo_t servo_info[MAX_SERVOS];                  // static array of servo info structures
62
-uint8_t ServoCount = 0;                              // the total number of attached servos
61
+ServoInfo_t servo_info[MAX_SERVOS];             // static array of servo info structures
62
+uint8_t ServoCount = 0;                         // the total number of attached servos
63 63
 
64
-#define SERVO_MIN() (MIN_PULSE_WIDTH - this->min * 4)  // minimum value in uS for this servo
65
-#define SERVO_MAX() (MAX_PULSE_WIDTH - this->max * 4)  // maximum value in uS for this servo
64
+#define SERVO_MIN(v) (MIN_PULSE_WIDTH - (v) * 4) // minimum value in uS for this servo
65
+#define SERVO_MAX(v) (MAX_PULSE_WIDTH - (v) * 4) // maximum value in uS for this servo
66 66
 
67 67
 /************ static functions common to all instances ***********************/
68 68
 
@@ -79,54 +79,54 @@ static boolean isTimerActive(timer16_Sequence_t timer) {
79 79
 
80 80
 Servo::Servo() {
81 81
   if (ServoCount < MAX_SERVOS) {
82
-    this->servoIndex = ServoCount++;                    // assign a servo index to this instance
83
-    servo_info[this->servoIndex].ticks = usToTicks(DEFAULT_PULSE_WIDTH);   // store default values  - 12 Aug 2009
82
+    servoIndex = ServoCount++;                    // assign a servo index to this instance
83
+    servo_info[servoIndex].ticks = usToTicks(DEFAULT_PULSE_WIDTH);   // store default values  - 12 Aug 2009
84 84
   }
85 85
   else
86
-    this->servoIndex = INVALID_SERVO;  // too many servos
86
+    servoIndex = INVALID_SERVO;  // too many servos
87 87
 }
88 88
 
89
-int8_t Servo::attach(const int pin) {
90
-  return this->attach(pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
89
+int8_t Servo::attach(const int inPin) {
90
+  return attach(inPin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
91 91
 }
92 92
 
93
-int8_t Servo::attach(const int pin, const int min, const int max) {
93
+int8_t Servo::attach(const int inPin, const int inMin, const int inMax) {
94 94
 
95
-  if (this->servoIndex >= MAX_SERVOS) return -1;
95
+  if (servoIndex >= MAX_SERVOS) return -1;
96 96
 
97
-  if (pin > 0) servo_info[this->servoIndex].Pin.nbr = pin;
98
-  pinMode(servo_info[this->servoIndex].Pin.nbr, OUTPUT); // set servo pin to output
97
+  if (inPin > 0) servo_info[servoIndex].Pin.nbr = inPin;
98
+  pinMode(servo_info[servoIndex].Pin.nbr, OUTPUT); // set servo pin to output
99 99
 
100
-  // todo min/max check: ABS(min - MIN_PULSE_WIDTH) /4 < 128
101
-  this->min = (MIN_PULSE_WIDTH - min) / 4; //resolution of min/max is 4 uS
102
-  this->max = (MAX_PULSE_WIDTH - max) / 4;
100
+  // TODO: min/max check: ABS(min - MIN_PULSE_WIDTH) / 4 < 128
101
+  min = (MIN_PULSE_WIDTH - inMin) / 4; //resolution of min/max is 4 uS
102
+  max = (MAX_PULSE_WIDTH - inMax) / 4;
103 103
 
104 104
   // initialize the timer if it has not already been initialized
105 105
   timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex);
106 106
   if (!isTimerActive(timer)) initISR(timer);
107
-  servo_info[this->servoIndex].Pin.isActive = true;  // this must be set after the check for isTimerActive
107
+  servo_info[servoIndex].Pin.isActive = true;  // this must be set after the check for isTimerActive
108 108
 
109
-  return this->servoIndex;
109
+  return servoIndex;
110 110
 }
111 111
 
112 112
 void Servo::detach() {
113
-  servo_info[this->servoIndex].Pin.isActive = false;
113
+  servo_info[servoIndex].Pin.isActive = false;
114 114
   timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex);
115 115
   if (!isTimerActive(timer)) finISR(timer);
116 116
 }
117 117
 
118 118
 void Servo::write(int value) {
119 119
   if (value < MIN_PULSE_WIDTH)    // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
120
-    value = map(constrain(value, 0, 180), 0, 180, SERVO_MIN(), SERVO_MAX());
121
-  this->writeMicroseconds(value);
120
+    value = map(constrain(value, 0, 180), 0, 180, SERVO_MIN(min), SERVO_MAX(max));
121
+  writeMicroseconds(value);
122 122
 }
123 123
 
124 124
 void Servo::writeMicroseconds(int value) {
125 125
   // calculate and store the values for the given channel
126
-  byte channel = this->servoIndex;
126
+  byte channel = servoIndex;
127 127
   if (channel < MAX_SERVOS) {  // ensure channel is valid
128 128
     // ensure pulse width is valid
129
-    value = constrain(value, SERVO_MIN(), SERVO_MAX()) - (TRIM_DURATION);
129
+    value = constrain(value, SERVO_MIN(min), SERVO_MAX(max)) - (TRIM_DURATION);
130 130
     value = usToTicks(value);  // convert to ticks after compensating for interrupt overhead - 12 Aug 2009
131 131
 
132 132
     CRITICAL_SECTION_START;
@@ -136,22 +136,22 @@ void Servo::writeMicroseconds(int value) {
136 136
 }
137 137
 
138 138
 // return the value as degrees
139
-int Servo::read() { return map(this->readMicroseconds() + 1, SERVO_MIN(), SERVO_MAX(), 0, 180); }
139
+int Servo::read() { return map(readMicroseconds() + 1, SERVO_MIN(min), SERVO_MAX(max), 0, 180); }
140 140
 
141 141
 int Servo::readMicroseconds() {
142
-  return (this->servoIndex == INVALID_SERVO) ? 0 : ticksToUs(servo_info[this->servoIndex].ticks) + (TRIM_DURATION);
142
+  return (servoIndex == INVALID_SERVO) ? 0 : ticksToUs(servo_info[servoIndex].ticks) + (TRIM_DURATION);
143 143
 }
144 144
 
145
-bool Servo::attached() { return servo_info[this->servoIndex].Pin.isActive; }
145
+bool Servo::attached() { return servo_info[servoIndex].Pin.isActive; }
146 146
 
147 147
 void Servo::move(const int value) {
148 148
   constexpr uint16_t servo_delay[] = SERVO_DELAY;
149 149
   static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
150
-  if (this->attach(0) >= 0) {
151
-    this->write(value);
152
-    safe_delay(servo_delay[this->servoIndex]);
150
+  if (attach(0) >= 0) {
151
+    write(value);
152
+    safe_delay(servo_delay[servoIndex]);
153 153
     #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
154
-      this->detach();
154
+      detach();
155 155
     #endif
156 156
   }
157 157
 }

+ 24
- 24
Marlin/src/feature/twibus.cpp View File

@@ -34,12 +34,12 @@ TWIBus::TWIBus() {
34 34
   #else
35 35
     Wire.begin(I2C_SLAVE_ADDRESS); // Join the bus as a slave
36 36
   #endif
37
-  this->reset();
37
+  reset();
38 38
 }
39 39
 
40 40
 void TWIBus::reset() {
41
-  this->buffer_s = 0;
42
-  this->buffer[0] = 0x00;
41
+  buffer_s = 0;
42
+  buffer[0] = 0x00;
43 43
 }
44 44
 
45 45
 void TWIBus::address(const uint8_t adr) {
@@ -47,7 +47,7 @@ void TWIBus::address(const uint8_t adr) {
47 47
     SERIAL_ECHO_MSG("Bad I2C address (8-127)");
48 48
   }
49 49
 
50
-  this->addr = adr;
50
+  addr = adr;
51 51
 
52 52
   #if ENABLED(DEBUG_TWIBUS)
53 53
     debug(PSTR("address"), adr);
@@ -55,8 +55,8 @@ void TWIBus::address(const uint8_t adr) {
55 55
 }
56 56
 
57 57
 void TWIBus::addbyte(const char c) {
58
-  if (this->buffer_s >= COUNT(this->buffer)) return;
59
-  this->buffer[this->buffer_s++] = c;
58
+  if (buffer_s >= COUNT(buffer)) return;
59
+  buffer[buffer_s++] = c;
60 60
   #if ENABLED(DEBUG_TWIBUS)
61 61
     debug(PSTR("addbyte"), c);
62 62
   #endif
@@ -66,26 +66,26 @@ void TWIBus::addbytes(char src[], uint8_t bytes) {
66 66
   #if ENABLED(DEBUG_TWIBUS)
67 67
     debug(PSTR("addbytes"), bytes);
68 68
   #endif
69
-  while (bytes--) this->addbyte(*src++);
69
+  while (bytes--) addbyte(*src++);
70 70
 }
71 71
 
72 72
 void TWIBus::addstring(char str[]) {
73 73
   #if ENABLED(DEBUG_TWIBUS)
74 74
     debug(PSTR("addstring"), str);
75 75
   #endif
76
-  while (char c = *str++) this->addbyte(c);
76
+  while (char c = *str++) addbyte(c);
77 77
 }
78 78
 
79 79
 void TWIBus::send() {
80 80
   #if ENABLED(DEBUG_TWIBUS)
81
-    debug(PSTR("send"), this->addr);
81
+    debug(PSTR("send"), addr);
82 82
   #endif
83 83
 
84
-  Wire.beginTransmission(I2C_ADDRESS(this->addr));
85
-  Wire.write(this->buffer, this->buffer_s);
84
+  Wire.beginTransmission(I2C_ADDRESS(addr));
85
+  Wire.write(buffer, buffer_s);
86 86
   Wire.endTransmission();
87 87
 
88
-  this->reset();
88
+  reset();
89 89
 }
90 90
 
91 91
 // static
@@ -103,22 +103,22 @@ void TWIBus::echodata(uint8_t bytes, const char prefix[], uint8_t adr) {
103 103
 }
104 104
 
105 105
 void TWIBus::echobuffer(const char prefix[], uint8_t adr) {
106
-  echoprefix(this->buffer_s, prefix, adr);
107
-  for (uint8_t i = 0; i < this->buffer_s; i++) SERIAL_CHAR(this->buffer[i]);
106
+  echoprefix(buffer_s, prefix, adr);
107
+  for (uint8_t i = 0; i < buffer_s; i++) SERIAL_CHAR(buffer[i]);
108 108
   SERIAL_EOL();
109 109
 }
110 110
 
111 111
 bool TWIBus::request(const uint8_t bytes) {
112
-  if (!this->addr) return false;
112
+  if (!addr) return false;
113 113
 
114 114
   #if ENABLED(DEBUG_TWIBUS)
115 115
     debug(PSTR("request"), bytes);
116 116
   #endif
117 117
 
118 118
   // requestFrom() is a blocking function
119
-  if (Wire.requestFrom(this->addr, bytes) == 0) {
119
+  if (Wire.requestFrom(addr, bytes) == 0) {
120 120
     #if ENABLED(DEBUG_TWIBUS)
121
-      debug("request fail", this->addr);
121
+      debug("request fail", addr);
122 122
     #endif
123 123
     return false;
124 124
   }
@@ -131,12 +131,12 @@ void TWIBus::relay(const uint8_t bytes) {
131 131
     debug(PSTR("relay"), bytes);
132 132
   #endif
133 133
 
134
-  if (this->request(bytes))
135
-    echodata(bytes, PSTR("i2c-reply"), this->addr);
134
+  if (request(bytes))
135
+    echodata(bytes, PSTR("i2c-reply"), addr);
136 136
 }
137 137
 
138 138
 uint8_t TWIBus::capture(char *dst, const uint8_t bytes) {
139
-  this->reset();
139
+  reset();
140 140
   uint8_t count = 0;
141 141
   while (count < bytes && Wire.available())
142 142
     dst[count++] = Wire.read();
@@ -168,13 +168,13 @@ void TWIBus::flush() {
168 168
     #endif
169 169
 
170 170
     if (str) {
171
-      this->reset();
172
-      this->addstring(str);
171
+      reset();
172
+      addstring(str);
173 173
     }
174 174
 
175
-    Wire.write(this->buffer, this->buffer_s);
175
+    Wire.write(buffer, buffer_s);
176 176
 
177
-    this->reset();
177
+    reset();
178 178
   }
179 179
 
180 180
 #endif

+ 1
- 1
Marlin/src/feature/twibus.h View File

@@ -218,7 +218,7 @@ class TWIBus {
218 218
        *          If a string is passed, write it into the buffer first.
219 219
        */
220 220
       void reply(char str[]=nullptr);
221
-      inline void reply(const char str[]) { this->reply((char*)str); }
221
+      inline void reply(const char str[]) { reply((char*)str); }
222 222
 
223 223
     #endif
224 224
 

+ 18
- 28
Marlin/src/libs/circularqueue.h View File

@@ -52,8 +52,8 @@ class CircularQueue {
52 52
      *          items that can be stored on the queue.
53 53
      */
54 54
     CircularQueue<T, N>() {
55
-      this->buffer.size = N;
56
-      this->buffer.count = this->buffer.head = this->buffer.tail = 0;
55
+      buffer.size = N;
56
+      buffer.count = buffer.head = buffer.tail = 0;
57 57
     }
58 58
 
59 59
     /**
@@ -63,15 +63,15 @@ class CircularQueue {
63 63
      * @return  type T item
64 64
      */
65 65
     T dequeue() {
66
-      if (this->isEmpty()) return T();
66
+      if (isEmpty()) return T();
67 67
 
68
-      uint8_t index = this->buffer.head;
68
+      uint8_t index = buffer.head;
69 69
 
70
-      --this->buffer.count;
71
-      if (++this->buffer.head == this->buffer.size)
72
-        this->buffer.head = 0;
70
+      --buffer.count;
71
+      if (++buffer.head == buffer.size)
72
+        buffer.head = 0;
73 73
 
74
-      return this->buffer.queue[index];
74
+      return buffer.queue[index];
75 75
     }
76 76
 
77 77
     /**
@@ -82,13 +82,13 @@ class CircularQueue {
82 82
      * @return  true if the operation was successful
83 83
      */
84 84
     bool enqueue(T const &item) {
85
-      if (this->isFull()) return false;
85
+      if (isFull()) return false;
86 86
 
87
-      this->buffer.queue[this->buffer.tail] = item;
87
+      buffer.queue[buffer.tail] = item;
88 88
 
89
-      ++this->buffer.count;
90
-      if (++this->buffer.tail == this->buffer.size)
91
-        this->buffer.tail = 0;
89
+      ++buffer.count;
90
+      if (++buffer.tail == buffer.size)
91
+        buffer.tail = 0;
92 92
 
93 93
       return true;
94 94
     }
@@ -98,27 +98,21 @@ class CircularQueue {
98 98
      * @details Returns true if there are no items on the queue, false otherwise.
99 99
      * @return  true if queue is empty
100 100
      */
101
-    bool isEmpty() {
102
-      return this->buffer.count == 0;
103
-    }
101
+    bool isEmpty() { return buffer.count == 0; }
104 102
 
105 103
     /**
106 104
      * @brief   Checks if the queue is full
107 105
      * @details Returns true if the queue is full, false otherwise.
108 106
      * @return  true if queue is full
109 107
      */
110
-    bool isFull() {
111
-      return this->buffer.count == this->buffer.size;
112
-    }
108
+    bool isFull() { return buffer.count == buffer.size; }
113 109
 
114 110
     /**
115 111
      * @brief   Gets the queue size
116 112
      * @details Returns the maximum number of items a queue can have.
117 113
      * @return  the queue size
118 114
      */
119
-    uint8_t size() {
120
-      return this->buffer.size;
121
-    }
115
+    uint8_t size() { return buffer.size; }
122 116
 
123 117
     /**
124 118
      * @brief   Gets the next item from the queue without removing it
@@ -126,16 +120,12 @@ class CircularQueue {
126 120
      *          or updating the pointers.
127 121
      * @return  first item in the queue
128 122
      */
129
-    T peek() {
130
-      return this->buffer.queue[this->buffer.head];
131
-    }
123
+    T peek() { return buffer.queue[buffer.head]; }
132 124
 
133 125
     /**
134 126
      * @brief Gets the number of items on the queue
135 127
      * @details Returns the current number of items stored on the queue.
136 128
      * @return number of items in the queue
137 129
      */
138
-    uint8_t count() {
139
-      return this->buffer.count;
140
-    }
130
+    uint8_t count() { return buffer.count; }
141 131
 };

Loading…
Cancel
Save