1
0
mirror of https://github.com/kalymos/PsNee.git synced 2026-03-01 09:40:53 +00:00

The v6 release

This commit is contained in:
kalymos
2025-11-30 13:22:50 +01:00
parent a5cc9f7c1d
commit a4dc6c2fce
55 changed files with 326 additions and 4173 deletions

24
LICENSE
View File

@@ -1,24 +0,0 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>

Binary file not shown.

View File

@@ -1,100 +0,0 @@
#pragma once
#ifdef BIOS_PATCH
void Timer_Start(void);
void Timer_Stop(void);
extern volatile uint8_t count_isr;
extern volatile uint32_t microsec;
volatile uint8_t impulse = 0;
volatile uint8_t patch = 0;
ISR(PIN_AX_INTERRUPT_VECTOR) {
impulse++;
if (impulse == TRIGGER){ // If impulse reaches the value defined by TRIGGER, the following actions are performed:
HOLD;
#ifdef HIGH_PATCH
PIN_DX_SET;
#endif
PIN_DX_OUTPUT;
PATCHING;
#ifdef HIGH_PATCH
PIN_DX_CLEAR;
#endif
PIN_DX_INPUT;
PIN_AX_INTERRUPT_DISABLE;
impulse = 0;
patch = 1; // patch is set to 1, indicating that the first patch is completed.
}
}
#ifdef HIGH_PATCH
ISR(PIN_AY_INTERRUPT_VECTOR){
impulse++;
if (impulse == TRIGGER2) // If impulse reaches the value defined by TRIGGER2, the following actions are performed:
{
HOLD2;
PIN_DX_OUTPUT;
PATCHING2;
PIN_DX_INPUT;
PIN_AY_INTERRUPT_DISABLE;
patch = 2; // patch is set to 2, indicating that the second patch is completed.
}
}
#endif
void Bios_Patching(){
// If LOW_TRIGGER is defined
#ifdef LOW_TRIGGER
PIN_AX_INTERRUPT_FALLING;
#else
PIN_AX_INTERRUPT_RISING;
#endif
if (PIN_AX_READ != 0) // If the AX pin is high
{
while (PIN_AX_READ != 0); // Wait for it to go low
while (PIN_AX_READ == 0); // Then wait for it to go high again.
}
else // If the AX pin is low
{
while (PIN_AX_READ == 0); // Wait for it to go high.
}
Timer_Start();
while (microsec < CHECKPOINT); // Wait until the number of microseconds elapsed reaches a value defined by CHECKPOINT.
Timer_Stop();
PIN_AX_INTERRUPT_ENABLE;
while (patch != 1); // Wait for the first stage of the patch to complete:
#ifdef HIGH_PATCH
#ifdef HIGH_PATCH
PIN_AY_INTERRUPT_FALLING;
#else
PIN_AY_INTERRUPT_RISING;
#endif
while (PIN_AY_READ != 0); // Wait for it to go low
Timer_Start();
while (microsec < CHECKPOINT2); // Wait until the number of microseconds elapsed reaches a value defined by CHECKPOINT2.
Timer_Stop();
PIN_AY_INTERRUPT_ENABLE;
while (patch != 2); // Wait for the second stage of the patch to complete:
#endif
}
#endif

View File

