mirror of
https://github.com/kalymos/PsNee.git
synced 2026-05-09 00:32:52 +00:00
Cleanup: Remove deprecated files for V9.0 merge
- Deleted obsolete files to prepare the branch for the V9.0 main integration. - Cleaning up the directory structure to avoid conflicts during the merge.
This commit is contained in:
@@ -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
|
||||
@@ -1,883 +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);
|
||||
|
||||
// Define the pins as inputs.
|
||||
|
||||
// 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);
|
||||
|
||||
// Enable pull-ups and set high on the pins.
|
||||
|
||||
// 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));
|
||||
|
||||
// Read the state of the input pins Equivalent.
|
||||
|
||||
// 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: PORTB |= (1<<PB0);
|
||||
|
||||
// Set the state of an output pin to HIGH (Equivalent of Arduino digitalWrite(8, HIGH);).
|
||||
|
||||
// Create a mask by shifting the bit 1 to the left by PB0's position (bit 0),
|
||||
// and then apply a bitwise OR operation to force the PB0 pin to a high state.
|
||||
// This operation modifies only the target bit without affecting the others in the register.
|
||||
//
|
||||
// For instance, if PORTB = b10101010 (binary value), the operation shifts the bit 1 to the left to create the mask
|
||||
// (1<<PB0) = b00000001. The OR operation between PORTB and the mask ensures the 0th bit becomes 1 (high).
|
||||
//
|
||||
// Before: PORTB = b10101010 // Initial value of PORTB (register controlling output pin states)
|
||||
// Mask: (1<<PB0) = b00000001 // Mask generated by shifting the bit 1 to the left to position PB0
|
||||
// Operation: PORTB | b00000001 = b10101011 // The 0th bit is set to 1 (high)
|
||||
//
|
||||
//******************************************************************************************************************
|
||||
|
||||
//******************************************************************************************************************
|
||||
|
||||
// Example: PORTB &= ~(1<<PB0);
|
||||
|
||||
// Set the state of an output pin to LOW (Equivalent of Arduino digitalWrite(8, LOW);).
|
||||
|
||||
// Create a mask by shifting the bit 1 to the left by PB0's position (bit 0).
|
||||
// The mask is then inverted at the bit level (binary NOT) to create a clearing mask (all bits are 1 except the target bit, which is 0).
|
||||
// Finally, a bitwise AND operation is applied to force the PB0 pin to a low state.
|
||||
// This operation modifies only the target bit without affecting the others in the register.
|
||||
//
|
||||
// For instance, if PORTB = b10101011 (binary value), the generated mask is (1<<PB0) = b00000001.
|
||||
// Inverting (NOT) the mask yields ~(1<<PB0) = b11111110.
|
||||
// The bitwise AND operation between PORTB and the clearing mask ensures the 0th bit becomes 0 (low).
|
||||
//
|
||||
// Before: PORTB = b10101011 // Initial value of PORTB (register controlling output pin states)
|
||||
// Mask: ~(1<<PB0) = b11111110 // Generated clearing mask
|
||||
// Operation: PORTB & b11111110 = b10101010 // The 0th bit is set to 0 (low)
|
||||
//
|
||||
//******************************************************************************************************************
|
||||
|
||||
//******************************************************************************************************************
|
||||
|
||||
// Enables (masks in) the Hardware External Interrupt 0 (INT0).
|
||||
|
||||
// Equivalent to the Arduino function: attachInterrupt(digitalPinToInterrupt(2), myFunctionName, CHANGE);
|
||||
//
|
||||
// Example: EIMSK |= (1<<INT0);
|
||||
//
|
||||
// Creates a mask by shifting the bit 1 to the left to the position of the INT0 bit.
|
||||
// A bitwise OR operation is then applied to the EIMSK (External Interrupt Mask Register) register to set that specific bit to 1.
|
||||
// Enabling this bit tells the microcontroller to start listening for signals on the physical pin associated with INT0 (typically Pin D2 on the Arduino UNO/Nano).
|
||||
//
|
||||
// For instance, if EIMSK = b00000000 (all interrupts disabled), the generated mask is (1<<INT0) = b00000001 (assuming INT0 is defined as 0).
|
||||
// The bitwise OR operation ensures the INT0 bit is set to 1, without affecting the other interrupts.
|
||||
//
|
||||
// Before: EIMSK = b00000000 // All interrupts disabled
|
||||
// Mask: (1<<INT0) = b00000001 // Generated enable mask
|
||||
// Operation: EIMSK | b00000001 = b00000001 // The INT0 interrupt is now enabled
|
||||
//
|
||||
//******************************************************************************************************************
|
||||
|
||||
//******************************************************************************************************************
|
||||
|
||||
// Disables (masks out) the Hardware External Interrupt 0 (INT0).
|
||||
|
||||
// Equivalent to the Arduino function: detachInterrupt(digitalPinToInterrupt(2));
|
||||
//
|
||||
// Example: EIMSK &= ~(1<<INT0);
|
||||
//
|
||||
// Creates a mask by shifting the bit 1 to the left by the position of the INT0 bit.
|
||||
// The mask is then inverted at the bit level (binary NOT) to create a clearing mask (all bits are 1 except the target bit, which is 0).
|
||||
// A bitwise AND operation is applied to the EIMSK (External Interrupt Mask Register) register to force that specific bit to 0.
|
||||
// Disabling this bit tells the microcontroller to stop listening for signals on the physical pin associated with INT0 (typically Pin D2 on the Arduino UNO/Nano).
|
||||
//
|
||||
// For instance, if EIMSK = b00000001 (INT0 interrupt is enabled), the generated mask is (1<<INT0) = b00000001.
|
||||
// Inverting (NOT) the mask yields ~(1<<INT0) = b11111110.
|
||||
// The bitwise AND operation between EIMSK and the clearing mask ensures the INT0 bit becomes 0 (disabled).
|
||||
//
|
||||
// Before: EIMSK = b00000001 // INT0 interrupt is enabled
|
||||
// Mask: ~(1<<INT0) = b11111110 // Generated disable mask
|
||||
// Operation: EIMSK & b11111110 = b00000000 // The INT0 interrupt is now disabled
|
||||
//
|
||||
//******************************************************************************************************************
|
||||
|
||||
//******************************************************************************************************************
|
||||
|
||||
// Configures the external interrupt 0 (INT0) to trigger on a RISING edge (when the signal goes from LOW to HIGH).
|
||||
|
||||
// Equivalent to the Arduino function: attachInterrupt(digitalPinToInterrupt(2), myFunctionName, RISING);
|
||||
//
|
||||
// Example: EICRA |= (1<<ISC01)|(1<<ISC00);
|
||||
//
|
||||
// This operation sets both the ISC01 and ISC00 bits within the EICRA register (External Interrupt Control Register A) to 1.
|
||||
// These two bits together form a 2-bit control field that determines how the INT0 pin should react to changes in voltage.
|
||||
// The specific combination of ISC01=1 and ISC00=1 defines the "RISING Edge" mode according to the AVR datasheet.
|
||||
//
|
||||
// EICRA register (simplified view of relevant bits):
|
||||
// | Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 (ISC01) | Bit 0 (ISC00) |
|
||||
// | :---: | :---: | :---: | :---: | :---: | :---: | :-----------: | :-----------: |
|
||||
// | | | | | | | 1 | 1 |
|
||||
//
|
||||
// The bitwise OR (|=) ensures that only these two specific bits are modified, leaving all other interrupt configurations unchanged.
|
||||
//
|
||||
// Before: EICRA = b00000000 // Default state (usually LOW level triggers)
|
||||
// Mask: (1<<ISC01)|(1<<ISC00) = b00000011 // Mask to set both bits 0 and 1
|
||||
// Operation: EICRA | b00000011 = b00000011 // INT0 is now configured for RISING edge triggers
|
||||
//
|
||||
//******************************************************************************************************************
|
||||
|
||||
//******************************************************************************************************************
|
||||
|
||||
// Configures the external interrupt 0 (INT0) to trigger on a FALLING edge (when the signal goes from HIGH to LOW).
|
||||
// Equivalent to the Arduino function: attachInterrupt(digitalPinToInterrupt(2), myFunctionName, FALLING);
|
||||
//
|
||||
// Example: (EICRA = (EICRA & ~(1<<ISC00)) | (1<<ISC01));
|
||||
//
|
||||
// This combined operation first ensures that the ISC00 bit is cleared to 0 (& ~(1<<ISC00)), and then sets the ISC01 bit to 1 (| (1<<ISC01)).
|
||||
// These two bits together form a 2-bit control field that determines how the INT0 pin should react to changes in voltage.
|
||||
// The specific combination of ISC01=1 and ISC00=0 defines the "FALLING Edge" mode according to the AVR datasheet.
|
||||
//
|
||||
// EICRA register (simplified view of relevant bits):
|
||||
// | Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 (ISC01) | Bit 0 (ISC00) |
|
||||
// | :---: | :---: | :---: | :---: | :---: | :---: | :-----------: | :-----------: |
|
||||
// | | | | | | | 1 | 0 |
|
||||
//
|
||||
// The complex bitwise operation ensures that we set a specific 2-bit value while leaving other unrelated bits in the EICRA register unchanged.
|
||||
//
|
||||
// Operation Breakdown:
|
||||
// 1. Clear ISC00 bit: EICRA & ~(1<<ISC00)
|
||||
// 2. Set ISC01 bit: ... | (1<<ISC01)
|
||||
// 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.
|
||||
//
|
||||
//******************************************************************************************************************
|
||||
|
||||
//******************************************************************************************************************
|
||||
// Identifier for the Interrupt Vector for External Interrupt 0 (INT0).
|
||||
//
|
||||
// Example: ISR(INT0_vect) { ... }
|
||||
//
|
||||
// This is not an executable instruction but a symbolic name (an alias or macro) defined in the AVR-GCC header files
|
||||
// (<avr/interrupt.h>). It points to the specific memory address in the microcontroller's flash memory where the
|
||||
// Interrupt Service Routine (ISR) for the INT0 event must reside.
|
||||
//
|
||||
// When you write ISR(INT0_vect) { ... }, you are telling the compiler: "Place this block of code at the
|
||||
// location the CPU jumps to when a hardware signal is detected on the INT0 pin."
|
||||
//
|
||||
// In Arduino code, this identifier is hidden from the user and managed internally by the
|
||||
// attachInterrupt() function.
|
||||
//
|
||||
//******************************************************************************************************************
|
||||
|
||||
|
||||
#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. Equivalent Arduino code: pinMode(x, INPUT));
|
||||
#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. Equivalent Arduino code: pinMode(x, OUTPUT);
|
||||
#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. Equivalent Arduino code: digitalWrite(x, HIGH);
|
||||
#define PIN_DATA_SET PORTB |= (1<<PB0) // Set PORTB register to make PINB0 high (enable pull-up)
|
||||
|
||||
// Clear the main pins (set low). Equivalent Arduino code: digitalWrite(x, 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 Equivalent. Arduino code: (digitalRead(x) == HIGH)
|
||||
#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
|
||||
@@ -1,493 +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_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_3500 // 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
|
||||
// The detection performed here allows us to determine the code's behavior.
|
||||
//
|
||||
// In the case of older generations like PU-7 through PU-20, we are connected to the output of an operational amplifier used as a buffer
|
||||
//(this part of the motherboard was detailed in the official schematics; by convention, this point was labeled GATE).
|
||||
//In normal operation, this line is always high, but pulling it down frees the DATA line, allowing the SCEX code to be injected without any further issues.
|
||||
//
|
||||
//If we are dealing with PU-22 or newer models, it is connected to a WFCK clock output. This clock signal will be used to synchronize the SCEX injection.
|
||||
//************************************************************************
|
||||
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)
|
||||
{
|
||||
PIN_WFCK_INPUT;
|
||||
}
|
||||
|
||||
PIN_DATA_INPUT;
|
||||
|
||||
#ifdef LED_RUN
|
||||
PIN_LED_OFF;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,171 +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.75)
|
||||
#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.75)
|
||||
#define PATCHING _delay_us(0.2)
|
||||
#define CHECKPOINT 76100
|
||||
#define TRIGGER 21
|
||||
#define LOW_TRIGGER
|
||||
#endif
|
||||
|
||||
// #ifdef SCPH_3500_5000
|
||||
// #define SCEI
|
||||
// #define BIOS_PATCH
|
||||
// #define HOLD _delay_us(2.75)
|
||||
// #define PATCHING _delay_us(0.2)
|
||||
// #define CHECKPOINT 75260
|
||||
// #define TRIGGER 21
|
||||
// #define LOW_TRIGGER
|
||||
// #endif
|
||||
|
||||
// #ifdef SCPH_5500
|
||||
// #define SCEI
|
||||
// #define BIOS_PATCH
|
||||
// #define HOLD _delay_us(2.75)
|
||||
// #define PATCHING _delay_us(0.2)
|
||||
// #define CHECKPOINT 76130
|
||||
// #define TRIGGER 21
|
||||
// #define LOW_TRIGGER
|
||||
// #endif
|
||||
|
||||
#ifdef SCPH_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_3500
|
||||
#define SCEI
|
||||
#define BIOS_PATCH
|
||||
#define LOW_TRIGGER
|
||||
#define CHECKPOINT 75200 //75.12 - 75.27
|
||||
#define TRIGGER 21
|
||||
#define HOLD _delay_us(2.75) //2.65 - 2.85
|
||||
#define PATCHING _delay_us(0.2)
|
||||
#endif
|
||||
|
||||
#ifdef SCPH_3000
|
||||
#define SCEI
|
||||
#define BIOS_PATCH
|
||||
#define HOLD _delay_us(2.70)
|
||||
#define PATCHING _delay_us(0.15)
|
||||
#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_5000) && !defined(SCPH_3500) && !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_5000) ^ defined(SCPH_3500) ^ defined(SCPH_3000) ^ \
|
||||
defined(SCPH_1000) ^ defined(SCPH_xxxx))
|
||||
#error "May be selected only one console! Please check #define with SCPH model number."
|
||||
#endif
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
@@ -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 */
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user