From a5f3fb73a6ce38f7bbaeb26a0a8cf9269d571dc7 Mon Sep 17 00:00:00 2001 From: mnm-isola Date: Tue, 13 Sep 2022 15:27:03 +0800 Subject: [PATCH 1/3] added 328p digitalwritefast definition --- src/arduino_psx.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/arduino_psx.h b/src/arduino_psx.h index 00715dd..a9364b8 100644 --- a/src/arduino_psx.h +++ b/src/arduino_psx.h @@ -18,6 +18,7 @@ All rights reserved. */ +// --- Arduino Leonardo and ATmega16U4/32U4 based boards --- #if (defined(ARDUINO_AVR_LEONARDO) || \ defined(__AVR_ATmega16U4__) || \ defined(__AVR_ATmega32U4__)) @@ -42,6 +43,54 @@ #define __digitalPinToBit(P) \ (((P) >= 8 && (P) <= 11) ? (P) - 4 : (((P) >= 18 && (P) <= 21) ? 25 - (P) : (((P) == 0) ? 2 : (((P) == 1) ? 3 : (((P) == 2) ? 1 : (((P) == 3) ? 0 : (((P) == 4) ? 4 : (((P) == 6) ? 7 : (((P) == 13) ? 7 : (((P) == 14) ? 3 : (((P) == 15) ? 1 : (((P) == 16) ? 2 : (((P) == 17) ? 0 : (((P) == 22) ? 1 : (((P) == 23) ? 0 : (((P) == 24) ? 4 : (((P) == 25) ? 7 : (((P) == 26) ? 4 : (((P) == 27) ? 5 : 6 ))))))))))))))))))) + +// --- Arduino Uno and ATmega168/328 based boards --- +#elif (defined(ARDUINO_AVR_UNO) || \ + defined(ARDUINO_AVR_DUEMILANOVE) || \ + defined(__AVR_ATmega8__) || \ + defined(__AVR_ATmega48__) || \ + defined(__AVR_ATmega48P__) || \ + defined(__AVR_ATmega48PB__) || \ + defined(__AVR_ATmega88P__) || \ + defined(__AVR_ATmega88PB__) || \ + defined(__AVR_ATmega168__) || \ + defined(__AVR_ATmega168PA__) || \ + defined(__AVR_ATmega168PB__) || \ + defined(__AVR_ATmega328__) || \ + defined(__AVR_ATmega328P__) || \ + defined(__AVR_ATmega328PB__)) + +#define UART_RX_PIN (0) //PD0 +#define UART_TX_PIN (1) //PD1 + +#define I2C_SDA_PIN (18) //A4 +#define I2C_SCL_PIN (19) //A5 + +#define SPI_HW_SS_PIN (10) //PB0 +#define SPI_HW_MOSI_PIN (11) //PB2 +#define SPI_HW_MISO_PIN (12) //PB3 +#define SPI_HW_SCK_PIN (13) //PB1 + +#if defined(__AVR_ATmega48PB__) || defined(__AVR_ATmega88PB__) || defined(__AVR_ATmega168PB__) || defined(__AVR_ATmega328PB__) +#define __digitalPinToPortReg(P) \ +(((P) >= 0 && (P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : (((P) >= 14 && (P) <= 19) ? &PORTC : &PORTE))) +#define __digitalPinToDDRReg(P) \ +(((P) >= 0 && (P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : (((P) >= 14 && (P) <= 19) ? &DDRC : &DDRE))) +#define __digitalPinToPINReg(P) \ +(((P) >= 0 && (P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : (((P) >= 14 && (P) <= 19) ? &PINC : &PINE))) +#define __digitalPinToBit(P) \ +(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (((P) >= 14 && (P) <= 19) ? (P) - 14 : (((P) >= 20 && (P) <= 21) ? (P) - 18 : (P) - 22)))) +#else +#define __digitalPinToPortReg(P) \ +(((P) >= 0 && (P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : &PORTC)) +#define __digitalPinToDDRReg(P) \ +(((P) >= 0 && (P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : &DDRC)) +#define __digitalPinToPINReg(P) \ +(((P) >= 0 && (P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : &PINC)) +#define __digitalPinToBit(P) \ +(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (P) - 14)) +#endif + #else #error "This library does not support any processor besides the ATmega32U4 or ATmega16U4" #endif -- 2.54.0 From 83c865115858eb172df6c41c0fbdd5223e110a97 Mon Sep 17 00:00:00 2001 From: Lay31415 <65494889+Lay31415@users.noreply.github.com> Date: Sun, 1 Jun 2025 00:57:38 +0900 Subject: [PATCH 2/3] Fix SPR2 register error for ATmega32U4 compatibility - Replace non-existent SPR2 with correct SPR1 and SPI2X combination - SPR1=1, SPR0=0, SPI2X=1 achieves Fosc/32 = 250kHz at 8MHz - Resolves compilation error on SparkFun Pro Micro and other ATmega32U4 boards --- src/arduino_psx.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/arduino_psx.cpp b/src/arduino_psx.cpp index 1b454b6..0157305 100644 --- a/src/arduino_psx.cpp +++ b/src/arduino_psx.cpp @@ -30,7 +30,8 @@ void PSX_::init(int ackPin = 8, bool invACK = false, bool invCIPO = true) { #if (F_CPU == 16000000L) SPCR |= (1 << SPR1); // Fosc/64 @16MHz==250KHz #elif (F_CPU == 8000000L) - SPCR |= (1 << SPR2) | (1 << SPR1); // Fosc/32 @8MHz==250KHz + SPCR |= (1 << SPR1); // SPR1=1, SPR0=0 for Fosc/64 base + SPSR |= (1 << SPI2X); // SPI2X=1 for double speed -> Fosc/32 @8MHz==250KHz #endif SPCR |= (1 << CPHA); // Setup @ leading edge, sample @ falling edge SPCR |= (1 << CPOL); // Leading edge is falling edge, trailing edge is rising edge @@ -110,4 +111,4 @@ void PSX_::isr() { } } -PSX_ PSX; \ No newline at end of file +PSX_ PSX; -- 2.54.0 From 70b3a745ab4348f77b95defa2a6f6b43f15406d7 Mon Sep 17 00:00:00 2001 From: veroxzik <43590004+veroxzik@users.noreply.github.com> Date: Sat, 31 May 2025 19:49:02 -0400 Subject: [PATCH 3/3] Updated donation link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 14cc670..14fb259 100644 --- a/README.md +++ b/README.md @@ -196,4 +196,4 @@ Additional suggestions and feedback from [progmem](https://github.com/progmem). If you appreciate this library or the other projects I do, you can make a monetary donation below. Thanks! -[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/donate/?business=6M7ENNVE2ZP5Q&no_recurring=1¤cy_code=USD) +[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/vxzk/tip) -- 2.54.0