@@ -1,753 +0,0 @@
// *****************************************************************************************************************
// Configuration for different microcontrollers (MUC) to ensure compatibility with the code:
// - Defines the clock speed, timers, and interrupts for each MUC.
// - Configures I/O pins for data, clocks, and switches according to the requirements.
// - Enables pull-up resistors on input pins where needed.
// - Manages external interrupts and LED outputs for system feedback.
// - Ensures the setup is compatible with various microcontroller models (e.g., ATmega328, ATtiny series, etc.)
// *****************************************************************************************************************
//******************************************************************************************************************
// Configuring the clock speed and associated registers. The formula for calculating
// the clock frequency is F_CPU / (TCCR0B |= (1<<CS00)) * (OCR0A = 159 +1) = 16000000 / (0 * (160)) = 100KHz
//******************************************************************************************************************
//******************************************************************************************************************
// Example: DDRB &= ~(1<<DDB0); // Create a mask by shifting the bit 1 to the left by DDB0's position (bit 0), and then inverting it.
// The bitwise AND operation (&=) updates the register DDRB by clearing the DDB0 bit (setting it to 0)
// without affecting the other bits.
//
// For instance, if DDRB = b11111111 (binary value), the operation shifts the bit 1 to the left to create the mask
// (1<<DDB0) = b00000001, and then inverts it, which results in b11111110. The AND operation with DDRB clears DDB0.
//
// Before: DDRB = b11111111 // Initial value of DDRB (all pins set as output)
// Mask: ~(b00000001) = b11111110 // Mask generated by shifting and inverting the bit
// After: DDRB = b11111110 // The DDB0 bit is cleared (set to 0), while other bits remain unchanged
//******************************************************************************************************************
//******************************************************************************************************************
// Example: DDRB |= (1<<DDB0); // Create a mask by shifting the bit 1 to the left by DDB0's position (bit 0),
// and then apply a bitwise OR operation to set DDB0 to 1 (configure pin PB0 as an output).
//
// For instance, if DDRB = b11111111 (binary value), the operation shifts the bit 1 to the left to create the mask
// (1<<DDB0) = b00000001. The OR operation with DDRB sets the DDB0 bit to 1, leaving other bits unchanged.
//
// Before: DDRB = b11111111 // Initial value of DDRB (all pins set as output)
// Mask: (1<<DDB0) = b00000001 // Mask generated by shifting the bit 1 to the left to position DDB0
// After: DDRB = b11111111 // The DDB0 bit is set to 1, configuring pin PB0 as an output
//******************************************************************************************************************
//******************************************************************************************************************
// Example: (PIND & (1<<PIND6)); // Create a mask by shifting the bit 1 to the left by PIND6's position (bit 6),
// and then apply a bitwise AND operation to read the state of the PIND6 pin.
// The result will be non-zero (true) if the PIND6 pin is high (1), and zero (false) if the PIND6 pin is low (0).
//
// For instance, if PIND = b10101010 (binary value), the operation shifts the bit 1 to the left to create the mask
// (1<<PIND6) = b01000000. The AND operation between PIND and the mask checks if the 6th bit is set to 1 (high).
//
// Before: PIND = b10101010 // Initial value of PIND (register containing input pin states)
// Mask: (1<<PIND6) = b01000000 // Mask generated by shifting the bit 1 to the left to position PIND6
// Operation: PIND & b01000000 = b00000000 // If PIND6 is low (0)
// Operation: PIND & b01000000 = b01000000 // If PIND6 is high (1)
//
//******************************************************************************************************************
//******************************************************************************************************************
// Example: EICRA |= (1<<ISC01) | (1<<ISC00);
// This operation configures the external interrupt sense control (ISC) for interrupt INT0 (External Interrupt Request 0).
// Specifically, it sets the mode of INT0 to "rising edge" trigger, meaning the interrupt will be triggered when the pin
// transitions from low to high (rising edge).
//
// EICRA (External Interrupt Control Register A) controls how external interrupts INT0 and INT1 are triggered.
// The bits ISC01 and ISC00 in this register define the trigger mode for interrupt INT0.
//
// - Setting ISC01 to 1 and ISC00 to 1 (via the OR operation) configures INT0 to trigger on the rising edge.
//
// Before: EICRA = b00000000 // Initial value of EICRA, all interrupt sense control bits are cleared (no trigger mode set).
// Operation: EICRA |= (1<<ISC01) | (1<<ISC00) // Set ISC01 and ISC00 to 1 for rising edge trigger.
// After: EICRA = b00000011 // The bits ISC01 and ISC00 are now set, configuring INT0 to trigger on rising edge.
//
// This technique is commonly used to configure external interrupts to trigger based on specific events like a rising
// or falling edge on the external interrupt pin (INT0 or INT1).
//******************************************************************************************************************
//******************************************************************************************************************
// Example: EICRA = (EICRA & ~(1<<ISC00)) | (1<<ISC01);
// This operation configures the external interrupt sense control (ISC) for interrupt INT0 (External Interrupt Request 0).
// Specifically, it sets INT0 to trigger on a "falling edge" (when the signal transitions from high to low).
//
// The bits ISC01 and ISC00 in the EICRA register define how the external interrupt INT0 is triggered. The operation
// clears the bit ISC00 while setting ISC01 to 1, configuring INT0 to trigger when the pin transitions from high to low,
// i.e., on the falling edge.
//
// EICRA (External Interrupt Control Register A) controls how external interrupts INT0 and INT1 are triggered.
// - ISC01 = 1, ISC00 = 0 configures INT0 to trigger on falling edge (high to low transition).
//
// Before: EICRA = b00000011 // Initial value with ISC01 = 1 and ISC00 = 1 (rising edge trigger for INT0)
// Operation: EICRA & ~(1<<ISC00) clears ISC00 bit (sets it to 0) while keeping ISC01 at 1. Then OR operation with (1<<ISC01) ensures ISC01 stays 1.
// After: EICRA = b00000010 // The bit ISC00 is now cleared, configuring INT0 to trigger on the falling edge.
//
// This technique is used to configure the interrupt to trigger on the falling edge (transition from high to low),
// without changing the state of other control bits in the EICRA register.
//******************************************************************************************************************
#pragma once
#ifdef ATmega328_168
// Define the clock speed for the microcontroller
#define F_CPU 16000000L
// Clear the timer count register (TCNT0)
#define TIMER_TCNT_CLEAR TCNT0 = 0x00 // TCNT0 - Timer/Counter Register, clears the timer count
// Set OCR0A to achieve a 100KHz clock frequency
#define SET_OCROA_DIV OCR0A = 159; // OCR0A Output Compare Register A, 100KHz clock generation, 0x10011111
// Configure Timer/Counter 0 for CTC mode and enable the clock source
#define SET_TIMER_TCCROA TCCR0A |= (1 << WGM01); // TCCR0A Timer/Counter Control Register A, enable CTC mode (WGM01)
#define SET_TIMER_TCCROB TCCR0B |= (1 << CS00); // TCCR0B Timer/Counter Control Register B, set clock source to I/O clock
//Waveform Generation Mode, Mode 2 CTC
// Interrupt vector for timer compare match event
#define CTC_TIMER_VECTOR TIMER0_COMPA_vect //interrupt vector for match event, OCR0A comparison and Timer/Counter 0
#include <stdint.h>
#include <stdbool.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sfr_defs.h>
#include <util/delay.h>
// Global interrupt control settings
#define GLOBAL_INTERRUPT_ENABLE SREG |= (1<<7) // Set the I-bit (bit 7) in the Status Register to enable global interrupts
#define GLOBAL_INTERRUPT_DISABLE SREG &= ~(1<<7) // Clear the I-bit (bit 7) in the Status Register to disable global interrupts
// Main pin configuration for input and output
// Define the main pins as inputs
#define PIN_DATA_INPUT DDRB &= ~(1<<DDB0) // Set DDRB register to configure PINB0 as input
#define PIN_WFCK_INPUT DDRB &= ~(1<<DDB1) // Set DDRB register to configure PINB1 as input
#define PIN_SQCK_INPUT DDRD &= ~(1<<DDD6) // Set DDRB register to configure PINB6 as input
#define PIN_SUBQ_INPUT DDRD &= ~(1<<DDD7) // Set DDRB register to configure PINB7 as input
// Enable pull-ups and set high on the main pins
#define PIN_DATA_OUTPUT DDRB |= (1<<DDB0) // Set DDRB register to configure PINB0 as output
#define PIN_WFCK_OUTPUT DDRB |= (1<<DDB1) // Set DDRB register to configure PINB1 as output
// Define pull-ups and set high at the main pin
#define PIN_DATA_SET PORTB |= (1<<PB0) // Set PORTB register to make PINB0 high (enable pull-up)
// Clear the main pins (set low)
#define PIN_DATA_CLEAR PORTB &= ~(1<<PB0) // Set PORTB register to make PINB0 low
#define PIN_WFCK_CLEAR PORTB &= ~(1<<PB1) // Set PORTB register to make PINB1 low
// Read the state of the main input pins
#define PIN_SQCK_READ (PIND & (1<<PIND6)) // Check if the value of PIND6 is high (1)
#define PIN_SUBQ_READ (PIND & (1<<PIND7)) // Check if the value of PIND7 is high (1)
#define PIN_WFCK_READ (PINB & (1<<PINB1)) // Check if the value of PIND1 is high (1)
// LED pin handling (for indication)
#define LED_RUN
#define PIN_LED_OUTPUT DDRB |= (1<<DDB5) // Configure PINB5 as output (for LED)
#define PIN_LED_ON PORTB |= (1<<PB5) // Set PINB5 high (turn on LED)
#define PIN_LED_OFF PORTB &= ~(1<<PB5) // Set PINB5 low (turn off LED)
// Handling the BIOS patch
// Enable/Disable timer interrupts
#define TIMER_INTERRUPT_ENABLE TIMSK0 |= (1<<OCIE0A) // Enable interrupt on Timer0 Compare Match A
#define TIMER_INTERRUPT_DISABLE TIMSK0 &= ~(1<<OCIE0A) // Disable interrupt on Timer0 Compare Match A
// Clear the timer interrupt flag
#define TIMER_TIFR_CLEAR TIFR0 |= (1<<OCF0A) // Clear the Timer0 Compare Match A interrupt flag
// Define input pins for the BIOS patch
#define PIN_AX_INPUT DDRD &= ~(1<<DDD2) // Set DDRD register to configure PIND2 as input
#define PIN_AY_INPUT DDRD &= ~(1<<DDD3) // Set DDRD register to configure PIND3 as input
#define PIN_DX_INPUT DDRD &= ~(1<<DDD4) // Set DDRD register to configure PIND4 as input
// Define output pins for the BIOS patch
#define PIN_DX_OUTPUT DDRD |= (1<<DDD4) // Set DDRD register to configure PIND4 as output
// Set pull-ups high on output pins
#define PIN_DX_SET PORTD |= (1<<PD4) // Set PORTD register to make PIND4 high
// Set pull-ups low on output pins
#define PIN_DX_CLEAR PORTD &= ~(1<<PD4) // Set PORTD register to make PIND4 low
// Read the input pins for the BIOS patch
#define PIN_AX_READ (PIND & (1<<PIND2)) // Read the state of PIND2
#define PIN_AY_READ (PIND & (1<<PIND3)) // Read the state of PIND3
// External interrupt configuration for BIOS patch
#define PIN_AX_INTERRUPT_ENABLE EIMSK |= (1<<INT0) // Enable external interrupt on INT0 (PINB2)
#define PIN_AY_INTERRUPT_ENABLE EIMSK |= (1<<INT1) // Enable external interrupt on INT1 (PINB3)
#define PIN_AX_INTERRUPT_DISABLE EIMSK &= ~(1<<INT0) // Disable external interrupt on INT0
#define PIN_AY_INTERRUPT_DISABLE EIMSK &= ~(1<<INT1) // Disable external interrupt on INT1
#define PIN_AX_INTERRUPT_RISING EICRA |= (1<<ISC01)|(1<<ISC00) // Configure INT0 for rising edge trigger
#define PIN_AY_INTERRUPT_RISING EICRA |= (1<<ISC11)|(1<<ISC10) // Configure INT1 for rising edge trigger
#define PIN_AX_INTERRUPT_FALLING (EICRA = (EICRA & ~(1<<ISC00)) | (1<<ISC01)) // Configure INT0 for falling edge trigger
#define PIN_AY_INTERRUPT_FALLING (EICRA = (EICRA & ~(1<<ISC10)) | (1<<ISC11)) // Configure INT1 for falling edge trigger
// Interrupt vectors for external interrupts
#define PIN_AX_INTERRUPT_VECTOR INT0_vect // Interrupt vector for INT0 (external interrupt)
#define PIN_AY_INTERRUPT_VECTOR INT1_vect // Interrupt vector for INT1 (external interrupt)
// Handle switch input for BIOS patch
#define PIN_SWITCH_INPUT DDRD &= ~(1<<DDD5) // Configure PIND5 as input for switch
#define PIN_SWITCH_SET PORTD |= (1<<PD5) // Set PIND5 high (enable pull-up)
#define PIN_SWICHE_READ (PIND & (1<<PIND5)) // Read the state of PIND5 (switch input)
#endif
#ifdef ATmega32U4_16U4
#define F_CPU 16000000L
#define TIMER_TCNT_CLEAR TCNT0 = 0x00;
#define SET_OCROA_DIV OCR0A = 159;
#define SET_TIMER_TCCROA TCCR0A |= (1 << WGM01);
#define SET_TIMER_TCCROB TCCR0B |= (1 << CS00);
#define CTC_TIMER_VECTOR TIMER0_COMPA_vect
#include <stdint.h>
#include <stdbool.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sfr_defs.h>
#include <util/delay.h>
// Globale interrupt seting
#define GLOBAL_INTERRUPT_ENABLE SREG |= (1<<7)
#define GLOBAL_INTERRUPT_DISABLE SREG &= ~(1<<7)
#define TIMER_INTERRUPT_ENABLE TIMSK0 |= (1<<OCIE0A)
#define TIMER_INTERRUPT_DISABLE TIMSK0 &= ~(1<<OCIE0A)
// Handling the main pins
// Main pins
#define PIN_DATA_INPUT DDRB &= ~(1<<DDB4)
#define PIN_WFCK_INPUT DDRB &= ~(1<<DDB5)
#define PIN_SQCK_INPUT DDRD &= ~(1<<DDD7)
#define PIN_SUBQ_INPUT DDRE &= ~(1<<DDE6)
#define PIN_DATA_OUTPUT DDRB |= (1<<DDB4)
#define PIN_WFCK_OUTPUT DDRB |= (1<<DDB5)
// Define pull-ups and set high at the main pin
#define PIN_DATA_SET PORTB |= (1<<PB4)
// Define pull-ups set down at the main pin
#define PIN_DATA_CLEAR PORTB &= ~(1<<PB4)
#define PIN_WFCK_CLEAR PORTB &= ~(1<<PB5)
// Read the main pins
#define PIN_SQCK_READ (PIND & (1<<PIND7))
#define PIN_SUBQ_READ (PINE & (1<<PINE6))
#define PIN_WFCK_READ (PINB & (1<<PINB5))
// Handling and use of the LED pin
#define LED_RUN
#define PIN_LED_OUTPUT DDRB |= (1<<DDB6)
#define PIN_LED_ON PORTB |= (1<<PB6)
#define PIN_LED_OFF PORTB &= ~(1<<PB6)
// Handling the BIOS patch
// Pins input
#define PIN_AX_INPUT DDRD &= ~(1<<DDD1)
#define PIN_AY_INPUT DDRD &= ~(1<<DDD0)
#define PIN_DX_INPUT DDRD &= ~(1<<DDD4)
// Pin output
#define PIN_DX_OUTPUT DDRD |= (1<<DDD4)
// Define pull-ups set high
#define PIN_DX_SET PORTD |= (1<<PD4)
// Define pull-ups set down
#define PIN_DX_CLEAR PORTD &= ~(1<<PD4)
// Read pins for BIOS patch
#define PIN_AX_READ (PIND & (1<<PIND1))
#define PIN_AY_READ (PIND & (1<<PIND0))
// Handling and reading the switch pin for patch BIOS
#define PIN_SWITCH_INPUT DDRC &= ~(1<<DDC6)
#define PIN_SWITCH_SET PORTC |= (1<<PC6)
#define PIN_SWICHE_READ (PINC & (1<<PINC6))
// BIOS timer clear
#define TIMER_TCNT_CLEAR TCNT0 = 0x00
#define TIMER_TIFR_CLEAR TIFR0 |= (1<<OCF0A)
// Handling the external interrupt
#define PIN_AX_INTERRUPT_ENABLE EIMSK |= (1<<INT1)
#define PIN_AY_INTERRUPT_ENABLE EIMSK |= (1<<INT0)
#define PIN_AX_INTERRUPT_DISABLE EIMSK &= ~(1<<INT1)
#define PIN_AY_INTERRUPT_DISABLE EIMSK &= ~(1<<INT0)
#define PIN_AX_INTERRUPT_RISING EICRA |= (1<<ISC11)|(1<<ISC10)
#define PIN_AY_INTERRUPT_RISING EICRA |= (1<<ISC01)|(1<<ISC00)
#define PIN_AX_INTERRUPT_FALLING (EICRA = (EICRA & ~(1<<ISC10)) | (1<<ISC11))
#define PIN_AY_INTERRUPT_FALLING (EICRA = (EICRA & ~(1<<ISC00)) | (1<<ISC01))
#define PIN_AX_INTERRUPT_VECTOR INT1_vect
#define PIN_AY_INTERRUPT_VECTOR INT0_vect
#endif
#ifdef ATtiny85_45_25
#define DF_CPU 8000000L
#define TIMER_TCNT_CLEAR TCNT0 = 0x00;
#define SET_OCROA_DIV OCR0A = 79; //OCR0A Output Compare Register A,100KHz
#define SET_TIMER_TCCROA TCCR0A |= (1 << WGM01);
#define SET_TIMER_TCCROB TCCR0B |= (1 << CS00);
#define CTC_TIMER_VECTOR TIMER0_COMPA_vect
#include <stdint.h>
#include <stdbool.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sfr_defs.h>
#include <util/delay.h>
// Globale interrupt seting
#define GLOBAL_INTERRUPT_ENABLE SREG |= (1<<7)
#define GLOBAL_INTERRUPT_DISABLE SREG &= ~(1<<7)
// Handling the main pins
// Main pins input
#define PIN_DATA_INPUT DDRB &= ~(1<<DDB2)
#define PIN_WFCK_INPUT DDRB &= ~(1<<DDB4)
#define PIN_SQCK_INPUT DDRB &= ~(1<<DDB0)
#define PIN_SUBQ_INPUT DDRB &= ~(1<<DDB1)
// Main pin output
#define PIN_DATA_OUTPUT DDRB |= (1<<DDB2)
#define PIN_WFCK_OUTPUT DDRB |= (1<<DDB4)
// Define pull-ups and set high at the main pin
#define PIN_DATA_SET PORTB |= (1<<PB2)
// Define pull-ups set down at the main pin
#define PIN_DATA_CLEAR PORTB &= ~(1<<PB2)
#define PIN_WFCK_CLEAR PORTB &= ~(1<<PB4)
// Read the main pins
#define PIN_SQCK_READ (PINB & (1<<PINB0))
#define PIN_SUBQ_READ (PINB & (1<<PINB1))
#define PIN_WFCK_READ (PINB & (1<<PINB4))
#define TIMER_INTERRUPT_ENABLE TIMSK |= (1<<OCIE0A)
#define TIMER_INTERRUPT_DISABLE TIMSK &= ~(1<<OCIE0A)
// Handling and use of the LED pin
#define LED_RUN
#define PIN_LED_OUTPUT DDRB |= (1<<DDB3)
#define PIN_LED_ON PORTB |= (1<<PB3)
#define PIN_LED_OFF PORTB &= ~(1<<PB3)
#if !defined(SCPH_xxx1) && !defined(SCPH_xxx2) && !defined(SCPH_103) && !defined(SCPH_xxxx)
#error "ATtiny85_45_25 Not compatible with BIOS patch"
#endif
// *****************************************************************************************************************
// WARNING:
// The following code is not functional as-is.
// *****************************************************************************************************************
#ifdef ATtiny88_48
#define F_CPU 16000000L
#define TIMER_TCNT_CLEAR TCNT0 = 0x00 //TCNT0 - Timer/Counter Register
#define SET_OCROA_DIV OCR0A = 159; //OCR0A Output Compare Register A, 0x10011111, 100KHz
#define SET_TIMER_TCCROA TCCR0A |= (1 << CTC0 ); //TCCR0A Timer/Counter Control Register A. turn on CTC mode, CTC0
#define SET_TIMER_TCCROB TCCR0A |= (1 << CS00); //TCCR0B Timer/Counter Control Register B, CS00: Clock Select, clk I/O
//Waveform Generation Mode, Mode 2 CTC
#define CTC_TIMER_VECTOR TIMER0_COMPA_vect //interrupt vector for match event, OCR0A comparison and Timer/Counter 0
#include <stdint.h>
#include <stdbool.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sfr_defs.h>
#include <util/delay.h>
// Globale interrupt seting
#define GLOBAL_INTERRUPT_ENABLE SREG |= (1<<7)
#define GLOBAL_INTERRUPT_DISABLE SREG &= ~(1<<7)
// Handling the main pins
// Main pins input
#define PIN_DATA_INPUT DDRB &= ~(1<<DDB0)
#define PIN_WFCK_INPUT DDRB &= ~(1<<DDB1) // Create a mask (1<<0) with the first bit at 1 b00000001 uses the ~ operator to perform a bit inversion b11111110,
#define PIN_SQCK_INPUT DDRD &= ~(1<<DDD6) // &= updates the DDRB register with the AND operator and the mask, DDRB bxxxxxxxx OR mask b11111110 = bxxxxxxx0
#define PIN_SUBQ_INPUT DDRD &= ~(1<<DDD7)
// Main pin output
#define PIN_DATA_OUTPUT DDRB |= (1<<DDB0) // Create a mask (1<<0) with the first bit at 1 b00000001,
#define PIN_WFCK_OUTPUT DDRB |= (1<<DDB1) // |= updates the DDRB register with the OR operator and the mask, DDRB bxxxxxxxx OR mask b00000001 = bxxxxxxx1
// Define pull-ups and set high at the main pin
#define PIN_DATA_SET PORTB |= (1<<PB0) // Create a mask (1<<0) with the first bit at 1 b00000001,
// |= updates the PORTB register with the OR operator and the mask, PORTB bxxxxxxxx OR mask b00000001 = bxxxxxxx1
// Define pull-ups set down at the main pin
#define PIN_DATA_CLEAR PORTB &= ~(1<<PB0) // Create a mask (1<<0) with the first bit at 1 b00000001 uses the ~ operator to perform a bit inversion b11111110,
#define PIN_WFCK_CLEAR PORTB &= ~(1<<PB1) // &= updates the DDRB register with the AND operator and the mask, DDRB bxxxxxxxx OR mask b11111110 = bxxxxxxx0
// Read the main pins
#define PIN_SQCK_READ (PIND & (1<<PIND6)) // Create a mask (1<<6) with the six bit at 1 b00100000,
#define PIN_SUBQ_READ (PIND & (1<<PIND7)) // compare the PINB register and the mask with the AND operator, and returns the result, PINB bxx1xxxxx AND mask b00100000 = 1
#define PIN_WFCK_READ (PINB & (1<<PINB1))
// Handling and use of the LED pin
//#define LED_RUN
//#define PIN_LED_OUTPUT DDRB |= (1<<DDB5)
//#define PIN_LED_ON PORTB |= (1<<PB5)
//#define PIN_LED_OFF PORTB &= ~(1<<PB5)
// Handling the BIOS patch
// BIOS interrupt seting
#define TIMER_INTERRUPT_ENABLE TIMSK0 |= (1<<OCIE0A)
#define TIMER_INTERRUPT_DISABLE TIMSK0 &= ~(1<<OCIE0A)
// BIOS timer clear
#define TIMER_TIFR_CLEAR TIFR0 |= (1<<OCF0A)
// Pins input
#define PIN_AX_INPUT DDRD &= ~(1<<DDD2)
#define PIN_AY_INPUT DDRD &= ~(1<<DDD3)
#define PIN_DX_INPUT DDRD &= ~(1<<DDD4)
// Pin output
#define PIN_DX_OUTPUT DDRD |= (1<<DDD4)
// Define pull-ups set high
#define PIN_DX_SET PORTD |= (1<<PD4)
// Define pull-ups set down
#define PIN_DX_CLEAR PORTD &= ~(1<<PD4)
// Read pins for BIOS patch
#define PIN_AX_READ (PIND & (1<<PIND2))
#define PIN_AY_READ (PIND & (1<<PIND3))
// Handling the external interrupt
#define PIN_AX_INTERRUPT_ENABLE EIMSK |= (1<<INT0)
#define PIN_AY_INTERRUPT_ENABLE EIMSK |= (1<<INT1)
#define PIN_AX_INTERRUPT_DISABLE EIMSK &= ~(1<<INT0)
#define PIN_AY_INTERRUPT_DISABLE EIMSK &= ~(1<<INT1)
#define PIN_AX_INTERRUPT_RISING EICRA |= (1<<ISC01)|(1<<ISC00)
#define PIN_AY_INTERRUPT_RISING EICRA |= (1<<ISC11)|(1<<ISC10)
#define PIN_AX_INTERRUPT_FALLING (EICRA = (EICRA & ~(1<<ISC00)) | (1<<ISC01))
#define PIN_AY_INTERRUPT_FALLING (EICRA = (EICRA & ~(1<<ISC10)) | (1<<ISC11))
#define PIN_AX_INTERRUPT_VECTOR INT0_vect
#define PIN_AY_INTERRUPT_VECTOR INT1_vect
// Handling and reading the switch pin for patch BIOS
#define PIN_SWITCH_INPUT DDRD &= ~(1<<DDD5)
#define PIN_SWITCH_SET PORTD |= (1<<PD5)
#define PIN_SWICHE_READ (PIND & (1<<PIND5))
#endif
#ifdef ATtiny214_414
//#define SET_CTRLA
#define DF_CPU 20000000L
#define TIMER_TCNT_CLEAR TCA0.SINGLE.CNT = 0x00 //TCNT0 - Timer/Counter Register
#define SET_OCROA_DIV TCA0.SINGLE.CMP0L = 100; //OCR0A Output Compare Register A, 0x10011111, 100KHz
#define SET_TIMER_TCCROA TCA0.SINGLE.CTRLB |= (1 << TCA_SINGLE_WGM0); //TCA_SINGLE_WGMODE_FRQ_gc //TCCR0A Timer/Counter Control Register A. turn on CTC mode, CTC0
#define SET_TIMER_TCCROB TCA0.SINGLE.CTRLA |= (1 << TCA_SINGLE_CLKSEL0); //TCA_SINGLE_CLKSEL_DIV1_gc//TCCR0B Timer/Counter Control Register B, CS00: Clock Select, clk I/O
//Waveform Generation Mode, Mode 2 CTC
#define CTC_TIMER_VECTOR TCA0_OVF_vect //TCA0_CMP0_vect //interrupt vector for match event, OCR0A comparison and Timer/Counter 0
#include <stdint.h>
#include <stdbool.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sfr_defs.h>
#include <util/delay.h>
// Globale interrupt seting
#define GLOBAL_INTERRUPT_ENABLE __asm__ __volatile__ ("sei" ::) //CPU.SREG |= (1<<7)
#define GLOBAL_INTERRUPT_DISABLE __asm__ __volatile__ ("cli" ::) //CPU.SREG &= ~(1<<7)
// Handling the main pins
// Main pins input
#define PIN_DATA_INPUT PORTA.DIR = PIN2_bm
#define PIN_WFCK_INPUT PORTA.DIR = PIN1_bm // Create a mask (1<<0) with the first bit at 1 b00000001 uses the ~ operator to perform a bit inversion b11111110,
#define PIN_SQCK_INPUT PORTA.DIR = PIN4_bm // &= updates the DDRB register with the AND operator and the mask, DDRB bxxxxxxxx OR mask b11111110 = bxxxxxxx0
#define PIN_SUBQ_INPUT PORTA.DIR = PIN3_bm
// Main pin output
#define PIN_DATA_OUTPUT PORTA.DIR |= PIN2_bm // Create a mask (1<<0) with the first bit at 1 b00000001,
#define PIN_WFCK_OUTPUT PORTA.DIR |= PIN1_bm // |= updates the DDRB register with the OR operator and the mask, DDRB bxxxxxxxx OR mask b00000001 = bxxxxxxx1
// Define pull-ups and set high at the main pin
#define PIN_DATA_SET PORTA.OUT |= PIN2_bm // Create a mask (1<<0) with the first bit at 1 b00000001,
// |= updates the PORTB register with the OR operator and the mask, PORTB bxxxxxxxx OR mask b00000001 = bxxxxxxx1
// Define pull-ups set down at the main pin
#define PIN_DATA_CLEAR PORTA.OUT &= ~PIN2_bm // Create a mask (1<<0) with the first bit at 1 b00000001 uses the ~ operator to perform a bit inversion b11111110,
#define PIN_WFCK_CLEAR PORTA.OUT &= ~PIN1_bm // &= updates the DDRB register with the AND operator and the mask, DDRB bxxxxxxxx OR mask b11111110 = bxxxxxxx0
// Read the main pins
#define PIN_SQCK_READ PORTA.IN & PIN4_bm // Create a mask (1<<6) with the six bit at 1 b00100000,
#define PIN_SUBQ_READ PORTA.IN & PIN3_bm // compare the PINB register and the mask with the AND operator, and returns the result, PINB bxx1xxxxx AND mask b00100000 = 1
#define PIN_WFCK_READ PORTA.IN & PIN1_bm
// Handling and use of the LED pin
#define LED_RUN
#define PIN_LED_OUTPUT PORTB.DIR |= PIN2_bm
#define PIN_LED_ON PORTB.OUT |= PIN2_bm
#define PIN_LED_OFF PORTB.OUT &= ~PIN2_bm
// Handling the BIOS patch
// BIOS interrupt seting
#define TIMER_INTERRUPT_ENABLE TCA0.SPLIT.INTCTRL |= TCA_SINGLE_CMP0_bm
#define TIMER_INTERRUPT_DISABLE TCA0.SPLIT.INTCTRL &= ~TCA_SPLIT_HCMP0_bm
// BIOS timer clear
#define TIMER_TIFR_CLEAR TCA0.SPLIT.INTFLAGS = TCA_SPLIT_HCMP0_bm
// Pins input
#define PIN_AX_INPUT PORTB.DIR &= ~PIN3_bm
#define PIN_AY_INPUT PORTA.DIR &= ~PIN7_bm
#define PIN_DX_INPUT PORTA.DIR &= ~PIN6_bm
// Pin output
#define PIN_DX_OUTPUT PORTA.DIR |= PIN6_bm
// Define pull-ups set high
#define PIN_DX_SET PORTA.OUT |= PIN6_bm
// Define pull-ups set down
#define PIN_DX_CLEAR PORTA.OUT &= ~PIN6_bm
// Read pins for BIOS patch
#define PIN_AX_READ PORTB.IN & PIN3_bm
#define PIN_AY_READ PORTA.IN & PIN6_bm
// Handling the external interrupt
//#define PIN_AX_INTERRUPT_ENABLE PORTB.PIN3CTRL |= (1<<INTn)
//#define PIN_AY_INTERRUPT_ENABLE PORTA.PIN7CTRL |= (1<<INTn)
#define PIN_AX_INTERRUPT_DISABLE PORTB.PIN3CTRL = PORT_ISC_INTDISABLE_gc
#define PIN_AY_INTERRUPT_DISABLE PORTA.PIN7CTRL = PORT_ISC_INTDISABLE_gc
#define PIN_AX_INTERRUPT_RISING PORTB.PIN3CTRL = PORT_ISC_RISING_gc
#define PIN_AY_INTERRUPT_RISING PORTA.PIN7CTRL = PORT_ISC_RISING_gc
#define PIN_AX_INTERRUPT_FALLING PORTB.PIN3CTRL = PORT_ISC_FALLING_gc
#define PIN_AY_INTERRUPT_FALLING PORTA.PIN7CTRL = PORT_ISC_FALLING_gc
//#define PB3_INTERRUPT PORTB.INTFLAGS & PIN3_bm
//#define PA7_INTERRUPT PORTB.INTFLAGS & PIN7_bm
#define PIN_AX_INTERRUPT_VECTOR PORTB_PORT_vect
#define PIN_AY_INTERRUPT_VECTOR PORTA_PORT_vect
// Handling and reading the switch pin for patch BIOS
#define PIN_SWITCH_INPUT PORTA.DIR &= ~PIN5_bm
#define PIN_SWITCH_SET PORTA.OUT |= PIN5_bm
#define PIN_SWICHE_READ PORTA.IN & PIN5_bm
#endif
#ifdef LGT8F328P
#define F_CPU 32000000L
#define TIMER_TCNT_CLEAR TCNT0 = 0x00
#define SET_OCROA_DIV OCR0A = 319;
#define SET_TIMER_TCCROA TCCR0A |= (1 << WGM01);
#define SET_TIMER_TCCROB TCCR0B |= (1 << CS00);
#define CTC_TIMER_VECTOR TIMER0_COMPA_vect
#include <stdint.h>
#include <stdbool.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sfr_defs.h>
#include <util/delay.h>
// Globale interrupt seting
#define GLOBAL_INTERRUPT_ENABLE SREG |= (1<<7)
#define GLOBAL_INTERRUPT_DISABLE SREG &= ~(1<<7)
// Handling the main pins
// Main pins input
#define PIN_DATA_INPUT DDRB &= ~(1<<DDB0)
#define PIN_WFCK_INPUT DDRB &= ~(1<<DDB1)
#define PIN_SQCK_INPUT DDRD &= ~(1<<DDD6)
#define PIN_SUBQ_INPUT DDRD &= ~(1<<DDD7)
// Main pin output
#define PIN_DATA_OUTPUT DDRB |= (1<<DDB0)
#define PIN_WFCK_OUTPUT DDRB |= (1<<DDB1)
// Define pull-ups and set high at the main pin
#define PIN_DATA_SET PORTB |= (1<<PB0)
// Define pull-ups set down at the main pin
#define PIN_DATA_CLEAR PORTB &= ~(1<<PB0)
#define PIN_WFCK_CLEAR PORTB &= ~(1<<PB1)
// Read the main pins
#define PIN_SQCK_READ (PIND & (1<<PIND6))
#define PIN_SUBQ_READ (PIND & (1<<PIND7))
#define PIN_WFCK_READ (PINB & (1<<PINB1))
// Handling and use of the LED pin
#define LED_RUN
#define PIN_LED_OUTPUT DDRB |= (1<<DDB5)
#define PIN_LED_ON PORTB |= (1<<PB5)
#define PIN_LED_OFF PORTB &= ~(1<<PB5)
// Handling the BIOS patch
// BIOS interrupt seting
#define TIMER_INTERRUPT_ENABLE TIMSK0 |= (1<<OCIE0A)
#define TIMER_INTERRUPT_DISABLE TIMSK0 &= ~(1<<OCIE0A)
// BIOS timer clear
#define TIMER_TIFR_CLEAR TIFR0 |= (1<<OCF0A)
// Pins input
#define PIN_AX_INPUT DDRD &= ~(1<<DDD2)
#define PIN_AY_INPUT DDRD &= ~(1<<DDD3)
#define PIN_DX_INPUT DDRD &= ~(1<<DDD4)
// Pin output
#define PIN_DX_OUTPUT DDRD |= (1<<DDD4)
// Define pull-ups set high
#define PIN_DX_SET PORTD |= (1<<PD4)
// Define pull-ups set down
#define PIN_DX_CLEAR PORTD &= ~(1<<PD4)
// Read pins for BIOS patch
#define PIN_AX_READ (PIND & (1<<PIND2))
#define PIN_AY_READ (PIND & (1<<PIND3))
// Handling the external interrupt
#define PIN_AX_INTERRUPT_ENABLE EIMSK |= (1<<INT0)
#define PIN_AY_INTERRUPT_ENABLE EIMSK |= (1<<INT1)
#define PIN_AX_INTERRUPT_DISABLE EIMSK &= ~(1<<INT0)
#define PIN_AY_INTERRUPT_DISABLE EIMSK &= ~(1<<INT1)
#define PIN_AX_INTERRUPT_RISING EICRA |= (1<<ISC01)|(1<<ISC00)
#define PIN_AY_INTERRUPT_RISING EICRA |= (1<<ISC11)|(1<<ISC10)
#define PIN_AX_INTERRUPT_FALLING (EICRA = (EICRA & ~(1<<ISC00)) | (1<<ISC01))
#define PIN_AY_INTERRUPT_FALLING (EICRA = (EICRA & ~(1<<ISC10)) | (1<<ISC11))
#define PIN_AX_INTERRUPT_VECTOR INT0_vect
#define PIN_AY_INTERRUPT_VECTOR INT1_vect
// Handling and reading the switch pin for patch BIOS
#define PIN_SWITCH_INPUT DDRD &= ~(1<<DDD5)
#define PIN_SWITCH_SET PORTD |= (1<<PD5)
#define PIN_SWICHE_READ (PIND & (1<<PIND5))
#endif
#ifdef CH32V003
#include "ch32v003.h" // Inclure le fichier d'en-tête spécifique au microcontrôleur
#include <stdint.h>
#include <stdbool.h>
// Fréquence d'horloge
#define F_CPU 8000000L
// Configuration du timer pour une fréquence de 100 kHz
#define TIMER_TCNT_CLEAR TIM2_CNT = 0x00 // ok Effacer le compteur du Timer 2
#define SET_OCROA_DIV TIM2_ARR = 79 // not Définir la valeur de comparaison pour générer une interruption à 100 kHz
#define SET_TIMER_TCCROA TIM2_CR1 |= TIM_CR1_OPM // notMettre le Timer en mode One Pulse (à adapter selon le mode souhaité)
#define SET_TIMER_TCCROB TIM2_PSC = 0 // ok Définir le prescaler à 0 pour une fréquence maximale
// Vecteur d'interruption pour le Timer 2
#define CTC_TIMER_VECTOR TIM2_UP_IRQHandler // Remplacer par le vecteur d'interruption approprié
// Interruption globale
#define GLOBAL_INTERRUPT_ENABLE __enable_irq()
#define GLOBAL_INTERRUPT_DISABLE __disable_irq()
// Configuration des broches GPIO
#define PIN_DATA_INPUT GPIOA->INDR &= ~(GPIO_MODER_MODER0)
#define PIN_WFCK_INPUT GPIOA->INDR &= ~(GPIO_MODER_MODER1)
#define PIN_SQCK_INPUT GPIOA->INDR &= ~(GPIO_MODER_MODER6)
#define PIN_SUBQ_INPUT GPIOA->INDR &= ~(GPIO_MODER_MODER7)
#define PIN_DATA_OUTPUT GPIOA->OUTDR |= (GPIO_MODER_MODER0_0)
#define PIN_WFCK_OUTPUT GPIOA->OUTDR |= (GPIO_MODER_MODER1_0)
#define PIN_DATA_SET GPIOA->BSHR |= (GPIO_ODR_ODR_0)
#define PIN_DATA_CLEAR GPIOA->BRC &= ~(GPIO_ODR_ODR_0)
#define PIN_WFCK_CLEAR GPIOA->BRC &= ~(GPIO_ODR_ODR_1)
#define PIN_SQCK_READ (GPIOA->IDR & (GPIO_IDR_IDR_6))
#define PIN_SUBQ_READ (GPIOA->IDR & (GPIO_IDR_IDR_7))
#define PIN_WFCK_READ (GPIOA->IDR & (GPIO_IDR_IDR_1))
// Gestion de la broche LED
#define PIN_LED_OUTPUT GPIOA->MODER |= (GPIO_MODER_MODER5_0)
#define PIN_LED_ON GPIOA->ODR |= (GPIO_ODR_ODR_5)
#define PIN_LED_OFF GPIOA->ODR &= ~(GPIO_ODR_ODR_5)
// Gestion des interruptions du timer
#define TIMER_INTERRUPT_ENABLE TIM2_DIER |= (TIM_DIER_UIE)
#define TIMER_INTERRUPT_DISABLE TIM2_DIER &= ~(TIM_DIER_UIE)
#define TIMER_TIFR_CLEAR TIM2_SR &= ~(TIM_SR_UIF)
// Configuration des broches pour le BIOS
#define PIN_AX_INPUT GPIOA->MODER &= ~(GPIO_MODER_MODER2) AFIO_EXTICR
#define PIN_AY_INPUT GPIOA->MODER &= ~(GPIO_MODER_MODER3)
#define PIN_DX_INPUT GPIOA->MODER &= ~(GPIO_MODER_MODER4)
#define PIN_DX_OUTPUT GPIOA->MODER |= (GPIO_MODER_MODER4_0)
#define PIN_DX_SET GPIOA->ODR |= (GPIO_ODR_ODR_4)
#define PIN_DX_CLEAR GPIOA->ODR &= ~(GPIO_ODR_ODR_4)
#define PIN_AX_READ (GPIOA->IDR & (GPIO_IDR_IDR_2))
#define PIN_AY_READ (GPIOA->IDR & (GPIO_IDR_IDR_3))
// Gestion des interruptions externes
#define PIN_AX_INTERRUPT_ENABLE EXTI->IMR |= (EXTI_IMR_MR0) //1<<EXTI_INTENR_MR0
#define PIN_AY_INTERRUPT_ENABLE EXTI->IMR |= (EXTI_IMR_MR1)
#define PIN_AX_INTERRUPT_DISABLE EXTI->IMR &= ~(EXTI_IMR_MR0) //EXTI_INTENR
#define PIN_AY_INTERRUPT_DISABLE EXTI->IMR &= ~(EXTI_IMR_MR1)
#define PIN_AX_INTERRUPT_RISING EXTI->RTSR |= (EXTI_RTSR_TR0) //EXTI_RTENR
#define PIN_AY_INTERRUPT_RISING EXTI->RTSR |= (EXTI_RTSR_TR1)
#define PIN_AX_INTERRUPT_FALLING EXTI->FTSR |= (EXTI_FTENR_MR0) //EXTI_FTENR
#define PIN_AY_INTERRUPT_FALLING EXTI->FTSR |= (EXTI_FTENR_MR1)
#define PIN_AX_INTERRUPT_VECTOR EXTI0_IRQHandler
#define PIN_AY_INTERRUPT_VECTOR EXTI1_IRQHandler
// Gestion de la broche de commutation pour le BIOS
#define PIN_SWITCH_INPUT GPIOA->MODER &= ~(GPIO_MODER_MODER5)
#define PIN_SWITCH_SET GPIOA->ODR |= (GPIO_ODR_ODR_5)
#define PIN_SWICHE_READ (GPIOA->IDR & (GPIO_IDR_IDR_5))
#endif
#endif

