소스 검색

HAL SPI pin init cleanup

Scott Lahteine 5 년 전
부모
커밋
26de051e92

+ 22
- 29
Marlin/src/HAL/HAL_AVR/HAL_spi_AVR.cpp 파일 보기

21
  */
21
  */
22
 
22
 
23
 /**
23
 /**
24
- * Originally from Arduino Sd2Card Library
24
+ * Adapted from Arduino Sd2Card Library
25
  * Copyright (C) 2009 by William Greiman
25
  * Copyright (C) 2009 by William Greiman
26
  */
26
  */
27
 
27
 
28
 /**
28
 /**
29
- * Description: HAL for AVR - SPI functions
29
+ * HAL for AVR - SPI functions
30
  */
30
  */
31
 
31
 
32
 #ifdef __AVR__
32
 #ifdef __AVR__
37
 
37
 
38
 #include "../../inc/MarlinConfig.h"
38
 #include "../../inc/MarlinConfig.h"
39
 
39
 
40
-// --------------------------------------------------------------------------
41
-// Public Variables
42
-// --------------------------------------------------------------------------
43
-
44
-
45
-// --------------------------------------------------------------------------
46
-// Public functions
47
-// --------------------------------------------------------------------------
48
-
49
-void spiBegin (void) {
50
-  SET_OUTPUT(SS_PIN);
51
-  WRITE(SS_PIN, HIGH);
40
+void spiBegin(void) {
41
+  OUT_WRITE(SS_PIN, HIGH);
52
   SET_OUTPUT(SCK_PIN);
42
   SET_OUTPUT(SCK_PIN);
53
   SET_INPUT(MISO_PIN);
43
   SET_INPUT(MISO_PIN);
54
   SET_OUTPUT(MOSI_PIN);
44
   SET_OUTPUT(MOSI_PIN);
55
 
45
 
56
   #if DISABLED(SOFTWARE_SPI)
46
   #if DISABLED(SOFTWARE_SPI)
57
     // SS must be in output mode even it is not chip select
47
     // SS must be in output mode even it is not chip select
58
-    SET_OUTPUT(SS_PIN);
48
+    //SET_OUTPUT(SS_PIN);
59
     // set SS high - may be chip select for another SPI device
49
     // set SS high - may be chip select for another SPI device
60
-    #if SET_SPI_SS_HIGH
61
-      WRITE(SS_PIN, HIGH);
62
-    #endif  // SET_SPI_SS_HIGH
50
+    //#if SET_SPI_SS_HIGH
51
+      //WRITE(SS_PIN, HIGH);
52
+    //#endif
63
     // set a default rate
53
     // set a default rate
64
     spiInit(1);
54
     spiInit(1);
65
-  #endif  // SOFTWARE_SPI
55
+  #endif
66
 }
56
 }
67
 
57
 
68
-
69
 #if DISABLED(SOFTWARE_SPI, FORCE_SOFT_SPI)
58
 #if DISABLED(SOFTWARE_SPI, FORCE_SOFT_SPI)
70
 
59
 
71
   //------------------------------------------------------------------------------
60
   //------------------------------------------------------------------------------
190
   }
179
   }
191
 
180
 
192
 
181
 
193
-#else
182
+#else // SOFTWARE_SPI || FORCE_SOFT_SPI
183
+
184
+  //------------------------------------------------------------------------------
185
+  // Software SPI
186
+  //------------------------------------------------------------------------------
194
 
187
 
195
-  /** nop to tune soft SPI timing */
188
+  // nop to tune soft SPI timing
196
   #define nop asm volatile ("\tnop\n")
189
   #define nop asm volatile ("\tnop\n")
197
 
190
 
198
-  /** Set SPI rate */
191
+  // Set SPI rate
199
   void spiInit(uint8_t spiRate) {
192
   void spiInit(uint8_t spiRate) {
200
     UNUSED(spiRate);  // nothing to do
193
     UNUSED(spiRate);  // nothing to do
201
   }
194
   }
