|
@@ -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 "HAL.h"
|
|
@@ -8,32 +29,27 @@
|
8
|
29
|
|
9
|
30
|
static SPISettings spiConfig;
|
10
|
31
|
|
11
|
|
-// Standard SPI functions
|
12
|
|
-/** Initialize SPI bus */
|
13
|
32
|
void spiBegin(void) {
|
14
|
33
|
#if !PIN_EXISTS(SS)
|
15
|
34
|
#error SS_PIN not defined!
|
16
|
35
|
#endif
|
17
|
|
- SET_OUTPUT(SS_PIN);
|
18
|
|
- WRITE(SS_PIN, HIGH);
|
|
36
|
+ OUT_WRITE(SS_PIN, HIGH);
|
19
|
37
|
SET_OUTPUT(SCK_PIN);
|
20
|
38
|
SET_INPUT(MISO_PIN);
|
21
|
39
|
SET_OUTPUT(MOSI_PIN);
|
22
|
40
|
|
23
|
|
- //#if DISABLED(SOFTWARE_SPI)
|
24
|
|
- #if 0
|
|
41
|
+ #if 0 && DISABLED(SOFTWARE_SPI)
|
25
|
42
|
// set SS high - may be chip select for another SPI device
|
26
|
43
|
#if SET_SPI_SS_HIGH
|
27
|
44
|
WRITE(SS_PIN, HIGH);
|
28
|
|
- #endif // SET_SPI_SS_HIGH
|
|
45
|
+ #endif
|
29
|
46
|
// set a default rate
|
30
|
47
|
spiInit(SPI_HALF_SPEED); // 1
|
31
|
|
- #endif // SOFTWARE_SPI
|
|
48
|
+ #endif
|
32
|
49
|
}
|
33
|
50
|
|
34
|
|
-/** Configure SPI for specified SPI speed */
|
35
|
51
|
void spiInit(uint8_t spiRate) {
|
36
|
|
- // Use datarates Marlin uses
|
|
52
|
+ // Use Marlin data-rates
|
37
|
53
|
uint32_t clock;
|
38
|
54
|
switch (spiRate) {
|
39
|
55
|
case SPI_FULL_SPEED: clock = 10000000; break;
|
|
@@ -49,44 +65,39 @@ void spiInit(uint8_t spiRate) {
|
49
|
65
|
SPI.begin();
|
50
|
66
|
}
|
51
|
67
|
|
52
|
|
-//------------------------------------------------------------------------------
|
53
|
|
-/** SPI receive a byte */
|
54
|
68
|
uint8_t spiRec(void) {
|
55
|
69
|
SPI.beginTransaction(spiConfig);
|
56
|
70
|
uint8_t returnByte = SPI.transfer(0xFF);
|
57
|
71
|
SPI.endTransaction();
|
58
|
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
|
78
|
void spiRead(uint8_t* buf, uint16_t nbyte) {
|
66
|
79
|
SPI.beginTransaction(spiConfig);
|
67
|
80
|
SPI.transfer(buf, nbyte);
|
68
|
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
|
93
|
void spiSend(uint8_t b) {
|
82
|
94
|
SPI.beginTransaction(spiConfig);
|
83
|
95
|
SPI.transfer(b);
|
84
|
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
|
101
|
void spiSendBlock(uint8_t token, const uint8_t* buf) {
|
91
|
102
|
SPI.beginTransaction(spiConfig);
|
92
|
103
|
SPDR = token;
|
|
@@ -100,11 +111,9 @@ void spiSendBlock(uint8_t token, const uint8_t* buf) {
|
100
|
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
|
115
|
void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
|
106
|
116
|
spiConfig = SPISettings(spiClock, bitOrder, dataMode);
|
107
|
|
-
|
108
|
117
|
SPI.beginTransaction(spiConfig);
|
109
|
118
|
}
|
110
|
119
|
|