Add check if Clockgen is working

This commit is contained in:
sanni 2021-11-18 14:55:50 +01:00
parent ed3663a21f
commit eef1c6e8cc
7 changed files with 142 additions and 89 deletions

View File

@ -4,7 +4,7 @@
This project represents a community-driven effort to provide This project represents a community-driven effort to provide
an easy to build and easy to modify cartridge dumper. an easy to build and easy to modify cartridge dumper.
Date: 17.11.2021 Date: 18.11.2021
Version: 7.2 Version: 7.2
SD lib: https://github.com/greiman/SdFat SD lib: https://github.com/greiman/SdFat
@ -140,6 +140,7 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Adafruit Clock Generator // Adafruit Clock Generator
#include <si5351.h> #include <si5351.h>
Si5351 clockgen; Si5351 clockgen;
bool i2c_found;
// RTC Library // RTC Library
#ifdef RTC_installed #ifdef RTC_installed
@ -1804,7 +1805,7 @@ browserstart:
} }
// Read in File as long as there are files // Read in File as long as there are files
while (myFile.openNext(&myDir, O_READ)) { while (myFile.openNext(&myDir, O_READ) && (currFile < 29)) {
// Get name of file // Get name of file
myFile.getName(nameStr, FILENAME_LENGTH); myFile.getName(nameStr, FILENAME_LENGTH);
@ -1994,9 +1995,11 @@ void loop() {
} }
#endif #endif
#ifdef enable_NP #ifdef enable_NP
#ifdef enable_FLASH
else if (mode == mode_SFM_Flash) { else if (mode == mode_SFM_Flash) {
sfmFlashMenu(); sfmFlashMenu();
} }
#endif
else if (mode == mode_SFM_Game) { else if (mode == mode_SFM_Game) {
sfmGameOptions(); sfmGameOptions();
} }

View File

@ -242,8 +242,8 @@ void gbMenu() {
// create menu with title and 3 options to choose from // create menu with title and 3 options to choose from
unsigned char mainMenu; unsigned char mainMenu;
// Copy menuOptions out of progmem // Copy menuOptions out of progmem
convertPgm(menuOptionsGB, 3); convertPgm(menuOptionsGB, 4);
mainMenu = question_box(F("GB Cart Reader"), menuOptions, 3, 0); mainMenu = question_box(F("GB Cart Reader"), menuOptions, 4, 0);
// wait for user choice to come back from the question box menu // wait for user choice to come back from the question box menu
switch (mainMenu) switch (mainMenu)

View File

@ -431,15 +431,20 @@ void setup_N64_Cart() {
#ifdef clockgen_calibration #ifdef clockgen_calibration
int32_t clock_offset = readClockOffset(); int32_t clock_offset = readClockOffset();
if (clock_offset > INT32_MIN) { if (clock_offset > INT32_MIN) {
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, clock_offset); i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, clock_offset);
} else { } else {
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0); i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
} }
#else #else
// last number is the clock correction factor which is custom for each clock generator // last number is the clock correction factor which is custom for each clock generator
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0); i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
#endif #endif
if (!i2c_found) {
display_Clear();
print_Error(F("Clock Generator not found"), true);
}
// Set Eeprom clock to 2Mhz // Set Eeprom clock to 2Mhz
clockgen.set_freq(200000000ULL, SI5351_CLK1); clockgen.set_freq(200000000ULL, SI5351_CLK1);
@ -3549,7 +3554,7 @@ redumpsamefolder:
myFile.close(); myFile.close();
unsigned long timeElapsed = (millis() - startTime) / 1000; // seconds unsigned long timeElapsed = (millis() - startTime) / 1000; // seconds
print_Msg(F("CRC: ")); print_Msg(F("CRC: "));
// convert checksum to string // convert checksum to string
char crcStr[9]; char crcStr[9];

View File

@ -609,22 +609,30 @@ void setup_SFM() {
#ifdef clockgen_calibration #ifdef clockgen_calibration
int32_t clock_offset = readClockOffset(); int32_t clock_offset = readClockOffset();
if (clock_offset > INT32_MIN) { if (clock_offset > INT32_MIN) {
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, clock_offset); i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, clock_offset);
} else { } else {
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0); i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
} }
#else #else
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0); i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
#endif #endif
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLA); if (i2c_found) {
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLB); clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
clockgen.set_freq(2147727200ULL, SI5351_CLK0); clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLB);
clockgen.set_freq(2147727200ULL, SI5351_CLK0);
// start outputting master clock // start outputting master clock
clockgen.output_enable(SI5351_CLK1, 0); clockgen.output_enable(SI5351_CLK1, 0);
clockgen.output_enable(SI5351_CLK2, 0); clockgen.output_enable(SI5351_CLK2, 0);
clockgen.output_enable(SI5351_CLK0, 1); clockgen.output_enable(SI5351_CLK0, 1);
}
#ifdef clockgen_installed
else {
display_Clear();
print_Error(F("Clock Generator not found"), true);
}
#endif
// Wait until all is stable // Wait until all is stable
delay(500); delay(500);

