mirror of
https://github.com/sanni/cartreader.git
synced 2024-11-27 15:04:15 +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);
|
||||
|
||||
|
@ -609,14 +609,15 @@ 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
|
||||
|
||||
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);
|
||||
@ -625,6 +626,13 @@ void setup_SFM() {
|
||||
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);
|
||||
|
@ -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:
|
||||
@ -385,10 +387,12 @@ 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
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************
|
||||
Setup
|
||||
@ -457,15 +461,16 @@ 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
|
||||
|
||||
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
|
||||
@ -479,6 +484,13 @@ void setup_Snes() {
|
||||
// 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,11 +501,13 @@ void setup_Snes() {
|
||||
// Print all the info
|
||||
getCartInfo_SNES();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************
|
||||
I/O Functions
|
||||
@ -1490,8 +1504,10 @@ void writeSRAM (boolean browseFile) {
|
||||
// SA1
|
||||
else if (romType == SA) {
|
||||
long lastByte = (long(sramSize) * 128);
|
||||
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,9 +1548,11 @@ void writeSRAM (boolean browseFile) {
|
||||
writeBank_SNES(0, 0x2224, 0);
|
||||
writeBank_SNES(0, 0x2226, 0x80);
|
||||
writeBank_SNES(0, 0x6000, firstByte);
|
||||
if (i2c_found) {
|
||||
// Disable CPU clock
|
||||
clockgen.output_enable(SI5351_CLK1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Set pins to input
|
||||
dataIn();
|
||||
@ -1986,8 +2004,10 @@ boolean eraseSRAM (byte b) {
|
||||
// SA1
|
||||
else if (romType == SA) {
|
||||
long lastByte = (long(sramSize) * 128);
|
||||
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,9 +2044,12 @@ boolean eraseSRAM (byte b) {
|
||||
writeBank_SNES(0, 0x2224, 0);
|
||||
writeBank_SNES(0, 0x2226, 0x80);
|
||||
writeBank_SNES(0, 0x6000, b);
|
||||
|
||||
if (i2c_found) {
|
||||
// Disable CPU clock
|
||||
clockgen.output_enable(SI5351_CLK1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
dataIn();
|
||||
|
||||
|
@ -113,7 +113,8 @@ void setup_SV() {
|
||||
DDRG &= ~(1 << 0);
|
||||
|
||||
// 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_PLLB);
|
||||
clockgen.set_freq(2147727200ULL, SI5351_CLK0);
|
||||
@ -121,6 +122,13 @@ void setup_SV() {
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user