2 serial modes + SD card

This commit is contained in:
Brian Peek 2022-07-09 18:08:39 -07:00
parent dd83387795
commit 586e2f5007
1 changed files with 37 additions and 10 deletions

View File

@ -1,4 +1,6 @@
#include <Arduino.h>
#include <SPI.h>
#include <SD.h>
// forced to a 2mbit eprom
// FLASHMEM
@ -7,16 +9,12 @@
#define ROM_BUFFER_LEN (256*1024)
char buffer[ROM_BUFFER_LEN];
const char *filename = "rom.bin";
// v1 uses 30/31
int32_t inPins[] = { 19,18,14,15,40,41,17,16,22,23,20,21,38,39,26,27,24,25,/*30,31,*/-1 };
int32_t inPins[] = { 19,18,14,15,40,41,17,16,22,23,20,21,38,39,26,27,24,25,-1 };
int32_t outPins[] = { 10,12,11,13,8,7,36,37,-1 };
// v1
//int32_t cePin = 30;
//int32_t pgmPin = 31;
void readFile()
void readFile(int port)
{
const int length = 1024;
char buff[length];
@ -30,7 +28,17 @@ void readFile()
do
{
memset(buff, 0, length);
read = Serial.readBytes(buff, length);
switch(port)
{
case 0:
read = Serial.readBytes(buff, length);
break;
case 1:
read = Serial1.readBytes(buff, length);
break;
}
total += read;
if(read > 0)
{
@ -43,6 +51,12 @@ void readFile()
// on GG (and lynx?) top address bit gets stuck high (?) so mirror to upper region too?
if(total == 131072)
memcpy(p, buffer, 131072);
SD.remove(filename);
File f = SD.open(filename, O_WRITE);
f.write(buffer, ROM_BUFFER_LEN);
f.close();
}
void setPinMode(int32_t* pins, int32_t direction)
@ -57,7 +71,17 @@ void setup()
setPinMode(outPins, OUTPUT);
GPIO7_DR = 0;
SD.begin(BUILTIN_SDCARD);
if(SD.exists(filename))
{
File f = SD.open(filename, O_READ);
f.read(buffer, f.size());
f.close();
}
Serial.begin(115200);
Serial1.begin(3000000);
}
void loop()
@ -73,9 +97,12 @@ void loop()
// set data pins
outb = ((b & 0x0F) << 0) | ((b & 0xF0) << 12);
GPIO7_DR = outb;
// read file from either serial port, if available
if(Serial.available())
readFile();
readFile(0);
if(Serial1.available())
readFile(1);
}