Automatically create snes_clk.txt if it doesn't exist

This commit is contained in:
Kreeblah 2022-02-26 21:20:33 -08:00
parent b5101b892d
commit 75e85af20f
No known key found for this signature in database
GPG Key ID: 6074237BF1AEEDFB
6 changed files with 5027 additions and 5026 deletions

View File

@ -428,17 +428,7 @@ void setup_N64_Cart() {
#ifdef clockgen_installed
// Adafruit Clock Generator
#ifdef clockgen_calibration
int32_t clock_offset = readClockOffset();
if (clock_offset > INT32_MIN) {
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, clock_offset);
} else {
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
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
#endif
initializeClockOffset();
if (!i2c_found) {
display_Clear();

View File

@ -606,16 +606,7 @@ void setup_SFM() {
//PORTH &= ~(1 << 1);
// Adafruit Clock Generator
#ifdef clockgen_calibration
int32_t clock_offset = readClockOffset();
if (clock_offset > INT32_MIN) {
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, clock_offset);
} else {
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
}
#else
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
#endif
initializeClockOffset();
if (i2c_found) {
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLA);

View File

@ -458,17 +458,7 @@ void setup_Snes() {
//PORTJ &= ~(1 << 0);
// Adafruit Clock Generator
#ifdef clockgen_calibration
int32_t clock_offset = readClockOffset();
if (clock_offset > INT32_MIN) {
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, clock_offset);
} else {
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
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
#endif
initializeClockOffset();
if (i2c_found) {
// Set clocks to 4Mhz/1Mhz for better SA-1 unlocking

View File

@ -1,6 +1,8 @@
#include "snes_clk.h"
#include <si5351.h>
#include "SdFat.h"
#include "atoi32.h"
#include "options.h"
int32_t readClockOffset() {
FsFile clock_file;
@ -8,7 +10,7 @@ int32_t readClockOffset() {
int16_t i;
int32_t clock_offset;
if (!clock_file.open("/snes_clk.txt", FILE_READ)) {
if (!clock_file.open("/snes_clk.txt", O_READ)) {
return INT32_MIN;
}
@ -44,3 +46,25 @@ int32_t readClockOffset() {
return clock_offset;
}
int32_t initializeClockOffset() {
#ifdef clockgen_calibration
FsFile clock_file;
const char zero_char_arr[] = {'0'};
int32_t clock_offset = readClockOffset();
if (clock_offset > INT32_MIN) {
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, clock_offset);
} else {
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
if(clock_file.open("/snes_clk.txt", O_WRITE | O_CREAT | O_TRUNC)) {
clock_file.write(zero_char_arr, 1);
clock_file.close();
}
}
return clock_offset;
#else
// last number is the clock correction factor which is custom for each clock generator
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
return 0;
#endif
}

View File

@ -1,7 +1,14 @@
#ifndef _SNES_CLK_H
#define _SNES_CLK_H
#include <si5351.h>
#include "SdFat.h"
#include "atoi32.h"
#include "options.h"
extern Si5351 clockgen;
extern bool i2c_found;
int32_t readClockOffset();
int32_t initializeClockOffset();
#endif

View File

@ -1 +0,0 @@
0