Skip to content

Commit 9915b7c

Browse files
Add fs support for Teensy
1 parent eddb0ce commit 9915b7c

File tree

4 files changed

+260
-3
lines changed

4 files changed

+260
-3
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ML_SynthTools",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"keywords": "ML_SynthTools, Synthesizer, Filter, Audio, ESP32, ESP32S2, ESP32S3, STM32, RP2040",
55
"description": "Synthesizer Tools; contains waveform generators etc.",
66
"repository":

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ML SynthTools
2-
version=2.0.1
2+
version=2.0.2
33
author=Marcel Licence <[email protected]>
44
maintainer=Marcel Licence <[email protected]>
55
sentence=Synthesizer Tools

src/fs/fs_teensy.h

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
/*
2+
* Copyright (c) 2024 Marcel Licence
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
* Dieses Programm ist Freie Software: Sie können es unter den Bedingungen
18+
* der GNU General Public License, wie von der Free Software Foundation,
19+
* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
20+
* veröffentlichten Version, weiter verteilen und/oder modifizieren.
21+
*
22+
* Dieses Programm wird in der Hoffnung bereitgestellt, dass es nützlich sein wird, jedoch
23+
* OHNE JEDE GEWÄHR,; sogar ohne die implizite
24+
* Gewähr der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
25+
* Siehe die GNU General Public License für weitere Einzelheiten.
26+
*
27+
* Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
28+
* Programm erhalten haben. Wenn nicht, siehe <https://www.gnu.org/licenses/>.
29+
*/
30+
31+
/**
32+
* @file fs_teensy.cpp
33+
* @author Marcel Licence
34+
* @data 15.11.2024
35+
*
36+
* @brief This file contains Teensy specific file system implementation
37+
*/
38+
39+
40+
#ifdef __CDT_PARSER__
41+
#include <cdt.h>
42+
#endif
43+
44+
45+
#ifdef TEENSYDUINO
46+
47+
#ifdef ML_SYNTH_INLINE_DEFINITION
48+
49+
50+
/*
51+
* include files
52+
*/
53+
#include <fs/fs_access.h>
54+
#include <ml_status.h>
55+
#include <string_utils.h>
56+
57+
#include <SD.h>
58+
59+
/*
60+
* definitions
61+
*/
62+
#define FST fs::FS
63+
64+
/*
65+
* static function declarations
66+
*/
67+
static void printDirectory(File dir, int numTabs);
68+
69+
/*
70+
* local variables
71+
*/
72+
static File f;
73+
static File *g_file = NULL;
74+
static File *t_file = NULL;
75+
const int SD_CS = BUILTIN_SDCARD;
76+
77+
/*
78+
* static function definitions
79+
*/
80+
static void printDirectory(File dir, int numTabs)
81+
{
82+
while (true)
83+
{
84+
85+
File entry = dir.openNextFile();
86+
if (! entry)
87+
{
88+
break;
89+
}
90+
for (uint8_t i = 0; i < numTabs; i++)
91+
{
92+
Serial.print('\t');
93+
}
94+
Serial.print(entry.name());
95+
if (entry.isDirectory())
96+
{
97+
Serial.println("/");
98+
printDirectory(entry, numTabs + 1);
99+
}
100+
else
101+
{
102+
Serial.print("\t\t");
103+
Serial.println(entry.size(), DEC);
104+
}
105+
entry.close();
106+
}
107+
}
108+
109+
uint32_t getFileFromIdx(File dir, int numTabs, uint32_t idx, char *filename, char *filter)
110+
{
111+
while (true)
112+
{
113+
114+
File entry = dir.openNextFile();
115+
if (! entry)
116+
{
117+
break;
118+
}
119+
120+
if (entry.isDirectory())
121+
{
122+
idx = getFileFromIdx(entry, numTabs + 1, idx, filename, filter);
123+
}
124+
else
125+
{
126+
if (str_ends_with_ul(entry.name(), filter))
127+
{
128+
if (idx == 0)
129+
{
130+
strcpy(filename, entry.name());
131+
return idx;
132+
}
133+
idx -= 1;
134+
}
135+
136+
}
137+
entry.close();
138+
}
139+
return idx;
140+
}
141+
142+
bool getFileFromIdx(uint32_t idx, char *filename, char *filter)
143+
{
144+
File dir = SD.open("/", "r");
145+
char filename_clean[64];
146+
147+
bool result = getFileFromIdx(dir, 0, idx, filename_clean, filter) == 0 ? true : false;
148+
sprintf(filename, "/%s", filename_clean);
149+
dir.close();
150+
return result;
151+
}
152+
153+
/*
154+
* function definitions
155+
*/
156+
void FS_Setup(void)
157+
{
158+
if (!SD.begin(SD_CS))
159+
{
160+
Serial.println("SD init failed!");
161+
}
162+
else
163+
{
164+
Serial.println("SD init passed.");
165+
File root;
166+
root = SD.open("/");
167+
while (true)
168+
{
169+
File entry = root.openNextFile();
170+
if (!entry)
171+
{
172+
break;
173+
}
174+
else
175+
{
176+
Serial.println(entry.name());
177+
}
178+
}
179+
}
180+
}
181+
182+
bool FS_OpenFile(int fs, const char *filename, const char *mode)
183+
{
184+
f = SD.open(filename, mode);
185+
if (f)
186+
{
187+
g_file = &f;
188+
return true;
189+
}
190+
else
191+
{
192+
Serial.printf("Error opening file: %s\n", filename);
193+
return false;
194+
}
195+
}
196+
197+
void FS_LittleFS_CloseFile(void)
198+
{
199+
g_file->close();
200+
g_file = NULL;
201+
}
202+
203+
void FS_CloseFile(void)
204+
{
205+
g_file->close();
206+
g_file = NULL;
207+
}
208+
209+
void FS_UseTempFile(void)
210+
{
211+
g_file = t_file;
212+
}
213+
214+
uint32_t readBytes(uint8_t *buffer, uint32_t len)
215+
{
216+
return g_file->read(buffer, len);
217+
}
218+
219+
uint32_t writeBytes(uint8_t *buffer, uint32_t len)
220+
{
221+
return g_file->write(buffer, len);
222+
}
223+
224+
uint32_t availableBytes(void)
225+
{
226+
return g_file->available();
227+
}
228+
229+
void fileSeekTo(uint32_t pos)
230+
{
231+
g_file->seek(0, SeekSet);
232+
g_file->seek(pos, SeekSet);
233+
}
234+
235+
uint32_t getStaticPos(void)
236+
{
237+
return g_file->position();
238+
}
239+
240+
uint32_t getCurrentOffset(void)
241+
{
242+
return g_file->position();
243+
}
244+
245+
uint32_t readBytesFromAddr(uint8_t *buffer, uint32_t addr, uint32_t len)
246+
{
247+
fileSeekTo(addr);
248+
return readBytes(buffer, len);
249+
}
250+
251+
#endif /* #ifdef ML_SYNTH_INLINE_DEFINITION */
252+
253+
#endif /* TEENSYDUINO */
254+

src/ml_inline.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@
4040
#include <blink.h>
4141
#include <es8388.h>
4242
#include <esp32_audio_kit_module.h>
43-
#if (defined ESP32) || (defined ESP8266) || (defined ARDUINO_RASPBERRY_PI_PICO) || (defined ARDUINO_ARCH_RP2040)
43+
#if defined (ESP32) || defined (ESP8266) || defined (ARDUINO_RASPBERRY_PI_PICO) || defined (ARDUINO_ARCH_RP2040)
4444
#include <fs/fs_access.h>
4545
#include <fs/fs_common.h>
4646
#include <fs/fs_esp32.h>
4747
#include <fs/fs_esp8266.h>
4848
#include <fs/fs_rp2040.h>
4949
#endif
50+
#if defined(TEENSYDUINO)
51+
#include <fs/fs_teensy.h>
52+
#endif
5053
#include <i2s_interface.h>
5154
#include <i2s_module.h>
5255
#include <midi_interface.h>

0 commit comments

Comments
 (0)