Browse Source

Merge pull request #8281 from thinkyhead/bf2_alligator_dac

[2.0] Use fastio for Alligator dac084s085, etc.
Scott Lahteine 7 years ago
parent
commit
94c7205d64
No account linked to committer's email address

+ 1
- 1
Marlin/src/HAL/HAL_AVR/HAL_AVR.h View File

66
 // Types
66
 // Types
67
 // --------------------------------------------------------------------------
67
 // --------------------------------------------------------------------------
68
 
68
 
69
-typedef uint16_t timer_t;
69
+typedef uint16_t hal_timer_t;
70
 #define HAL_TIMER_TYPE_MAX 0xFFFF
70
 #define HAL_TIMER_TYPE_MAX 0xFFFF
71
 
71
 
72
 typedef int8_t pin_t;
72
 typedef int8_t pin_t;

+ 2
- 2
Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h View File

40
 
40
 
41
 #define FORCE_INLINE __attribute__((always_inline)) inline
41
 #define FORCE_INLINE __attribute__((always_inline)) inline
42
 
42
 
43
-typedef uint32_t timer_t;
43
+typedef uint32_t hal_timer_t;
44
 #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
44
 #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
45
 
45
 
46
 #define STEP_TIMER_NUM 3  // index of timer to use for stepper
46
 #define STEP_TIMER_NUM 3  // index of timer to use for stepper
92
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = count;
92
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = count;
93
 }
93
 }
94
 
94
 
95
-static FORCE_INLINE timer_t HAL_timer_get_count(const uint8_t timer_num) {
95
+static FORCE_INLINE hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
96
   const tTimerConfig *pConfig = &TimerConfig[timer_num];
96
   const tTimerConfig *pConfig = &TimerConfig[timer_num];
97
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
97
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
98
 }
98
 }

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

40
 
40
 
41
 #define FORCE_INLINE __attribute__((always_inline)) inline
41
 #define FORCE_INLINE __attribute__((always_inline)) inline
42
 
42
 
43
-typedef uint32_t timer_t;
43
+typedef uint32_t hal_timer_t;
44
 #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
44
 #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
45
 
45
 
46
 #define STEP_TIMER_NUM 0  // index of timer to use for stepper
46
 #define STEP_TIMER_NUM 0  // index of timer to use for stepper
77
 void HAL_timer_init(void);
77
 void HAL_timer_init(void);
78
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
78
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
79
 
79
 
80
-static FORCE_INLINE void HAL_timer_set_count(const uint8_t timer_num, const timer_t count) {
80
+static FORCE_INLINE void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
81
   switch (timer_num) {
81
   switch (timer_num) {
82
     case 0:
82
     case 0:
83
       LPC_TIM0->MR0 = count;
83
       LPC_TIM0->MR0 = count;
92
   }
92
   }
93
 }
93
 }
94
 
94
 
95
-static FORCE_INLINE timer_t HAL_timer_get_count(const uint8_t timer_num) {
95
+static FORCE_INLINE hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
96
   switch (timer_num) {
96
   switch (timer_num) {
97
     case 0: return LPC_TIM0->MR0;
97
     case 0: return LPC_TIM0->MR0;
98
     case 1: return LPC_TIM1->MR0;
98
     case 1: return LPC_TIM1->MR0;
100
   return 0;
100
   return 0;
101
 }
101
 }
102
 
102
 
103
-static FORCE_INLINE timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
103
+static FORCE_INLINE hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
104
   switch (timer_num) {
104
   switch (timer_num) {
105
     case 0: return LPC_TIM0->TC;
105
     case 0: return LPC_TIM0->TC;
106
     case 1: return LPC_TIM1->TC;
106
     case 1: return LPC_TIM1->TC;

+ 5
- 5
Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h View File

43
  */
43
  */
44
 #define FORCE_INLINE __attribute__((always_inline)) inline
44
 #define FORCE_INLINE __attribute__((always_inline)) inline
45
 
45
 
46
-typedef uint16_t timer_t;
46
+typedef uint16_t hal_timer_t;
47
 #define HAL_TIMER_TYPE_MAX 0xFFFF
47
 #define HAL_TIMER_TYPE_MAX 0xFFFF
48
 
48
 
49
 #define STEP_TIMER_NUM 5  // index of timer to use for stepper
49
 #define STEP_TIMER_NUM 5  // index of timer to use for stepper
126
   }
126
   }
127
 }
