|
@@ -19,13 +19,12 @@
|
19
|
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
20
|
20
|
*
|
21
|
21
|
*/
|
22
|
|
-#include "../../../../inc/MarlinConfigPre.h"
|
23
|
22
|
|
24
|
|
-#if 1 // ENABLED(SPI_FLASH)
|
25
|
|
-#if HAS_TFT_LVGL_UI
|
|
23
|
+#include "../inc/MarlinConfig.h"
|
|
24
|
+
|
|
25
|
+#if HAS_SPI_FLASH
|
26
|
26
|
|
27
|
27
|
#include <SPI.h>
|
28
|
|
-#include "../../../../inc/MarlinConfig.h"
|
29
|
28
|
|
30
|
29
|
#include "W25Qxx.h"
|
31
|
30
|
|
|
@@ -45,9 +44,7 @@
|
45
|
44
|
#define W25QXX_CS_H OUT_WRITE(SPI_FLASH_CS_PIN, HIGH)
|
46
|
45
|
#define W25QXX_CS_L OUT_WRITE(SPI_FLASH_CS_PIN, LOW)
|
47
|
46
|
|
48
|
|
-ext_FLASH W25QXX;
|
49
|
|
-
|
50
|
|
-void ext_FLASH::init(uint8_t spiRate) {
|
|
47
|
+void W25QXXFlash::init(uint8_t spiRate) {
|
51
|
48
|
|
52
|
49
|
OUT_WRITE(SPI_FLASH_CS_PIN, HIGH);
|
53
|
50
|
|
|
@@ -85,12 +82,12 @@ void ext_FLASH::init(uint8_t spiRate) {
|
85
|
82
|
*
|
86
|
83
|
* @details
|
87
|
84
|
*/
|
88
|
|
-uint8_t ext_FLASH::spi_flash_Rec() {
|
|
85
|
+uint8_t W25QXXFlash::spi_flash_Rec() {
|
89
|
86
|
uint8_t returnByte = SPI.transfer(ff);
|
90
|
87
|
return returnByte;
|
91
|
88
|
}
|
92
|
89
|
|
93
|
|
-uint8_t ext_FLASH::spi_flash_read_write_byte(uint8_t data) {
|
|
90
|
+uint8_t W25QXXFlash::spi_flash_read_write_byte(uint8_t data) {
|
94
|
91
|
uint8_t returnByte = SPI.transfer(data);
|
95
|
92
|
return returnByte;
|
96
|
93
|
}
|
|
@@ -104,7 +101,7 @@ uint8_t ext_FLASH::spi_flash_read_write_byte(uint8_t data) {
|
104
|
101
|
*
|
105
|
102
|
* @details Uses DMA
|
106
|
103
|
*/
|
107
|
|
-void ext_FLASH::spi_flash_Read(uint8_t* buf, uint16_t nbyte) { SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte); }
|
|
104
|
+void W25QXXFlash::spi_flash_Read(uint8_t* buf, uint16_t nbyte) { SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte); }
|
108
|
105
|
|
109
|
106
|
/**
|
110
|
107
|
* @brief Send a single byte on SPI port
|
|
@@ -113,7 +110,7 @@ void ext_FLASH::spi_flash_Read(uint8_t* buf, uint16_t nbyte) { SPI.dmaTransfer(0
|
113
|
110
|
*
|
114
|
111
|
* @details
|
115
|
112
|
*/
|
116
|
|
-void ext_FLASH::spi_flash_Send(uint8_t b) { SPI.send(b); }
|
|
113
|
+void W25QXXFlash::spi_flash_Send(uint8_t b) { SPI.send(b); }
|
117
|
114
|
|
118
|
115
|
/**
|
119
|
116
|
* @brief Write token and then write from 512 byte buffer to SPI (for SD card)
|
|
@@ -123,12 +120,12 @@ void ext_FLASH::spi_flash_Send(uint8_t b) { SPI.send(b); }
|
123
|
120
|
*
|
124
|
121
|
* @details Use DMA
|
125
|
122
|
*/
|
126
|
|
-void ext_FLASH::spi_flash_SendBlock(uint8_t token, const uint8_t* buf) {
|
|
123
|
+void W25QXXFlash::spi_flash_SendBlock(uint8_t token, const uint8_t* buf) {
|
127
|
124
|
SPI.send(token);
|
128
|
125
|
SPI.dmaSend(const_cast<uint8_t*>(buf), 512);
|
129
|
126
|
}
|
130
|
127
|
|
131
|
|
-uint16_t ext_FLASH::W25QXX_ReadID(void) {
|
|
128
|
+uint16_t W25QXXFlash::W25QXX_ReadID(void) {
|
132
|
129
|
uint16_t Temp = 0;
|
133
|
130
|
W25QXX_CS_L;
|
134
|
131
|
spi_flash_Send(0x90);
|
|
@@ -141,7 +138,7 @@ uint16_t ext_FLASH::W25QXX_ReadID(void) {
|
141
|
138
|
return Temp;
|
142
|
139
|
}
|
143
|
140
|
|
144
|
|
-void ext_FLASH::SPI_FLASH_WriteEnable(void) {
|
|
141
|
+void W25QXXFlash::SPI_FLASH_WriteEnable(void) {
|
145
|
142
|
/* Select the FLASH: Chip Select low */
|
146
|
143
|
W25QXX_CS_L;
|
147
|
144
|
/* Send "Write Enable" instruction */
|
|
@@ -159,7 +156,7 @@ void ext_FLASH::SPI_FLASH_WriteEnable(void) {
|
159
|
156
|
* Output : None
|
160
|
157
|
* Return : None
|
161
|
158
|
*******************************************************************************/
|
162
|
|
-void ext_FLASH::SPI_FLASH_WaitForWriteEnd(void) {
|
|
159
|
+void W25QXXFlash::SPI_FLASH_WaitForWriteEnd(void) {
|
163
|
160
|
uint8_t FLASH_Status = 0;
|
164
|
161
|
|
165
|
162
|
/* Select the FLASH: Chip Select low */
|
|
@@ -178,7 +175,7 @@ void ext_FLASH::SPI_FLASH_WaitForWriteEnd(void) {
|
178
|
175
|
W25QXX_CS_H;
|
179
|
176
|
}
|
180
|
177
|
|
181
|
|
-void ext_FLASH::SPI_FLASH_SectorErase(uint32_t SectorAddr) {
|
|
178
|
+void W25QXXFlash::SPI_FLASH_SectorErase(uint32_t SectorAddr) {
|
182
|
179
|
/* Send write enable instruction */
|
183
|
180
|
SPI_FLASH_WriteEnable();
|
184
|
181
|
|
|
@@ -200,7 +197,7 @@ void ext_FLASH::SPI_FLASH_SectorErase(uint32_t SectorAddr) {
|
200
|
197
|
SPI_FLASH_WaitForWriteEnd();
|
201
|
198
|
}
|
202
|
199
|
|
203
|
|
-void ext_FLASH::SPI_FLASH_BlockErase(uint32_t BlockAddr) {
|
|
200
|
+void W25QXXFlash::SPI_FLASH_BlockErase(uint32_t BlockAddr) {
|
204
|
201
|
SPI_FLASH_WriteEnable();
|
205
|
202
|
W25QXX_CS_L;
|
206
|
203
|
/* Send Sector Erase instruction */
|
|
@@ -224,7 +221,7 @@ void ext_FLASH::SPI_FLASH_BlockErase(uint32_t BlockAddr) {
|
224
|
221
|
* Output : None
|
225
|
222
|
* Return : None
|
226
|
223
|
*******************************************************************************/
|
227
|
|
-void ext_FLASH::SPI_FLASH_BulkErase(void) {
|
|
224
|
+void W25QXXFlash::SPI_FLASH_BulkErase(void) {
|
228
|
225
|
/* Send write enable instruction */
|
229
|
226
|
SPI_FLASH_WriteEnable();
|
230
|
227
|
|
|
@@ -253,7 +250,7 @@ void ext_FLASH::SPI_FLASH_BulkErase(void) {
|
253
|
250
|
* Output : None
|
254
|
251
|
* Return : None
|
255
|
252
|
*******************************************************************************/
|
256
|
|
-void ext_FLASH::SPI_FLASH_PageWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite) {
|
|
253
|
+void W25QXXFlash::SPI_FLASH_PageWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite) {
|
257
|
254
|
/* Enable the write access to the FLASH */
|
258
|
255
|
SPI_FLASH_WriteEnable();
|
259
|
256
|
|
|
@@ -296,7 +293,7 @@ void ext_FLASH::SPI_FLASH_PageWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16
|
296
|
293
|
* Output : None
|
297
|
294
|
* Return : None
|
298
|
295
|
*******************************************************************************/
|
299
|
|
-void ext_FLASH::SPI_FLASH_BufferWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite) {
|
|
296
|
+void W25QXXFlash::SPI_FLASH_BufferWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite) {
|
300
|
297
|
uint8_t NumOfPage = 0, NumOfSingle = 0, Addr = 0, count = 0, temp = 0;
|
301
|
298
|
|
302
|
299
|
Addr = WriteAddr % SPI_FLASH_PageSize;
|
|
@@ -361,7 +358,7 @@ void ext_FLASH::SPI_FLASH_BufferWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint
|
361
|
358
|
* Output : None
|
362
|
359
|
* Return : None
|
363
|
360
|
*******************************************************************************/
|
364
|
|
-void ext_FLASH::SPI_FLASH_BufferRead(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead) {
|
|
361
|
+void W25QXXFlash::SPI_FLASH_BufferRead(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead) {
|
365
|
362
|
/* Select the FLASH: Chip Select low */
|
366
|
363
|
W25QXX_CS_L;
|
367
|
364
|
|
|
@@ -389,7 +386,4 @@ void ext_FLASH::SPI_FLASH_BufferRead(uint8_t* pBuffer, uint32_t ReadAddr, uint16
|
389
|
386
|
W25QXX_CS_H;
|
390
|
387
|
}
|
391
|
388
|
|
392
|
|
-void ext_FLASH::lv_pic_read(uint8_t *P_Rbuff, uint32_t addr, uint32_t size) {SPI_FLASH_BufferRead((uint8_t *)P_Rbuff, addr, size);}
|
393
|
|
-
|
394
|
|
-#endif // HAS_TFT_LVGL_UI
|
395
|
|
-#endif // 1 ... SPI_FLASH
|
|
389
|
+#endif // HAS_SPI_FLASH
|