Skip to content

Commit 1272318

Browse files
committed
fix esp32 file browser build, and add flash_config.h
1 parent e467531 commit 1272318

File tree

5 files changed

+148
-86
lines changed

5 files changed

+148
-86
lines changed

examples/MassStorage/msc_esp32_file_browser/msc_esp32_file_browser.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ bool fs_changed; // Set to true when browser write to flash
7171
const char* host = "esp32fs";
7272
WebServer server(80);
7373
//holds the current upload
74-
File fsUploadFile;
74+
File32 fsUploadFile;
7575

7676
//--------------------------------------------------------------------+
7777
// Setup
@@ -246,7 +246,7 @@ String getContentType(String filename) {
246246

247247
bool exists(String path){
248248
bool yes = false;
249-
File file = fatfs.open(path, O_READ);
249+
File32 file = fatfs.open(path, O_READ);
250250
if(file && !file.isDirectory()){
251251
yes = true;
252252
}
@@ -265,7 +265,7 @@ bool handleFileRead(String path) {
265265
// if (exists(pathWithGz)) {
266266
// path += ".gz";
267267
// }
268-
File file = fatfs.open(path, O_READ);
268+
File32 file = fatfs.open(path, O_READ);
269269
server.streamFile(file, contentType);
270270
file.close();
271271
return true;
@@ -333,7 +333,7 @@ void handleFileCreate() {
333333
if (exists(path)) {
334334
return server.send(500, "text/plain", "FILE EXISTS");
335335
}
336-
File file = fatfs.open(path, O_WRITE | O_CREAT);
336+
File32 file = fatfs.open(path, O_WRITE | O_CREAT);
337337
if (file) {
338338
file.close();
339339
} else {
@@ -352,12 +352,12 @@ void handleFileList() {
352352
String path = server.arg("dir");
353353
DBG_SERIAL.println("handleFileList: " + path);
354354

355-
File root = fatfs.open(path);
355+
File32 root = fatfs.open(path);
356356
path = String();
357357

358358
String output = "[";
359359
if(root.isDirectory()){
360-
File file = root.openNextFile();
360+
File32 file = root.openNextFile();
361361
char fname[256];
362362
while(file){
363363
if (output != "[") {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#ifndef FLASH_CONFIG_H_
26+
#define FLASH_CONFIG_H_
27+
28+
// Un-comment to run example with custom SPI and SS e.g with FRAM breakout
29+
// #define CUSTOM_CS A5
30+
// #define CUSTOM_SPI SPI
31+
32+
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
33+
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
34+
35+
#elif defined(ARDUINO_ARCH_ESP32)
36+
// ESP32 use same flash device that store code.
37+
// Therefore there is no need to specify the SPI and SS
38+
Adafruit_FlashTransport_ESP32 flashTransport;
39+
40+
#elif defined(ARDUINO_ARCH_RP2040)
41+
// RP2040 use same flash device that store code.
42+
// Therefore there is no need to specify the SPI and SS
43+
// Use default (no-args) constructor to be compatible with CircuitPython partition scheme
44+
Adafruit_FlashTransport_RP2040 flashTransport;
45+
46+
// For generic usage: Adafruit_FlashTransport_RP2040(start_address, size)
47+
// If start_address and size are both 0, value that match filesystem setting in
48+
// 'Tools->Flash Size' menu selection will be used
49+
50+
#else
51+
// On-board external flash (QSPI or SPI) macros should already
52+
// defined in your board variant if supported
53+
// - EXTERNAL_FLASH_USE_QSPI
54+
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
55+
#if defined(EXTERNAL_FLASH_USE_QSPI)
56+
Adafruit_FlashTransport_QSPI flashTransport;
57+
58+
#elif defined(EXTERNAL_FLASH_USE_SPI)
59+
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS, EXTERNAL_FLASH_USE_SPI);
60+
61+
#else
62+
#error No (Q)SPI flash are defined for your board !
63+
#endif
64+
#endif
65+
66+
67+
#endif

examples/MassStorage/msc_external_flash/msc_external_flash.ino

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,44 +27,8 @@
2727
#include "Adafruit_SPIFlash.h"
2828
#include "Adafruit_TinyUSB.h"
2929

30-
// Un-comment to run example with custom SPI SPI and SS e.g with FRAM breakout
31-
// #define CUSTOM_CS A5
32-
// #define CUSTOM_SPI SPI
33-
34-
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
35-
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
36-
37-
#elif defined(ARDUINO_ARCH_ESP32)
38-
// ESP32 use same flash device that store code.
39-
// Therefore there is no need to specify the SPI and SS
40-
Adafruit_FlashTransport_ESP32 flashTransport;
41-
42-
#elif defined(ARDUINO_ARCH_RP2040)
43-
// RP2040 use same flash device that store code.
44-
// Therefore there is no need to specify the SPI and SS
45-
// Use default (no-args) constructor to be compatible with CircuitPython partition scheme
46-
Adafruit_FlashTransport_RP2040 flashTransport;
47-
48-
// For generic usage:
49-
// Adafruit_FlashTransport_RP2040 flashTransport(start_address, size)
50-
// If start_address and size are both 0, value that match filesystem setting in
51-
// 'Tools->Flash Size' menu selection will be used
52-
53-
#else
54-
// On-board external flash (QSPI or SPI) macros should already
55-
// defined in your board variant if supported
56-
// - EXTERNAL_FLASH_USE_QSPI
57-
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
58-
#if defined(EXTERNAL_FLASH_USE_QSPI)
59-
Adafruit_FlashTransport_QSPI flashTransport;
60-
61-
#elif defined(EXTERNAL_FLASH_USE_SPI)
62-
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS, EXTERNAL_FLASH_USE_SPI);
63-
64-
#else
65-
#error No QSPI/SPI flash are defined on your board variant.h !
66-
#endif
67-
#endif
30+
// for flashTransport definition
31+
#include "flash_config.h"
6832

6933
Adafruit_SPIFlash flash(&flashTransport);
7034

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#ifndef FLASH_CONFIG_H_
26+
#define FLASH_CONFIG_H_
27+
28+
// Un-comment to run example with custom SPI and SS e.g with FRAM breakout
29+
// #define CUSTOM_CS A5
30+
// #define CUSTOM_SPI SPI
31+
32+
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
33+
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
34+
35+
#elif defined(ARDUINO_ARCH_ESP32)
36+
// ESP32 use same flash device that store code.
37+
// Therefore there is no need to specify the SPI and SS
38+
Adafruit_FlashTransport_ESP32 flashTransport;
39+
40+
#elif defined(ARDUINO_ARCH_RP2040)
41+
// RP2040 use same flash device that store code.
42+
// Therefore there is no need to specify the SPI and SS
43+
// Use default (no-args) constructor to be compatible with CircuitPython partition scheme
44+
Adafruit_FlashTransport_RP2040 flashTransport;
45+
46+
// For generic usage: Adafruit_FlashTransport_RP2040(start_address, size)
47+
// If start_address and size are both 0, value that match filesystem setting in
48+
// 'Tools->Flash Size' menu selection will be used
49+
50+
#else
51+
// On-board external flash (QSPI or SPI) macros should already
52+
// defined in your board variant if supported
53+
// - EXTERNAL_FLASH_USE_QSPI
54+
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
55+
#if defined(EXTERNAL_FLASH_USE_QSPI)
56+
Adafruit_FlashTransport_QSPI flashTransport;
57+
58+
#elif defined(EXTERNAL_FLASH_USE_SPI)
59+
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS, EXTERNAL_FLASH_USE_SPI);
60+
61+
#else
62+
#error No (Q)SPI flash are defined for your board !
63+
#endif
64+
#endif
65+
66+
67+
#endif

examples/MassStorage/msc_external_flash_sdcard/msc_external_flash_sdcard.ino

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,44 +28,8 @@
2828
// External Flash Config
2929
//--------------------------------------------------------------------+
3030

31-
// Un-comment to run example with custom SPI SPI and SS e.g with FRAM breakout
32-
// #define CUSTOM_CS A5
33-
// #define CUSTOM_SPI SPI
34-
35-
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
36-
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
37-
38-
#elif defined(ARDUINO_ARCH_ESP32)
39-
// ESP32 use same flash device that store code.
40-
// Therefore there is no need to specify the SPI and SS
41-
Adafruit_FlashTransport_ESP32 flashTransport;
42-
43-
#elif defined(ARDUINO_ARCH_RP2040)
44-
// RP2040 use same flash device that store code.
45-
// Therefore there is no need to specify the SPI and SS
46-
// Use default (no-args) constructor to be compatible with CircuitPython partition scheme
47-
Adafruit_FlashTransport_RP2040 flashTransport;
48-
49-
// For generic usage: Adafruit_FlashTransport_RP2040(start_address, size)
50-
// If start_address and size are both 0, value that match filesystem setting in
51-
// 'Tools->Flash Size' menu selection will be used
52-
53-
#else
54-
// On-board external flash (QSPI or SPI) macros should already
55-
// defined in your board variant if supported
56-
// - EXTERNAL_FLASH_USE_QSPI
57-
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
58-
#if defined(EXTERNAL_FLASH_USE_QSPI)
59-
Adafruit_FlashTransport_QSPI flashTransport;
60-
61-
#elif defined(EXTERNAL_FLASH_USE_SPI)
62-
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS, EXTERNAL_FLASH_USE_SPI);
63-
64-
#else
65-
#error No QSPI/SPI flash are defined on your board variant.h !
66-
#endif
67-
#endif
68-
31+
// for flashTransport definition
32+
#include "flash_config.h"
6933

7034
Adafruit_SPIFlash flash(&flashTransport);
7135

@@ -176,9 +140,9 @@ bool init_sdcard(void)
176140
return true;
177141
}
178142

179-
void print_rootdir(File* rdir)
143+
void print_rootdir(File32* rdir)
180144
{
181-
File file;
145+
File32 file;
182146

183147
// Open next file in root.
184148
// Warning, openNext starts at the current directory position
@@ -210,7 +174,7 @@ void loop()
210174
// skip if still not formatted
211175
if (flash_formatted)
212176
{
213-
File root;
177+
File32 root;
214178
root = fatfs.open("/");
215179

216180
Serial.println("Flash contents:");
@@ -225,7 +189,7 @@ void loop()
225189

226190
if ( sd_changed )
227191
{
228-
File root;
192+
File32 root;
229193
root = sd.open("/");
230194

231195
Serial.println("SD contents:");

0 commit comments

Comments
 (0)