127
 }
128
 
128
 
129
-static FORCE_INLINE timer_t HAL_timer_get_count (uint8_t timer_num) {
130
-  timer_t temp;
129
+static FORCE_INLINE hal_timer_t HAL_timer_get_count (uint8_t timer_num) {
130
+  hal_timer_t temp;
131
   switch (timer_num) {
131
   switch (timer_num) {
132
   case STEP_TIMER_NUM:
132
   case STEP_TIMER_NUM:
133
     temp = StepperTimer.getCompare(STEP_TIMER_CHAN);
133
     temp = StepperTimer.getCompare(STEP_TIMER_CHAN);
142
   return temp;
142
   return temp;
143
 }
143
 }
144
 
144
 
145
-static FORCE_INLINE timer_t HAL_timer_get_current_count(uint8_t timer_num) {
146
-  timer_t temp;
145
+static FORCE_INLINE hal_timer_t HAL_timer_get_current_count(uint8_t timer_num) {
146
+  hal_timer_t temp;
147
   switch (timer_num) {
147
   switch (timer_num) {
148
   case STEP_TIMER_NUM:
148
   case STEP_TIMER_NUM:
149
     temp = StepperTimer.getCount();
149
     temp = StepperTimer.getCount();

+ 9
- 9
Marlin/src/HAL/HAL_STM32F1/endstop_interrupts.h View File

51
 
51
 
52
 void setup_endstop_interrupts(void) {
52
 void setup_endstop_interrupts(void) {
53
   #if HAS_X_MAX
53
   #if HAS_X_MAX
54
-    pinMode(X_MAX_PIN, INPUT);
54
+    SET_INPUT(X_MAX_PIN);
55
     attachInterrupt(X_MAX_PIN, endstop_ISR, CHANGE); // assign it
55
     attachInterrupt(X_MAX_PIN, endstop_ISR, CHANGE); // assign it
56
   #endif
56
   #endif
57
   #if HAS_X_MIN
57
   #if HAS_X_MIN
58
-    pinMode(X_MIN_PIN, INPUT);
58
+    SET_INPUT(X_MIN_PIN);
59
     attachInterrupt(X_MIN_PIN, endstop_ISR, CHANGE);
59
     attachInterrupt(X_MIN_PIN, endstop_ISR, CHANGE);
60
   #endif
60
   #endif
61
   #if HAS_Y_MAX
61
   #if HAS_Y_MAX
62
-    pinMode(Y_MAX_PIN, INPUT);
62
+    SET_INPUT(Y_MAX_PIN);
63
     attachInterrupt(Y_MAX_PIN, endstop_ISR, CHANGE);
63
     attachInterrupt(Y_MAX_PIN, endstop_ISR, CHANGE);
64
   #endif
64
   #endif
65
   #if HAS_Y_MIN
65
   #if HAS_Y_MIN
66
-    pinMode(Y_MIN_PIN, INPUT);
66
+    SET_INPUT(Y_MIN_PIN);
67
     attachInterrupt(Y_MIN_PIN, endstop_ISR, CHANGE);
67
     attachInterrupt(Y_MIN_PIN, endstop_ISR, CHANGE);
68
   #endif
68
   #endif
69
   #if HAS_Z_MAX
69
   #if HAS_Z_MAX
70
-    pinMode(Z_MAX_PIN, INPUT);
70
+    SET_INPUT(Z_MAX_PIN);
71
     attachInterrupt(Z_MAX_PIN, endstop_ISR, CHANGE);
71
     attachInterrupt(Z_MAX_PIN, endstop_ISR, CHANGE);
72
   #endif
72
   #endif
73
   #if HAS_Z_MIN
73
   #if HAS_Z_MIN
74
-    pinMode(Z_MIN_PIN, INPUT);
74
+    SET_INPUT(Z_MIN_PIN);
75
     attachInterrupt(Z_MIN_PIN, endstop_ISR, CHANGE);
75
     attachInterrupt(Z_MIN_PIN, endstop_ISR, CHANGE);
76
   #endif
76
   #endif
77
   #if HAS_Z2_MAX
77
   #if HAS_Z2_MAX
78
-    pinMode(Z2_MAX_PIN, INPUT);
78
+    SET_INPUT(Z2_MAX_PIN);
79
     attachInterrupt(Z2_MAX_PIN, endstop_ISR, CHANGE);
79
     attachInterrupt(Z2_MAX_PIN, endstop_ISR, CHANGE);
80
   #endif
80
   #endif
81
   #if HAS_Z2_MIN
81
   #if HAS_Z2_MIN
82
-    pinMode(Z2_MIN_PIN, INPUT);
82
+    SET_INPUT(Z2_MIN_PIN);
83
     attachInterrupt(Z2_MIN_PIN, endstop_ISR, CHANGE);
83
     attachInterrupt(Z2_MIN_PIN, endstop_ISR, CHANGE);
84
   #endif
84
   #endif
85
   #if HAS_Z_MIN_PROBE_PIN
85
   #if HAS_Z_MIN_PROBE_PIN
86
-    pinMode(Z_MIN_PROBE_PIN, INPUT);
86
+    SET_INPUT(Z_MIN_PROBE_PIN);
87
     attachInterrupt(Z_MIN_PROBE_PIN, endstop_ISR, CHANGE);
87
     attachInterrupt(Z_MIN_PROBE_PIN, endstop_ISR, CHANGE);
88
   #endif
88
   #endif
89
 }
89
 }

+ 2
- 2
Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h View File

40
 
40
 
41
 #define FORCE_INLINE __attribute__((always_inline)) inline
41
 #define FORCE_INLINE __attribute__((always_inline)) inline
42
 
42
 
43
-typedef uint32_t timer_t;
43
+typedef uint32_t hal_timer_t;
44
 #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
44
 #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
45
 
45
 
46
 #define STEP_TIMER_NUM 0
46
 #define STEP_TIMER_NUM 0
82
   }
82
   }
83
 }
83
 }
84
 
84
 
85
-static FORCE_INLINE timer_t HAL_timer_get_count(const uint8_t timer_num) {
85
+static FORCE_INLINE hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
86
   switch(timer_num) {
86
   switch(timer_num) {
87
     case 0: return FTM0_C0V;
87
     case 0: return FTM0_C0V;
88
     case 1: return FTM1_C0V;
88
     case 1: return FTM1_C0V;

+ 14
- 14
Marlin/src/HAL/SpiEeprom.cpp View File

44
   eeprom_temp[0] = CMD_READ;
44
   eeprom_temp[0] = CMD_READ;
45
   eeprom_temp[1] = ((unsigned)pos>>8) & 0xFF; // addr High
45
   eeprom_temp[1] = ((unsigned)pos>>8) & 0xFF; // addr High
46
   eeprom_temp[2] = (unsigned)pos& 0xFF;       // addr Low
46
   eeprom_temp[2] = (unsigned)pos& 0xFF;       // addr Low
47
-  digitalWrite(SPI_EEPROM1_CS, HIGH);
48
-  digitalWrite(SPI_EEPROM1_CS, LOW);
47
+  WRITE(SPI_EEPROM1_CS, HIGH);
48
+  WRITE(SPI_EEPROM1_CS, LOW);
49
   spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3);
49
   spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3);
50
 
50
 
51
   v = spiRec(SPI_CHAN_EEPROM1);
51
   v = spiRec(SPI_CHAN_EEPROM1);
52
-  digitalWrite(SPI_EEPROM1_CS, HIGH);
52
+  WRITE(SPI_EEPROM1_CS, HIGH);
53
   return v;
53
   return v;
54
 }
54
 }
55
 
55
 
62
   eeprom_temp[0] = CMD_READ;
62
   eeprom_temp[0] = CMD_READ;
63
   eeprom_temp[1] = ((unsigned)eeprom_address>>8) & 0xFF; // addr High
63
   eeprom_temp[1] = ((unsigned)eeprom_address>>8) & 0xFF; // addr High
64
   eeprom_temp[2] = (unsigned)eeprom_address& 0xFF;       // addr Low
64
   eeprom_temp[2] = (unsigned)eeprom_address& 0xFF;       // addr Low
65
-  digitalWrite(SPI_EEPROM1_CS, HIGH);
66
-  digitalWrite(SPI_EEPROM1_CS, LOW);
65
+  WRITE(SPI_EEPROM1_CS, HIGH);
66
+  WRITE(SPI_EEPROM1_CS, LOW);
67
   spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3);