View File

@ -139,14 +139,14 @@ void snsMenu() {
// create menu with title and 6 options to choose from // create menu with title and 6 options to choose from
unsigned char snsCart; unsigned char snsCart;
// Copy menuOptions out of progmem // Copy menuOptions out of progmem
#ifdef clockgen_calibration #ifdef clockgen_calibration
convertPgm(menuOptionsSNS, 6); convertPgm(menuOptionsSNS, 6);
snsCart = question_box(F("Select Cart Type"), menuOptions, 6, 0); snsCart = question_box(F("Select Cart Type"), menuOptions, 6, 0);
#else #else
convertPgm(menuOptionsSNS, 5); convertPgm(menuOptionsSNS, 5);
snsCart = question_box(F("Select Cart Type"), menuOptions, 5, 0); snsCart = question_box(F("Select Cart Type"), menuOptions, 5, 0);
#endif #endif
// wait for user choice to come back from the question box menu // wait for user choice to come back from the question box menu
switch (snsCart) switch (snsCart)
@ -167,12 +167,14 @@ void snsMenu() {
break; break;
#endif #endif
#ifdef enable_SV
case 2: case 2:
display_Clear(); display_Clear();
display_Update(); display_Update();
setup_SV(); setup_SV();
mode = mode_SV; mode = mode_SV;
break; break;
#endif
#ifdef enable_FLASH #ifdef enable_FLASH
case 3: case 3:
@ -186,7 +188,7 @@ void snsMenu() {
break; break;
case 5: case 5:
#endif #endif
resetArduino(); resetArduino();
break; break;
} }
@ -385,9 +387,11 @@ void stopSnesClocks_resetCic_resetCart() {
PORTG |= (1 << 1); // pull high = reset CIC PORTG |= (1 << 1); // pull high = reset CIC
DDRH |= (1 << 0); // Set RST(PH0) pin to Output DDRH |= (1 << 0); // Set RST(PH0) pin to Output
PORTH &= ~(1 << 0); // Switch RST(PH0) to LOW PORTH &= ~(1 << 0); // Switch RST(PH0) to LOW
clockgen.output_enable(SI5351_CLK1, 0); // CPU clock if (i2c_found) {
clockgen.output_enable(SI5351_CLK2, 0); // CIC clock clockgen.output_enable(SI5351_CLK1, 0); // CPU clock
clockgen.output_enable(SI5351_CLK0, 0); // master clock clockgen.output_enable(SI5351_CLK2, 0); // CIC clock
clockgen.output_enable(SI5351_CLK0, 0); // master clock
}
} }
/****************************************** /******************************************
@ -457,28 +461,36 @@ void setup_Snes() {
#ifdef clockgen_calibration #ifdef clockgen_calibration
int32_t clock_offset = readClockOffset(); int32_t clock_offset = readClockOffset();
if (clock_offset > INT32_MIN) { if (clock_offset > INT32_MIN) {
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, clock_offset); i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, clock_offset);
} else { } else {
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0); i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
} }
#else #else
// last number is the clock correction factor which is custom for each clock generator // last number is the clock correction factor which is custom for each clock generator
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0); i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
#endif #endif
// Set clocks to 4Mhz/1Mhz for better SA-1 unlocking if (i2c_found) {
clockgen.set_freq(100000000ULL, SI5351_CLK1); // CPU // Set clocks to 4Mhz/1Mhz for better SA-1 unlocking
clockgen.set_freq(100000000ULL, SI5351_CLK2); // CIC clockgen.set_freq(100000000ULL, SI5351_CLK1); // CPU
clockgen.set_freq(400000000ULL, SI5351_CLK0); // EXT clockgen.set_freq(100000000ULL, SI5351_CLK2); // CIC
clockgen.set_freq(400000000ULL, SI5351_CLK0); // EXT
// Start outputting master clock, CIC clock // Start outputting master clock, CIC clock
clockgen.output_enable(SI5351_CLK1, 0); // no CPU clock yet; seems to affect SA-1 success a lot clockgen.output_enable(SI5351_CLK1, 0); // no CPU clock yet; seems to affect SA-1 success a lot
clockgen.output_enable(SI5351_CLK2, 1); // CIC clock (should go before master clock) clockgen.output_enable(SI5351_CLK2, 1); // CIC clock (should go before master clock)
clockgen.output_enable(SI5351_CLK0, 1); // master clock clockgen.output_enable(SI5351_CLK0, 1); // master clock
// Wait for clock generator // Wait for clock generator
clockgen.update_status(); clockgen.update_status();
delay(500); delay(500);
}
#ifdef clockgen_installed
else {
display_Clear();
print_Error(F("Clock Generator not found"), true);
}
#endif
// Start CIC by outputting a low signal to cicrstPin(PG1) // Start CIC by outputting a low signal to cicrstPin(PG1)
PORTG &= ~(1 << 1); PORTG &= ~(1 << 1);
@ -489,10 +501,12 @@ void setup_Snes() {
// Print all the info // Print all the info
getCartInfo_SNES(); getCartInfo_SNES();
//Set clocks to standard or else SA-1 sram writing will fail if (i2c_found) {
clockgen.set_freq(2147727200ULL, SI5351_CLK0); //Set clocks to standard or else SA-1 sram writing will fail
clockgen.set_freq(357954500ULL, SI5351_CLK1); clockgen.set_freq(2147727200ULL, SI5351_CLK0);
clockgen.set_freq(307200000ULL, SI5351_CLK2); clockgen.set_freq(357954500ULL, SI5351_CLK1);
clockgen.set_freq(307200000ULL, SI5351_CLK2);
}
} }
/****************************************** /******************************************
@ -1490,8 +1504,10 @@ void writeSRAM (boolean browseFile) {
// SA1 // SA1
else if (romType == SA) { else if (romType == SA) {
long lastByte = (long(sramSize) * 128); long lastByte = (long(sramSize) * 128);
// Enable CPU Clock if (i2c_found) {
clockgen.output_enable(SI5351_CLK1, 1); // Enable CPU Clock
clockgen.output_enable(SI5351_CLK1, 1);
}
// Direct writes to BW-RAM (SRAM) in banks 0x40-0x43 don't work // Direct writes to BW-RAM (SRAM) in banks 0x40-0x43 don't work
// Break BW-RAM (SRAM) into 0x2000 blocks // Break BW-RAM (SRAM) into 0x2000 blocks
@ -1532,8 +1548,10 @@ void writeSRAM (boolean browseFile) {
writeBank_SNES(0, 0x2224, 0); writeBank_SNES(0, 0x2224, 0);
writeBank_SNES(0, 0x2226, 0x80); writeBank_SNES(0, 0x2226, 0x80);
writeBank_SNES(0, 0x6000, firstByte); writeBank_SNES(0, 0x6000, firstByte);
// Disable CPU clock if (i2c_found) {
clockgen.output_enable(SI5351_CLK1, 0); // Disable CPU clock
clockgen.output_enable(SI5351_CLK1, 0);
}
} }
// Set pins to input // Set pins to input
@ -1986,8 +2004,10 @@ boolean eraseSRAM (byte b) {
// SA1 // SA1
else if (romType == SA) { else if (romType == SA) {
long lastByte = (long(sramSize) * 128); long lastByte = (long(sramSize) * 128);
// Enable CPU Clock if (i2c_found) {
clockgen.output_enable(SI5351_CLK1, 1); // Enable CPU Clock
clockgen.output_enable(SI5351_CLK1, 1);
}
// Direct writes to BW-RAM (SRAM) in banks 0x40-0x43 don't work // Direct writes to BW-RAM (SRAM) in banks 0x40-0x43 don't work
// Break BW-RAM (SRAM) into 0x2000 blocks // Break BW-RAM (SRAM) into 0x2000 blocks
@ -2024,8 +2044,11 @@ boolean eraseSRAM (byte b) {
writeBank_SNES(0, 0x2224, 0); writeBank_SNES(0, 0x2224, 0);
writeBank_SNES(0, 0x2226, 0x80); writeBank_SNES(0, 0x2226, 0x80);
writeBank_SNES(0, 0x6000, b); writeBank_SNES(0, 0x6000, b);
// Disable CPU clock
clockgen.output_enable(SI5351_CLK1, 0); if (i2c_found) {
// Disable CPU clock
clockgen.output_enable(SI5351_CLK1, 0);
}
} }
dataIn(); dataIn();

View File

@ -113,14 +113,22 @@ void setup_SV() {
DDRG &= ~(1 << 0); DDRG &= ~(1 << 0);
// Adafruit Clock Generator // Adafruit Clock Generator
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0); i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLA); if (i2c_found) {
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLB); clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
clockgen.set_freq(2147727200ULL, SI5351_CLK0); clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLB);
clockgen.set_freq(307200000ULL, SI5351_CLK2); clockgen.set_freq(2147727200ULL, SI5351_CLK0);
clockgen.output_enable(SI5351_CLK0, 1); clockgen.set_freq(307200000ULL, SI5351_CLK2);
clockgen.output_enable(SI5351_CLK1, 0); clockgen.output_enable(SI5351_CLK0, 1);
clockgen.output_enable(SI5351_CLK2, 1); clockgen.output_enable(SI5351_CLK1, 0);
clockgen.output_enable(SI5351_CLK2, 1);
}
#ifdef clockgen_installed
else {
display_Clear();
print_Error(F("Clock Generator not found"), true);
}
#endif
// Set Address Pins to Output // Set Address Pins to Output
//A0-A7 //A0-A7

View File

@ -31,11 +31,17 @@ void clkcal() {
delay(500); delay(500);
if (cal_factor > INT32_MIN) { if (cal_factor > INT32_MIN) {
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, cal_factor); i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, cal_factor);
} else { } else {
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0); i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
cal_factor = 0; cal_factor = 0;
} }
if (!i2c_found) {
display_Clear();
print_Error(F("Clock Generator not found"), true);
}
//clockgen.set_correction(cal_factor, SI5351_PLL_INPUT_XO); //clockgen.set_correction(cal_factor, SI5351_PLL_INPUT_XO);
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLA); clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLB); clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLB);
@ -51,7 +57,7 @@ void clkcal() {
// Frequency Counter // Frequency Counter
delay(500); delay(500);
FreqCount.begin(1000); FreqCount.begin(1000);
while (1) while (1)
{ {
if (old_cal != cal_factor) { if (old_cal != cal_factor) {
display_Clear(); display_Clear();
@ -76,7 +82,7 @@ void clkcal() {
clockgen.update_status(); clockgen.update_status();
while (clockgen.dev_status.SYS_INIT == 1) { while (clockgen.dev_status.SYS_INIT == 1) {
} }
if (FreqCount.available()) { if (FreqCount.available()) {
float count = FreqCount.read(); float count = FreqCount.read();
display_Clear(); display_Clear();
@ -94,19 +100,19 @@ void clkcal() {
println_Msg(F("")); println_Msg(F(""));
println_Msg(F("Decrease Increase")); println_Msg(F("Decrease Increase"));
#else #else
#ifdef enable_rotary #ifdef enable_rotary
println_Msg(F("Rotate to adjust")); println_Msg(F("Rotate to adjust"));
#else #else
println_Msg(F("Click/dbl to adjust")); println_Msg(F("Click/dbl to adjust"));
#endif #endif
#endif #endif
display_Update(); display_Update();
} }
#ifdef enable_Button2 #ifdef enable_Button2
// get input button // get input button
int a = checkButton1(); int a = checkButton1();
int b = checkButton2(); int b = checkButton2();
// if the cart readers input button is pressed shortly // if the cart readers input button is pressed shortly
if (a == 1) { if (a == 1) {
old_cal = cal_factor; old_cal = cal_factor;
@ -116,7 +122,7 @@ void clkcal() {
old_cal = cal_factor; old_cal = cal_factor;
cal_factor += cal_offset; cal_factor += cal_offset;
} }
// if the cart readers input buttons is double clicked // if the cart readers input buttons is double clicked
if (a == 2) { if (a == 2) {
cal_offset /= 10ULL; cal_offset /= 10ULL;
@ -132,7 +138,7 @@ void clkcal() {
cal_offset = 1; cal_offset = 1;
} }
} }
// if the cart readers input button is pressed long // if the cart readers input button is pressed long
if (a == 3) { if (a == 3) {
savetofile(); savetofile();
@ -141,30 +147,30 @@ void clkcal() {
savetofile(); savetofile();
} }
#else #else
//Handle inputs for either rotary encoder or single button interface. //Handle inputs for either rotary encoder or single button interface.
int a = checkButton(); int a = checkButton();
if (a == 1) { //clockwise rotation or single click
old_cal = cal_factor;
cal_factor += cal_offset;
}
if (a == 2) { //counterclockwise rotation or double click if (a == 1) { //clockwise rotation or single click
old_cal = cal_factor; old_cal = cal_factor;
cal_factor -= cal_offset; cal_factor += cal_offset;
} }
if (a == 3) { //button short hold if (a == 2) { //counterclockwise rotation or double click
cal_offset *= 10ULL; old_cal = cal_factor;
cal_factor -= cal_offset;
}
if (a == 3) { //button short hold
cal_offset *= 10ULL;
if (cal_offset > 100000000ULL) if (cal_offset > 100000000ULL)
{ {
cal_offset = 1; cal_offset = 1;
} }
} }
if (a == 4) { //button long hold if (a == 4) { //button long hold
savetofile(); savetofile();
} }
#endif #endif
} }
} }
@ -180,7 +186,7 @@ void print_right(int32_t number)
if (abs_number == 0) if (abs_number == 0)
abs_number = 1; abs_number = 1;
while(abs_number < 100000000ULL) while (abs_number < 100000000ULL)
{ {
print_Msg(F(" ")); print_Msg(F(" "));
abs_number *= 10ULL; abs_number *= 10ULL;