View File

@@ -1,485 +0,0 @@
//------------------------------------------------------------------------------------------------
// Select your console
//------------------------------------------------------------------------------------------------
// Attention!
// If a BIOS checksum is specified, it is more important than the SCPH model number!
//------------------------------------------------------------------------------------------------
//All NTSC-U/C SCPH_xxx1, all PAL FAT models SCPH_xxx2, SCPH_103. It's 0.5 seconds longer than choosing a specific region.
//#define SCPH_xxxx
//Here the regions are specified
//#define SCPH_xxx1 // Use for all NTSC-U/C models. No BIOS patching needed.
//#define SCPH_xxx2 // Use for all PAL FAT models. No BIOS patching needed.
//#define SCPH_103 // Maybe for all SCPH_xxx3 but I have no info.
//And all models that require a BIOS patch
//#define SCPH_102 // DX - D0, AX - A7. BIOS ver. 4.4e, CRC 0BAD7EA9 | 4.5e, CRC 76B880E5
//#define SCPH_100 // DX - D0, AX - A7. BIOS ver. 4.3j, CRC F2AF798B
//#define SCPH_7000_9000 // DX - D0, AX - A7. BIOS ver. 4.0j, CRC EC541CD0
//#define SCPH_5500 // DX - D0, AX - A5. BIOS ver. 3.0j, CRC FF3EEB8C
//#define SCPH_3500_5000 // DX - D0, for 40-pin BIOS: AX - A4, for 32-pin BIOS: AX - A5. BIOS ver. 2.2j, CRC 24FC7E17 | 2.1j, CRC BC190209
//#define SCPH_3000 // DX - D5, for 40-pin BIOS: AX - A6, AY - A7, for 32-pin BIOS: AX - A7, AY - A8. BIOS ver. 1.1j, CRC 3539DEF6
//#define SCPH_1000 // DX - D5, for 40-pin BIOS: AX - A6, AY - A7, for 32-pin BIOS: AX - A7, AY - A8. BIOS ver. 1.0j, CRC 3B601FC8
//------------------------------------------------------------------------------------------------
// Select your chip
//------------------------------------------------------------------------------------------------
//#define ATmega328_168
//#define ATmega32U4_16U4
//#define ATtiny85_45_25
/*
Fuses:
ATmega 328/168 - H: DF, L: EE, E: FD.
ATmega32U4_16U4 - H: DF, L: EE, E: FB.
ATmega 328PB - H: DF, L: EE, E: F5.
ATtiny - H: DF, L: E2; E: FF.
Pinout Arduino:
5v-VCC, PinGND-GND,
D2-BIOS AX (Only for Bios patch)
D3-BIOS AY (Only for BIOS ver. 1.0j-1.1j)
D4-BIOS DX (Only for Bios patch)
D5-Switch* (Optional for Bios patch)
D6-SQCK
D7-SUBQ
D8-DATA
D9-WFCK
RST-RESET* (Only for JAP_FAT)
GND-GND
Pinout ATtiny:
Pin1-RESET
Pin2-LED
Pin3-WFCK
Pin4-GND
Pin5-SQCK (MOSI)
Pin6-SUBQ (MISO)
Pin7_DATA (SCK)
Pin8-VCC
*/
//------------------------------------------------------------------------------------------------
// Options
//------------------------------------------------------------------------------------------------
#define LED_RUN // Turns on the LED when injections occur. D13 for Arduino, ATtiny add a led between PB3 (pin 2) and gnd with a 1k resistor in series, ATmega32U4 (Pro Micro) add a led between PB6 (pin 10) and gnd with a 1k resistor in series
//#define PATCH_SWITCHE // Enables hardware support for disabling BIOS patching, to allow access to the console memory card menu for model 7000. Useful in rare cases where the BIOS patch prevents the playback of original games
//------------------------------------------------------------------------------------------------
// pointer and variable section
//------------------------------------------------------------------------------------------------
#include "MUC.h"
#include "settings.h"
#include "BIOS_patching.h"
//Initializing values for region code injection timing
#define DELAY_BETWEEN_BITS 4000 // 250 bits/s (microseconds) (ATtiny 8Mhz works from 3950 to 4100) PU-23 PU-22 MAX 4250 MIN 3850
#define DELAY_BETWEEN_INJECTIONS 90 // The sweet spot is around 80~100. For all observed models, the worst minimum time seen is 72, and it works well up to 250.
#define HYSTERESIS_MAX 17 // The sweet spot is between 11~19. All models have bad behavior below 11, PU-41 can start to have bad behavior beyond 20, for fat models we can go up to 60
// On fat models if your reader is really bad you can increase this value in steps of 5.
//Creation of the different variables for the counter
volatile uint8_t count_isr = 0;
volatile uint32_t microsec = 0;
volatile uint16_t millisec = 0;
//Flag initializing for automatic console generation selection 0 = old, 1 = pu-22 end ++
volatile bool wfck_mode = 0;
volatile bool Flag_Switch = 0;
//------------------------------------------------------------------------------------------------
// Code section
//------------------------------------------------------------------------------------------------
// *****************************************************************************************
// Interrupt Service Routine: CTC_TIMER_VECTOR
// Description:
// This ISR is triggered by the Timer/Counter Compare Match event. It increments time-related
// counters used for tracking microseconds and milliseconds.
//
// Functionality:
// - Increments `microsec` by 10 on each interrupt call.
// - Increments `count_isr` to keep track of the number of interrupts.
// - When `count_isr` reaches 100, it means 1 millisecond has elapsed:
// - `millisec` is incremented.
// - `count_isr` is reset to 0.
//
// Notes:
// - This method provides a simple way to maintain a software-based timekeeping system.
// *****************************************************************************************
ISR(CTC_TIMER_VECTOR) {
microsec += 10;
count_isr++;
if (count_isr == 100)
{
millisec++;
count_isr = 0;
}
}
// *****************************************************************************************
// Function: Timer_Start
// Description:
// This function initializes and starts the timer by resetting the timer counter register
// and enabling timer interrupts. It ensures compatibility across multiple microcontrollers.
//
// Supported Microcontrollers:
// - ATmega328/168
// - ATmega32U4/16U4
// - ATtiny85/45/25
//
// Functionality:
// - Clears the timer counter to ensure a fresh start.
// - Enables the timer interrupt to allow periodic execution of ISR routines.
// - If BIOS_PATCH is defined, it also clears the timer interrupt flag to prevent
// unwanted immediate interrupts.
//
// Notes:
// - The actual timer configuration is handled in MUC.h.
// - This function ensures that all supported MCUs behave consistently.
//
// *****************************************************************************************
void Timer_Start() {
#if defined(ATmega328_168) || defined(ATmega32U4_16U4) || defined(ATtiny85_45_25)
TIMER_TCNT_CLEAR;
TIMER_INTERRUPT_ENABLE;
#if defined(BIOS_PATCH)
TIMER_TIFR_CLEAR;
#endif
#endif
}
// *****************************************************************************************
// Function: Timer_Stop
// Description:
// Stops the timer by disabling interrupts and resetting the timer counter.
// It also clears the time tracking variables (count_isr, microsec, millisec)
// to ensure a fresh start when the timer is restarted.
//
// Supported Microcontrollers:
// - ATmega328/168
// - ATmega32U4/16U4
// - ATtiny85/45/25
//
// *****************************************************************************************
void Timer_Stop() {
#if defined(ATmega328_168) || defined(ATmega32U4_16U4) || defined(ATtiny85_45_25)
TIMER_INTERRUPT_DISABLE; // Disable timer interrupts to stop counting
TIMER_TCNT_CLEAR; // Reset the timer counter to ensure proper timing when restarted
#endif
// Reset time tracking variables
count_isr = 0;
microsec = 0;
millisec = 0;
}
// *****************************************************************************************
// Function: readBit
// Description:
// Reads a specific bit from an array of bytes.
// This function helps retrieve SCEX data efficiently while working within
// the constraints of Harvard architecture.
//
// Parameters:
// - index: The bit position to read within the byte array.
// - ByteSet: A pointer to the byte array containing the data.
//
// Return:
// - Returns 1 if the specified bit at the given index is set (1).
// - Returns 0 if the specified bit is cleared (0).
//
// Explanation:
// - The function determines which byte contains the requested bit using (index / 8).
// - It then calculates the bit position within that byte using (index % 8).
// - A bitwise AND operation extracts the bit's value, and the double NOT (!!) operator
// ensures a clean boolean return value (1 or 0).
//
// *****************************************************************************************
uint8_t readBit(uint8_t index, const uint8_t* ByteSet) {
return !!(ByteSet[index / 8] & (1 << (index % 8))); // Return true if the specified bit is set in ByteSet[index]
}
// *****************************************************************************************
// Function: inject_SCEX
// Description:
// Injects SCEX data corresponding to a given region ('e' for Europe, 'a' for America,
// 'i' for Japan). This function is used for modulating the SCEX signal to bypass
// region-locking mechanisms.
//
// Parameters:
// - region: A character ('e', 'a', or 'i') representing the target region.
//
// *****************************************************************************************
void inject_SCEX(const char region) {
// SCEX data patterns for different regions (SCEE, SCEA, SCEI)
static const uint8_t SCEEData[] = {
0b01011001,
0b11001001,
0b01001011,
0b01011101,
0b11101010,
0b00000010
};
static const uint8_t SCEAData[] = {
0b01011001,
0b11001001,
0b01001011,
0b01011101,
0b11111010,
0b00000010
};
static const uint8_t SCEIData[] = {
0b01011001,
0b11001001,
0b01001011,
0b01011101,
0b11011010,
0b00000010
};
// Iterate through 44 bits of SCEX data
for (uint8_t bit_counter = 0; bit_counter < 44; bit_counter++) {
// Check if the current bit is 0
if (readBit(bit_counter, region == 'e' ? SCEEData : region == 'a' ? SCEAData : SCEIData) == 0) {
PIN_DATA_OUTPUT;
PIN_DATA_CLEAR;
_delay_us(DELAY_BETWEEN_BITS); // Wait for specified delay between bits
}
else {
// modulate DATA pin based on WFCK_READ
if (wfck_mode) // WFCK mode (pu22mode enabled): synchronize PIN_DATA with WFCK clock signal
{
PIN_DATA_OUTPUT;
Timer_Start();
do {
// Read the WFCK pin and set or clear DATA accordingly
if (PIN_WFCK_READ) {
PIN_DATA_SET;
}
else {
PIN_DATA_CLEAR;
}
}
while (microsec < DELAY_BETWEEN_BITS);
Timer_Stop(); // Stop the timer after the delay
}
// PU-18 or lower mode: simply set PIN_DATA as input with a delay
else {
PIN_DATA_INPUT;
_delay_us(DELAY_BETWEEN_BITS);
}
}
}
// After injecting SCEX data, set DATA pin as output and clear (low)
PIN_DATA_OUTPUT;
PIN_DATA_CLEAR;
_delay_ms(DELAY_BETWEEN_INJECTIONS);
}
void Init() {
#if defined(ATmega328_168) || defined(ATmega32U4_16U4) || defined(ATtiny85_45_25)
TIMER_TCNT_CLEAR;
SET_OCROA_DIV;
SET_TIMER_TCCROA;
SET_TIMER_TCCROB;
#endif
#if defined(PATCH_SWITCHE) && defined(BIOS_PATCH)
PIN_SWITCH_INPUT;
PIN_SWITCH_SET;
if (PIN_SWICHE_READ == 0){
Flag_Switch =1;
}
#endif
#ifdef LED_RUN
PIN_LED_OUTPUT;
#endif
GLOBAL_INTERRUPT_ENABLE;
PIN_SQCK_INPUT;
PIN_SUBQ_INPUT;
}
int main() {
uint8_t hysteresis = 0;
uint8_t scbuf[12] = { 0 }; // SUBQ bit storage
uint16_t timeout_clock_counter = 0;
uint8_t bitbuf = 0;
uint8_t bitpos = 0;
uint8_t scpos = 0; // scbuf position
uint16_t lows = 0;
Init();
#if defined(BIOS_PATCH)
#ifdef LED_RUN
PIN_LED_ON;
#endif
if (Flag_Switch == 0) {
Bios_Patching();
}
#ifdef LED_RUN
PIN_LED_OFF;
#endif
#endif
Timer_Start();
//************************************************************************
// Board detection
//
// WFCK: __----------------------- // this is a PU-7 .. PU-20 board!
//
// WFCK: __-_-_-_-_-_-_-_-_-_-_-_- // this is a PU-22 or newer board!
// typical readouts PU-22: highs: 2449 lows: 2377
//************************************************************************
do {
if (PIN_WFCK_READ == 0) lows++; // good for ~5000 reads in 1s
_delay_us(200);
}
while (millisec < 1000); // sample 1s
Timer_Stop();
if (lows > 100) {
wfck_mode = 1; //flag pu22mode
}
else {
wfck_mode = 0; //flag oldmod
}
while (1) {
_delay_ms(1); /* Start with a small delay, which can be necessary
in cases where the MCU loops too quickly and picks up the laster SUBQ trailing end*/
GLOBAL_INTERRUPT_DISABLE; // start critical section
// Capture 8 bits for 12 runs > complete SUBQ transmission
do {
for (bitpos = 0; bitpos < 8; bitpos++) {
while (PIN_SQCK_READ != 0) // wait for clock to go low
{
timeout_clock_counter++;
// a timeout resets the 12 byte stream in case the PSX sends malformatted clock pulses, as happens on bootup
if (timeout_clock_counter > 1000) {
scpos = 0;
timeout_clock_counter = 0;
bitbuf = 0;
bitpos = 0;
continue;
}
}
// Wait for clock to go high
while (PIN_SQCK_READ == 0);
if (PIN_SUBQ_READ) // If clock pin high
{
bitbuf |= 1 << bitpos; // Set the bit at position bitpos in the bitbuf to 1. Using OR combined with a bit shift
}
timeout_clock_counter = 0; // no problem with this bit
}
scbuf[scpos] = bitbuf; // One byte done
scpos++;
bitbuf = 0;
}
while (scpos < 12); // Repeat for all 12 bytes
GLOBAL_INTERRUPT_ENABLE; // End critical section
//************************************************************************
// Check if read head is in wobble area
// We only want to unlock game discs (0x41) and only if the read head is in the outer TOC area.
// We want to see a TOC sector repeatedly before injecting (helps with timing and marginal lasers).
// All this logic is because we don't know if the HC-05 is actually processing a getSCEX() command.
// Hysteresis is used because older drives exhibit more variation in read head positioning.
// While the laser lens moves to correct for the error, they can pick up a few TOC sectors.
//************************************************************************
//This variable initialization macro is to replace (0x41) with a filter that will check that only the three most significant bits are correct. 0x001xxxxx
uint8_t isDataSector = (((scbuf[0] & 0x40) == 0x40) && (((scbuf[0] & 0x10) == 0) && ((scbuf[0] & 0x80) == 0)));
if (
(isDataSector && scbuf[1] == 0x00 && scbuf[6] == 0x00) && // [0] = 41 means psx game disk. the other 2 checks are garbage protection
(scbuf[2] == 0xA0 || scbuf[2] == 0xA1 || scbuf[2] == 0xA2 || // if [2] = A0, A1, A2 ..
(scbuf[2] == 0x01 && (scbuf[3] >= 0x98 || scbuf[3] <= 0x02))) // .. or = 01 but then [3] is either > 98 or < 02
) {
hysteresis++;
}
// This CD has the wobble into CD-DA space. (started at 0x41, then went into 0x01)
else if (hysteresis > 0 && ((scbuf[0] == 0x01 || isDataSector) && (scbuf[1] == 0x00 /*|| scbuf[1] == 0x01*/) && scbuf[6] == 0x00)) {
hysteresis++;
}
// None of the above. Initial detection was noise. Decrease the counter.
else if (hysteresis > 0) {
hysteresis--;
}
// hysteresis value "optimized" using very worn but working drive on ATmega328 @ 16Mhz
// should be fine on other MCUs and speeds, as the PSX dictates SUBQ rate
if (hysteresis >= HYSTERESIS_MAX) {
// If the read head is still here after injection, resending should be quick.
// Hysteresis naturally goes to 0 otherwise (the read head moved).
hysteresis = 11;
//************************************************************************
//Executes the region code patch injection sequence.
//************************************************************************
#ifdef LED_RUN
PIN_LED_ON;
#endif
PIN_DATA_OUTPUT;
PIN_DATA_CLEAR;
if (!wfck_mode) // If wfck_mode is fals (oldmode)
{
PIN_WFCK_OUTPUT;
PIN_WFCK_CLEAR;
}
_delay_ms(DELAY_BETWEEN_INJECTIONS); // HC-05 waits for a bit of silence (pin low) before it begins decoding.
// inject symbols now. 2 x 3 runs seems optimal to cover all boards
for (uint8_t scex = 0; scex < 2; scex++) {
inject_SCEX(region[scex]);
}
if (!wfck_mode) // Set WFCK pin input
{
PIN_WFCK_INPUT;
}
PIN_DATA_INPUT;
#ifdef LED_RUN
PIN_LED_OFF;
#endif
}
}
}