67
   spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3);
68
 
68
 
69
   uint8_t *p_dest = (uint8_t *)dest;
69
   uint8_t *p_dest = (uint8_t *)dest;
70
   while (n--)
70
   while (n--)
71
     *p_dest++ = spiRec(SPI_CHAN_EEPROM1);
71
     *p_dest++ = spiRec(SPI_CHAN_EEPROM1);
72
-  digitalWrite(SPI_EEPROM1_CS, HIGH);
72
+  WRITE(SPI_EEPROM1_CS, HIGH);
73
 }
73
 }
74
 
74
 
75
 void eeprom_write_byte(uint8_t* pos, uint8_t value) {
75
 void eeprom_write_byte(uint8_t* pos, uint8_t value) {
77
 
77
 
78
   /*write enable*/
78
   /*write enable*/
79
   eeprom_temp[0] = CMD_WREN;
79
   eeprom_temp[0] = CMD_WREN;
80
-  digitalWrite(SPI_EEPROM1_CS, LOW);
80
+  WRITE(SPI_EEPROM1_CS, LOW);
81
   spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 1);
81
   spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 1);
82
-  digitalWrite(SPI_EEPROM1_CS, HIGH);
82
+  WRITE(SPI_EEPROM1_CS, HIGH);
83
   delay(1);