202
 
195
 
203
-  /** Begin SPI transaction, set clock, bit order, data mode */
196
+  // Begin SPI transaction, set clock, bit order, data mode
204
   void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
197
   void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
205
     UNUSED(spiBeginTransaction);  // nothing to do
198
     UNUSED(spiBeginTransaction);  // nothing to do
206
   }
199
   }
207
 
200
 
208
-  /** Soft SPI receive byte */
201
+  // Soft SPI receive byte
209
   uint8_t spiRec() {
202
   uint8_t spiRec() {
210
     uint8_t data = 0;
203
     uint8_t data = 0;
211
     // no interrupts during byte receive - about 8µs
204
     // no interrupts during byte receive - about 8µs
230
     return data;
223
     return data;
231
   }
224
   }
232
 
225
 
233
-  /** Soft SPI read data */
226
+  // Soft SPI read data
234
   void spiRead(uint8_t* buf, uint16_t nbyte) {
227
   void spiRead(uint8_t* buf, uint16_t nbyte) {
235
     for (uint16_t i = 0; i < nbyte; i++)
228
     for (uint16_t i = 0; i < nbyte; i++)
236
       buf[i] = spiRec();
229
       buf[i] = spiRec();
237
   }
230
   }
238
 
231
 
239
-  /** Soft SPI send byte */
232
+  // Soft SPI send byte
240
   void spiSend(uint8_t data) {
233
   void spiSend(uint8_t data) {
241
     // no interrupts during byte send - about 8µs
234
     // no interrupts during byte send - about 8µs
242
     cli();
235
     cli();
257
     sei();
250
     sei();
258
   }
251
   }
259
 
252
 
260
-  /** Soft SPI send block */
253
+  // Soft SPI send block
261
   void spiSendBlock(uint8_t token, const uint8_t* buf) {
254
   void spiSendBlock(uint8_t token, const uint8_t* buf) {
262
     spiSend(token);
255
     spiSend(token);
263
     for (uint16_t i = 0; i < 512; i++)
256
     for (uint16_t i = 0; i < 512; i++)
264
       spiSend(buf[i]);
257
       spiSend(buf[i]);
265
   }
258
   }
266
 
259
 
267
-#endif // SOFTWARE_SPI, FORCE_SOFT_SPI
260
+#endif // SOFTWARE_SPI || FORCE_SOFT_SPI
268
 
261
 
269
 #endif // __AVR__
262
 #endif // __AVR__

+ 2
- 4
Marlin/src/HAL/HAL_TEENSY31_32/HAL_spi_Teensy.cpp 파일 보기

38
   #if !PIN_EXISTS(SS)
38
   #if !PIN_EXISTS(SS)
39
     #error "SS_PIN not defined!"
39
     #error "SS_PIN not defined!"
40
   #endif
40
   #endif
41
-  SET_OUTPUT(SS_PIN);
42
-  WRITE(SS_PIN, HIGH);
41
+  OUT_WRITE(SS_PIN, HIGH);
43
   SET_OUTPUT(SCK_PIN);
42
   SET_OUTPUT(SCK_PIN);
44
   SET_INPUT(MISO_PIN);
43
   SET_INPUT(MISO_PIN);
45
   SET_OUTPUT(MOSI_PIN);
44
   SET_OUTPUT(MOSI_PIN);
46
 
45
 
47
-  //#if DISABLED(SOFTWARE_SPI)
48
-  #if 0
46
+  #if 0 && DISABLED(SOFTWARE_SPI)
49
     // set SS high - may be chip select for another SPI device
47
     // set SS high - may be chip select for another SPI device
50
     #if SET_SPI_SS_HIGH
48
     #if SET_SPI_SS_HIGH
51
       WRITE(SS_PIN, HIGH);
49
       WRITE(SS_PIN, HIGH);

+ 2
- 2
Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.h 파일 보기

23
 
23
 