View File

@@ -1,141 +0,0 @@
#pragma once
/*
The _delay_us function uses loops to generate an approximate delay for the specified number of microseconds.
It calculates the number of clock cycles required to achieve the requested delay and loops the corresponding number of times.
The temporal precision of _delay_us depends on the microcontroller's clock frequency (F_CPU).
For the ATmega328 operating at a typical frequency of 16 MHz, here are some details on the precision.
Clock Frequency: F_CPU must be defined correctly before using the function. For an ATmega328 operating at 16 MHz:
1 clock cycle = 1 / 16,000,000 s ≈ 62.5 ns
1 µs ≈ 16 clock cycles
HOLD _delay_us(2.75) = 44 clock cycles
PATCHING _delay_us(0.2) = 3,2 clock cycles
*/
#ifdef SCPH_xxxx
#define SCEZ
#endif
#ifdef SCPH_xxx1
#define SCEA
#endif
#ifdef SCPH_xxx2
#define SCEE
#endif
#ifdef SCPH_103
#define SCEI
#endif
#ifdef SCPH_102
#define SCEE
#define BIOS_PATCH
#define HOLD _delay_us(2.75)
#define PATCHING _delay_us(0.2)
#define CHECKPOINT 83900
#define TRIGGER 48
#endif
#ifdef SCPH_100
#define SCEI
#define BIOS_PATCH
#define HOLD _delay_us(2.7)
#define PATCHING _delay_us(0.2)
#define CHECKPOINT 83900
#define TRIGGER 48
#endif
#ifdef SCPH_7000_9000
#define SCEI
#define BIOS_PATCH
#define HOLD _delay_us(2.85)
#define PATCHING _delay_us(0.1)
#define CHECKPOINT 75270
#define TRIGGER 16
#endif
#ifdef SCPH_5500
#define SCEI
#define BIOS_PATCH
#define HOLD _delay_us(2.85)
#define PATCHING _delay_us(0.1)
#define CHECKPOINT 76130
#define TRIGGER 21
#define LOW_TRIGGER
#endif
#ifdef SCPH_3500_5000
#define SCEI
#define BIOS_PATCH
#define HOLD _delay_us(2.85)
#define PATCHING _delay_us(0.1)
#define CHECKPOINT 75260
#define TRIGGER 21
#define LOW_TRIGGER
#endif
#ifdef SCPH_3000
#define SCEI
#define BIOS_PATCH
#define HOLD _delay_us(2.75)
#define PATCHING _delay_us(0.1)
#define CHECKPOINT 83000
#define TRIGGER 60
//#define DOUBLE_PATCH
//#define LOW_TRIGGER2
#define HIGH_PATCH
#define HOLD2 _delay_us(2.88)
#define PATCHING2 _delay_us(0.15)
#define CHECKPOINT2 253300
#define TRIGGER2 43
#endif
#ifdef SCPH_1000
#define SCEI
#define BIOS_PATCH
#define HOLD _delay_us(2.7)
#define PATCHING _delay_us(0.1)
#define CHECKPOINT 83000
#define TRIGGER 92
//#define DOUBLE_PATCH
//#define LOW_TRIGGER2
#define HIGH_PATCH
#define HOLD2 _delay_us(2.88)
#define PATCHING2 _delay_us(0.15)
#define CHECKPOINT2 272800
#define TRIGGER2 71
#endif
#ifdef SCEA
const char region[1] = {'a'};
#endif
#ifdef SCEE
const char region[1] = {'e'};
#endif
#ifdef SCEI
const char region[1] = {'i'};
#endif
#ifdef SCEZ
const char region[3] = {'a', 'e', 'i'};
#endif
#if !defined(SCPH_xxx1) && !defined(SCPH_xxx2) && !defined(SCPH_103) && \
!defined(SCPH_102) && !defined(SCPH_100) && !defined(SCPH_7000_9000) && \
!defined(SCPH_5500) && !defined(SCPH_3500_5000) && !defined(SCPH_3000) && \
!defined(SCPH_1000) && !defined(SCPH_xxxx)
#error "Console not selected! Please uncoment #define with SCPH model number."
#elif !(defined(SCPH_xxx1) ^ defined(SCPH_xxx2) ^ defined(SCPH_103) ^ \
defined(SCPH_102) ^ defined(SCPH_100) ^ defined(SCPH_7000_9000) ^ \
defined(SCPH_5500) ^ defined(SCPH_3500_5000) ^ defined(SCPH_3000) ^ \
defined(SCPH_1000) ^ defined(SCPH_xxxx))
#error "May be selected only one console! Please check #define with SCPH model number."
#endif

View File

@@ -1,200 +0,0 @@
# Menu options
menu.variant=Variant
#menu.fuses=Fuses
##############################
### ATiny25/45/85 ########
##############################
# General
ATtinyX5.name=ATtiny25/45/85
ATtinyX5.upload.tool=arduino:avrdude
ATtinyX5.upload.low_fuses=0xe2
ATtinyX5.program.tool=arduino:avrdude
ATtinyX5.program.unlock_bits=0xff
ATtinyX5.program.lock_bits=0xff
ATtinyX5.build.core=arduino:arduino
ATtinyX5.build.board=attiny
ATtinyX5.build.variant=tiny8
ATtinyX5.build.f_cpu=8000000L
# Variants
ATtinyX5.menu.variant.attiny25=ATtiny25
ATtinyX5.menu.variant.attiny25.upload.maximum_size=2048
ATtinyX5.menu.variant.attiny25.upload.maximum_data_size=128
ATtinyX5.menu.variant.attiny25.build.mcu=attiny25
ATtinyX5.menu.variant.attiny45=ATtiny45
ATtinyX5.menu.variant.attiny45.upload.maximum_size=4096
ATtinyX5.menu.variant.attiny45.upload.maximum_data_size=256
ATtinyX5.menu.variant.attiny45.build.mcu=attiny45
ATtinyX5.menu.variant.attiny85=ATtiny85
ATtinyX5.menu.variant.attiny85.upload.maximum_size=8192
ATtinyX5.menu.variant.attiny85.upload.maximum_data_size=512
ATtinyX5.menu.variant.attiny85.build.mcu=attiny85
##############################
### ATiny48/88 ########
##############################
# General
ATtinyX8.name=ATtiny88/48
ATtinyX8.upload.tool=arduino:avrdude
ATtinyX8.program.tool=arduino:avrdude
ATtinyX8.program.unlock_bits=0xff
ATtinyX8.program.lock_bits=0xff
ATtinyX8.build.core=arduino:arduino
ATtinyX8.build.board=AVR_ATTINYX8
ATtinyX8.build.variant=tinyx8
ATtinyX8.build.f_cpu=16000000L
ATtinyX8.menu.variant.attiny48=ATtiny48
ATtinyX8.menu.variant.attiny48.upload.maximum_size=4096
ATtinyX8.menu.variant.attiny48.upload.maximum_data_size=256
ATtinyX8.menu.variant.attiny48.build.mcu=attiny48
ATtinyX8.menu.variant.attiny88=ATtiny88
ATtinyX8.menu.variant.attiny88.upload.maximum_size=8192
ATtinyX8.menu.variant.attiny88.upload.maximum_data_size=512
ATtinyX8.menu.variant.attiny88.build.mcu=attiny88
ATtinyX8.menu.fuses.BIOSpatch=BIOS patch
ATtinyX8.menu.fuses.BIOSpatch.upload.low_fuses=0xee
ATtinyX8.menu.fuses.NoBIOSpatch=No BIOS patch
ATtinyX8.menu.fuses.NoBIOSpatch.upload.low_fuses=0xff
#############################
#### ATmega328/A/P/PA/PB ####
#############################
# General
328.name=ATmega328
328.upload.tool=arduino:avrdude
328.upload.default_speed=57600
328.upload.maximum_data_size=2048
328.upload.maximum_size=30720
328.upload.low_fuses=0xee
328.build.core=arduino:arduino
328.build.board=AVR_ATmega328
328.build.f_cpu=16000000L
# Variants
328.menu.variant.modelP=328P / 328PA
328.menu.variant.modelP.build.variant=standard
328.menu.variant.modelP.build.mcu=atmega328p
328.menu.variant.modelNonP=328 / 328A
328.menu.variant.modelNonP.build.variant=standard
328.menu.variant.modelNonP.build.mcu=atmega328
328.menu.variant.modelPB=328PB
328.menu.variant.modelPB.build.variant=pb-variant
328.menu.variant.modelPB.build.mcu=atmega328pb
#############################
#### ATmega168/A/P/PA/PB ####
#############################
168.name=ATmega168
168.upload.tool=arduino:avrdude
168.upload.default_speed=57600
168.upload.maximum_size=15872
168.upload.maximum_data_size=1024
168.upload.low_fuses=0xee
168.build.core=arduino:arduino
168.build.board=AVR_ATmega168
168.build.f_cpu=16000000L
# Variants
168.menu.variant.modelP=168P / 168PA
168.menu.variant.modelP.build.variant=standard
168.menu.variant.modelP.build.mcu=atmega168p
168.menu.variant.modelNonP=168 / 168A
168.menu.variant.modelNonP.build.variant=standard
168.menu.variant.modelNonP.build.mcu=atmega168
168.menu.variant.modelPB=168PB
168.menu.variant.modelPB.build.variant=pb-variant
168.menu.variant.modelPB.build.mcu=atmega168pb
#############################
#### atmega32u4 ####
#############################
32u4.name=ATmega32u4
32u4.vid.0=0x2341
32u4.pid.0=0x0037
32u4.vid.1=0x2341
32u4.pid.1=0x8037
32u4.vid.2=0x2A03
32u4.pid.2=0x0037
32u4.vid.3=0x2A03
32u4.pid.3=0x8037
32u4.vid.4=0x2341
32u4.pid.4=0x0237
32u4.vid.5=0x2341
32u4.pid.5=0x8237
32u4.upload_port.0.vid=0x2341
32u4.upload_port.0.pid=0x0037
32u4.upload_port.1.vid=0x2341
32u4.upload_port.1.pid=0x8037
32u4.upload_port.2.vid=0x2A03
32u4.upload_port.2.pid=0x0037
32u4.upload_port.3.vid=0x2A03
32u4.upload_port.3.pid=0x8037
32u4.upload_port.4.vid=0x2341
32u4.upload_port.4.pid=0x0237
32u4.upload_port.5.vid=0x2341
32u4.upload_port.5.pid=0x8237
32u4.upload_port.6.board=micro
32u4.upload.tool=arduino:avrdude
32u4.upload.default_speed=57600
32u4.upload.maximum_data_size=2048
32u4.upload.maximum_size=30720
32u4.upload.use_1200bps_touch=true
32u4.upload.wait_for_upload_port=true
32u4.upload.low_fuses=0xee
32u4.build.mcu=atmega32u4
32u4.build.f_cpu=16000000L
32u4.build.vid=0x2341
32u4.build.pid=0x8037
32u4.build.usb_product="Arduino Micro"
32u4.build.board=AVR_MICRO
32u4.build.core=arduino:arduino
32u4.build.variant=micro
32u4.build.extra_flags={build.usb_flags}
32u4.vid.0=0x239A
32u4.pid.0=0x800C

View File

@@ -1,23 +0,0 @@
name=PSNeeCore
version=1.2.0
tools.avrdude.path={runtime.tools.avrdude.path}
tools.avrdude.cmd.path={path}/bin/avrdude
tools.avrdude.config.path={path}/etc/avrdude.conf
tools.avrdude.program.params.verbose=-v
tools.avrdude.program.params.quiet=-q -q
# tools.avrdude.program.verify is needed for backwards compatibility with IDE 1.6.8 or older, IDE 1.6.9 or newer overrides this value
tools.avrdude.program.verify=
tools.avrdude.program.params.noverify=-V
tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" -F {program.verbose} {program.verify} -p{build.mcu} -c{protocol} {program.extra_params} -Uefuse:w:0xfd:m -Uhfuse:w:0xdf:m -Ulfuse:w:{upload.low_fuses}:m "-Uflash:w:{build.path}/{build.project_name}.hex:i"
tools.avrdude.erase.params.verbose=-v -v -v -v
tools.avrdude.erase.params.quiet=-q -q
tools.avrdude.erase.pattern="{cmd.path}" "-C{config.path}" {erase.verbose} -p{build.mcu} -c{protocol} {program.extra_params} -e -Uefuse:w:0xfd:m -Uhfuse:w:0xdf:m -Ulfuse:w:{bootloader.low_fuses}:m
##tools.avrdude.bootloader.params.verbose=-v
##tools.avrdude.bootloader.params.quiet=-q -q
##tools.avrdude.bootloader.pattern="{cmd.path}" "-C{config.path}" {bootloader.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{runtime.platform.path}/bootloaders/{bootloader.file}:i" -Ulock:w:{bootloader.lock_bits}:m

View File

@@ -1,391 +0,0 @@
/*
pins_arduino.h - Pin definition functions for Arduino
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2007 David A. Mellis
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <avr/pgmspace.h>
// Workaround for wrong definitions in "iom32u4.h".
// This should be fixed in the AVR toolchain.
#undef UHCON
#undef UHINT
#undef UHIEN
#undef UHADDR
#undef UHFNUM
#undef UHFNUML
#undef UHFNUMH
#undef UHFLEN
#undef UPINRQX
#undef UPINTX
#undef UPNUM
#undef UPRST
#undef UPCONX
#undef UPCFG0X
#undef UPCFG1X
#undef UPSTAX
#undef UPCFG2X
#undef UPIENX
#undef UPDATX
#undef TCCR2A
#undef WGM20
#undef WGM21
#undef COM2B0
#undef COM2B1
#undef COM2A0
#undef COM2A1
#undef TCCR2B
#undef CS20
#undef CS21
#undef CS22
#undef WGM22
#undef FOC2B
#undef FOC2A
#undef TCNT2
#undef TCNT2_0
#undef TCNT2_1
#undef TCNT2_2
#undef TCNT2_3
#undef TCNT2_4
#undef TCNT2_5
#undef TCNT2_6
#undef TCNT2_7
#undef OCR2A
#undef OCR2_0
#undef OCR2_1
#undef OCR2_2
#undef OCR2_3
#undef OCR2_4
#undef OCR2_5
#undef OCR2_6
#undef OCR2_7
#undef OCR2B
#undef OCR2_0
#undef OCR2_1
#undef OCR2_2
#undef OCR2_3
#undef OCR2_4
#undef OCR2_5
#undef OCR2_6
#undef OCR2_7
#define NUM_DIGITAL_PINS 31
#define NUM_ANALOG_INPUTS 12
#define TX_RX_LED_INIT DDRD |= (1<<5), DDRB |= (1<<0)
#define TXLED0 PORTD |= (1<<5)
#define TXLED1 PORTD &= ~(1<<5)
#define RXLED0 PORTB |= (1<<0)
#define RXLED1 PORTB &= ~(1<<0)
#define PIN_WIRE_SDA (2)
#define PIN_WIRE_SCL (3)
static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;
#define LED_BUILTIN 13
#define LED_BUILTIN_RX 17
#define LED_BUILTIN_TX 30
// Map SPI port to 'new' pins D14..D17
#define PIN_SPI_SS (17)
#define PIN_SPI_MOSI (16)
#define PIN_SPI_MISO (14)
#define PIN_SPI_SCK (15)
static const uint8_t SS = PIN_SPI_SS;
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;
// Mapping of analog pins as digital I/O
// A6-A11 share with digital pins
#define PIN_A0 (18)
#define PIN_A1 (19)
#define PIN_A2 (20)
#define PIN_A3 (21)
#define PIN_A4 (22)
#define PIN_A5 (23)
#define PIN_A6 (24)
#define PIN_A7 (25)
#define PIN_A8 (26)
#define PIN_A9 (27)
#define PIN_A10 (28)
#define PIN_A11 (29)
static const uint8_t A0 = PIN_A0;
static const uint8_t A1 = PIN_A1;
static const uint8_t A2 = PIN_A2;
static const uint8_t A3 = PIN_A3;
static const uint8_t A4 = PIN_A4;
static const uint8_t A5 = PIN_A5;
static const uint8_t A6 = PIN_A6; // D4
static const uint8_t A7 = PIN_A7; // D6
static const uint8_t A8 = PIN_A8; // D8
static const uint8_t A9 = PIN_A9; // D9
static const uint8_t A10 = PIN_A10; // D10
static const uint8_t A11 = PIN_A11; // D12
#define digitalPinToPCICR(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCICR) : ((uint8_t *)0))
#define digitalPinToPCICRbit(p) 0
#define digitalPinToPCMSK(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCMSK0) : ((uint8_t *)0))
#define digitalPinToPCMSKbit(p) ( ((p) >= 8 && (p) <= 11) ? (p) - 4 : ((p) == 14 ? 3 : ((p) == 15 ? 1 : ((p) == 16 ? 2 : ((p) == 17 ? 0 : (p - A8 + 4))))))
// __AVR_ATmega32U4__ has an unusual mapping of pins to channels
extern const uint8_t PROGMEM analog_pin_to_channel_PGM[];
#define analogPinToChannel(P) ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) )
#define digitalPinHasPWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11 || (p) == 13)
#define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT)))))
#ifdef ARDUINO_MAIN
// On the Arduino board, digital pins are also used
// for the analog output (software PWM). Analog input
// pins are a separate set.
// ATMEL ATMEGA32U4 / ARDUINO LEONARDO
//
// D0 PD2 RXD1/INT2
// D1 PD3 TXD1/INT3
// D2 PD1 SDA SDA/INT1
// D3# PD0 PWM8/SCL OC0B/SCL/INT0
// D4 A6 PD4 ADC8
// D5# PC6 ??? OC3A/#OC4A
// D6# A7 PD7 FastPWM #OC4D/ADC10
// D7 PE6 INT6/AIN0
//
// D8 A8 PB4 ADC11/PCINT4
// D9# A9 PB5 PWM16 OC1A/#OC4B/ADC12/PCINT5
// D10# A10 PB6 PWM16 OC1B/0c4B/ADC13/PCINT6
// D11# PB7 PWM8/16 0C0A/OC1C/#RTS/PCINT7
// D12 A11 PD6 T1/#OC4D/ADC9
// D13# PC7 PWM10 CLK0/OC4A
//
// A0 D18 PF7 ADC7
// A1 D19 PF6 ADC6
// A2 D20 PF5 ADC5
// A3 D21 PF4 ADC4
// A4 D22 PF1 ADC1
// A5 D23 PF0 ADC0
//
// New pins D14..D17 to map SPI port to digital pins
//
// MISO D14 PB3 MISO,PCINT3
// SCK D15 PB1 SCK,PCINT1
// MOSI D16 PB2 MOSI,PCINT2
// SS D17 PB0 RXLED,SS/PCINT0
//
// TXLED D30 PD5 XCK1
// RXLED D17 PB0
// HWB PE2 HWB
// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
const uint16_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &DDRB,
(uint16_t) &DDRC,
(uint16_t) &DDRD,
(uint16_t) &DDRE,
(uint16_t) &DDRF,
};
const uint16_t PROGMEM port_to_output_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &PORTB,
(uint16_t) &PORTC,
(uint16_t) &PORTD,
(uint16_t) &PORTE,
(uint16_t) &PORTF,
};
const uint16_t PROGMEM port_to_input_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &PINB,
(uint16_t) &PINC,
(uint16_t) &PIND,
(uint16_t) &PINE,
(uint16_t) &PINF,
};
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
PD, // D0 - PD2
PD, // D1 - PD3
PD, // D2 - PD1
PD, // D3 - PD0
PD, // D4 - PD4
PC, // D5 - PC6
PD, // D6 - PD7
PE, // D7 - PE6
PB, // D8 - PB4
PB, // D9 - PB5
PB, // D10 - PB6
PB, // D11 - PB7
PD, // D12 - PD6
PC, // D13 - PC7
PB, // D14 - MISO - PB3
PB, // D15 - SCK - PB1
PB, // D16 - MOSI - PB2
PB, // D17 - SS - PB0
PF, // D18 - A0 - PF7
PF, // D19 - A1 - PF6
PF, // D20 - A2 - PF5
PF, // D21 - A3 - PF4
PF, // D22 - A4 - PF1
PF, // D23 - A5 - PF0
PD, // D24 / D4 - A6 - PD4
PD, // D25 / D6 - A7 - PD7
PB, // D26 / D8 - A8 - PB4
PB, // D27 / D9 - A9 - PB5
PB, // D28 / D10 - A10 - PB6
PD, // D29 / D12 - A11 - PD6
PD, // D30 / TX Led - PD5
};
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
_BV(2), // D0 - PD2
_BV(3), // D1 - PD3
_BV(1), // D2 - PD1
_BV(0), // D3 - PD0
_BV(4), // D4 - PD4
_BV(6), // D5 - PC6
_BV(7), // D6 - PD7
_BV(6), // D7 - PE6
_BV(4), // D8 - PB4
_BV(5), // D9 - PB5
_BV(6), // D10 - PB6
_BV(7), // D11 - PB7
_BV(6), // D12 - PD6
_BV(7), // D13 - PC7
_BV(3), // D14 - MISO - PB3
_BV(1), // D15 - SCK - PB1
_BV(2), // D16 - MOSI - PB2
_BV(0), // D17 - SS - PB0
_BV(7), // D18 - A0 - PF7
_BV(6), // D19 - A1 - PF6
_BV(5), // D20 - A2 - PF5
_BV(4), // D21 - A3 - PF4
_BV(1), // D22 - A4 - PF1
_BV(0), // D23 - A5 - PF0
_BV(4), // D24 / D4 - A6 - PD4
_BV(7), // D25 / D6 - A7 - PD7
_BV(4), // D26 / D8 - A8 - PB4
_BV(5), // D27 / D9 - A9 - PB5
_BV(6), // D28 / D10 - A10 - PB6
_BV(6), // D29 / D12 - A11 - PD6
_BV(5), // D30 / TX Led - PD5
};
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
TIMER0B, /* 3 */
NOT_ON_TIMER,
TIMER3A, /* 5 */
TIMER4D, /* 6 */
NOT_ON_TIMER,
NOT_ON_TIMER,
TIMER1A, /* 9 */
TIMER1B, /* 10 */
TIMER0A, /* 11 */
NOT_ON_TIMER,
TIMER4A, /* 13 */
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
};
const uint8_t PROGMEM analog_pin_to_channel_PGM[] = {
7, // A0 PF7 ADC7
6, // A1 PF6 ADC6
5, // A2 PF5 ADC5
4, // A3 PF4 ADC4
1, // A4 PF1 ADC1
0, // A5 PF0 ADC0
8, // A6 D4 PD4 ADC8
10, // A7 D6 PD7 ADC10
11, // A8 D8 PB4 ADC11
12, // A9 D9 PB5 ADC12
13, // A10 D10 PB6 ADC13
9 // A11 D12 PD6 ADC9
};
#endif /* ARDUINO_MAIN */
// These serial port names are intended to allow libraries and architecture-neutral
// sketches to automatically default to the correct port name for a particular type
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
//
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
//
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
//
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
//
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
//
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
// pins are NOT connected to anything by default.
#define SERIAL_PORT_MONITOR Serial
#define SERIAL_PORT_USBVIRTUAL Serial
#define SERIAL_PORT_HARDWARE Serial1
#define SERIAL_PORT_HARDWARE_OPEN Serial1
// Alias SerialUSB to Serial
#define SerialUSB SERIAL_PORT_USBVIRTUAL
#endif /* Pins_Arduino_h */