83
   delay(1);
84
 
84
 
85
   /*write addr*/
85
   /*write addr*/
86
   eeprom_temp[0] = CMD_WRITE;
86
   eeprom_temp[0] = CMD_WRITE;
87
   eeprom_temp[1] = ((unsigned)pos>>8) & 0xFF;  //addr High
87
   eeprom_temp[1] = ((unsigned)pos>>8) & 0xFF;  //addr High
88
   eeprom_temp[2] = (unsigned)pos & 0xFF;       //addr Low
88
   eeprom_temp[2] = (unsigned)pos & 0xFF;       //addr Low
89
-  digitalWrite(SPI_EEPROM1_CS, LOW);
89
+  WRITE(SPI_EEPROM1_CS, LOW);
90
   spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3);
90
   spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3);
91
 
91
 
92
   spiSend(SPI_CHAN_EEPROM1, value);
92
   spiSend(SPI_CHAN_EEPROM1, value);
93
-  digitalWrite(SPI_EEPROM1_CS, HIGH);
93
+  WRITE(SPI_EEPROM1_CS, HIGH);
94
   delay(7);   // wait for page write to complete
94
   delay(7);   // wait for page write to complete
95
 }
95
 }
96
 
96
 
99
 
99
 
100
   /*write enable*/
100
   /*write enable*/
101
   eeprom_temp[0] = CMD_WREN;
101
   eeprom_temp[0] = CMD_WREN;
102
-  digitalWrite(SPI_EEPROM1_CS, LOW);
102
+  WRITE(SPI_EEPROM1_CS, LOW);
103
   spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 1);
103
   spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 1);
104
-  digitalWrite(SPI_EEPROM1_CS, HIGH);
104
+  WRITE(SPI_EEPROM1_CS, HIGH);
105
   delay(1);
105
   delay(1);
106
 
106
 
107
   /*write addr*/
107
   /*write addr*/
108
   eeprom_temp[0] = CMD_WRITE;
108
   eeprom_temp[0] = CMD_WRITE;
109
   eeprom_temp[1] = ((unsigned)eeprom_address>>8) & 0xFF;  //addr High
109
   eeprom_temp[1] = ((unsigned)eeprom_address>>8) & 0xFF;  //addr High
110
   eeprom_temp[2] = (unsigned)eeprom_address & 0xFF;       //addr Low
110
   eeprom_temp[2] = (unsigned)eeprom_address & 0xFF;       //addr Low
111
-  digitalWrite(SPI_EEPROM1_CS, LOW);
111
+  WRITE(SPI_EEPROM1_CS, LOW);
112
   spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3);
112
   spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3);
113
 
113
 
114
   spiSend(SPI_CHAN_EEPROM1, (const uint8_t*)src, n);
114
   spiSend(SPI_CHAN_EEPROM1, (const uint8_t*)src, n);
115
-  digitalWrite(SPI_EEPROM1_CS, HIGH);
115
+  WRITE(SPI_EEPROM1_CS, HIGH);
116
   delay(7);   // wait for page write to complete
116
   delay(7);   // wait for page write to complete
117
 }
117
 }
118
 
118
 

+ 41
- 56
Marlin/src/feature/dac/dac_dac084s085.cpp View File

