11/*
22 * This is free and unencumbered software released into the public domain.
3- *
3+ *
44 * Anyone is free to copy, modify, publish, use, compile, sell, or
55 * distribute this software, either in source code form or as a compiled
66 * binary, for any purpose, commercial or non-commercial, and by any
77 * means.
8- *
8+ *
99 * In jurisdictions that recognize copyright laws, the author or authors
1010 * of this software dedicate any and all copyright interest in the
1111 * software to the public domain. We make this dedication for the benefit
1212 * of the public at large and to the detriment of our heirs and
1313 * successors. We intend this dedication to be an overt act of
1414 * relinquishment in perpetuity of all present and future rights to this
1515 * software under copyright law.
16- *
16+ *
1717 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1818 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1919 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
2020 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
2121 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
2222 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2323 * OTHER DEALINGS IN THE SOFTWARE.
24- *
24+ *
2525 * For more information, please refer to <http://unlicense.org>
2626 * -------------------------------------------------------------------------
27- *
28- * This is example code to 1) format an SPI Flash chip, and 2) copy raw
29- * audio files (mono channel, 16 bit signed, 44100Hz) to it using the
30- * SerialFlash library. The audio can then be played back using the
27+ *
28+ * This is example code to 1) format an SPI Flash chip, and 2) copy raw
29+ * audio files (mono channel, 16 bit signed, 44100Hz) to it using the
30+ * SerialFlash library. The audio can then be played back using the
3131 * AudioPlaySerialflashRaw object in the Teensy Audio library.
32- *
32+ *
3333 * To convert a .wav file to the proper .RAW format, use sox:
3434 * sox input.wav -r 44100 -b 16 --norm -e signed-integer -t raw OUTPUT.RAW remix 1,2
35- *
35+ *
3636 * Note that the OUTPUT.RAW filename must be all caps and contain only the following
3737 * characters: A-Z, 0-9, comma, period, colon, dash, underscore. (The SerialFlash
3838 * library converts filenames to caps, so to avoid confusion we just enforce it here).
39- *
39+ *
4040 * It is a little difficult to see what is happening; aswe are using the Serial port
4141 * to upload files, we can't just throw out debug information. Instead, we use the LED
4242 * (pin 13) to convey state.
43- *
44- * While the chip is being formatted, the LED (pin 13) will toggle at 1Hz rate. When
45- * the formatting is done, it flashes quickly (10Hz) for one second, then stays on
46- * solid. When nothing has been received for 3 seconds, the upload is assumed to be
43+ *
44+ * While the chip is being formatted, the LED (pin 13) will toggle at 1Hz rate. When
45+ * the formatting is done, it flashes quickly (10Hz) for one second, then stays on
46+ * solid. When nothing has been received for 3 seconds, the upload is assumed to be
4747 * completed, and the light goes off.
48- *
48+ *
4949 * Use the 'rawfile-uploader.py' python script (included in the extras folder) to upload
5050 * the files. You can start the script as soon as the Teensy is turned on, and the
5151 * USB serial upload will just buffer and wait until the flash is formatted.
52- *
53- * This code was written by Wyatt Olson <[email protected] > (originally as part 54- * of Drum Master http://drummaster.digitalcave.ca and later modified into a
52+ *
53+ * This code was written by Wyatt Olson <[email protected] > (originally as part 54+ * of Drum Master http://drummaster.digitalcave.ca and later modified into a
5555 * standalone sample).
56- *
56+ *
5757 * Enjoy!
5858 *
5959 * SerialFlash library API: https://github.com/PaulStoffregen/SerialFlash
6060 *
61- * This example depens on http://librarymanager/all#SerialFlash&SPI (clickme!)
61+ * This example depends on Paul Stoffregen's SerialFlash library
62+ * Download at https://github.com/PaulStoffregen/SerialFlash
6263 */
6364
6465#include < CurieSerialFlash.h>
@@ -85,14 +86,14 @@ void setup(){
8586 Serial.begin (9600 ); // Teensy serial is always at full USB speed and buffered... the baud rate here is required but ignored
8687
8788 pinMode (13 , OUTPUT);
88-
89+
8990 SerialFlash.begin (ONBOARD_FLASH_SPI_PORT, ONBOARD_FLASH_CS_PIN);
9091
9192 // We start by formatting the flash...
9293 uint8_t id[5 ];
9394 SerialFlash.readID (id);
9495 SerialFlash.eraseAll ();
95-
96+
9697 // Flash LED at 1Hz while formatting
9798 while (!SerialFlash.ready ()) {
9899 delay (500 );
@@ -109,26 +110,26 @@ void setup(){
109110 digitalWrite (13 , LOW);
110111 }
111112 digitalWrite (13 , HIGH);
112-
113+
113114 // We are now going to wait for the upload program
114115 while (!Serial.available ());
115-
116+
116117 SerialFlashFile flashFile;
117-
118+
118119 uint8_t state = STATE_START;
119120 uint8_t escape = 0 ;
120121 uint8_t fileSizeIndex = 0 ;
121122 uint32_t fileSize = 0 ;
122123 char filename[FILENAME_STRING_SIZE];
123-
124+
124125 char usbBuffer[USB_BUFFER_SIZE];
125126 uint8_t flashBuffer[FLASH_BUFFER_SIZE];
126-
127+
127128 uint16_t flashBufferIndex = 0 ;
128129 uint8_t filenameIndex = 0 ;
129-
130+
130131 uint32_t lastReceiveTime = millis ();
131-
132+
132133 // We assume the serial receive part is finished when we have not received something for 3 seconds
133134 while (Serial.available () || lastReceiveTime + 3000 > millis ()){
134135 uint16_t available = Serial.readBytes (usbBuffer, USB_BUFFER_SIZE);
@@ -138,7 +139,7 @@ void setup(){
138139
139140 for (uint16_t usbBufferIndex = 0 ; usbBufferIndex < available; usbBufferIndex++){
140141 uint8_t b = usbBuffer[usbBufferIndex];
141-
142+
142143 if (state == STATE_START){
143144 // Start byte. Repeat start is fine.
144145 if (b == BYTE_START){
@@ -163,12 +164,12 @@ void setup(){
163164 flushError ();
164165 return ;
165166 }
166-
167+
167168 // Change state
168169 state = STATE_SIZE;
169170 fileSizeIndex = 0 ;
170171 fileSize = 0 ;
171-
172+
172173 }
173174 // Invalid character
174175 else {
@@ -187,11 +188,11 @@ void setup(){
187188 state = STATE_CONTENT;
188189 flashBufferIndex = 0 ;
189190 escape = 0 ;
190-
191+
191192 if (SerialFlash.exists (filename)){
192193 SerialFlash.remove (filename); // It doesn't reclaim the space, but it does let you create a new file with the same name.
193194 }
194-
195+
195196 // Create a new file and open it for writing
196197 if (SerialFlash.create (filename, fileSize)) {
197198 flashFile = SerialFlash.open (filename);
@@ -236,7 +237,7 @@ void setup(){
236237 else {
237238 flashBuffer[flashBufferIndex++] = b;
238239 }
239-
240+
240241 // The buffer is filled; write to SD card
241242 if (flashBufferIndex >= FLASH_BUFFER_SIZE){
242243 flashFile.write (flashBuffer, FLASH_BUFFER_SIZE);
0 commit comments