24
 #include <Servo.h>
24
 #include <Servo.h>
25
 
25
 
26
-// Inherit and expand on the official library
26
+// Inherit and expand on core Servo library
27
 class libServo : public Servo {
27
 class libServo : public Servo {
28
   public:
28
   public:
29
     int8_t attach(const int pin);
29
     int8_t attach(const int pin);
32
   private:
32
   private:
33
      uint16_t min_ticks;
33
      uint16_t min_ticks;
34
      uint16_t max_ticks;
34
      uint16_t max_ticks;
35
-     uint8_t servoIndex;               // index into the channel data for this servo
35
+     uint8_t servoIndex; // Index into the channel data for this servo
36
 };
36
 };

+ 44
- 35
Marlin/src/HAL/HAL_TEENSY35_36/HAL_spi_Teensy.cpp 파일 보기

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
 #if defined(__MK64FX512__) || defined(__MK66FX1M0__)
22
 #if defined(__MK64FX512__) || defined(__MK66FX1M0__)
2
 
23
 
3
 #include "HAL.h"
24
 #include "HAL.h"
8
 
29
 
9
 static SPISettings spiConfig;
30
 static SPISettings spiConfig;
10
 
31
 
11
-// Standard SPI functions
12
-/** Initialize SPI bus */
13
 void spiBegin(void) {
32
 void spiBegin(void) {
14
   #if !PIN_EXISTS(SS)
33
   #if !PIN_EXISTS(SS)
15
     #error SS_PIN not defined!
34
     #error SS_PIN not defined!
16
   #endif
35
   #endif
17
-  SET_OUTPUT(SS_PIN);
18
-  WRITE(SS_PIN, HIGH);
36
+  OUT_WRITE(SS_PIN, HIGH);
19
   SET_OUTPUT(SCK_PIN);
37
   SET_OUTPUT(SCK_PIN);
20
   SET_INPUT(MISO_PIN);
38
   SET_INPUT(MISO_PIN);
21
   SET_OUTPUT(MOSI_PIN);
39
   SET_OUTPUT(MOSI_PIN);
22
 
40
 
23
-  //#if DISABLED(SOFTWARE_SPI)
24
-  #if 0
41
+  #if 0 && DISABLED(SOFTWARE_SPI)
25
     // set SS high - may be chip select for another SPI device
42
     // set SS high - may be chip select for another SPI device
26
     #if SET_SPI_SS_HIGH
43
     #if SET_SPI_SS_HIGH
27
       WRITE(SS_PIN, HIGH);
44
       WRITE(SS_PIN, HIGH);
28
-    #endif  // SET_SPI_SS_HIGH
45
+    #endif
29
     // set a default rate
46
     // set a default rate
30
     spiInit(SPI_HALF_SPEED); // 1
47
     spiInit(SPI_HALF_SPEED); // 1
31
-  #endif  // SOFTWARE_SPI
48
+  #endif
32
 }
49
 }
33
 
50
 