View File

@@ -1,330 +0,0 @@
/*
pins_arduino.h - Pin definition functions for Arduino
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2007 David A. Mellis
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <avr/pgmspace.h>
// Workaround for wrong definitions in "iom32u4.h".
// This should be fixed in the AVR toolchain.
#undef UHCON
#undef UHINT
#undef UHIEN
#undef UHADDR
#undef UHFNUM
#undef UHFNUML
#undef UHFNUMH
#undef UHFLEN
#undef UPINRQX
#undef UPINTX
#undef UPNUM
#undef UPRST
#undef UPCONX
#undef UPCFG0X
#undef UPCFG1X
#undef UPSTAX
#undef UPCFG2X
#undef UPIENX
#undef UPDATX
#undef TCCR2A
#undef WGM20
#undef WGM21
#undef COM2B0
#undef COM2B1
#undef COM2A0
#undef COM2A1
#undef TCCR2B
#undef CS20
#undef CS21
#undef CS22
#undef WGM22
#undef FOC2B
#undef FOC2A
#undef TCNT2
#undef TCNT2_0
#undef TCNT2_1
#undef TCNT2_2
#undef TCNT2_3
#undef TCNT2_4
#undef TCNT2_5
#undef TCNT2_6
#undef TCNT2_7
#undef OCR2A
#undef OCR2_0
#undef OCR2_1
#undef OCR2_2
#undef OCR2_3
#undef OCR2_4
#undef OCR2_5
#undef OCR2_6
#undef OCR2_7
#undef OCR2B
#undef OCR2_0
#undef OCR2_1
#undef OCR2_2
#undef OCR2_3
#undef OCR2_4
#undef OCR2_5
#undef OCR2_6
#undef OCR2_7
#define NUM_DIGITAL_PINS 31
#define NUM_ANALOG_INPUTS 12
#define TXLED0 0
#define TXLED1 0
#define RXLED0 0
#define RXLED1 0
#define TX_RX_LED_INIT 0
static const uint8_t SDA = 2;
static const uint8_t SCL = 3;
#define LED_BUILTIN 13
// Map SPI port to 'new' pins D14..D17
static const uint8_t SS = 17;
static const uint8_t MOSI = 16;
static const uint8_t MISO = 14;
static const uint8_t SCK = 15;
// Mapping of analog pins as digital I/O
// A6-A11 share with digital pins
static const uint8_t A0 = 18;
static const uint8_t A1 = 19;
static const uint8_t A2 = 20;
static const uint8_t A3 = 21;
static const uint8_t A4 = 22;
static const uint8_t A5 = 23;
static const uint8_t A6 = 24; // D4
static const uint8_t A7 = 25; // D6
static const uint8_t A8 = 26; // D8
static const uint8_t A9 = 27; // D9
static const uint8_t A10 = 28; // D10
static const uint8_t A11 = 29; // D12
#define digitalPinToPCICR(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCICR) : ((uint8_t *)0))
#define digitalPinToPCICRbit(p) 0
#define digitalPinToPCMSK(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCMSK0) : ((uint8_t *)0))
#define digitalPinToPCMSKbit(p) ( ((p) >= 8 && (p) <= 11) ? (p) - 4 : ((p) == 14 ? 3 : ((p) == 15 ? 1 : ((p) == 16 ? 2 : ((p) == 17 ? 0 : (p - A8 + 4))))))
// __AVR_ATmega32U4__ has an unusual mapping of pins to channels
extern const uint8_t PROGMEM analog_pin_to_channel_PGM[];
#define analogPinToChannel(P) ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) )
#define digitalPinHasPWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11 || (p) == 13)
#define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT)))))
#ifdef ARDUINO_MAIN
// On the Arduino board, digital pins are also used
// for the analog output (software PWM). Analog input
// pins are a separate set.
// ATMEL ATMEGA32U4 / ARDUINO LEONARDO / Flora
//
// D0 PD2 RXD1/INT2
// D1 PD3 TXD1/INT3
// D2 PD1 SDA SDA/INT1
// D3# PD0 PWM8/SCL OC0B/SCL/INT0
// D4 A6 PD4 ADC8
// D5# PC6 ??? OC3A/#OC4A
// D6# A7 PD7 FastPWM #OC4D/ADC10
// D7 PE6 INT6/AIN0
//
// D8 A8 PB4 ADC11/PCINT4
// D9# A9 PB5 PWM16 OC1A/#OC4B/ADC12/PCINT5
// D10# A10 PB6 PWM16 OC1B/0c4B/ADC13/PCINT6
// D11# PB7 PWM8/16 0C0A/OC1C/#RTS/PCINT7
// D12 A11 PD6 T1/#OC4D/ADC9
// D13# PC7 PWM10 CLK0/OC4A
//
// A0 D18 PF7 ADC7
// A1 D19 PF6 ADC6
// A2 D20 PF5 ADC5
// A3 D21 PF4 ADC4
// A4 D22 PF1 ADC1
// A5 D23 PF0 ADC0
//
// New pins D14..D17 to map SPI port to digital pins
//
// MISO D14 PB3 MISO,PCINT3
// SCK D15 PB1 SCK,PCINT1
// MOSI D16 PB2 MOSI,PCINT2
// SS D17 PB0 RXLED,SS/PCINT0
//
// TXLED PD5
// RXLED PB0
// HWB PE2 HWB
// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
const uint16_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &DDRB,
(uint16_t) &DDRC,
(uint16_t) &DDRD,
(uint16_t) &DDRE,
(uint16_t) &DDRF,
};
const uint16_t PROGMEM port_to_output_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &PORTB,
(uint16_t) &PORTC,
(uint16_t) &PORTD,
(uint16_t) &PORTE,
(uint16_t) &PORTF,
};
const uint16_t PROGMEM port_to_input_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &PINB,
(uint16_t) &PINC,
(uint16_t) &PIND,
(uint16_t) &PINE,
(uint16_t) &PINF,
};
const uint8_t PROGMEM digital_pin_to_port_PGM[30] = {
PD, // D0 - PD2
PD, // D1 - PD3
PD, // D2 - PD1
PD, // D3 - PD0
PD, // D4 - PD4
PC, // D5 - PC6
PD, // D6 - PD7
PE, // D7 - PE6
PB, // D8 - PB4
PB, // D9 - PB5
PB, // D10 - PB6
PB, // D11 - PB7
PD, // D12 - PD6
PC, // D13 - PC7
PB, // D14 - MISO - PB3
PB, // D15 - SCK - PB1
PB, // D16 - MOSI - PB2
PB, // D17 - SS - PB0
PF, // D18 - A0 - PF7
PF, // D19 - A1 - PF6
PF, // D20 - A2 - PF5
PF, // D21 - A3 - PF4
PF, // D22 - A4 - PF1
PF, // D23 - A5 - PF0
PD, // D24 / D4 - A6 - PD4
PD, // D25 / D6 - A7 - PD7
PB, // D26 / D8 - A8 - PB4
PB, // D27 / D9 - A9 - PB5
PB, // D28 / D10 - A10 - PB6
PD, // D29 / D12 - A11 - PD6
};
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[30] = {
_BV(2), // D0 - PD2
_BV(3), // D1 - PD3
_BV(1), // D2 - PD1
_BV(0), // D3 - PD0
_BV(4), // D4 - PD4
_BV(6), // D5 - PC6
_BV(7), // D6 - PD7
_BV(6), // D7 - PE6
_BV(4), // D8 - PB4
_BV(5), // D9 - PB5
_BV(6), // D10 - PB6
_BV(7), // D11 - PB7
_BV(6), // D12 - PD6
_BV(7), // D13 - PC7
_BV(3), // D14 - MISO - PB3
_BV(1), // D15 - SCK - PB1
_BV(2), // D16 - MOSI - PB2
_BV(0), // D17 - SS - PB0
_BV(7), // D18 - A0 - PF7
_BV(6), // D19 - A1 - PF6
_BV(5), // D20 - A2 - PF5
_BV(4), // D21 - A3 - PF4
_BV(1), // D22 - A4 - PF1
_BV(0), // D23 - A5 - PF0
_BV(4), // D24 / D4 - A6 - PD4
_BV(7), // D25 / D6 - A7 - PD7
_BV(4), // D26 / D8 - A8 - PB4
_BV(5), // D27 / D9 - A9 - PB5
_BV(6), // D28 / D10 - A10 - PB6
_BV(6), // D29 / D12 - A11 - PD6
};
const uint8_t PROGMEM digital_pin_to_timer_PGM[16] = {
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
TIMER0B, /* 3 */
NOT_ON_TIMER,
TIMER3A, /* 5 */
TIMER4D, /* 6 */
NOT_ON_TIMER,
NOT_ON_TIMER,
TIMER1A, /* 9 */
TIMER1B, /* 10 */
TIMER0A, /* 11 */
NOT_ON_TIMER,
TIMER4A, /* 13 */
NOT_ON_TIMER,
NOT_ON_TIMER,
};
const uint8_t PROGMEM analog_pin_to_channel_PGM[12] = {
7, // A0 PF7 ADC7
6, // A1 PF6 ADC6
5, // A2 PF5 ADC5
4, // A3 PF4 ADC4
1, // A4 PF1 ADC1
0, // A5 PF0 ADC0
8, // A6 D4 PD4 ADC8
10, // A7 D6 PD7 ADC10
11, // A8 D8 PB4 ADC11
12, // A9 D9 PB5 ADC12
13, // A10 D10 PB6 ADC13
9 // A11 D12 PD6 ADC9
};
#endif /* ARDUINO_MAIN */
#endif /* Pins_Arduino_h */

View File

