mirror of
https://github.com/sanni/cartreader.git
synced 2024-12-24 03:51:54 +01:00
Merge pull request #338 from Kreeblah/clkgen_file_create
Automatically create snes_clk.txt if it doesn't exist
This commit is contained in:
commit
d83482dd4c
9996
Cart_Reader/N64.ino
9996
Cart_Reader/N64.ino
File diff suppressed because it is too large
Load Diff
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -1 +0,0 @@
|
||||
0
|
Loading…
Reference in New Issue
Block a user