13
 #include "../../Marlin.h"
13
 #include "../../Marlin.h"
14
 #include "../../module/stepper.h"
14
 #include "../../module/stepper.h"
15
 
15
 
16
-dac084s085::dac084s085() {
17
-  return ;
18
-}
16
+dac084s085::dac084s085() { }
19
 
17
 
20
 void dac084s085::begin() {
18
 void dac084s085::begin() {
21
-  uint8_t externalDac_buf[2] = {0x20,0x00};//all off
19
+  uint8_t externalDac_buf[] = { 0x20, 0x00 }; // all off
22
 
20
 
23
   // All SPI chip-select HIGH
21
   // All SPI chip-select HIGH
24
-  pinMode(DAC0_SYNC, OUTPUT);
25
-  digitalWrite( DAC0_SYNC , HIGH );
22
+  SET_OUTPUT(DAC0_SYNC);
26
   #if EXTRUDERS > 1
23
   #if EXTRUDERS > 1
27
-    pinMode(DAC1_SYNC, OUTPUT);
28
-    digitalWrite( DAC1_SYNC , HIGH );
24
+    SET_OUTPUT(DAC1_SYNC);
29
   #endif
25
   #endif
30
-  digitalWrite( SPI_EEPROM1_CS , HIGH );
31
-  digitalWrite( SPI_EEPROM2_CS , HIGH );
32
-  digitalWrite( SPI_FLASH_CS , HIGH );
33
-  digitalWrite( SS_PIN , HIGH );
26
+  cshigh();
34
   spiBegin();
27
   spiBegin();
35
 
28
 
36
   //init onboard DAC
29
   //init onboard DAC
37
   delayMicroseconds(2U);
30
   delayMicroseconds(2U);
38
-  digitalWrite( DAC0_SYNC , LOW );
31
+  WRITE(DAC0_SYNC, LOW);
39
   delayMicroseconds(2U);
32
   delayMicroseconds(2U);
40
-  digitalWrite( DAC0_SYNC , HIGH );
33
+  WRITE(DAC0_SYNC, HIGH);
41
   delayMicroseconds(2U);
34
   delayMicroseconds(2U);
42
-  digitalWrite( DAC0_SYNC , LOW );
35
+  WRITE(DAC0_SYNC, LOW);
43
 
36
 
44
-  spiSend(SPI_CHAN_DAC,externalDac_buf , 2);
45
-  digitalWrite( DAC0_SYNC , HIGH );
37
+  spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
38
+  WRITE(DAC0_SYNC, HIGH);
46
 
39
 
47
   #if EXTRUDERS > 1
40
   #if EXTRUDERS > 1
48
     //init Piggy DAC
41
     //init Piggy DAC
49
     delayMicroseconds(2U);
42
     delayMicroseconds(2U);
50
-    digitalWrite( DAC1_SYNC , LOW );
43
+    WRITE(DAC1_SYNC, LOW);
51
     delayMicroseconds(2U);
44
     delayMicroseconds(2U);
52
-    digitalWrite( DAC1_SYNC , HIGH );
45
+    WRITE(DAC1_SYNC, HIGH);
53
     delayMicroseconds(2U);
46
     delayMicroseconds(2U);
54
-    digitalWrite( DAC1_SYNC , LOW );
47
+    WRITE(DAC1_SYNC, LOW);
55
 
48
 
56
-    spiSend(SPI_CHAN_DAC,externalDac_buf , 2);
57
-    digitalWrite( DAC1_SYNC , HIGH );
49
+    spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
50
+    WRITE(DAC1_SYNC, HIGH);
58
   #endif
51
   #endif
59
 
52
 
60
   return;
53
   return;
61
 }
54
 }
62
 
55
 
