Skip to content

Commit 9b37e28

Browse files
committed
add InternalFileSystem lib
1 parent fda0899 commit 9b37e28

File tree

11 files changed

+900
-3
lines changed

11 files changed

+900
-3
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
*.app
88

99
*.pyc
10-
/tools/nrfutil-0.5.2/build/
11-
/tools/nrfutil-0.5.2/dist/
12-
/tools/nrfutil-0.5.2/nrfutil.egg-info/
1310
/tools/.idea/
1411
/tools/midi_tests/node_modules
1512

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*********************************************************************
2+
This is an example for our nRF52 based Bluefruit LE modules
3+
4+
Pick one up today in the adafruit shop!
5+
6+
Adafruit invests time and resources providing this open source code,
7+
please support Adafruit and open-source hardware by purchasing
8+
products from Adafruit!
9+
10+
MIT license, check LICENSE for more information
11+
All text above, and the splash screen below must be included in
12+
any redistribution
13+
*********************************************************************/
14+
15+
#include <Adafruit_LittleFS.h>
16+
#include <InternalFileSystem.h>
17+
18+
using namespace Adafruit_LittleFS_Namespace;
19+
20+
// the setup function runs once when you press reset or power the board
21+
void setup()
22+
{
23+
Serial.begin(115200);
24+
while ( !Serial ) delay(10); // for nrf52840 with native usb
25+
26+
Serial.println("InternalFS Format Example");
27+
Serial.println();
28+
29+
// Wait for user input to run.
30+
Serial.println("This sketch will destroy all of your data in External Flash!");
31+
Serial.print("Enter any keys to continue:");
32+
while ( !Serial.available() ) delay(1);
33+
Serial.println();
34+
Serial.println();
35+
36+
// Initialize Internal File System
37+
InternalFS.begin();
38+
39+
Serial.print("Formating ... ");
40+
delay(1); // for message appear on monitor
41+
42+
// Format
43+
InternalFS.format();
44+
45+
Serial.println("Done");
46+
}
47+
48+
// the loop function runs over and over again forever
49+
void loop()
50+
{
51+
// nothing to do
52+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*********************************************************************
2+
This is an example for our nRF52 based Bluefruit LE modules
3+
4+
Pick one up today in the adafruit shop!
5+
6+
Adafruit invests time and resources providing this open source code,
7+
please support Adafruit and open-source hardware by purchasing
8+
products from Adafruit!
9+
10+
MIT license, check LICENSE for more information
11+
All text above, and the splash screen below must be included in
12+
any redistribution
13+
*********************************************************************/
14+
15+
#include <Adafruit_LittleFS.h>
16+
#include <InternalFileSystem.h>
17+
18+
using namespace Adafruit_LittleFS_Namespace;
19+
20+
/* This example print out Internal Flash contents up to
21+
* MAX_LEVEL level of directories (including root)
22+
* WARNING: This example uses recursive call to print out directory tree
23+
* be extra careful, high number of MAX_LEVEL can cause memory overflow
24+
*/
25+
#define MAX_LEVEL 2
26+
27+
// the setup function runs once when you press reset or power the board
28+
void setup()
29+
{
30+
Serial.begin(115200);
31+
while ( !Serial ) delay(10); // for nrf52840 with native usb
32+
33+
Serial.println("InternalFS List Files Example");
34+
35+
// Initialize Internal File System
36+
InternalFS.begin();
37+
38+
// Print whole directory tree of root whose level is 0
39+
printTreeDir("/", 0);
40+
41+
// Print prompt
42+
Serial.println();
43+
Serial.println("Enter anything to print directory tree:");
44+
}
45+
46+
// the loop function runs over and over again forever
47+
void loop()
48+
{
49+
if ( Serial.available() )
50+
{
51+
delay(10); // delay for all input arrived
52+
while( Serial.available() ) Serial.read();
53+
54+
printTreeDir("/", 0);
55+
56+
// Print prompt
57+
Serial.println();
58+
Serial.println("Enter anything to print directory tree:");
59+
}
60+
}
61+
62+
/**************************************************************************/
63+
/*!
64+
@brief Print out whole directory tree of an folder
65+
until the level reach MAX_LEVEL
66+
67+
@note Recursive call
68+
*/
69+
/**************************************************************************/
70+
void printTreeDir(const char* cwd, uint8_t level)
71+
{
72+
// Open the input folder
73+
File dir(cwd, FILE_READ, InternalFS);
74+
75+
// Print root
76+
if (level == 0) Serial.println("root");
77+
78+
// File within folder
79+
File item(InternalFS);
80+
81+
// Loop through the directory
82+
while( (item = dir.openNextFile(FILE_READ)) )
83+
{
84+
// Indentation according to dir level
85+
for(int i=0; i<level; i++) Serial.print("| ");
86+
87+
Serial.print("|_ ");
88+
Serial.print( item.name() );
89+
90+
if ( item.isDirectory() )
91+
{
92+
Serial.println("/");
93+
94+
// ATTENTION recursive call to print sub folder with level+1 !!!!!!!!
95+
// High number of MAX_LEVEL can cause memory overflow
96+
if ( level < MAX_LEVEL )
97+
{
98+
char dpath[strlen(cwd) + strlen(item.name()) + 2 ];
99+
strcpy(dpath, cwd);
100+
strcat(dpath, "/");
101+
strcat(dpath, item.name());
102+
103+
printTreeDir( dpath, level+1 );
104+
}
105+
}else
106+
{
107+
// Print file size starting from position 30
108+
int pos = level*3 + 3 + strlen(item.name());
109+
110+
// Print padding
111+
for (int i=pos; i<30; i++) Serial.print(' ');
112+
113+
// Print at least one extra space in case current position > 50
114+
Serial.print(' ');
115+
116+
Serial.print( item.size() );
117+
Serial.println( " Bytes");
118+
}
119+
120+
item.close();
121+
}
122+
123+
dir.close();
124+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*********************************************************************
2+
This is an example for our nRF52 based Bluefruit LE modules
3+
4+
Pick one up today in the adafruit shop!
5+
6+
Adafruit invests time and resources providing this open source code,
7+
please support Adafruit and open-source hardware by purchasing
8+
products from Adafruit!
9+
10+
MIT license, check LICENSE for more information
11+
All text above, and the splash screen below must be included in
12+
any redistribution
13+
*********************************************************************/
14+
15+
#include <Adafruit_LittleFS.h>
16+
#include <InternalFileSystem.h>
17+
18+
using namespace Adafruit_LittleFS_Namespace;
19+
20+
#define FILENAME "/adafruit.txt"
21+
#define CONTENTS "Adafruit Little File System test file contents"
22+
23+
File file(InternalFS);
24+
25+
// the setup function runs once when you press reset or power the board
26+
void setup()
27+
{
28+
Serial.begin(115200);
29+
while ( !Serial ) delay(10); // for nrf52840 with native usb
30+
31+
Serial.println("Internal Read Write File Example");
32+
Serial.println();
33+
34+
// Wait for user input to run. Otherwise the code will
35+
// always run immediately after flash and create the FILENAME in advance
36+
Serial.print("Enter to any keys to continue:");
37+
while ( !Serial.available() )
38+
{
39+
delay(1);
40+
}
41+
Serial.println();
42+
Serial.println();
43+
44+
// Initialize Internal File System
45+
InternalFS.begin();
46+
47+
file.open(FILENAME, FILE_READ);
48+
49+
// file existed
50+
if ( file )
51+
{
52+
Serial.println(FILENAME " file exists");
53+
54+
uint32_t readlen;
55+
char buffer[64] = { 0 };
56+
readlen = file.read(buffer, sizeof(buffer));
57+
58+
buffer[readlen] = 0;
59+
Serial.println(buffer);
60+
file.close();
61+
}else
62+
{
63+
Serial.print("Open " FILENAME " file to write ... ");
64+
65+
if( file.open(FILENAME, FILE_WRITE) )
66+
{
67+
Serial.println("OK");
68+
file.write(CONTENTS, strlen(CONTENTS));
69+
file.close();
70+
}else
71+
{
72+
Serial.println("Failed!");
73+
}
74+
}
75+
76+
Serial.println("Done");
77+
}
78+
79+
// the loop function runs over and over again forever
80+
void loop()
81+
{
82+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=Adafruit Internal File System on Bluefruit nRF52
2+
version=0.10.5
3+
author=Adafruit
4+
maintainer=Adafruit <[email protected]>
5+
sentence=Adafruit Internal File System on Bluefruit nRF52
6+
paragraph=Adafruit Internal File System on Bluefruit nRF52
7+
category=Data Storage
8+
url=https://github.com/adafruit/Adafruit_nRF52_Arduino
9+
architectures=*
10+
includes=InternalFileSystem.h

0 commit comments

Comments
 (0)