mirror of
https://github.com/sanni/cartreader.git
synced 2025-02-25 09:03:34 +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
|
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();
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -609,14 +609,15 @@ 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
|
||||||
|
|
||||||
|
if (i2c_found) {
|
||||||
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);
|
||||||
clockgen.set_freq(2147727200ULL, SI5351_CLK0);
|
clockgen.set_freq(2147727200ULL, SI5351_CLK0);
|
||||||
@ -625,6 +626,13 @@ void setup_SFM() {
|
|||||||
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);
|
||||||
|
@ -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:
|
||||||
@ -385,10 +387,12 @@ 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
|
||||||
|
if (i2c_found) {
|
||||||
clockgen.output_enable(SI5351_CLK1, 0); // CPU clock
|
clockgen.output_enable(SI5351_CLK1, 0); // CPU clock
|
||||||
clockgen.output_enable(SI5351_CLK2, 0); // CIC clock
|
clockgen.output_enable(SI5351_CLK2, 0); // CIC clock
|
||||||
clockgen.output_enable(SI5351_CLK0, 0); // master clock
|
clockgen.output_enable(SI5351_CLK0, 0); // master clock
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************
|
/******************************************
|
||||||
Setup
|
Setup
|
||||||
@ -457,15 +461,16 @@ 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
|
||||||
|
|
||||||
|
if (i2c_found) {
|
||||||
// Set clocks to 4Mhz/1Mhz for better SA-1 unlocking
|
// Set clocks to 4Mhz/1Mhz for better SA-1 unlocking
|
||||||
clockgen.set_freq(100000000ULL, SI5351_CLK1); // CPU
|
clockgen.set_freq(100000000ULL, SI5351_CLK1); // CPU
|
||||||
clockgen.set_freq(100000000ULL, SI5351_CLK2); // CIC
|
clockgen.set_freq(100000000ULL, SI5351_CLK2); // CIC
|
||||||
@ -479,6 +484,13 @@ void setup_Snes() {
|
|||||||
// 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,11 +501,13 @@ void setup_Snes() {
|
|||||||
// Print all the info
|
// Print all the info
|
||||||
getCartInfo_SNES();
|
getCartInfo_SNES();
|
||||||
|
|
||||||
|
if (i2c_found) {
|
||||||
//Set clocks to standard or else SA-1 sram writing will fail
|
//Set clocks to standard or else SA-1 sram writing will fail
|
||||||
clockgen.set_freq(2147727200ULL, SI5351_CLK0);
|
clockgen.set_freq(2147727200ULL, SI5351_CLK0);
|
||||||
clockgen.set_freq(357954500ULL, SI5351_CLK1);
|
clockgen.set_freq(357954500ULL, SI5351_CLK1);
|
||||||
clockgen.set_freq(307200000ULL, SI5351_CLK2);
|
clockgen.set_freq(307200000ULL, SI5351_CLK2);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************
|
/******************************************
|
||||||
I/O Functions
|
I/O Functions
|
||||||
@ -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);
|
||||||
|
if (i2c_found) {
|
||||||
// Enable CPU Clock
|
// Enable CPU Clock
|
||||||
clockgen.output_enable(SI5351_CLK1, 1);
|
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,9 +1548,11 @@ 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);
|
||||||
|
if (i2c_found) {
|
||||||
// Disable CPU clock
|
// Disable CPU clock
|
||||||
clockgen.output_enable(SI5351_CLK1, 0);
|
clockgen.output_enable(SI5351_CLK1, 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set pins to input
|
// Set pins to input
|
||||||
dataIn();
|
dataIn();
|
||||||
@ -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);
|
||||||
|
if (i2c_found) {
|
||||||
// Enable CPU Clock
|
// Enable CPU Clock
|
||||||
clockgen.output_enable(SI5351_CLK1, 1);
|
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,9 +2044,12 @@ 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);
|
||||||
|
|
||||||
|
if (i2c_found) {
|
||||||
// Disable CPU clock
|
// Disable CPU clock
|
||||||
clockgen.output_enable(SI5351_CLK1, 0);
|
clockgen.output_enable(SI5351_CLK1, 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dataIn();
|
dataIn();
|
||||||
|
|
||||||
|
@ -113,7 +113,8 @@ 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);
|
||||||
|
if (i2c_found) {
|
||||||
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);
|
||||||
clockgen.set_freq(2147727200ULL, SI5351_CLK0);
|
clockgen.set_freq(2147727200ULL, SI5351_CLK0);
|
||||||
@ -121,6 +122,13 @@ void setup_SV() {
|
|||||||
clockgen.output_enable(SI5351_CLK0, 1);
|
clockgen.output_enable(SI5351_CLK0, 1);
|
||||||
clockgen.output_enable(SI5351_CLK1, 0);
|
clockgen.output_enable(SI5351_CLK1, 0);
|
||||||
clockgen.output_enable(SI5351_CLK2, 1);
|
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
|
||||||
|
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user