mirror of
https://github.com/sanni/cartreader.git
synced 2024-11-13 08:25:05 +01:00
Add check if Clockgen is working
This commit is contained in:
parent
ed3663a21f
commit
eef1c6e8cc
@ -4,7 +4,7 @@
|
||||
This project represents a community-driven effort to provide
|
||||
an easy to build and easy to modify cartridge dumper.
|
||||
|
||||
Date: 17.11.2021
|
||||
Date: 18.11.2021
|
||||
Version: 7.2
|
||||
|
||||
SD lib: https://github.com/greiman/SdFat
|
||||
@ -140,6 +140,7 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||
// Adafruit Clock Generator
|
||||
#include <si5351.h>
|
||||
Si5351 clockgen;
|
||||
bool i2c_found;
|
||||
|
||||
// RTC Library
|
||||
#ifdef RTC_installed
|
||||
@ -1804,7 +1805,7 @@ browserstart:
|
||||
}
|
||||
|
||||
// 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
|
||||
myFile.getName(nameStr, FILENAME_LENGTH);
|
||||
@ -1994,9 +1995,11 @@ void loop() {
|
||||
}
|
||||
#endif
|
||||
#ifdef enable_NP
|
||||
#ifdef enable_FLASH
|
||||
else if (mode == mode_SFM_Flash) {
|
||||
sfmFlashMenu();
|
||||
}
|
||||
#endif
|
||||
else if (mode == mode_SFM_Game) {
|
||||
sfmGameOptions();
|
||||
}
|
||||
|
@ -242,8 +242,8 @@ void gbMenu() {
|
||||
// create menu with title and 3 options to choose from
|
||||
unsigned char mainMenu;
|
||||
// Copy menuOptions out of progmem
|
||||
convertPgm(menuOptionsGB, 3);
|
||||
mainMenu = question_box(F("GB Cart Reader"), menuOptions, 3, 0);
|
||||
convertPgm(menuOptionsGB, 4);
|
||||
mainMenu = question_box(F("GB Cart Reader"), menuOptions, 4, 0);
|
||||
|
||||
// wait for user choice to come back from the question box menu
|
||||
switch (mainMenu)
|
||||
|
@ -431,15 +431,20 @@ void setup_N64_Cart() {
|
||||
#ifdef clockgen_calibration
|
||||
int32_t clock_offset = readClockOffset();
|
||||
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 {
|
||||
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
|
||||
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
|
||||
}
|
||||
#else
|
||||
// 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
|
||||
|
||||
if (!i2c_found) {
|
||||
display_Clear();
|
||||
print_Error(F("Clock Generator not found"), true);
|
||||
}
|
||||
|
||||
// Set Eeprom clock to 2Mhz
|
||||
clockgen.set_freq(200000000ULL, SI5351_CLK1);
|
||||
|
||||
@ -3549,7 +3554,7 @@ redumpsamefolder:
|
||||
myFile.close();
|
||||
|
||||
unsigned long timeElapsed = (millis() - startTime) / 1000; // seconds
|
||||
|
||||
|
||||
print_Msg(F("CRC: "));
|
||||
// convert checksum to string
|
||||
char crcStr[9];
|
||||
|
@ -609,22 +609,30 @@ void setup_SFM() {
|
||||
#ifdef clockgen_calibration
|
||||
int32_t clock_offset = readClockOffset();
|
||||
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 {
|
||||
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
|
||||
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
|
||||
}
|
||||
#else
|
||||
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
|
||||
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
|
||||
#endif
|
||||
|
||||
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
|
||||
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLB);
|
||||
clockgen.set_freq(2147727200ULL, SI5351_CLK0);
|
||||
if (i2c_found) {
|
||||
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
|
||||
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLB);
|
||||
clockgen.set_freq(2147727200ULL, SI5351_CLK0);
|
||||
|
||||
// start outputting master clock
|
||||
clockgen.output_enable(SI5351_CLK1, 0);
|
||||
clockgen.output_enable(SI5351_CLK2, 0);
|
||||
clockgen.output_enable(SI5351_CLK0, 1);
|
||||
// start outputting master clock
|
||||
clockgen.output_enable(SI5351_CLK1, 0);
|
||||
clockgen.output_enable(SI5351_CLK2, 0);
|
||||
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
|
||||
delay(500);
|
||||
|
@ -139,14 +139,14 @@ void snsMenu() {
|
||||
// create menu with title and 6 options to choose from
|
||||
unsigned char snsCart;
|
||||
// Copy menuOptions out of progmem
|
||||
#ifdef clockgen_calibration
|
||||
#ifdef clockgen_calibration
|
||||
convertPgm(menuOptionsSNS, 6);
|
||||
snsCart = question_box(F("Select Cart Type"), menuOptions, 6, 0);
|
||||
#else
|
||||
#else
|
||||
convertPgm(menuOptionsSNS, 5);
|
||||
snsCart = question_box(F("Select Cart Type"), menuOptions, 5, 0);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// wait for user choice to come back from the question box menu
|
||||
switch (snsCart)
|
||||
@ -167,12 +167,14 @@ void snsMenu() {
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef enable_SV
|
||||
case 2:
|
||||
display_Clear();
|
||||
display_Update();
|
||||
setup_SV();
|
||||
mode = mode_SV;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef enable_FLASH
|
||||
case 3:
|
||||
@ -186,7 +188,7 @@ void snsMenu() {
|
||||
break;
|
||||
|
||||
case 5:
|
||||
#endif
|
||||
#endif
|
||||
resetArduino();
|
||||
break;
|
||||
}
|
||||
@ -385,9 +387,11 @@ void stopSnesClocks_resetCic_resetCart() {
|
||||
PORTG |= (1 << 1); // pull high = reset CIC
|
||||
DDRH |= (1 << 0); // Set RST(PH0) pin to Output
|
||||
PORTH &= ~(1 << 0); // Switch RST(PH0) to LOW
|
||||
clockgen.output_enable(SI5351_CLK1, 0); // CPU clock
|
||||
clockgen.output_enable(SI5351_CLK2, 0); // CIC clock
|
||||
clockgen.output_enable(SI5351_CLK0, 0); // master clock
|
||||
if (i2c_found) {
|
||||
clockgen.output_enable(SI5351_CLK1, 0); // CPU 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
|
||||
int32_t clock_offset = readClockOffset();
|
||||
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 {
|
||||
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
|
||||
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
|
||||
}
|
||||
#else
|
||||
// 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
|
||||
|
||||
// Set clocks to 4Mhz/1Mhz for better SA-1 unlocking
|
||||
clockgen.set_freq(100000000ULL, SI5351_CLK1); // CPU
|
||||
clockgen.set_freq(100000000ULL, SI5351_CLK2); // CIC
|
||||
clockgen.set_freq(400000000ULL, SI5351_CLK0); // EXT
|
||||
if (i2c_found) {
|
||||
// Set clocks to 4Mhz/1Mhz for better SA-1 unlocking
|
||||
clockgen.set_freq(100000000ULL, SI5351_CLK1); // CPU
|
||||
clockgen.set_freq(100000000ULL, SI5351_CLK2); // CIC
|
||||
clockgen.set_freq(400000000ULL, SI5351_CLK0); // EXT
|
||||
|
||||
// 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_CLK2, 1); // CIC clock (should go before master clock)
|
||||
clockgen.output_enable(SI5351_CLK0, 1); // master 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_CLK2, 1); // CIC clock (should go before master clock)
|
||||
clockgen.output_enable(SI5351_CLK0, 1); // master clock
|
||||
|
||||
// Wait for clock generator
|
||||
clockgen.update_status();
|
||||
delay(500);
|
||||
// Wait for clock generator
|
||||
clockgen.update_status();
|
||||
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)
|
||||
PORTG &= ~(1 << 1);
|
||||
@ -489,10 +501,12 @@ void setup_Snes() {
|
||||
// Print all the info
|
||||
getCartInfo_SNES();
|
||||
|
||||
//Set clocks to standard or else SA-1 sram writing will fail
|
||||
clockgen.set_freq(2147727200ULL, SI5351_CLK0);
|
||||
clockgen.set_freq(357954500ULL, SI5351_CLK1);
|
||||
clockgen.set_freq(307200000ULL, SI5351_CLK2);
|
||||
if (i2c_found) {
|
||||
//Set clocks to standard or else SA-1 sram writing will fail
|
||||
clockgen.set_freq(2147727200ULL, SI5351_CLK0);
|
||||
clockgen.set_freq(357954500ULL, SI5351_CLK1);
|
||||
clockgen.set_freq(307200000ULL, SI5351_CLK2);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************
|
||||
@ -1490,8 +1504,10 @@ void writeSRAM (boolean browseFile) {
|
||||
// SA1
|
||||
else if (romType == SA) {
|
||||
long lastByte = (long(sramSize) * 128);
|
||||
// Enable CPU Clock
|
||||
clockgen.output_enable(SI5351_CLK1, 1);
|
||||
if (i2c_found) {
|
||||
// Enable CPU Clock
|
||||
clockgen.output_enable(SI5351_CLK1, 1);
|
||||
}
|
||||
|
||||
// Direct writes to BW-RAM (SRAM) in banks 0x40-0x43 don't work
|
||||
// Break BW-RAM (SRAM) into 0x2000 blocks
|
||||
@ -1532,8 +1548,10 @@ void writeSRAM (boolean browseFile) {
|
||||
writeBank_SNES(0, 0x2224, 0);
|
||||
writeBank_SNES(0, 0x2226, 0x80);
|
||||
writeBank_SNES(0, 0x6000, firstByte);
|
||||
// Disable CPU clock
|
||||
clockgen.output_enable(SI5351_CLK1, 0);
|
||||
if (i2c_found) {
|
||||
// Disable CPU clock
|
||||
clockgen.output_enable(SI5351_CLK1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Set pins to input
|
||||
@ -1986,8 +2004,10 @@ boolean eraseSRAM (byte b) {
|
||||
// SA1
|
||||
else if (romType == SA) {
|
||||
long lastByte = (long(sramSize) * 128);
|
||||
// Enable CPU Clock
|
||||
clockgen.output_enable(SI5351_CLK1, 1);
|
||||
if (i2c_found) {
|
||||
// Enable CPU Clock
|
||||
clockgen.output_enable(SI5351_CLK1, 1);
|
||||
}
|
||||
|
||||
// Direct writes to BW-RAM (SRAM) in banks 0x40-0x43 don't work
|
||||
// Break BW-RAM (SRAM) into 0x2000 blocks
|
||||
@ -2024,8 +2044,11 @@ boolean eraseSRAM (byte b) {
|
||||
writeBank_SNES(0, 0x2224, 0);
|
||||
writeBank_SNES(0, 0x2226, 0x80);
|
||||
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();
|
||||
|
@ -113,14 +113,22 @@ void setup_SV() {
|
||||
DDRG &= ~(1 << 0);
|
||||
|
||||
// Adafruit Clock Generator
|
||||
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
|
||||
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
|
||||
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLB);
|
||||
clockgen.set_freq(2147727200ULL, SI5351_CLK0);
|
||||
clockgen.set_freq(307200000ULL, SI5351_CLK2);
|
||||
clockgen.output_enable(SI5351_CLK0, 1);
|
||||
clockgen.output_enable(SI5351_CLK1, 0);
|
||||
clockgen.output_enable(SI5351_CLK2, 1);
|
||||
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
|
||||
if (i2c_found) {
|
||||
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
|
||||
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLB);
|
||||
clockgen.set_freq(2147727200ULL, SI5351_CLK0);
|
||||
clockgen.set_freq(307200000ULL, SI5351_CLK2);
|
||||
clockgen.output_enable(SI5351_CLK0, 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
|
||||
//A0-A7
|
||||
|
@ -31,11 +31,17 @@ void clkcal() {
|
||||
delay(500);
|
||||
|
||||
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 {
|
||||
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
|
||||
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 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_pll(SI5351_PLL_FIXED, SI5351_PLLA);
|
||||
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLB);
|
||||
@ -51,7 +57,7 @@ void clkcal() {
|
||||
// Frequency Counter
|
||||
delay(500);
|
||||
FreqCount.begin(1000);
|
||||
while (1)
|
||||
while (1)
|
||||
{
|
||||
if (old_cal != cal_factor) {
|
||||
display_Clear();
|
||||
@ -76,7 +82,7 @@ void clkcal() {
|
||||
clockgen.update_status();
|
||||
while (clockgen.dev_status.SYS_INIT == 1) {
|
||||
}
|
||||
|
||||
|
||||
if (FreqCount.available()) {
|
||||
float count = FreqCount.read();
|
||||
display_Clear();
|
||||
@ -94,19 +100,19 @@ void clkcal() {
|
||||
println_Msg(F(""));
|
||||
println_Msg(F("Decrease Increase"));
|
||||
#else
|
||||
#ifdef enable_rotary
|
||||
#ifdef enable_rotary
|
||||
println_Msg(F("Rotate to adjust"));
|
||||
#else
|
||||
#else
|
||||
println_Msg(F("Click/dbl to adjust"));
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
display_Update();
|
||||
}
|
||||
#ifdef enable_Button2
|
||||
#ifdef enable_Button2
|
||||
// get input button
|
||||
int a = checkButton1();
|
||||
int b = checkButton2();
|
||||
|
||||
|
||||
// if the cart readers input button is pressed shortly
|
||||
if (a == 1) {
|
||||
old_cal = cal_factor;
|
||||
@ -116,7 +122,7 @@ void clkcal() {
|
||||
old_cal = cal_factor;
|
||||
cal_factor += cal_offset;
|
||||
}
|
||||
|
||||
|
||||
// if the cart readers input buttons is double clicked
|
||||
if (a == 2) {
|
||||
cal_offset /= 10ULL;
|
||||
@ -132,7 +138,7 @@ void clkcal() {
|
||||
cal_offset = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if the cart readers input button is pressed long
|
||||
if (a == 3) {
|
||||
savetofile();
|
||||
@ -141,30 +147,30 @@ void clkcal() {
|
||||
savetofile();
|
||||
}
|
||||
#else
|
||||
//Handle inputs for either rotary encoder or single button interface.
|
||||
int a = checkButton();
|
||||
|
||||
if (a == 1) { //clockwise rotation or single click
|
||||
old_cal = cal_factor;
|
||||
cal_factor += cal_offset;
|
||||
}
|
||||
//Handle inputs for either rotary encoder or single button interface.
|
||||
int a = checkButton();
|
||||
|
||||
if (a == 2) { //counterclockwise rotation or double click
|
||||
old_cal = cal_factor;
|
||||
cal_factor -= cal_offset;
|
||||
}
|
||||
if (a == 1) { //clockwise rotation or single click
|
||||
old_cal = cal_factor;
|
||||
cal_factor += cal_offset;
|
||||
}
|
||||
|
||||
if (a == 3) { //button short hold
|
||||
cal_offset *= 10ULL;
|
||||
if (a == 2) { //counterclockwise rotation or double click
|
||||
old_cal = cal_factor;
|
||||
cal_factor -= cal_offset;
|
||||
}
|
||||
|
||||
if (a == 3) { //button short hold
|
||||
cal_offset *= 10ULL;
|
||||
if (cal_offset > 100000000ULL)
|
||||
{
|
||||
cal_offset = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (a == 4) { //button long hold
|
||||
savetofile();
|
||||
}
|
||||
if (a == 4) { //button long hold
|
||||
savetofile();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -180,7 +186,7 @@ void print_right(int32_t number)
|
||||
|
||||
if (abs_number == 0)
|
||||
abs_number = 1;
|
||||
while(abs_number < 100000000ULL)
|
||||
while (abs_number < 100000000ULL)
|
||||
{
|
||||
print_Msg(F(" "));
|
||||
abs_number *= 10ULL;
|
||||
|
Loading…
Reference in New Issue
Block a user