@@ -1,329 +0,0 @@
/*
pins_arduino.h - Pin definition functions for Arduino
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2007 David A. Mellis
ATmega*PB support jan 2018 by MCUdude
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <avr/pgmspace.h>
#define MINICORE
#define MCUDUDE_MINICORE
// Digital pins
#define NUM_DIGITAL_PINS (27)
// PWM pins
#if defined(__AVR_ATmega48PB__) || defined(__AVR_ATmega88PB__) || defined(__AVR_ATmega168PB__)
#define digitalPinHasPWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11)
#elif defined(__AVR_ATmega328PB__)
#define digitalPinHasPWM(p) ((p) == 0 || (p) == 1 || (p) == 2 ||(p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11)
#endif
// Builtin LED
#if !defined(LED_BUILTIN)
#define LED_BUILTIN (13)
#endif
static const uint8_t LED = LED_BUILTIN;
// Analog pins
#define PIN_A0 (14)
#define PIN_A1 (15)
#define PIN_A2 (16)
#define PIN_A3 (17)
#define PIN_A4 (18)
#define PIN_A5 (19)
#define PIN_A6 (25)
#define PIN_A7 (26)
static const uint8_t A0 = PIN_A0;
static const uint8_t A1 = PIN_A1;
static const uint8_t A2 = PIN_A2;
static const uint8_t A3 = PIN_A3;
static const uint8_t A4 = PIN_A4;
static const uint8_t A5 = PIN_A5;
static const uint8_t A6 = PIN_A6;
static const uint8_t A7 = PIN_A7;
#define NUM_ANALOG_INPUTS (8)
#define analogInputToDigitalPin(p) (((p) < 6) ? ((p) + 14) : (((p) < 8) ? ((p) + 19) : -1))
#define analogPinToChannel(p) ((p) < NUM_ANALOG_INPUTS ? (p) : ((p) >= 14 && (p) < 25) ? (p) - 14 : ((p) >= 25) ? (p) - 19 : -1)
// SPI
#define PIN_SPI_SS (10)
#define PIN_SPI_MOSI (11)
#define PIN_SPI_MISO (12)
#define PIN_SPI_SCK (13)
static const uint8_t SS = PIN_SPI_SS;
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;
#if defined(__AVR_ATmega328PB__)
#define PIN_SPI_SS0 PIN_SPI_SS
#define PIN_SPI_MOSI0 PIN_SPI_MOSI
#define PIN_SPI_MISO0 PIN_SPI_MISO
#define PIN_SPI_SCK0 PIN_SPI_SCK
#define PIN_SPI_SS1 (25)
#define PIN_SPI_MOSI1 (26)
#define PIN_SPI_MISO1 (14)
#define PIN_SPI_SCK1 (15)
static const uint8_t SS0 = PIN_SPI_SS0;
static const uint8_t MOSI0 = PIN_SPI_MOSI0;
static const uint8_t MISO0 = PIN_SPI_MISO0;
static const uint8_t SCK0 = PIN_SPI_SCK0;
static const uint8_t SS1 = PIN_SPI_SS1;
static const uint8_t MOSI1 = PIN_SPI_MOSI1;
static const uint8_t MISO1 = PIN_SPI_MISO1;
static const uint8_t SCK1 = PIN_SPI_SCK1;
#endif
// i2c
#define PIN_WIRE_SDA (18)
#define PIN_WIRE_SCL (19)
static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;
#if defined(__AVR_ATmega328PB__)
#define WIRE_INTERFACES_COUNT (2)
#define PIN_WIRE_SDA0 PIN_WIRE_SDA
#define PIN_WIRE_SCL0 PIN_WIRE_SCL
#define PIN_WIRE_SDA1 (23)
#define PIN_WIRE_SCL1 (24)
static const uint8_t SDA0 = PIN_WIRE_SDA0;
static const uint8_t SCL0 = PIN_WIRE_SCL0;
static const uint8_t SDA1 = PIN_WIRE_SDA1;
static const uint8_t SCL1 = PIN_WIRE_SCL1;
#endif
// Interrupts
#define EXTERNAL_NUM_INTERRUPTS (2)
#define digitalPinToInterrupt(p) ((p) == 2 ? 0 : ((p) == 3 ? 1 : NOT_AN_INTERRUPT))
// PCINT
#if defined(__AVR_ATmega48PB__) || defined(__AVR_ATmega88PB__) || defined(__AVR_ATmega168PB__)
#define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 22) ? (&PCICR) : ((uint8_t *)0))
#define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13 || (p) == 20 || (p) == 21) ? 0 : 1))
#define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 13 || (p) == 20 || (p) == 21) ? (&PCMSK0) : (((p) <= 22) ? (&PCMSK1) : ((uint8_t *)0))))
#define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) <= 21) ? ((p) - 14) : ((p) - 16)))
#elif defined(__AVR_ATmega328PB__)
#define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 26) ? (&PCICR) : ((uint8_t *)0))
#define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13 || (p) == 20 || (p) == 21) ? 0 : (((p) <= 22) ? 1 : 3)))
#define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 13 || (p) == 20 || (p) == 21) ? (&PCMSK0) : (((p) <= 22) ? (&PCMSK1) : (((p) <= 26) ? (&PCMSK3) : ((uint8_t *)0)))))
#define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) <= 21) ? ((p) - 14) : ((p) == 22) ? ((p) - 16) : ((p) - 23)))
#endif
#define PIN_PD0 0
#define PIN_PD1 1
#define PIN_PD2 2
#define PIN_PD3 3
#define PIN_PD4 4
#define PIN_PD5 5
#define PIN_PD6 6
#define PIN_PD7 7
#define PIN_PB0 8
#define PIN_PB1 9
#define PIN_PB2 10
#define PIN_PB3 11
#define PIN_PB4 12
#define PIN_PB5 13
#define PIN_PC0 14 // A0
#define PIN_PC1 15 // A1
#define PIN_PC2 16 // A2
#define PIN_PC3 17 // A3
#define PIN_PC4 18 // A4
#define PIN_PC5 19 // A5
#define PIN_PB6 20 // XTAL1
#define PIN_PB7 21 // XTAL2
#define PIN_PC6 22 // RESET
#define PIN_PE0 23
#define PIN_PE1 24
#define PIN_PE2 25 // A6
#define PIN_PE3 26 // A7
#ifdef ARDUINO_MAIN
// These arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
const uint16_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &DDRB,
(uint16_t) &DDRC,
(uint16_t) &DDRD,
(uint16_t) &DDRE,
};
const uint16_t PROGMEM port_to_output_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &PORTB,
(uint16_t) &PORTC,
(uint16_t) &PORTD,
(uint16_t) &PORTE,
};
const uint16_t PROGMEM port_to_input_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &PINB,
(uint16_t) &PINC,
(uint16_t) &PIND,
(uint16_t) &PINE,
};
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
PD, // PD0 - D0
PD, // PD1 - D1
PD, // PD2 - D2
PD, // PD3 - D3
PD, // PD4 - D4
PD, // PD5 - D5
PD, // PD6 - D6
PD, // PD7 - D7
PB, // PB0 - D8
PB, // PB1 - D9
PB, // PB2 - D10
PB, // PB3 - D11
PB, // PB4 - D12
PB, // PB5 - D13
PC, // PC0 - D14 / A0
PC, // PC1 - D15 / A1
PC, // PC2 - D16 / A2
PC, // PC3 - D17 / A3
PC, // PC4 - D18 / A4
PC, // PC5 - D19 / A5
PB, // PB6 - D20 / XTAL1
PB, // PB7 - D21 / XTAL2
PC, // PC6 - D22 / RESET
PE, // PE0 - D23
PE, // PE1 - D24
PE, // PE2 - D25 / A6
PE, // PE3 - D26 / A7
};
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
_BV(0), // PD0 - D0
_BV(1), // PD1 - D1
_BV(2), // PD2 - D2
_BV(3), // PD3 - D3
_BV(4), // PD4 - D4
_BV(5), // PD5 - D5
_BV(6), // PD6 - D6
_BV(7), // PD7 - D7
_BV(0), // PB0 - D8
_BV(1), // PB1 - D9
_BV(2), // PB2 - D10
_BV(3), // PB3 - D11
_BV(4), // PB4 - D12
_BV(5), // PB5 - D13
_BV(0), // PC0 - D14 / A0
_BV(1), // PC1 - D15 / A1
_BV(2), // PC2 - D16 / A2
_BV(3), // PC3 - D17 / A3
_BV(4), // PC4 - D18 / A4
_BV(5), // PC5 - D19 / A5
_BV(6), // PB6 - D20 / XTAL1
_BV(7), // PB7 - D21 / XTAL2
_BV(6), // PC6 - D22 / RESET
_BV(0), // PE0 - D23
_BV(1), // PE1 - D24
_BV(2), // PE2 - D25 / A6
_BV(3), // PE3 - D26 / A7
};
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
#if defined(__AVR_ATmega48PB__) || defined(__AVR_ATmega88PB__) || defined(__AVR_ATmega168PB__)
NOT_ON_TIMER, // PD0 - D0
NOT_ON_TIMER, // PD1 - D1
NOT_ON_TIMER, // PD2 - D2
#elif defined(__AVR_ATmega328PB__)
TIMER3A, // PD0 - D0
TIMER4A, // PD1 - D1
TIMER4B, // PD2 - D2 -> TIMER3B is also an option
#endif
TIMER2B, // PD3 - D3
NOT_ON_TIMER, // PD4 - D4
TIMER0B, // PD5 - D5
TIMER0A, // PD6 - D6
NOT_ON_TIMER, // PD7 - D7
NOT_ON_TIMER, // PB0 - D8
TIMER1A, // PB1 - D9
TIMER1B, // PB2 - D10
TIMER2A, // PB3 - D11
NOT_ON_TIMER, // PB4 - D12
NOT_ON_TIMER, // PB5 - D13
NOT_ON_TIMER, // PC0 - D14 / A0
NOT_ON_TIMER, // PC1 - D15 / A1
NOT_ON_TIMER, // PC2 - D16 / A2
NOT_ON_TIMER, // PC3 - D17 / A3
NOT_ON_TIMER, // PC4 - D18 / A4
NOT_ON_TIMER, // PC5 - D19 / A5
NOT_ON_TIMER, // PB6 - D20 / XTAL1
NOT_ON_TIMER, // PB7 - D21 / XTAL2
NOT_ON_TIMER, // PC6 - D22 / RESET
NOT_ON_TIMER, // PE0 - D23
NOT_ON_TIMER, // PE1 - D24
NOT_ON_TIMER, // PE2 - D25 / A6
NOT_ON_TIMER, // PE3 - D26 / A7
};
#endif // ARDUINO_MAIN
// Make sure the ATmega328PB is backwards compatible with the 328 and 328P
#if defined(__AVR_ATmega328PB__)
// SPI
#define SPCR SPCR0
#define SPSR SPSR0
#define SPDR SPDR0
#define SPI_STC_vect SPI0_STC_vect
#define SPI_STC_vect_num SPI0_STC_vect_num
// I2C
#define TWBR TWBR0
#define TWSR TWSR0
#define TWAR TWAR0
#define TWDR TWDR0
#define TWCR TWCR0
#define TWAMR TWAMR0
#define TWI_vect TWI0_vect
#define TWI_vect_num TWI0_vect_num
// UART
#define USART_RX_vect USART0_RX_vect
#define USART_RX_vect_num USART0_RX_vect_num
#define USART_UDRE_vect USART0_UDRE_vect
#define USART_UDRE_vect_num USART0_UDRE_vect_num
#define USART_TX_vect USART0_TX_vect
#define USART_TX_vect_num USART0_TX_vect_num
#endif // 328PB defs
// These serial port names are intended to allow libraries and architecture-neutral
// sketches to automatically default to the correct port name for a particular type
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
#define SERIAL_PORT_MONITOR Serial
#define SERIAL_PORT_HARDWARE Serial
#define SERIAL_PORT_HARDWARE_OPEN Serial
#if defined(__AVR_ATmega328PB__)
#define SERIAL_PORT_HARDWARE1 Serial1
#define SERIAL_PORT_HARDWARE_OPEN1 Serial1
#endif
#endif // Pins_Arduino_h

View File

@@ -1,311 +0,0 @@
/*
pins_arduino.h - Pin definition functions for Arduino
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2007 David A. Mellis
Edited july 2016 by MCUdude
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <avr/pgmspace.h>
#define MINICORE
#define MCUDUDE_MINICORE
// Definitions to make sure all variants will be supported
#if defined(__AVR_ATmega48__)
#define __AVR_ATMEGA48A__
#define __AVR_ATMEGA48P__
#define __AVR_ATMEGA48PA__
#elif defined(__AVR_ATmega48A__)
#define __AVR_ATMEGA48__
#define __AVR_ATMEGA48P__
#define __AVR_ATMEGA48PA__
#elif defined(__AVR_ATmega48P__)
#define __AVR_ATMEGA48__
#define __AVR_ATMEGA48A__
#define __AVR_ATMEGA48PA__
#elif defined(__AVR_ATmega48PA__)
#define __AVR_ATMEGA48__
#define __AVR_ATMEGA48A__
#define __AVR_ATMEGA48P__
#elif defined(__AVR_ATmega8__)
#define __AVR_ATMEGA8A__
#elif defined(__AVR_ATmega8A__)
#define __AVR_ATMEGA8__
#elif defined(__AVR_ATmega88__)
#define __AVR_ATMEGA88A__
#define __AVR_ATMEGA88P__
#define __AVR_ATMEGA88PA__
#elif defined(__AVR_ATmega88A__)
#define __AVR_ATMEGA88__
#define __AVR_ATMEGA88P__
#define __AVR_ATMEGA88PA__
#elif defined(__AVR_ATmega88P__)
#define __AVR_ATMEGA88__
#define __AVR_ATMEGA88A__
#define __AVR_ATMEGA88PA__
#elif defined(__AVR_ATmega88PA__)
#define __AVR_ATMEGA88__
#define __AVR_ATMEGA88A__
#define __AVR_ATMEGA88P__
#elif defined(__AVR_ATmega168__)
#define __AVR_ATMEGA168A__
#define __AVR_ATMEGA168P__
#define __AVR_ATMEGA168PA__
#elif defined(__AVR_ATmega168A__)
#define __AVR_ATMEGA168__
#define __AVR_ATMEGA168P__
#define __AVR_ATMEGA168PA__
#elif defined(__AVR_ATmega168P__)
#define __AVR_ATMEGA168__
#define __AVR_ATMEGA168A__
#define __AVR_ATMEGA168PA__
#elif defined(__AVR_ATmega168PA__)
#define __AVR_ATMEGA168__
#define __AVR_ATMEGA168A__
#define __AVR_ATMEGA168P__
#endif
// Digital pins
#define NUM_DIGITAL_PINS (23)
// PWM pins
#if defined(__AVR_ATmega8__)
#define digitalPinHasPWM(p) ((p) == 9 || (p) == 10 || (p) == 11)
#else
#define digitalPinHasPWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11)
#endif
// Builtin LED
#if !defined(LED_BUILTIN)
#define LED_BUILTIN (13)
#endif
static const uint8_t LED = LED_BUILTIN;
// Analog pins
#define PIN_A0 (14)
#define PIN_A1 (15)
#define PIN_A2 (16)
#define PIN_A3 (17)
#define PIN_A4 (18)
#define PIN_A5 (19)
#define PIN_A6 (6)
#define PIN_A7 (7)
static const uint8_t A0 = PIN_A0;
static const uint8_t A1 = PIN_A1;
static const uint8_t A2 = PIN_A2;
static const uint8_t A3 = PIN_A3;
static const uint8_t A4 = PIN_A4;
static const uint8_t A5 = PIN_A5;
static const uint8_t A6 = PIN_A6;
static const uint8_t A7 = PIN_A7;
#define NUM_ANALOG_INPUTS (8)
#define analogInputToDigitalPin(p) ((p < 6) ? (p) + 14 : -1)
#define analogPinToChannel(p) ((p) < NUM_ANALOG_INPUTS ? (p) : (p) >= 14 ? (p) - 14 : -1)
// SPI
#define PIN_SPI_SS (10)
#define PIN_SPI_MOSI (11)
#define PIN_SPI_MISO (12)
#define PIN_SPI_SCK (13)
static const uint8_t SS = PIN_SPI_SS;
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;
// i2c
#define PIN_WIRE_SDA (18)
#define PIN_WIRE_SCL (19)
static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;
// Interrupts
#define EXTERNAL_NUM_INTERRUPTS (2)
#define digitalPinToInterrupt(p) ((p) == 2 ? 0 : ((p) == 3 ? 1 : NOT_AN_INTERRUPT))
// PCINT
#if !defined(__AVR_ATmega8__)
#define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 22) ? (&PCICR) : ((uint8_t *)0))
#define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : (((p) <= 19) ? 1 : (((p) <= 21) ? 0 : -1))))
#define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 19) ? (&PCMSK1) : (((p) <= 21) ? (&PCMSK0) : (((p) <= 22) ? (&PCMSK1) : ((uint8_t *)0))))))
#define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : (((p) <= 21) ? ((p) - 14) : (((p) <= 22) ? ((p) - 16) : -1))))
#endif
#define PIN_PD0 0
#define PIN_PD1 1
#define PIN_PD2 2
#define PIN_PD3 3
#define PIN_PD4 4
#define PIN_PD5 5
#define PIN_PD6 6
#define PIN_PD7 7
#define PIN_PB0 8
#define PIN_PB1 9
#define PIN_PB2 10
#define PIN_PB3 11
#define PIN_PB4 12
#define PIN_PB5 13
#define PIN_PC0 14 // A0
#define PIN_PC1 15 // A1
#define PIN_PC2 16 // A2
#define PIN_PC3 17 // A3
#define PIN_PC4 18 // A4
#define PIN_PC5 19 // A5
#define PIN_PB6 20 // XTAL1
#define PIN_PB7 21 // XTAL2
#define PIN_PC6 22 // RESET
#ifdef ARDUINO_MAIN
// These arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
const uint16_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &DDRB,
(uint16_t) &DDRC,
(uint16_t) &DDRD,
};
const uint16_t PROGMEM port_to_output_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &PORTB,
(uint16_t) &PORTC,
(uint16_t) &PORTD,
};
const uint16_t PROGMEM port_to_input_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &PINB,
(uint16_t) &PINC,
(uint16_t) &PIND,
};
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
PD, // PD0 - D0
PD, // PD1 - D1
PD, // PD2 - D2
PD, // PD3 - D3
PD, // PD4 - D4
PD, // PD5 - D5
PD, // PD6 - D6
PD, // PD7 - D7
PB, // PB0 - D8
PB, // PB1 - D9
PB, // PB2 - D10
PB, // PB3 - D11
PB, // PB4 - D12
PB, // PB5 - D13
PC, // PC0 - D14 / A0
PC, // PC1 - D15 / A1
PC, // PC2 - D16 / A2
PC, // PC3 - D17 / A3
PC, // PC4 - D18 / A4
PC, // PC5 - D19 / A5
PB, // PB6 - D20 / XTAL1
PB, // PB7 - D21 / XTAL2
PC, // PC6 - D22 / RESET
};
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
_BV(0), // PD0 - D0
_BV(1), // PD1 - D1
_BV(2), // PD2 - D2
_BV(3), // PD3 - D3
_BV(4), // PD4 - D4
_BV(5), // PD5 - D5
_BV(6), // PD6 - D6
_BV(7), // PD7 - D7
_BV(0), // PB0 - D8
_BV(1), // PB1 - D9
_BV(2), // PB2 - D10
_BV(3), // PB3 - D11
_BV(4), // PB4 - D12
_BV(5), // PB5 - D13
_BV(0), // PC0 - D14 / A0
_BV(1), // PC1 - D15 / A1
_BV(2), // PC2 - D16 / A2
_BV(3), // PC3 - D17 / A3
_BV(4), // PC4 - D18 / A4
_BV(5), // PC5 - D19 / A5
_BV(6), // PB6 - D20 / XTAL1
_BV(7), // PB7 - D21 / XTAL2
_BV(6), // PC6 - D22 / RESET
};
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
NOT_ON_TIMER, /* 0 - port D */
NOT_ON_TIMER,
NOT_ON_TIMER,
#if defined(__AVR_ATmega8__)
NOT_ON_TIMER,
#else
TIMER2B,
#endif
NOT_ON_TIMER,
#if defined(__AVR_ATmega8__)
NOT_ON_TIMER,
NOT_ON_TIMER,
#else
TIMER0B,
TIMER0A,
#endif
NOT_ON_TIMER,
NOT_ON_TIMER, /* 8 - port B */
TIMER1A,
TIMER1B,
#if defined(__AVR_ATmega8__)
TIMER2,
#else
TIMER2A,
#endif
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER, /* 14 - port C */
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER, // PB6 - D20 / XTAL1
NOT_ON_TIMER, // PB7 - D21 / XTAL2
NOT_ON_TIMER, // PC6 - D22 / RESET
};
#endif
// These serial port names are intended to allow libraries and architecture-neutral
// sketches to automatically default to the correct port name for a particular type
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
#define SERIAL_PORT_MONITOR Serial
#define SERIAL_PORT_HARDWARE Serial
#define SERIAL_PORT_HARDWARE_OPEN Serial
#endif

View File

@@ -1,126 +0,0 @@
/*
pins_arduino.c - pin definitions for the Arduino board
Part of Arduino / Wiring Lite
Copyright (c) 2005 David A. Mellis
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: pins_arduino.c 565 2009-03-25 10:50:00Z dmellis $
Modified 28-08-2009 for attiny84 R.Wiersma
Modified 09-10-2009 for attiny45 A.Saporetti
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <avr/pgmspace.h>
// ATMEL ATTINY45 / ARDUINO
//
// +-\/-+
// Ain0 (D 5) PB5 1| |8 Vcc
// Ain3 (D 3) PB3 2| |7 PB2 (D 2) Ain1
// Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1
// GND 4| |5 PB0 (D 0) pwm0
// +----+
static const uint8_t A0 = 6;
static const uint8_t A1 = 7;
static const uint8_t A2 = 8;
static const uint8_t A3 = 9;
#define digitalPinToPCICR(p) ( ((p) >= 0 && (p) <= 4) ? (&GIMSK) : ((uint8_t *)0) )
#define digitalPinToPCICRbit(p) ( PCIE )
#define digitalPinToPCMSK(p) ( ((p) <= 4) ? (&PCMSK) : ((uint8_t *)0) )
#define digitalPinToPCMSKbit(p) ( (p) )
#define analogPinToChannel(p) ( (p) < 6 ? (p) : (p) - 6 )
#define TCCR1A GTCCR
#ifdef ARDUINO_MAIN
void initVariant()
{
GTCCR |= (1 << PWM1B);
}
// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing) tiny45 only port B
const uint16_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &DDRB,
};
const uint16_t PROGMEM port_to_output_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &PORTB,
};
const uint16_t PROGMEM port_to_input_PGM[] = {
NOT_A_PIN,
NOT_A_PIN,
(uint16_t) &PINB,
};
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
PB, /* 0 */
PB,
PB,
PB,
PB,
PB, // 5
PB, // A0
PB,
PB,
PB, // A4
};
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
_BV(0), /* 0, port B */
_BV(1),
_BV(2),
_BV(3), /* 3 port B */
_BV(4),
_BV(5),
_BV(5),
_BV(2),
_BV(4),
_BV(3),
};
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
TIMER0A, /* OC0A */
TIMER0B,
NOT_ON_TIMER,
NOT_ON_TIMER,
TIMER1B,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
};
#endif
#endif

View File

