-
Notifications
You must be signed in to change notification settings - Fork 0
/
AudioLoader_WT588D.ino
72 lines (56 loc) · 1.74 KB
/
AudioLoader_WT588D.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Winbond serial flash loader. Runs on normal Arduino (e.g. Uno,
// NOT Trinket), works with 'AudioXfer' Processing code on host PC.
// Modified by purgedsoul for uploading bin file to WTD588-16P sound module.
// Use at your own risk!
#include <Esplora.h>
#include <Adafruit_TinyFlash.h>
#include <SPI.h>
#define CHIP_SELECT_PIN 7
void setup() {
Serial.begin(9600);
}
void loop() {
Adafruit_TinyFlash flash = Adafruit_TinyFlash(CHIP_SELECT_PIN);
uint8_t buffer[256];
int c, index = 0,
rmdr = 0,
numpages = 0,
page = 0;
uint32_t capacity,
address = 0,
bytesExpected = 0x7FFFFFFF,
bytesReceived = 0,
filesize=0;
pinMode(CHIP_SELECT_PIN, OUTPUT);
Serial.println("HELLO"); // ACK to host
capacity = flash.begin();
Serial.println(capacity); // Chip size to host
while(!Serial.find("ERASE")); // Wait for ERASE command from host
if(!flash.eraseChip()) {
Serial.println("ERROR");
}
while(!Serial.find("CAPACITY"));
filesize = Serial.parseInt();
numpages = filesize / 256;
rmdr = filesize % 256;
if(rmdr != 0) numpages = numpages + 1;
Serial.println("READY"); // ACK to host
for(;;) {
// Buffer data until a full page is ready or last packet arrives.
if((c = Serial.read()) >= 0) {
buffer[index] = c;
index=index+1;
if((index >= sizeof(buffer))) {
if(flash.writePage(address, buffer)) {
Serial.print('.');
} else {
Serial.print('X');
}
if(page >= numpages) break; //(address >= capacity) ||
index = 0;
page = page + 1;
address = address + sizeof(buffer);
}
}
}
}