34
-/** Configure SPI for specified SPI speed */
35
 void spiInit(uint8_t spiRate) {
51
 void spiInit(uint8_t spiRate) {
36
-  // Use datarates Marlin uses
52
+  // Use Marlin data-rates
37
   uint32_t clock;
53
   uint32_t clock;
38
   switch (spiRate) {
54
   switch (spiRate) {
39
   case SPI_FULL_SPEED:    clock = 10000000; break;
55
   case SPI_FULL_SPEED:    clock = 10000000; break;
49
   SPI.begin();
65
   SPI.begin();
50
 }
66
 }
51
 
67
 
52
-//------------------------------------------------------------------------------
53
-/** SPI receive a byte */
54
 uint8_t spiRec(void) {
68
 uint8_t spiRec(void) {
55
   SPI.beginTransaction(spiConfig);
69
   SPI.beginTransaction(spiConfig);
56
   uint8_t returnByte = SPI.transfer(0xFF);
70
   uint8_t returnByte = SPI.transfer(0xFF);
57
   SPI.endTransaction();
71
   SPI.endTransaction();
58
   return returnByte;
72
   return returnByte;
59
-//  SPDR = 0xFF;
60
-//  while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
61
-//  return SPDR;
73
+  //SPDR = 0xFF;
74
+  //while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
75
+  //return SPDR;
62
 }
76
 }
63
-//------------------------------------------------------------------------------
64
-/** SPI read data  */
77
+
65
 void spiRead(uint8_t* buf, uint16_t nbyte) {
78
 void spiRead(uint8_t* buf, uint16_t nbyte) {
66
   SPI.beginTransaction(spiConfig);
79
   SPI.beginTransaction(spiConfig);
67
   SPI.transfer(buf, nbyte);
80
   SPI.transfer(buf, nbyte);
68
   SPI.endTransaction();
81
   SPI.endTransaction();
69
-//if (nbyte-- == 0) return;
70
-//  SPDR = 0xFF;
71
-//for (uint16_t i = 0; i < nbyte; i++) {
72
-//  while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
73
-//  buf[i] = SPDR;
74
-//  SPDR = 0xFF;
75
-//}
76
-//while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
77
-//buf[nbyte] = SPDR;
82
+  //if (nbyte-- == 0) return;
83
+  //  SPDR = 0xFF;
84
+  //for (uint16_t i = 0; i < nbyte; i++) {
85
+  //  while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
86
+  //  buf[i] = SPDR;
87
+  //  SPDR = 0xFF;
88
+  //}
89
+  //while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
90
+  //buf[nbyte] = SPDR;
78
 }
91
 }
79
-//------------------------------------------------------------------------------
80
-/** SPI send a byte */
92
+
81
 void spiSend(uint8_t b) {
93
 void spiSend(uint8_t b) {
82
   SPI.beginTransaction(spiConfig);
94
   SPI.beginTransaction(spiConfig);
83
   SPI.transfer(b);
95
   SPI.transfer(b);
84
   SPI.endTransaction();
96
   SPI.endTransaction();
85
-//  SPDR = b;
86
-//  while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
97
+  //SPDR = b;
98
+  //while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
87
 }
99
 }
88
-//------------------------------------------------------------------------------
89
-/** SPI send block  */
100
+
90
 void spiSendBlock(uint8_t token, const uint8_t* buf) {
101
 void spiSendBlock(uint8_t token, const uint8_t* buf) {
91
   SPI.beginTransaction(spiConfig);
102
   SPI.beginTransaction(spiConfig);
92
   SPDR = token;
103
   SPDR = token;
100
   SPI.endTransaction();
111
   SPI.endTransaction();
101
 }
112
 }
102
 
113
 
103
-
104
-/** Begin SPI transaction, set clock, bit order, data mode */
114
+// Begin SPI transaction, set clock, bit order, data mode
105
 void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
115
 void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
106
   spiConfig = SPISettings(spiClock, bitOrder, dataMode);
116
   spiConfig = SPISettings(spiClock, bitOrder, dataMode);
107
-
108
   SPI.beginTransaction(spiConfig);
117
   SPI.beginTransaction(spiConfig);
109
 }
118
 }
110
 
119
 

+ 0
- 1
Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.cpp 파일 보기

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-
24
 /**
23
 /**
25
  * Teensy3.5 __MK64FX512__
24
  * Teensy3.5 __MK64FX512__
26
  * Teensy3.6 __MK66FX1M0__
25
  * Teensy3.6 __MK66FX1M0__

+ 1
- 2
Marlin/src/HAL/shared/SpiEeprom.cpp 파일 보기

115
   delay(7);   // wait for page write to complete
115
   delay(7);   // wait for page write to complete
116
 }
116
 }
117
 
117
 
118
-
119
-#endif // ENABLED(SPI_EEPROM)
118
+#endif // SPI_EEPROM

Loading…
취소
저장