|
@@ -0,0 +1,78 @@
|
|
1
|
+/**
|
|
2
|
+ * Marlin 3D Printer Firmware
|
|
3
|
+ * Copyright (C) 2016 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
|
+ */
|
|
22
|
+
|
|
23
|
+/**
|
|
24
|
+ * HAL/SPI.h
|
|
25
|
+ * Core Marlin definitions for SPI, implemented in the HALs
|
|
26
|
+ */
|
|
27
|
+
|
|
28
|
+#ifndef _SPI_H_
|
|
29
|
+#define _SPI_H_
|
|
30
|
+
|
|
31
|
+//#include "../inc/MarlinConfig.h"
|
|
32
|
+
|
|
33
|
+#include <stdint.h>
|
|
34
|
+
|
|
35
|
+#ifndef SPI_FULL_SPEED
|
|
36
|
+
|
|
37
|
+/**
|
|
38
|
+ * SPI speed where 0 <= index <= 6
|
|
39
|
+ *
|
|
40
|
+ * Approximate rates :
|
|
41
|
+ *
|
|
42
|
+ * 0 : 8 - 10 MHz
|
|
43
|
+ * 1 : 4 - 5 MHz
|
|
44
|
+ * 2 : 2 - 2.5 MHz
|
|
45
|
+ * 3 : 1 - 1.25 MHz
|
|
46
|
+ * 4 : 500 - 625 kHz
|
|
47
|
+ * 5 : 250 - 312 kHz
|
|
48
|
+ * 6 : 125 - 156 kHz
|
|
49
|
+ *
|
|
50
|
+ * On AVR, actual speed is F_CPU/2^(1 + index).
|
|
51
|
+ * On other platforms, speed should be in range given above where possible.
|
|
52
|
+ */
|
|
53
|
+
|
|
54
|
+#define SPI_FULL_SPEED 0 // Set SCK to max rate
|
|
55
|
+#define SPI_HALF_SPEED 1 // Set SCK rate to half of max rate
|
|
56
|
+#define SPI_QUARTER_SPEED 2 // Set SCK rate to quarter of max rate
|
|
57
|
+#define SPI_EIGHTH_SPEED 3 // Set SCK rate to 1/8 of max rate
|
|
58
|
+#define SPI_SIXTEENTH_SPEED 4 // Set SCK rate to 1/16 of max rate
|
|
59
|
+#define SPI_SPEED_5 5 // Set SCK rate to 1/32 of max rate
|
|
60
|
+#define SPI_SPEED_6 6 // Set SCK rate to 1/64 of max rate
|
|
61
|
+
|
|
62
|
+// Standard SPI functions
|
|
63
|
+/** Initialise SPI bus */
|
|
64
|
+void spiBegin(void);
|
|
65
|
+/** Configure SPI for specified SPI speed */
|
|
66
|
+void spiInit(uint8_t spiRate);
|
|
67
|
+/** Write single byte to SPI */
|
|
68
|
+void spiSend(uint8_t b);
|
|
69
|
+/** Read single byte from SPI */
|
|
70
|
+uint8_t spiRec(void);
|
|
71
|
+/** Read from SPI into buffer */
|
|
72
|
+void spiRead(uint8_t* buf, uint16_t nbyte);
|
|
73
|
+/** Write token and then write from 512 byte buffer to SPI (for SD card) */
|
|
74
|
+void spiSendBlock(uint8_t token, const uint8_t* buf);
|
|
75
|
+
|
|
76
|
+#endif // SPI_FULL_SPEED
|
|
77
|
+
|
|
78
|
+#endif // _SPI_H_
|