@@ -1,384 +0,0 @@
/* pins_arduino.h - Pin definition functions for ATTinyCore
Part of ATTinyCore - github.com/SpenceKonde/ATTinyCore
Copyright (c) 2015~2021 Spence Konde, (c) 2007 David A. Mellis
Free Software - LGPL 2.1, please see LICENCE.md for details */
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <avr/pgmspace.h>
/*===========================================================================
* Microchip ATtiny88, ATtiny48
*===========================================================================
* ATTinyCore Standard Pin Mapping
* Similar to Uno et. al. pin mapping, use this unless working with an
* MH-ET/MH-Tiny board, which have a different numbering scheme.
*---------------------------------------------------------------------------*/
#define ATTINYX8 1 // backwards compatibility
#define __AVR_ATtinyX8__ // recommended
#define NUM_DIGITAL_PINS (28)
#define NUM_ANALOG_INPUTS (8)
/* Basic Pin Numbering - PIN_Pxn notation is always recommended
* as it is totally unambiguous, but numbers may be used too */
#define PIN_PD0 ( 0)
#define PIN_PD1 ( 1)
#define PIN_PD2 ( 2)
#define PIN_PD3 ( 3)
#define PIN_PD4 ( 4)
#define PIN_PD5 ( 5)
#define PIN_PD6 ( 6)
#define PIN_PD7 ( 7)
#define PIN_PB0 ( 8)
#define PIN_PB1 ( 9)
#define PIN_PB2 (10)
#define PIN_PB3 (11)
#define PIN_PB4 (12)
#define PIN_PB5 (13)
#define PIN_PB6 (14)
#define PIN_PB7 (15)
#define PIN_PC7 (16)
#define PIN_PC0 (17)
#define PIN_PC1 (18)
#define PIN_PC2 (19)
#define PIN_PC3 (20)
#define PIN_PC4 (21)
#define PIN_PC5 (22)
#define PIN_PA0 (23)
#define PIN_PA1 (24)
#define PIN_PA2 (25)
#define PIN_PA3 (26)
#define PIN_PC6 (27)
#ifndef LED_BUILTIN
#define LED_BUILTIN (PIN_PB5)
#endif
/* PIN_An is the digital pin with analog channel An on it. */
#define PIN_A0 (PIN_PC0)
#define PIN_A1 (PIN_PC1)
#define PIN_A2 (PIN_PC2)
#define PIN_A3 (PIN_PC3)
#define PIN_A4 (PIN_PC4)
#define PIN_A5 (PIN_PC5)
#define PIN_A6 (PIN_PA0)
#define PIN_A7 (PIN_PA1)
/* The "analog pins" of the form An, where n is a number map directly to
* analog channels of the same number. Except on Digispark Pro pin mapping.
*---------------------------------------------------------------------------*/
static const uint8_t A0 = ADC_CH(0);
static const uint8_t A1 = ADC_CH(1);
static const uint8_t A2 = ADC_CH(2);
static const uint8_t A3 = ADC_CH(3);
static const uint8_t A4 = ADC_CH(4);
static const uint8_t A5 = ADC_CH(5);
static const uint8_t A6 = ADC_CH(6);
static const uint8_t A7 = ADC_CH(7);
/* Interrupt macros to go from pin to PCMSK register and bit within it, and
* the register to enable/disable banks of PCINTs, and bit within it PCICR
* is almost always the same for all PCINTs; but must return null pointer
* if the pin is invalid. The PCICRbit and PCMSK are almost always directly
* mapped to port; particularly on ugly mappings like this, taking advantage
* of this is more efficient and easier to write.
* digitalPinToInterrupt gets the number of the "full service" pin interrupt
*---------------------------------------------------------------------------*/
#define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 26) ? (&PCICR) : ((uint8_t *)0))
#define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 15) ? 0 : (((p) <= 22) ? 1 : 3)))
#define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 15) ? (&PCMSK0) : (((p) <= 22) ? (&PCMSK1) : (((p) <= 26) ? (&PCMSK3) : ((uint8_t *)0)))))
#define digitalPinToPCMSKbit(p) (((p) <= 15) ? ((p)& 0x7) : (((p) == 16) ? (7) : (((p) <= 22) ? ((p) - 17) : ((p) - 23))))
#define digitalPinToInterrupt(p) ((p) == 2 ? 0 : ((p)==3?1: NOT_AN_INTERRUPT))
/* Analog Channel <-> Digital Pin macros */
#define analogInputToDigitalPin(p) (((p) < 8) ? (p) + 17 : -1);
#define digitalPinToAnalogInput(p) ((p) >= 16 && (p) <= 22) ? ((p)-17):NOT_A_PIN;
/* Which pins have PWM? */
#define digitalPinHasPWM(p) ((p) == 9 || (p) == 10)
#define PINMAPPING_NORMAL
/*---------------------------------------------------------------------------
* Core Configuration where these are not the defaults
*---------------------------------------------------------------------------*/
// Choosing not to initialise saves flash. 1 = initialise.
// #define DEFAULT_INITIALIZE_ADC 1
// #define DEFAULT_INITIALIZE_SECONDARY_TIMERS 1
/* Builtin Software Serial "Serial"
* TX is on AIN0, RX is on AIN1. Comparator interrupt used so PCINTs remain
* available for other uses. Comparator pins in Analog section below. */
#define USE_SOFTWARE_SERIAL 1
/*---------------------------------------------------------------------------
* Chip Features - Timers amnd PWM
*---------------------------------------------------------------------------
* Basic PWM is covered elsewhere, but this lets you look up what pin is on
* a given compare channel easily. Used to generate some pinmapping independent
* defines for TimerOne library back in Arduino.h
*
* Functions of timers associated with pins have pins specified by macros of
* the form PIN_TIMER_ followed by the function.
*
* PWM_CHANNEL_REMAPPING is defined and true where the PWM channels from timers
* has additional non-standard behavior allowing the remapping of output from
* otherwise normal pins (and interfering with naive code that enables them,
* though if the code acts only on the timer registers, it will often work if
* user code calls analogWrite() on the pin before letting the library use it.
* Where this is not the case, it is not defined.
*
* TIMER0_TYPICAL is 1 if that timer is present, and is an 8-bit timer with or
* without two output compare channels. PIN_TIMER_OC0A/OC0B will be defined if
* it has them.
*
* TIMER1_TYPICAL is 1 if that timer is present, and is a 16-bit timer with PWM
* as opposed to some bizarro one like the 85 and 861 have.
*
* TIMER2_TYPICAL is 1 if that timer is present, and is an 8-bit asynch timer,
* like on classic ATmega parts. There is only one ATTinyCore part with a
* Timer2, and this is false there, because that timer is instead like Timer1.
*
* We do not provide further macros to characterize the type of a timer in more
* detail but the sheer variety of atypical timers on classic AVRs made it hard
* to derive a quick test of whether the normal stuff will work.
*---------------------------------------------------------------------------*/
/* Timer 0 - 8-bit timer without PWM */
#define TIMER0_TYPICAL (1)
#define PIN_TIMER_T0 (PIN_PD4)
/* Timer 1 - 16-bit timer with PWM */
#define TIMER1_TYPICAL (1)
#define PIN_TIMER_OC1A (PIN_PB1)
#define PIN_TIMER_OC1B (PIN_PB2)
#define PIN_TIMER_T1 (PIN_PD5)
#define PIN_TIMER_ICP1 (PIN_PB0)
/*---------------------------------------------------------------------------
* Chip Features (or lack thereof) - Analog stuff
*---------------------------------------------------------------------------
* Analog reference constants are pre-shifted to their final position in the
* registers to avoid leftshifting at runtime, which is surprisingly slow and
* wasteful of flash.
*---------------------------------------------------------------------------*/
#define ADC_REF(x) (x << 6)
/* Analog reference bit masks. */
#define DEFAULT ADC_REF(1)
#define INTERNAL1V1 ADC_REF(0)
#define INTERNAL INTERNAL1V1 /* deprecated */
/* Special Analog Channels */
#define ADC_TEMPERATURE ADC_CH(0x08)
#define ADC_INTERNAL1V1 ADC_CH(0x0E)
#define ADC_GROUND ADC_CH(0x0F)
/* Not a differential ADC *
* single ended channels only */
/* Analog Comparator - used for soft-serial*/
#define ANALOG_COMP_DDR DDRD
#define ANALOG_COMP_PORT PORTD
#define ANALOG_COMP_PIN PIND
#define ANALOG_COMP_AIN0_BIT (6)
#define ANALOG_COMP_AIN1_BIT (7)
/*---------------------------------------------------------------------------
* Chip Features - SPI, I2C, USART, etc
*---------------------------------------------------------------------------*/
/* This part has a real SPI module and a real master/slave TWI module
* You may not get decent on-chip peripherals, but you can at least effectively
* talk to off-chip ones! Seems like it's meant to be a replacement for cost
* optimizing designs that don't need any of the expensive features, which
* covers a lot of use cases. Reimplementing something to use a USI instead of
* a real SPI or TWI interface is not for the faint of heart. Nor really anyone
* who isn't a digital masochist - unlike reimplementing things in assembly,
* using the USI is never illuminating, but is every bit as annoying.
*---------------------------------------------------------------------------*/
/* Hardware SPI */
#define SS PIN_PB2
#define MOSI PIN_PB3
#define MISO PIN_PB4
#define SCK PIN_PB5
/* Hardware TWI */
#define SDA PIN_PC4
#define SCL PIN_PC5
#ifdef ARDUINO_MAIN
/*---------------------------------------------------------------------------
* ATMEL ATTINY88/48 ATTinyCore Standard Pin Mapping
*
* +-\/-+
* (27) PC6 1 | |28 PC5 (22)
* ( 0) PD0 2 | |27 PC4 (21)
* ( 1) PD1 3 | |26 PC3 (20)
* ( 2) PD2 4 | |25 PC2 (19)
* ( 3) PD3 5 | |24 PC1 (18)
* ( 4) PD4 6 | |23 PC0 (17)
* VCC 7 | |22 GND
* GND 8 | |21 PC7 (16)
* (14) PB6 9 | |20 AVCC
* (15) PB7 10| |19 PB5 (13)
* ( 5) PD5 11| |18 PB4 (12)
* ( 6) PD6 12| |17 PB3 (11)
* ( 7) PD7 13| |16 PB2 (10) PWM
* ( 8) PB0 14| |15 PB1 ( 9) PWM
* +----+
*
*
* ( 2) ( 0) (22) (20)
* (A5) (A3)
* ( 1) (27) (21) (19)
* (A4) (A2)
* PD2 PD0 PC5 PC3
* PD1 PC6 PC4 PC2
* 32 30 28 26
* 31 29 27 25
* ┌ ─ ─ ─ ─ ─ ─ ─ ─ ┐
* (3 ) PD3 1 |° | 24 PC1 (18/A1)
* (4 ) PD4 2 | | 23 PC0 (17/A0)
* (25) PA2 3 | ATtiny88 | 22 PA1 (24/A7)
* VCC 4 | | 21 GND
* GND 5 | | 20 PC7 (16)
* (26) PA3 6 | | 19 PA0 (23/A6)
* (14) PB6 7 | | 18 AVCC
* (15) PB7 8 | | 17 PB5 (13)
* └ ─ ─ ─ ─ ─ ─ ─ ─ ┘
* 9 11 13 15
* 10 12 14 16
* PD5 PD7 PB1 PB3
* PD6 PB0 PB2 PB4
* ( 5) ( 7) ( 9) (11)
* ( 6) ( 8) (10) (12)
* PWM
* PWM
*---------------------------------------------------------------------------*/
const uint8_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT,
(uint8_t)(uint16_t) &DDRA,
(uint8_t)(uint16_t) &DDRB,
(uint8_t)(uint16_t) &DDRC,
(uint8_t)(uint16_t) &DDRD,
};
const uint8_t PROGMEM port_to_output_PGM[] = {
NOT_A_PORT,
(uint8_t)(uint16_t) &PORTA,
(uint8_t)(uint16_t) &PORTB,
(uint8_t)(uint16_t) &PORTC,
(uint8_t)(uint16_t) &PORTD,
};
const uint8_t PROGMEM port_to_input_PGM[] = {
NOT_A_PORT,
(uint8_t)(uint16_t) &PINA,
(uint8_t)(uint16_t) &PINB,
(uint8_t)(uint16_t) &PINC,
(uint8_t)(uint16_t) &PIND,
};
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
PD, /* 0 */
PD,
PD,
PD,
PD,
PD,
PD,
PD,
PB, /* 8 */
PB,
PB,
PB,
PB,
PB,
PB,
PB,
PC, /* 16 */
PC,
PC,
PC,
PC,
PC,
PC,
PA, /* 23 */
PA,
PA,
PA,
PC
};
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
_BV(0), /* 0, port D */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(0), /* 8, port B */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(7), /* 16, port C */
_BV(0),
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(0), /* 23, port A */
_BV(1),
_BV(2),
_BV(3),
_BV(6)
};
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
NOT_ON_TIMER, /* 0 - port D */
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER, /* 8 - port B */
TIMER1A,
TIMER1B,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER, /* 16 - port C */
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER, /* 23 - port A */
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER
};
#endif
#endif

View File

@@ -1,372 +0,0 @@
/* pins_arduino.h - Pin definition functions for ATTinyCore
Part of ATTinyCore - github.com/SpenceKonde/ATTinyCore
Copyright (c) 2015~2021 Spence Konde, (c) 2007 David A. Mellis
Free Software - LGPL 2.1, please see LICENCE.md for details */
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <avr/pgmspace.h>
/*===========================================================================
* Microchip ATtiny88, ATtiny48
*===========================================================================
* MH-ET/MH-Tiny Pin Mapping
* The MH-Tiny VUSB board based on the ATtiny88 uses an external 16 MHz clock
* (so PB6 is out of the picture as far as I/O goes), numbers the pins up to
* that the same way as an Uno or the standard Tiny88 mapping. After that
* though, it's very different. Use this pinout if you're using one of those
* boards, otherwise use standard.
*---------------------------------------------------------------------------*/
#define ATTINYX8 1 // backwards compatibility
#define __AVR_ATtinyX8__ // recommended
#define NUM_DIGITAL_PINS (27)
#define NUM_ANALOG_INPUTS (8)
/* Basic Pin Numbering - PIN_Pxn notation is always recommended
* as it is totally unambiguous, but numbers may be used too */
#define PIN_PD0 ( 0)
#define PIN_PD1 ( 1)
#define PIN_PD2 ( 2)
#define PIN_PD3 ( 3)
#define PIN_PD4 ( 4)
#define PIN_PD5 ( 5)
#define PIN_PD6 ( 6)
#define PIN_PD7 ( 7)
#define PIN_PB0 ( 8)
#define PIN_PB1 ( 9)
#define PIN_PB2 (10)
#define PIN_PB3 (11)
#define PIN_PB4 (12)
#define PIN_PB5 (13)
// PIN_PB6 is the CLKI pin, which is not available on the MH-Tiny
// because they use an external 16 MHz clock.
#define PIN_PB7 (14)
#define PIN_PA2 (15) /* Wait what? There's a reason */
#define PIN_PA3 (16) /* PA0 and PA1 have ADC, and they */
#define PIN_PA0 (17) /* wanted to keep the ADC pins together */
#define PIN_PA1 (18) /* but also keep the ports together, so */
#define PIN_PC0 (19) /* they didn't want to put PORTA after */
#define PIN_PC1 (20) /* the first 6 PORTC pins, since PC7 */
#define PIN_PC2 (21) /* would then be on the other side of it */
#define PIN_PC3 (22)
#define PIN_PC4 (23)
#define PIN_PC5 (24)
#define PIN_PC7 (25)
#define PIN_PC6 (26) /* PC6 is reset; convention is to number reset last. */
/* The t88 removed a Vcc/Gnd pair and the dedicated AREF pin, as compaared to
* the mega x8-series, and made the last two ADC channels into real pins
* on a new port. The pins that replaced the Vcc/Gnd pair joined those two
* in the newly created half-size PORTA, while the AREF pin became the
* final bit of PORTC.
*/
#ifndef LED_BUILTIN
#define LED_BUILTIN (PIN_PD0)
#endif
/* PIN_An is the digital pin with analog channel An on it. */
#define PIN_A0 (PIN_PC0)
#define PIN_A1 (PIN_PC1)
#define PIN_A2 (PIN_PC2)
#define PIN_A3 (PIN_PC3)
#define PIN_A4 (PIN_PC4)
#define PIN_A5 (PIN_PC5)
#define PIN_A6 (PIN_PA0)
#define PIN_A7 (PIN_PA1)
/* An "analog pins" these map directly to analog channels */
static const uint8_t A0 = ADC_CH(0);
static const uint8_t A1 = ADC_CH(1);
static const uint8_t A2 = ADC_CH(2);
static const uint8_t A3 = ADC_CH(3);
static const uint8_t A4 = ADC_CH(4);
static const uint8_t A5 = ADC_CH(5);
static const uint8_t A6 = ADC_CH(6);
static const uint8_t A7 = ADC_CH(7);
/* Interrupt macros to go from pin to PCMSK register and bit within it, and
* the register to enable/disable banks of PCINTs, and bit within it PCICR
* is almost always the same for all PCINTs; but must return null pointer
* if the pin is invalid. The PCICRbit and PCMSK are almost always directly
* mapped to port; particularly on ugly mappings like this, taking advantage
* of this is more efficient and easier to write.
* digitalPinToInterrupt gets the number of the "full service" pin interrupt
*---------------------------------------------------------------------------*/
#define digitalPinToPCICR(p) (&PCICR)
/* PORTD: PORTB (PB6 is osc, skipped in pin #'s PORTA - numbered PA2, PA3, PA0, PA1 see above note PORTC */
#define digitalPinToPCICRbit(p) (((p) <= 7) ? PCIE2 : (((p) <= 14) ? PCIE0 : (((p) <= 18) ? PCIE3 : PCIE1)))
#define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 14) ? (&PCMSK0) : (((p) <= 18) ? (&PCMSK3) : (&PCMSK1))))
#define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : (((p) == 14) ? 7 : (((p) <= 16) ? ((p) - 14) : (((p) <= 18) ? ((p) - 17) : (((p) == 25) ? 7 : ((p) - 19)))))))
#define digitalPinToInterrupt(p) ((p) == 2 ? 0 : ((p) == 3 ? 1: NOT_AN_INTERRUPT))
/* Analog Channel <-> Digital Pin macros */
#define analogInputToDigitalPin(p) (((p) < 8) ? (((p) < 6) ? (p) + 11 :(p) + 19 ): NOT_A_PIN)
#define digitalPinToAnalogInput(p) ((p) < 25 ? (((p) > 18) ? ((p) - 19) : (((p) > 16) ? ((p) - 11) : NOT_A_PIN)) : NOT_A_PIN)
/* Which pins have PWM? */
#define digitalPinHasPWM(p) ((p) == 9 || (p) == 10)
#define PINMAPPING_MHTINY
/*---------------------------------------------------------------------------
* Core Configuration where these are not the defaults
*---------------------------------------------------------------------------*/
// Choosing not to initialise saves flash. 1 = initialise.
// #define DEFAULT_INITIALIZE_ADC 1
// #define DEFAULT_INITIALIZE_SECONDARY_TIMERS 1
/* Builtin Software Serial "Serial"
* TX is on AIN0, RX is on AIN1. Comparator interrupt used so PCINTs remain
* available for other uses. Comparator pins in Analog section below. */
#define USE_SOFTWARE_SERIAL 1
/*---------------------------------------------------------------------------
* Chip Features - Timers amnd PWM
*---------------------------------------------------------------------------
* Basic PWM is covered elsewhere, but this lets you look up what pin is on
* a given compare channel easily. Used to generate some pinmapping independent
* defines for TimerOne library back in Arduino.h
*
* Functions of timers associated with pins have pins specified by macros of
* the form PIN_TIMER_ followed by the function.
*
* PWM_CHANNEL_REMAPPING is defined and true where the PWM channels from timers
* has additional non-standard behavior allowing the remapping of output from
* otherwise normal pins (and interfering with naive code that enables them,
* though if the code acts only on the timer registers, it will often work if
* user code calls analogWrite() on the pin before letting the library use it.
* Where this is not the case, it is not defined.
*
* TIMER0_TYPICAL is 1 if that timer is present, and is an 8-bit timer with or
* without two output compare channels. PIN_TIMER_OC0A/OC0B will be defined if
* it has them.
*
* TIMER1_TYPICAL is 1 if that timer is present, and is a 16-bit timer with PWM
* as opposed to some bizarro one like the 85 and 861 have.
*
* TIMER2_TYPICAL is 1 if that timer is present, and is an 8-bit asynch timer,
* like on classic ATmega parts. There is only one ATTinyCore part with a
* Timer2, and this is false there, because that timer is instead like Timer1.
*
* We do not provide further macros to characterize the type of a timer in more
* detail but the sheer variety of atypical timers on classic AVRs made it hard
* to derive a quick test of whether the normal stuff will work.
*---------------------------------------------------------------------------*/
/* Timer 0 - 8-bit timer without PWM */
#define TIMER0_TYPICAL (1)
#define PIN_TIMER_T0 (PIN_PD4)
/* Timer 1 - 16-bit timer with PWM */
#define TIMER1_TYPICAL (1)
#define PIN_TIMER_OC1A (PIN_PB1)
#define PIN_TIMER_OC1B (PIN_PB2)
#define PIN_TIMER_T1 (PIN_PD5)
#define PIN_TIMER_ICP1 (PIN_PB0)
/*---------------------------------------------------------------------------
* Chip Features (or lack thereof) - Analog stuff
*---------------------------------------------------------------------------
* Analog reference constants are pre-shifted to their final position in the
* registers to avoid leftshifting at runtime, which is surprisingly slow and
* wasteful of flash.
*---------------------------------------------------------------------------*/
#define ADC_REF(x) (x << 6)
/* Analog reference bit masks. */
#define DEFAULT ADC_REF(1)
#define INTERNAL1V1 ADC_REF(0)
#define INTERNAL INTERNAL1V1 /* deprecated */
/* Special Analog Channels */
#define ADC_TEMPERATURE ADC_CH(0x08)
#define ADC_INTERNAL1V1 ADC_CH(0x0E)
#define ADC_GROUND ADC_CH(0x0F)
/* Not a differential ADC */
/* Analog Comparator - used for soft-serial*/
#define ANALOG_COMP_DDR DDRD
#define ANALOG_COMP_PORT PORTD
#define ANALOG_COMP_PIN PIND
#define ANALOG_COMP_AIN0_BIT (6)
#define ANALOG_COMP_AIN1_BIT (7)
/*---------------------------------------------------------------------------
* Chip Features - SPI, I2C, USART, etc
*---------------------------------------------------------------------------*/
/* This part has a real SPI module and a real master/slave TWI module
* You may not get decent on-chip peripherals, but you can at least effectively
* talk to off-chip ones! Seems like it's meant to be a replacement for cost
* optimizing designs that don't need any of the expensive features, which
* covers a lot of use cases. Reimplementing something to use a USI instead of
* a real SPI or TWI interface is not for the faint of heart. Nor really anyone
* who isn't a digital masochist - unlike reimplementing things in assembly,
* using the USI is never illuminating, but is every bit as annoying.
*---------------------------------------------------------------------------*/
/* Hardware SPI */
#define SS PIN_PB2
#define MOSI PIN_PB3
#define MISO PIN_PB4
#define SCK PIN_PB5
/* Hardware TWI */
#define SDA PIN_PC4
#define SCL PIN_PC5
#ifdef ARDUINO_MAIN
/*---------------------------------------------------------------------------
* ATMEL ATTINY88 MH-ET / MH-Tiny Pin Mapping
*
* ( 2) ( 0) (24/ (22/
* /A5) /A3)
* ( 1) (26) (23/ (21/
* /RST /A4) /A2)
* PD2 PD0 PC5 PC3
* PD1 PC6 PC4 PC2
* 32 30 28 26
* 31 29 27 25
* ┌ ─ ─ ─ ─ ─ ─ ─ ─ ┐
* ( 3) PD3 1 |° | 24 PC1 (20/A1)
* ( 4) PD4 2 | | 23 PC0 (19/A0)
* (17) PA2 3 | ATtiny88 | 22 PA1 (16/A7)
* VCC 4 | on | 21 GND
* GND 5 | "MH-ET" or "MH-tiny" | 20 PC7 (25)
* (18) PA3 6 | board | 19 PA0 (15/A6)
* CLKIN PB6 7 | | 18 AVCC
* (14) PB7 8 | | 17 PB5 (13)
* └ ─ ─ ─ ─ ─ ─ ─ ─ ┘
* 9 11 13 15
* 10 12 14 16
* PD5 PD7 PB1 PB3
* PD6 PB0 PB2 PB4
* ( 5) ( 7) ( 9) (11)
* ( 6) ( 8) (10) (12)
*
* PWM on pins 9 and 10 only.
*---------------------------------------------------------------------------*/
const uint8_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT,
(uint16_t) &DDRA,
(uint16_t) &DDRB,
(uint16_t) &DDRC,
(uint16_t) &DDRD,
};
const uint8_t PROGMEM port_to_output_PGM[] = {
NOT_A_PORT,
(uint16_t) &PORTA,
(uint16_t) &PORTB,
(uint16_t) &PORTC,
(uint16_t) &PORTD,
};
const uint8_t PROGMEM port_to_input_PGM[] = {
NOT_A_PORT,
(uint16_t) &PINA,
(uint16_t) &PINB,
(uint16_t) &PINC,
(uint16_t) &PIND,
};
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
PD, /* 0 */
PD,
PD,
PD,
PD,
PD,
PD,
PD,
PB, /* 8 */
PB,
PB,
PB,
PB,
PB,
// /* no PB6 */
PB,
PA, /* 15 */
PA,
PA,
PA,
PC,
PC,
PC,
PC,
PC,
PC,
PC,
PC
};
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
_BV(0), /* 0, port D */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(0), /* 8, port B */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
// /* no PB6 */
_BV(7),
_BV(2),
_BV(3),
_BV(0),
_BV(1),
_BV(0),
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(7),
_BV(6)
};
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
TIMER1A,
TIMER1B,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER
};
#endif
#endif

326
PsNeeV6.ino Normal file
View File