63
-void dac084s085::setValue(uint8_t channel, uint8_t value) {
64
-  if(channel >= 7) // max channel (X,Y,Z,E0,E1,E2,E3)
65
-    return;
66
-  if(value > 255) value = 255;
67
-
68
-  uint8_t externalDac_buf[2] = {0x10,0x00};
69
-
70
-  if(channel > 3)
71
-    externalDac_buf[0] |= (7 - channel << 6);
72
-  else
73
-    externalDac_buf[0] |= (3 - channel << 6);
56
+void dac084s085::setValue(const uint8_t channel, const uint8_t value) {
57
+  if (channel >= 7) return; // max channel (X,Y,Z,E0,E1,E2,E3)
74
 
58
 
75
-  externalDac_buf[0] |= (value >> 4);
76
-  externalDac_buf[1] |= (value << 4);
59
+  const uint8_t externalDac_buf[] = {
60
+    0x10 | ((channel > 3 ? 7 : 3) - channel << 6) | (value >> 4),
61
+    0x00 | (value << 4)
62
+  };
77
 
63
 
78
   // All SPI chip-select HIGH
64
   // All SPI chip-select HIGH
79
-  digitalWrite( DAC0_SYNC , HIGH );
80
-  #if EXTRUDERS > 1
81
-    digitalWrite( DAC1_SYNC , HIGH );
82
-  #endif
83
-  digitalWrite( SPI_EEPROM1_CS , HIGH );
84
-  digitalWrite( SPI_EEPROM2_CS , HIGH );
85
-  digitalWrite( SPI_FLASH_CS , HIGH );
86
-  digitalWrite( SS_PIN , HIGH );
87
-
88
-  if(channel > 3) { // DAC Piggy E1,E2,E3
65
+  cshigh();
89
 
66
 
90
-    digitalWrite(DAC1_SYNC , LOW);
67
+  if (channel > 3) {        // DAC Piggy E1,E2,E3
68
+    WRITE(DAC1_SYNC, LOW);
91
     delayMicroseconds(2U);
69
     delayMicroseconds(2U);
92
-    digitalWrite(DAC1_SYNC , HIGH);
70
+    WRITE(DAC1_SYNC, HIGH);
93
     delayMicroseconds(2U);
71
     delayMicroseconds(2U);
94
-    digitalWrite(DAC1_SYNC , LOW);
72
+    WRITE(DAC1_SYNC, LOW);
95
   }
73
   }
96
-
97
-  else { // DAC onboard X,Y,Z,E0
98
-
99
-    digitalWrite(DAC0_SYNC , LOW);
74
+  else {                    // DAC onboard X,Y,Z,E0
75
+    WRITE(DAC0_SYNC, LOW);
100
     delayMicroseconds(2U);
76
     delayMicroseconds(2U);
101
-    digitalWrite(DAC0_SYNC , HIGH);
77
+    WRITE(DAC0_SYNC, HIGH);
102
     delayMicroseconds(2U);
78
     delayMicroseconds(2U);
103
-    digitalWrite(DAC0_SYNC , LOW);
79
+    WRITE(DAC0_SYNC, LOW);
104
   }
80
   }
105
 
81
 
106
   delayMicroseconds(2U);
82
   delayMicroseconds(2U);
107
-  spiSend(SPI_CHAN_DAC,externalDac_buf , 2);
83
+  spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
84
+}
108
 
85
 
109
-  return;
86
+void dac084s085::cshigh() {
87
+  WRITE(DAC0_SYNC, HIGH);
88
+  #if EXTRUDERS > 1
89
+    WRITE(DAC1_SYNC, HIGH);
90
+  #endif
91
+  WRITE(SPI_EEPROM1_CS, HIGH);
92
+  WRITE(SPI_EEPROM2_CS, HIGH);
93
+  WRITE(SPI_FLASH_CS, HIGH);
94
+  WRITE(SS_PIN, HIGH);
110
 }
95
 }
111
 
96
 
112
 #endif // MB(ALLIGATOR)
97
 #endif // MB(ALLIGATOR)

+ 3
- 1
Marlin/src/feature/dac/dac_dac084s085.h View File

5
   public:
5
   public:
6
     dac084s085();
6
     dac084s085();
7
     static void begin(void);
7
     static void begin(void);
8
-    static void setValue(uint8_t channel, uint8_t value);
8
+    static void setValue(const uint8_t channel, const uint8_t value);
9
+  private:
10
+    static void cshigh();
9
 };
11
 };
10
 
12
 
11
 #endif // DAC084S085_H
13
 #endif // DAC084S085_H

+ 11
- 11
Marlin/src/module/stepper.cpp View File

120
 
120
 
121
 #if ENABLED(LIN_ADVANCE)
121
 #if ENABLED(LIN_ADVANCE)
122
 
122
 
123
-  constexpr timer_t ADV_NEVER = HAL_TIMER_TYPE_MAX;
123
+  constexpr hal_timer_t ADV_NEVER = HAL_TIMER_TYPE_MAX;
124
 
124
 
