|
@@ -36,20 +36,14 @@
|
36
|
36
|
// Includes
|
37
|
37
|
// --------------------------------------------------------------------------
|
38
|
38
|
|
39
|
|
-#include "HAL.h"
|
40
|
|
-#include "../shared/HAL_SPI.h"
|
41
|
|
-#include "pins_arduino.h"
|
42
|
|
-#include "spi_pins.h"
|
|
39
|
+#include "../../inc/MarlinConfig.h"
|
43
|
40
|
#include <SPI.h>
|
44
|
41
|
|
45
|
|
-#include "../../inc/MarlinConfigPre.h"
|
46
|
42
|
|
47
|
43
|
// --------------------------------------------------------------------------
|
48
|
44
|
// Public Variables
|
49
|
45
|
// --------------------------------------------------------------------------
|
50
|
46
|
|
51
|
|
-static SPISettings spiConfig;
|
52
|
|
-
|
53
|
47
|
// --------------------------------------------------------------------------
|
54
|
48
|
// Public functions
|
55
|
49
|
// --------------------------------------------------------------------------
|
|
@@ -82,8 +76,7 @@ void spiBegin() {
|
82
|
76
|
#if !PIN_EXISTS(SS)
|
83
|
77
|
#error "SS_PIN not defined!"
|
84
|
78
|
#endif
|
85
|
|
- SET_OUTPUT(SS_PIN);
|
86
|
|
- WRITE(SS_PIN, HIGH);
|
|
79
|
+ OUT_WRITE(SS_PIN, HIGH);
|
87
|
80
|
}
|
88
|
81
|
|
89
|
82
|
/**
|
|
@@ -105,8 +98,11 @@ void spiInit(uint8_t spiRate) {
|
105
|
98
|
case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break;
|
106
|
99
|
default: clock = SPI_CLOCK_DIV2; // Default from the SPI library
|
107
|
100
|
}
|
108
|
|
- spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
|
|
101
|
+ SPI.setModule(SPI_DEVICE);
|
109
|
102
|
SPI.begin();
|
|
103
|
+ SPI.setClockDivider(clock);
|
|
104
|
+ SPI.setBitOrder(MSBFIRST);
|
|
105
|
+ SPI.setDataMode(SPI_MODE0);
|
110
|
106
|
}
|
111
|
107
|
|
112
|
108
|
/**
|
|
@@ -117,9 +113,9 @@ void spiInit(uint8_t spiRate) {
|
117
|
113
|
* @details
|
118
|
114
|
*/
|
119
|
115
|
uint8_t spiRec(void) {
|
120
|
|
- SPI.beginTransaction(spiConfig);
|
|
116
|
+ WRITE(SS_PIN, LOW);
|
121
|
117
|
uint8_t returnByte = SPI.transfer(0xFF);
|
122
|
|
- SPI.endTransaction();
|
|
118
|
+ WRITE(SS_PIN, HIGH);
|
123
|
119
|
return returnByte;
|
124
|
120
|
}
|
125
|
121
|
|
|
@@ -133,9 +129,9 @@ uint8_t spiRec(void) {
|
133
|
129
|
* @details Uses DMA
|
134
|
130
|
*/
|
135
|
131
|
void spiRead(uint8_t* buf, uint16_t nbyte) {
|
136
|
|
- SPI.beginTransaction(spiConfig);
|
|
132
|
+ WRITE(SS_PIN, LOW);
|
137
|
133
|
SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte);
|
138
|
|
- SPI.endTransaction();
|
|
134
|
+ WRITE(SS_PIN, HIGH);
|
139
|
135
|
}
|
140
|
136
|
|
141
|
137
|
/**
|
|
@@ -146,9 +142,9 @@ void spiRead(uint8_t* buf, uint16_t nbyte) {
|
146
|
142
|
* @details
|
147
|
143
|
*/
|
148
|
144
|
void spiSend(uint8_t b) {
|
149
|
|
- SPI.beginTransaction(spiConfig);
|
|
145
|
+ WRITE(SS_PIN, LOW);
|
150
|
146
|
SPI.send(b);
|
151
|
|
- SPI.endTransaction();
|
|
147
|
+ WRITE(SS_PIN, HIGH);
|
152
|
148
|
}
|
153
|
149
|
|
154
|
150
|
/**
|
|
@@ -160,25 +156,10 @@ void spiSend(uint8_t b) {
|
160
|
156
|
* @details Use DMA
|
161
|
157
|
*/
|
162
|
158
|
void spiSendBlock(uint8_t token, const uint8_t* buf) {
|
163
|
|
- SPI.beginTransaction(spiConfig);
|
|
159
|
+ WRITE(SS_PIN, LOW);
|
164
|
160
|
SPI.send(token);
|
165
|
161
|
SPI.dmaSend(const_cast<uint8_t*>(buf), 512);
|
166
|
|
- SPI.endTransaction();
|
167
|
|
-}
|
168
|
|
-
|
169
|
|
-/**
|
170
|
|
- * @brief Begin SPI transaction, set clock, bit order, data mode
|
171
|
|
- *
|
172
|
|
- * @param spiClock Clock setting
|
173
|
|
- * @param bitOrder Bit Order setting
|
174
|
|
- * @param dataMode Data Mode setting
|
175
|
|
- * @return Nothing
|
176
|
|
- *
|
177
|
|
- * @details Uses an SPI Config via SPISettings
|
178
|
|
- */
|
179
|
|
-void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
|
180
|
|
- spiConfig = SPISettings(spiClock, (BitOrder)bitOrder, dataMode);
|
181
|
|
- SPI.beginTransaction(spiConfig);
|
|
162
|
+ WRITE(SS_PIN, HIGH);
|
182
|
163
|
}
|
183
|
164
|
|
184
|
165
|
#if ENABLED(SPI_EEPROM)
|