@@ -0,0 +1,326 @@
// PPPPPPPPPPPPPPPP P P
// P P PP P
// P P P P P
// P P P P P
// P P P P P
// P P P P P
// P P P P P
// PPPPPPPPPPPPPPPP PPPPPPPPPPP P P P PPPPPPPPPPP PPPPPPPPPPP
// P P P P P P P
// P P P P P P P
// P P P P P P P
// P P P P P P P
// P PPPPPPPPPPPPPP P PP PPPPPPP PPPPPPP
// P P P P P P
// P P P P P P
// P P P P P P
// P P P P P P
// P P P P P P
// P P P P P P
// PPPPPPPPPPPP P P PPPPPPPPPPP PPPPPPPPPPP VERSION 6!
//UPDATED AT MAY 14 2016, CODED BY THE FRIENDLY FRIETMAN :-)
//PsNee, an open source stealth modchip for the Sony Playstation 1, usable on
//all platforms supported by Arduino, preferably ATTiny. Finally something modern!
//--------------------------------------------------
// TL;DR
//--------------------------------------------------
//Look for the "Arduino selection!" section and verify the target platform. Hook up your target device and hit Upload!
//BEWARE: when using ATTiny45, make sure the proper device is selected (Extra=>Board=>ATTiny45 (internal 8MHz clock))
//and the proper fuses are burnt (use Extra=>Burn bootloader for this), otherwise PsNee will malfunction. A tutorial on
//uploading Arduino code via an Arduino Uno to an ATTiny device: http://highlowtech.org/?p=1695
//Look at the pinout for your device and hook PsNee up to the points on your Playstation.
//--------------------------------------------------
// General info!
//--------------------------------------------------
//PLAYSTATION 1 SECURITY - HOW IT DOES IT'S THING:
//Sony didn't really go through great lenghts to protect it's precious Playstation
//from running unauthorised software; the main security is based on a simple ASCII
//string of text that is read from a part of an original Playstation disc that cannot
//be reproduced by an ordinary PC CD burner.
//As most of you will know, a CD is basically a very long rolled up (carrier) string in which very
//little pits and ehm... little not-pits are embedded that represent the data stored on the disc.
//The nifty Sony engineers did not use the pits and stuff to store the security checks for
//Playstation discs but went crazy with the rolled up carrier string. In an ordinary CD, the
//string is rolled up so that the spacing between the tracks is as equal as possible. If that
//is not the case, the laser itself needs to move a bit to keep track of the track and
//reliably read the data off the disc.
//If you wonder how the laser knows when it follows the track optimally: four photodiodes, light
//intensity measurement, difference measurements, servo. There.
//To the point: the Sony engineers decidedly "fumbled up" the track of sector 4 on a Playstation
//disc (the track was modulated in nerd-speak) so that the error correction circuit outputs a
//recognisable signal, as the laser needs to be corrected to follow the track optimally.
//This output signal actually is a 250bps serial bitstream (with 1 start bit and 2 stop bits) which
//in plain ASCII says SCEA (Sony Computer Entertainment of America), SCEE (Sony Computer Entertainment
//of Europe) or SCEI (Sony Computer Entertainment of Japan), depending on the region of the disc inserted.
//The security thus functions not only as copy protection, but also as region protection.
//The text string from the disc is compared with the text string that is embedded in the Playstation
//hardware. When these text strings are the same, the disc is interpreted to be authentic and from
//the correct region. Bingo!
//HOW THE MODCHIP TRICKS THE PLAYSTATION:
//The modchip isn't all that of a complicated device: clever reverse engineers found the point on the
//Playstation motherboard that carried the text string from the disc and found a way to temporarily block
//this signal (by grounding an input of an op-amp buffer) to be able to inject the signal from the modchip
//The modchip injects after about 1500ms the text strings SCEE SCEA SCEI on the motherboard point and stops
//with this after about 25 seconds. Because all the possible valid region options are outputted on the
//motherboard the Playstation gets a bit confused and simply accepts the inserted disc as authentic; after all,
//one of the codes was the same as that of the Playstation hardware...
//Early modchips applied the text strings as long as power was applied to them, whereby later Playstation
//software could detect whether a modchip was installed. This is circumvented in this application by idling the
//modchip after about 25 seconds. The text strings are only tranmitted again when the CD lid is opened and closed
//again, to enable playing multi-disc games. This is also called a stealth modchip in marketing-speak.
//--------------------------------------------------
// New in this version!
//--------------------------------------------------
//A lot!
// - The PAL SCPH-102 NTSC BIOS-patch works flawlessly! For speed reasons this is implemented in bare
// AVR C. It is functionally identical to the OneChip modchip, this modchip firmware was disassembled,
// documented (available on request, but written in Dutch...) and analyzed with a logic analyzer to
// make sure PsNee works just as well.
// - The code now is segmented in functions which make the program a lot more maintable and readable
// - Timing is perfected, all discs (both backups and originals of PAL and NTSC games) now work in the
// PAL SCPH-102 test machine
// - It was found out that the gate signal doesn't havbe to be hooked up to a PAL SCPH-102 Playstation
// to circumvent the copy protection. This is not tested on other Playstation models so the signal still
// is available
// - The /xlat signal is no longer required to time the PAL SCPH-102 NTSC BIOS-patch
// - Only AVR PORTB is used for compatibility reasons (almost all the AVR chips available have PORTB)
//--------------------------------------------------
// Pinouts!
//--------------------------------------------------
//FOR ARDUINO UNO (WITH ATMEGA328):
// - Arduino pin 8 = data = ATMega pin 14
// - Arduino pin 9 = gate = ATMega pin 15
// - Arduino pin 10 = lid = ATMega pin 16
// - Arduino pin 11 = biosA18 = ATMega pin 17
// - Arduino pin 12 = biosD2 = ATMega pin 18
//FOR ATTINY25/45/85:
// - Arduino pin 0 = data = ATTiny pin 5
// - Arduino pin 1 = gate = ATTiny pin 6
// - Arduino pin 2 = lid = ATTiny pin 7
// - Arduino pin 3 = biosA18 = ATTiny pin 2
// - Arduino pin 4 = biosD2 = ATTiny pin 3
//--------------------------------------------------
// Includes!
//--------------------------------------------------
#include <Flash.h>
//--------------------------------------------------
// Arduino selection!
//--------------------------------------------------
#define ATTINY //Make that "#define ARDUINO_UNO" if you want to compile for Arduino Uno instead of ATTiny25/45/85
#ifdef ARDUINO_UNO
//Pins
int data = 8; //The pin that outputs the SCEE SCEA SCEI string
int gate = 9; //The pin that outputs the SCEE SCEA SCEI string
int lid = 10; //The pin that gets connected to the internal CD lid signal; active high
int biosA18 = 11; //Only used in SCPH-102 PAL mode
int biosD2 = 12; //Only used in SCPH-102 PAL mode
int delay_ntsc = 2350;
int delay_between_bits = 4;
int delay_between_injections = 74;
#endif
#ifdef ATTINY
//Pins
int data = 0; //The pin that outputs the SCEE SCEA SCEI string
int gate = 1;
int lid = 2; //The pin that gets connected to the internal CD lid signal; active high
int biosA18 = 3; //Only used in SCPH-102 PAL mode
int biosD2 = 4; //Only used in SCPH-102 PAL mode
int delay_ntsc = 2400;
int delay_between_bits = 4;
int delay_between_injections = 68;
#endif
//--------------------------------------------------
// Global variables!
//--------------------------------------------------
//None, just like it should be!
//--------------------------------------------------
// Seperate functions!
//--------------------------------------------------
void NTSC_fix()
{
//Make sure all pins are inputs
DDRB = 0x00;
//Wait until just before the pulse on BIOS A18 arrives
delay(delay_ntsc);
//...And wait here until it actually happened
while(!(PINB & B00001000))
{
; //Wait
}
delayMicroseconds(12);
PORTB = B00000000;
DDRB = B00010000;
delayMicroseconds(5);
DDRB = 0x00;
}
void inject_SCEE()
{
//SCEE-array // Start Data Stop
FLASH_ARRAY (boolean, SCEEData, 1,0,0,1,1,0,1,0,1,0,0,1,0,0,1,1,1,1,0,1,0,0,1,0,1,0,1,1,1,0,1,0,0,1,0,1,0,1,1,1,0,1,0,0); //SCEE: 1 00110101 00, 1 00111101 00, 1 01011101 00, 1 01011101 00 44 bits total
int bit_counter;
for (bit_counter = 0; bit_counter < 44; bit_counter = bit_counter + 1)
{
if (SCEEData[bit_counter] == 0)
{
pinMode(data, OUTPUT);
digitalWrite(data, 0);
delay(delay_between_bits);
}
else
{
pinMode(data, INPUT); //We make the data pin high-impedance to let the pull-up of the Playstation motherboard make a 1
delay(delay_between_bits);
}
}
pinMode(data, OUTPUT);
digitalWrite(data, 0);
delay(delay_between_injections);
}
void inject_SCEA()
{
//SCEE-array // Start Data Stop
FLASH_ARRAY (boolean, SCEAData, 1,0,0,1,1,0,1,0,1,0,0,1,0,0,1,1,1,1,0,1,0,0,1,0,1,0,1,1,1,0,1,0,0,1,0,1,1,1,1,1,0,1,0,0); //SCEA: 1 00110101 00, 1 00111101 00, 1 01011101 00, 1 01111101 00
int bit_counter;
for (bit_counter = 0; bit_counter < 44; bit_counter = bit_counter + 1)
{
if (SCEAData[bit_counter] == 0)
{
pinMode(data, OUTPUT);
digitalWrite(data, 0);
delay(delay_between_bits);
}
else
{
pinMode(data, INPUT); //We make the data pin high-impedance to let the pull-up of the Playstation motherboard make a 1
delay(delay_between_bits);
}
}
pinMode(data, OUTPUT);
digitalWrite(data, 0);
delay(delay_between_injections);
}
void inject_SCEI()
{
//SCEE-array // Start Data Stop
FLASH_ARRAY (boolean, SCEIData, 1,0,0,1,1,0,1,0,1,0,0,1,0,0,1,1,1,1,0,1,0,0,1,0,1,0,1,1,1,0,1,0,0,1,0,1,1,0,1,1,0,1,0,0); //SCEI: 1 00110101 00, 1 00111101 00, 1 01011101 00, 1 01101101 00
int bit_counter;
for (bit_counter = 0; bit_counter < 44; bit_counter = bit_counter + 1)
{
if (SCEIData[bit_counter] == 0)
{
pinMode(data, OUTPUT);
digitalWrite(data, 0);
delay(delay_between_bits);
}
else
{
pinMode(data, INPUT); //We make the data pin high-impedance to let the pull-up of the Playstation motherboard make a 1
delay(delay_between_bits);
}
}
pinMode(data, OUTPUT);
digitalWrite(data, 0);
delay(delay_between_injections);
}
void inject_multiple_times(int number_of_injection_cycles)
{
int cycle_counter;
for(cycle_counter = 0; cycle_counter < number_of_injection_cycles; cycle_counter = cycle_counter + 1)
{
inject_SCEE();
inject_SCEA();
inject_SCEI();
}
}
void inject_playstation()
{
//Variables
int loop_counter;
//Code
NTSC_fix();
delay(6900);
digitalWrite(data, 0);
pinMode(data, OUTPUT);
delay(100);
pinMode(gate, OUTPUT);
digitalWrite(gate, 0);
for (loop_counter = 0; loop_counter < 25; loop_counter = loop_counter + 1)
{
inject_SCEE();
}
pinMode(gate, INPUT);
pinMode(data, INPUT);
delay(11000);
pinMode(gate, OUTPUT);
digitalWrite(gate, 0);
for (loop_counter = 0; loop_counter < 60; loop_counter = loop_counter + 1)
{
inject_SCEE();
}
pinMode(gate, INPUT);
pinMode(data, INPUT);
}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//--------------------------------------------------
// Setup function - execution starts here!
//--------------------------------------------------
void setup()
{
inject_playstation();
}
//----------------------------------------------------------------
// Loop function - executes after the initial injection cycle
//----------------------------------------------------------------
void loop()
{
if(lid == 0)
{
while(lid != 1); //Wait until the lid is closed again (after being opened) to initiate a new injection cycle
inject_playstation();
}
}

View File

@@ -1,25 +0,0 @@
# PSNee V8.6
THE modechip supports the largest number of Playstation 1 variants, and the largest number of microcontrollers
# For all useful information consult the ![Wiki](https://github.com/kalymos/PsNee/wiki)
![Logo](/images/PSNee-8.6-logo.png)
## Features
- Remove Disk Region Protection
- Patch BIOS
- A specific library for card support, to solve the fuse setting problem.
- The mode does not take care of changing PAL <-> NTSC video output (in other words if you use a Japanese console and you put European games, or in older European models you use American or Japanese games... the display will not be correct)
## Supported Playstation 1
All US models, all European models, and the vast majority of Japanese models.
## Supported platforms
- ATmega328(A/P/PA) @16Mhz
- ATmega168(A/P/PA) @16Mhz
- Atmega32U4 @16Mhz
- ATtiny25/45/85 @8Mhz no BIOS patch!
## Model that I personally tested
![test](images/test-PSNee-v8.6.png)
Example of gray image
![gray](https://github.com/kalymos/PsNee/blob/master/images/issue/gray-screens.png)

178
changelog
View File

@@ -1,178 +0,0 @@
Update:mars 2025
-Added led support for ATtiny
-Added card support to simplify fuse management
Update:july 2024
-Reimplementation of support for MUCs ATtiny25/45/85, Atmega32u4
-------------------------------------------------------------
Update: 9 oct 2023
-Added support by brill & postal2201 of the bios patch for japanese consoles https://github.com/postal2201/PSNee_V8
--------------------------------------------------------------
Update: 16 August 2017
-changed the timing for the PAL PM-41 patch to make it more reliable (I had it failing occasionally).
Also I added a warning for people not to use 5V.
--------------------------------------------------------------
Update: 16 July 2017
-The BIOS patch works!
For now it only supports Arduino boards (ATmega chips).
Also, the Arduino must either be powered on first or have no bootloader present (flashed using SPI) since I expect a signal ~1 second after power on.
8Mhz boards are also supported.
--------------------------------------------------------------
Update: 10 July 2017
- finished porting to ATtinyX5 (25,45,85 although the 25 has too little resources. for now.)
- store the licensing symbols in flash again, frees a lot of RAM
- bit retrieval code lifted from AttyNee (Nice work guys!)
- extra RAM allows SoftwareSerial debugging prints on an ATtiny45!
- nicer intro readme ;p
---------------------------------------------------------------
Update 9 July 2017
Sure. Consider it work in progress quality ;)
Main changes:
- figured out ATtiny pin assignments :p
- RAM use reduced by only storing the "SCE" part of the license string once. Using a somewhat farfetched method. Maybe someone can make it nicer, without the recursion and over engineering? :p
- tried getting debug prints but it doesn't look like it'll happen (on ATtiny45), too little RAM > the chip crashes
- SUBQ sampling timing reverted to sample while clock is low, instead of right after it goes high
-------------------------------------------------------------
Updat 29 June 2017
- final modchip function I / Os: SQCK, SCLK, data, gate_wfck
- hysteresis for injections, fixes anti-mod occasionally triggering when using worn drives
- optimized injection timing for multi-region, multi BIOS versions (Sony added more protection checks over time)
- first attempt to make it more portable to other Arduino variants
- auto console detection works reliably, with and without Arduino bootloader present
- pin assignments changed for practical / installation reasons (ICSP capability, wire routing)
- so many changes, it surely contains all new bugs ;)
Pin assignments are finalized. We can start producing final installation images / help!
As always, I appreciate code reviews and bug fixes. I'm sorry some of it got so messy ;p
psxdev
------------------------------------------------------------
Update 4 June 2017
- unified SCEX injection function / easier to read code
- PU-22+ now work without the WFCK wire (but depends on tight timings, tested on 8 and 16Mhz mcu)
- interrupts disabled while sampling SUBQ > much better performance capturing all events correctly
- now blinks the built-in LED on injections for debugging
psxdev
------------------------------------------------------------
Update 31st May 2017
- supports all motherboard versions except PU-41 (PAL) (will get to it!)
- WFCK modulated injection method for PU-22 and up, just like the last multimode 3 chips
- minimized CD controller interference: PsNee only ever speaks when it has to (also: full stealth)
- not relying on BIOS delays: perfect boot disregarding extension cards etc
- might not be bug free! I'm just one guy and testing on a dozen consoles takes time ;)
psxdev
-------------------------------------------------------------
Update 27th of May 2017
This version is compatible with 8Mhz and 16Mhz ATmega328 / Arduino boards.
It uses polling to grab the SUBQ packets. This works better than relying on interrupts.
I even have a few cycles to spare on a 8Mhz chip!
psxdev
--------------------------------------------------------------
Update 15th of May 2017
PSNee now watches the subchannel data and looks at the position information contained within.
This allows deterministic SCEX injections. It knows (almost) exactly when to inject the SCEX string.
Therefore it is now a stealth modchip :)
Required connections: GND, VCC, data, gate, SQCL, SUBQ
No more need to watch the PSX reset or lid open signals or any other typical modchip points (like "sync")
WIP! Only tested on PU-18 board. Should work fine on PU-7, PU-8, PU-18 and PU-20.
Will need adaption for PU-22 to PU-41 (SCPH-750x, 900x and PSOne).
Note: Once this is installed in a PSX, mind the Pin13 LED that many Arduino boards have. Do not upload new sketches while the PSX is on!
(If the PSX is on while uploading a sketch (making the LED blink), a voltage will be fed back into the SCLK pin on the HC-05 in the PSX.
This didn't break my PSX in testing but it does stun the chip and halt CD operation. I'm thinking of a better method to do this but for now I need Arduino pin13..)
Very much recommended to install a 3.3V chip!
psxdev
-------------------------------------------------------------
Update 7th of May 2017
Branched and tweaked for use with the Position 0 switch on a PSX laser.
(Requires a bit of sticky tape at the point where the switch touches the laser assembly.)
This allows deterministic SCEX injections, without relying on timing. Also gets rid of connection wires for LID and RESET.
WIP!
psxdev
--------------------------------------------------------------
New in this version! V6
--------------------------------------------------------------
A lot!
- The PAL SCPH-102 NTSC BIOS-patch works flawlessly! For speed reasons this is implemented in bare
AVR C. It is functionally identical to the OneChip modchip, this modchip firmware was disassembled,
documented (available on request, but written in Dutch...) and analyzed with a logic analyzer to
make sure PsNee works just as well.
- The code now is segmented in functions which make the program a lot more maintable and readable
- Timing is perfected, all discs (both backups and originals of PAL and NTSC games) now work in the
PAL SCPH-102 test machine
- It was found out that the gate signal doesn't havbe to be hooked up to a PAL SCPH-102 Playstation
to circumvent the copy protection. This is not tested on other Playstation models so the signal still
is available
- The /xlat signal is no longer required to time the PAL SCPH-102 NTSC BIOS-patch
- Only AVR PORTB is used for compatibility reasons (almost all the AVR chips available have PORTB)
-------------------------------------------------------------
A minor detail: The lid detection is missing its digitalRead() ;p
psxdev
-------------------------------------------------
VERSION 2! :D
-------------------------------------------------
What has changed?
- Thanks to TriMesh, the gate-pin is now also used to determine in which model of
Playstation PsNee is installed. The modchip algorithm thus can be optimized for
optimal performance on specific Playstation revisions. This works by monitoring
whether a clock signal is present on this pin - when there is one, the modchip is
installed in a PU-22, PU-23 or PSOne Playstation, else it is installed in an older
model Playstation. In this version of PsNee, nothing is actually done with this information.
- Thanks to -again- TriMesh, NTSC support for PAL SCPH-102 Playstations is added! This uses
the same method the OneChip modchip used for achieving this:
1. Monitor the XLAT signal from the CD mechanism controller chip. This requires
another connection to the Playstation. When this signal is 0, the first CD copy
protection is passed! After this, there is another one.
2. After this, watch the Address18-pin (pin 31) on the BIOS-chip. When this signal
is high, this means the second CD copy protection is about to run.
3. Wait a short time.
4. Pull the Data2-pin (pin 15) on the BIOS-chip to 0. This effectively blocks the
execution of the region check of the inserted disc.
5. The Playstation plays the inserted disc and doesn't care whether it's PAL or NTSC!
6. Release the 0 of the Data2-pin.
To correctly output a PAL video color signal for a PAL TV on a PAL PSOne with an NTSC disc
inserted, Pin 3 of IC502 must be grounded with an external switch. The modchip also could do
this, although we would need a device with more pins available.
- The outputted data signal is now "sliced up" to improve (or less distort) the tracking
signal from the CD mechanism: later Playstations use the CD tracking signal for transmitting
the SCEx-string to the Playstation instead of using a seperate connection, so when the modchip
forces a 0 on the data-pin, the tracking signal also is gone temporarily. By slicing the data-
signal up in little pieces at least some of the tracking signal remains and the Playstation can
read discs more easily.
- The two big for-loops are combined into one with an OR-statement describing the two conditions
modchip should be active: when flagFirstCycle = 0 or when flagFirstCycle = 1 and the lid is opened
and closed again. This makes code maintenance easier.
- The pin-out of the modchip is changed slightly to be able to use an interrupt for the PAL=>NTSC
BIOS-patch for PAL SCPH-102. Please use the revised pin-out found below with this code.
~TheFrietMan, The Netherlands

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 461 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 408 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 785 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 908 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 451 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 383 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 358 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 MiB