125
-  timer_t Stepper::nextMainISR = 0,
125
+  hal_timer_t Stepper::nextMainISR = 0,
126
          Stepper::nextAdvanceISR = ADV_NEVER,
126
          Stepper::nextAdvanceISR = ADV_NEVER,
127
          Stepper::eISR_Rate = ADV_NEVER;
127
          Stepper::eISR_Rate = ADV_NEVER;
128
 
128
 
137
    * This fix isn't perfect and may lose steps - but better than locking up completely
137
    * This fix isn't perfect and may lose steps - but better than locking up completely
138
    * in future the planner should slow down if advance stepping rate would be too high
138
    * in future the planner should slow down if advance stepping rate would be too high
139
    */
139
    */
140
-  FORCE_INLINE timer_t adv_rate(const int steps, const timer_t timer, const uint8_t loops) {
140
+  FORCE_INLINE hal_timer_t adv_rate(const int steps, const hal_timer_t timer, const uint8_t loops) {
141
     if (steps) {
141
     if (steps) {
142
-      const timer_t rate = (timer * loops) / abs(steps);
142
+      const hal_timer_t rate = (timer * loops) / abs(steps);
143
       //return constrain(rate, 1, ADV_NEVER - 1)
143
       //return constrain(rate, 1, ADV_NEVER - 1)
144
       return rate ? rate : 1;
144
       return rate ? rate : 1;
145
     }
145
     }
157
   long Stepper::counter_m[MIXING_STEPPERS];
157
   long Stepper::counter_m[MIXING_STEPPERS];
158
 #endif
158
 #endif
159
 
159
 
160
-timer_t Stepper::acc_step_rate; // needed for deceleration start point
160
+hal_timer_t Stepper::acc_step_rate; // needed for deceleration start point
161
 uint8_t Stepper::step_loops, Stepper::step_loops_nominal;
161
 uint8_t Stepper::step_loops, Stepper::step_loops_nominal;
162
-timer_t Stepper::OCR1A_nominal;
162
+hal_timer_t Stepper::OCR1A_nominal;
163
 
163
 
164
 volatile long Stepper::endstops_trigsteps[XYZ];
164
 volatile long Stepper::endstops_trigsteps[XYZ];
165
 
165
 
341
 
341
 
342
 void Stepper::isr() {
342
 void Stepper::isr() {
343
 
343
 
344
-  timer_t ocr_val;
344
+  hal_timer_t ocr_val;
345
 
345
 
346
   #define ENDSTOP_NOMINAL_OCR_VAL 1500 * HAL_TICKS_PER_US    // check endstops every 1.5ms to guarantee two stepper ISRs within 5ms for BLTouch
346
   #define ENDSTOP_NOMINAL_OCR_VAL 1500 * HAL_TICKS_PER_US    // check endstops every 1.5ms to guarantee two stepper ISRs within 5ms for BLTouch
347
   #define OCR_VAL_TOLERANCE 500 * HAL_TICKS_PER_US           // First max delay is 2.0ms, last min delay is 0.5ms, all others 1.5ms
347
   #define OCR_VAL_TOLERANCE 500 * HAL_TICKS_PER_US           // First max delay is 2.0ms, last min delay is 0.5ms, all others 1.5ms
677
     NOMORE(acc_step_rate, current_block->nominal_rate);
677
     NOMORE(acc_step_rate, current_block->nominal_rate);
678
 
678
 
679
     // step_rate to timer interval
679
     // step_rate to timer interval
680
-    const timer_t timer = calc_timer(acc_step_rate);
680
+    const hal_timer_t timer = calc_timer(acc_step_rate);
681
 
681
 
682
     SPLIT(timer);  // split step into multiple ISRs if larger than  ENDSTOP_NOMINAL_OCR_VAL
682
     SPLIT(timer);  // split step into multiple ISRs if larger than  ENDSTOP_NOMINAL_OCR_VAL
683
     _NEXT_ISR(ocr_val);
683
     _NEXT_ISR(ocr_val);
699
     #endif // LIN_ADVANCE
699
     #endif // LIN_ADVANCE
700
   }
700
   }
701
   else if (step_events_completed > (uint32_t)current_block->decelerate_after) {
701
   else if (step_events_completed > (uint32_t)current_block->decelerate_after) {
702
-    timer_t step_rate;
702
+    hal_timer_t step_rate;
703
     #ifdef CPU_32_BIT
703
     #ifdef CPU_32_BIT
704
       MultiU32X24toH32(step_rate, deceleration_time, current_block->acceleration_rate);
704
       MultiU32X24toH32(step_rate, deceleration_time, current_block->acceleration_rate);
705
     #else
705
     #else
714
       step_rate = current_block->final_rate;
714
       step_rate = current_block->final_rate;
715
 
715
 
716
     // step_rate to timer interval
716
     // step_rate to timer interval
717
-    const timer_t timer = calc_timer(step_rate);
717
+    const hal_timer_t timer = calc_timer(step_rate);
718
 
718
 
719
     SPLIT(timer);  // split step into multiple ISRs if larger than  ENDSTOP_NOMINAL_OCR_VAL
719
     SPLIT(timer);  // split step into multiple ISRs if larger than  ENDSTOP_NOMINAL_OCR_VAL
720
     _NEXT_ISR(ocr_val);
720
     _NEXT_ISR(ocr_val);
754
   #if DISABLED(LIN_ADVANCE)
754
   #if DISABLED(LIN_ADVANCE)
755
     #ifdef CPU_32_BIT
755
     #ifdef CPU_32_BIT
756
       // Make sure stepper interrupt does not monopolise CPU by adjusting count to give about 8 us room
756
       // Make sure stepper interrupt does not monopolise CPU by adjusting count to give about 8 us room
757
-      timer_t stepper_timer_count = HAL_timer_get_count(STEP_TIMER_NUM),
757
+      hal_timer_t stepper_timer_count = HAL_timer_get_count(STEP_TIMER_NUM),
758
                      stepper_timer_current_count = HAL_timer_get_current_count(STEP_TIMER_NUM) + 8 * HAL_TICKS_PER_US;
758
                      stepper_timer_current_count = HAL_timer_get_current_count(STEP_TIMER_NUM) + 8 * HAL_TICKS_PER_US;
759
       HAL_timer_set_count(STEP_TIMER_NUM, max(stepper_timer_count, stepper_timer_current_count));
759
       HAL_timer_set_count(STEP_TIMER_NUM, max(stepper_timer_count, stepper_timer_current_count));
760
     #else
760
     #else

+ 5
- 5
Marlin/src/module/stepper.h View File

97
     static volatile uint32_t step_events_completed; // The number of step events executed in the current block
97
     static volatile uint32_t step_events_completed; // The number of step events executed in the current block
98
 
98
 
99
     #if ENABLED(LIN_ADVANCE)
99
     #if ENABLED(LIN_ADVANCE)
100
-      static timer_t nextMainISR, nextAdvanceISR, eISR_Rate;
100
+      static hal_timer_t nextMainISR, nextAdvanceISR, eISR_Rate;
101
       #define _NEXT_ISR(T) nextMainISR = T
101
       #define _NEXT_ISR(T) nextMainISR = T
102
 
102
 
103
       static volatile int e_steps[E_STEPPERS];
103
       static volatile int e_steps[E_STEPPERS];
112
 
112
 
113
     static long acceleration_time, deceleration_time;
113
     static long acceleration_time, deceleration_time;
114
     //unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
114
     //unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
115
-    static timer_t acc_step_rate; // needed for deceleration start point
115
+    static hal_timer_t acc_step_rate; // needed for deceleration start point
116
     static uint8_t step_loops, step_loops_nominal;
116
     static uint8_t step_loops, step_loops_nominal;
117
-    static timer_t OCR1A_nominal;
117
+    static hal_timer_t OCR1A_nominal;
118
 
118
 
119
     static volatile long endstops_trigsteps[XYZ];
119
     static volatile long endstops_trigsteps[XYZ];
120
     static volatile long endstops_stepsTotal, endstops_stepsDone;
120
     static volatile long endstops_stepsTotal, endstops_stepsDone;
277
 
277
 
278
   private:
278
   private:
279
 
279
 
280
-    static FORCE_INLINE timer_t calc_timer(timer_t step_rate) {
281
-      timer_t timer;
280
+    static FORCE_INLINE hal_timer_t calc_timer(hal_timer_t step_rate) {
281
+      hal_timer_t timer;
282
 
282
 
283
       NOMORE(step_rate, MAX_STEP_FREQUENCY);
283
       NOMORE(step_rate, MAX_STEP_FREQUENCY);
284
 
284
 

Loading…
Cancel
Save