From b46840ec4c7f3b52f24a62d2ab607fec04a0a2e9 Mon Sep 17 00:00:00 2001 From: JPZV Date: Mon, 16 Mar 2026 00:55:35 -0300 Subject: [PATCH 1/2] Changed return for a break in board_detection Otherwise the Debug_Log wouldn't never be called. Because the while is the last operation, this should affect any performance (maybe except if PSNEE_DEBUG_SERIAL_MONITOR is enabled) --- PSNee/PSNee.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSNee/PSNee.ino b/PSNee/PSNee.ino index bd85481..bc601b1 100644 --- a/PSNee/PSNee.ino +++ b/PSNee/PSNee.ino @@ -197,7 +197,7 @@ void board_detection() { */ if (!PIN_WFCK_READ) { wfck_mode = 1; // Target: PU-22 or newer - return; + break; } } } From b4d2df80e905e375fcb96ba82665bd250432565d Mon Sep 17 00:00:00 2001 From: JPZV Date: Wed, 18 Mar 2026 17:44:50 -0300 Subject: [PATCH 2/2] Added RP2040 support --- PSNee/MCU.h | 81 ++++++++++++++++++++++++++++++++++++++++++++++ PSNee/PSNee.ino | 22 +++++++++++-- PSNee/RP2040_MCU.h | 22 +++++++++++++ PSNee/settings.h | 6 ++-- 4 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 PSNee/RP2040_MCU.h diff --git a/PSNee/MCU.h b/PSNee/MCU.h index 989311d..77dd1fd 100644 --- a/PSNee/MCU.h +++ b/PSNee/MCU.h @@ -864,3 +864,84 @@ static inline void optimizePeripherals(void) { #endif +#ifdef RP2040 + + #include + #include + #include + + // Main pin configuration + + // Define the main pins as inputs + #define RP2040_INPUT(gpio) (gpio_set_dir(gpio, false)) + #define PIN_DATA_INPUT RP2040_INPUT(4) // Set GPIO4 as input + #define PIN_WFCK_INPUT RP2040_INPUT(5) // Set GPIO5 as input + #define PIN_SQCK_INPUT RP2040_INPUT(6) // Set GPIO6 as input + #define PIN_SUBQ_INPUT RP2040_INPUT(7) // Set GPIO7 as input + + // Enable pull-ups and set high on the main pins + #define RP2040_OUTPUT(gpio) (gpio_set_dir(gpio, true)) + #define PIN_DATA_OUTPUT RP2040_OUTPUT(4) // Set GPIO4 as output + #define PIN_WFCK_OUTPUT RP2040_OUTPUT(5) // Set GPIO5 as output + + // Define pull-ups and set high at the main pin + #define RP2040_SET(gpio, high) (gpio_put(gpio, high)) + #define PIN_DATA_SET RP2040_SET(4, true) // Set GPIO4 high + + // Clear the main pins (set low) + #define PIN_DATA_CLEAR RP2040_SET(4, false) // Set GPIO4 low + #define PIN_WFCK_CLEAR RP2040_SET(5, false) // Set GPIO5 low + + // Read the state of the main input pins + #define RP2040_READ(gpio) (gpio_get(gpio)) + #define PIN_WFCK_READ RP2040_READ(5) // Check if the value of GPIO5 is high (1) + #define PIN_SQCK_READ RP2040_READ(6) // Check if the value of GPIO6 is high (1) + #define PIN_SUBQ_READ RP2040_READ(7) // Check if the value of GPIO7 is high (1) + + // LED pin handling (for indication) + #ifdef LED_RUN + #define PIN_LED_OUTPUT RP2040_OUTPUT(25) // Configure GPIO25 as output (builtin LED) + #define PIN_LED_ON RP2040_SET(25, true) // Set GPIO25 high (turn on LED) + #define PIN_LED_OFF RP2040_SET(25, false) // Set GPIO25 low (turn off LED) + #endif + + // Handling the BIOS patch + #if defined(SCPH_102) || defined(SCPH_100) || defined(SCPH_7500_9000) || defined(SCPH_7000) || defined(SCPH_5000_5500) || defined(SCPH_3500) || defined(SCPH_3000) || defined(SCPH_1000) + + // Define input pins for the BIOS patch + #define PIN_AX_INPUT RP2040_INPUT(8) // Set GPIO8 as input + #define PIN_DX_INPUT RP2040_INPUT(9) // Set GPIO9 as input + + // Define output pins for the BIOS patch + #define PIN_DX_OUTPUT RP2040_OUTPUT(9) // Set GPIO9 as output + + // Set pull-ups high on output pins + #define PIN_DX_SET RP2040_SET(9, true) // Set GPIO9 high + + // Set pull-ups low on output pins + #define PIN_DX_CLEAR RP2040_SET(9, false) // Set GPIO4 low + + + #define WAIT_AX_RISING (!RP2040_READ(8)) // Attend le début de l'impulsion + #define WAIT_AX_FALLING (RP2040_READ(8)) // Attend la fin de l'impulsion + + // Read the input pins for the BIOS patch + #define PIN_AX_READ RP2040_READ(8) // Check if the value of GPIO8 is high (1) + + // Defin PIN_AY for HIGH_PATCH + #if defined(SCPH_3000) || defined(SCPH_1000) + #define PIN_AY_INPUT RP2040_INPUT(10) // Set GPIO10 as input + #define WAIT_AY_RISING (!RP2040_READ(10)) // AY est sur GPIO10 + #define WAIT_AY_FALLING (RP2040_READ(10)) + + #endif + // Handle switch input for BIOS patch + #if defined(SCPH_7000) + #define PIN_SWITCH_INPUT RP2040_INPUT(11) // Set GPIO11 as input + #define PIN_SWITCH_SET RP2040_SET(11, true) // Set GPIO11 high + #define PIN_SWITCH_READ RP2040_READ(11) // Check if the value of GPIO11 is high (1) + #endif + + #endif + +#endif \ No newline at end of file diff --git a/PSNee/PSNee.ino b/PSNee/PSNee.ino index bc601b1..3d905af 100644 --- a/PSNee/PSNee.ino +++ b/PSNee/PSNee.ino @@ -120,10 +120,14 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX pointer and variable section ------------------------------------------------------------------------------------------------*/ +#ifdef RP2040 + #include "RP2040_MCU.h" +#else + #include +#endif #include "MCU.h" #include "settings.h" #include "BIOS_patching.h" -#include //Flag initializing for automatic console generation selection 0 = old, 1 = pu-22 end ++ @@ -500,6 +504,8 @@ void Init() { #if defined(PSNEE_DEBUG_SERIAL_MONITOR) && defined(ATtiny85_45_25) //pinMode(debugtx, OUTPUT); // software serial tx pin mySerial.begin(115200); // 13,82 bytes in 12ms, max for softwareserial. (expected data: ~13 bytes / 12ms) // update: this is actually quicker + #elif defined(PSNEE_DEBUG_SERIAL_MONITOR) && defined(RP2040) + Serial.begin(115200); #elif defined(PSNEE_DEBUG_SERIAL_MONITOR) && !defined(ATtiny85_45_25) Serial.begin(500000); // 60 bytes in 12ms (expected data: ~26 bytes / 12ms) // update: this is actually quicker #endif @@ -508,10 +514,20 @@ void Init() { board_detection(); } -int main() { +#ifdef RP2040 +void loop() {} - Init(); +void setup() +#else +int main() +#endif +{ +#ifdef RP2040 + start_rp2040(); +#endif + + Init(); while (1) { diff --git a/PSNee/RP2040_MCU.h b/PSNee/RP2040_MCU.h new file mode 100644 index 0000000..2c33bf6 --- /dev/null +++ b/PSNee/RP2040_MCU.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include + +void start_rp2040() +{ + //Enabling this line will reproduce 16MHz as the Arduino (in theory), but the serial will be disabled. + //set_sys_clock_pll(882000000, 7, 7); //16MHz clock + const uint32_t gpio_pins_mask = (0xf << 4) | (1U << 25); + gpio_init_mask(gpio_pins_mask); +} + +void _delay_ms(double ms) +{ + sleep_ms(ms); +} + +void _delay_us(double us) +{ + sleep_us(us); +} \ No newline at end of file diff --git a/PSNee/settings.h b/PSNee/settings.h index 11a1f36..1cb506c 100644 --- a/PSNee/settings.h +++ b/PSNee/settings.h @@ -253,11 +253,13 @@ void Debug_Inject(){ // Confirmation of region code injection #if !defined(ATmega328_168) && \ !defined(ATmega32U4_16U4) && \ - !defined(ATtiny85_45_25) + !defined(ATtiny85_45_25) && \ + !defined(RP2040) #error "MCU not selected! Please choose one" #elif !defined(ATmega328_168) ^ \ defined(ATmega32U4_16U4 ) ^ \ - defined(ATtiny85_45_25) + defined(ATtiny85_45_25 ) ^ \ + defined(RP2040) #error "May be selected only one MCU" #endif