Skip to content

Commit 0f016ed

Browse files
committed
Fix attiny x4 pinout for fast pin read and write. Thanks to Mathias Moog. Closes Arduino-IRremote#1077
1 parent bde7204 commit 0f016ed

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ If IR_SEND_PIN is not defined you must use e.g. `IrSender.begin(3, ENABLE_LED_FE
145145
For converting MSB codes to LSB see [below](https://github.com/Arduino-IRremote/Arduino-IRremote#how-to-convert-old-msb-first-32-bit-ir-data-codes-to-new-lsb-first-32-bit-ir-data-codes).
146146

147147
### Example
148-
#### 2.x program:
148+
#### Old 2.x program:
149149

150150
```c++
151151
#include <IRremote.h>
@@ -169,7 +169,7 @@ void loop() {
169169
}
170170
```
171171
172-
#### 3.x program:
172+
#### New 3.x or 4.x program:
173173
174174
```c++
175175
#include <IRremote.hpp>
@@ -182,8 +182,10 @@ void setup()
182182
183183
void loop() {
184184
if (IrReceiver.decode()) {
185-
Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);
186-
IrReceiver.printIRResultShort(&Serial); // optional use new print version
185+
Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX); // Print "old" raw data
186+
/* USE NEW 3.x FUNCTIONS */
187+
IrReceiver.printIRResultShort(&Serial); // Print complete received data in one line
188+
IrReceiver.printIRSendUsage(&Serial); // Print the statement required to send this data
187189
...
188190
IrReceiver.resume(); // Enable receiving of the next value
189191
}

examples/UnitTest/UnitTest.ino

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ void checkReceivedRawData(IRRawDataType aRawData) {
223223
Serial.println();
224224
}
225225

226+
#if defined(DECODE_DISTANCE_WIDTH)
226227
void checkReceivedArray(uint32_t *aRawDataArrayPointer, uint8_t aArraySize) {
227228
// wait until signal has received
228229
while (!sDataJustReceived) {
@@ -243,15 +244,16 @@ void checkReceivedArray(uint32_t *aRawDataArrayPointer, uint8_t aArraySize) {
243244
IrReceiver.printIRResultRawFormatted(&Serial, true);
244245
}
245246
#endif
247+
246248
if (IrReceiver.decodedIRData.protocol == PULSE_DISTANCE || IrReceiver.decodedIRData.protocol == PULSE_WIDTH) {
247249
for (uint_fast8_t i = 0; i < aArraySize; ++i) {
248250
if (IrReceiver.decodedIRData.decodedRawDataArray[i] != *aRawDataArrayPointer) {
249251
Serial.print(F("ERROR: Received data=0x"));
250-
#if (__INT_WIDTH__ < 32)
252+
# if (__INT_WIDTH__ < 32)
251253
Serial.print(IrReceiver.decodedIRData.decodedRawDataArray[i], HEX);
252-
#else
254+
# else
253255
PrintULL::print(&Serial, IrReceiver.decodedIRData.decodedRawDataArray[i], HEX);
254-
#endif
256+
# endif
255257
Serial.print(F(" != sent data=0x"));
256258
Serial.println(*aRawDataArrayPointer, HEX);
257259
}
@@ -264,6 +266,7 @@ void checkReceivedArray(uint32_t *aRawDataArrayPointer, uint8_t aArraySize) {
264266
}
265267
Serial.println();
266268
}
269+
#endif
267270

268271
/*
269272
* Test callback function
@@ -466,65 +469,67 @@ void loop() {
466469
delay(DELAY_AFTER_SEND);
467470
# endif
468471

469-
# if defined(DISTANCE_DO_MSB_DECODING)
472+
# if defined(DECODE_DISTANCE_WIDTH)
473+
# if defined(DISTANCE_DO_MSB_DECODING)
470474
Serial.println(F("Send generic 52 bit PulseDistance 0x43D8613C and 0x3BC3B MSB first"));
471475
Serial.flush();
472-
# if __INT_WIDTH__ < 32
476+
# if __INT_WIDTH__ < 32
473477
tRawData[0] = 0x43D8613C; // MSB of tRawData[0] is sent first
474478
tRawData[1] = 0x3BC3B;
475479
IrSender.sendPulseDistanceWidthFromArray(38, 8900, 4450, 550, 1700, 550, 600, &tRawData[0], 52, PROTOCOL_IS_MSB_FIRST,
476480
SEND_STOP_BIT, 0, NO_REPEATS);
477481
checkReceivedArray(tRawData, 2);
478-
# else
482+
# else
479483
IrSender.sendPulseDistanceWidth(38, 8900, 4450, 550, 1700, 550, 600, 0x43D8613CBC3B, 52, PROTOCOL_IS_MSB_FIRST,
480484
SEND_STOP_BIT, 0, NO_REPEATS);
481485
checkReceivedRawData(0x43D8613CBC3B);
482-
# endif
486+
# endif
483487
delay(DELAY_AFTER_SEND);
484488

485489
Serial.println(F("Send generic 52 bit PulseDistanceWidth 0x43D8613C and 0x3BC3B MSB first"));
486490
Serial.flush();
487491
// Real PulseDistanceWidth (constant bit length) does not require a stop bit
488-
# if __INT_WIDTH__ < 32
492+
# if __INT_WIDTH__ < 32
489493
IrSender.sendPulseDistanceWidthFromArray(38, 300, 600, 600, 300, 300, 600, &tRawData[0], 52, PROTOCOL_IS_MSB_FIRST,
490494
SEND_NO_STOP_BIT, 0, 0);
491495
checkReceivedArray(tRawData, 2);
492-
# else
496+
# else
493497
IrSender.sendPulseDistanceWidth(38, 300, 600, 600, 300, 300, 600, 0x123456789ABC, 52, PROTOCOL_IS_MSB_FIRST,
494498
SEND_NO_STOP_BIT, 0, 0);
495499
checkReceivedRawData(0x123456789ABC);
496-
# endif
500+
# endif
497501
delay(DELAY_AFTER_SEND);
498-
# else
502+
# else // defined(DISTANCE_DO_MSB_DECODING)
499503
Serial.println(F("Send generic 52 bit PulseDistance 0xDCBA9 87654321 LSB first"));
500504
Serial.flush();
501-
# if __INT_WIDTH__ < 32
505+
# if __INT_WIDTH__ < 32
502506
tRawData[0] = 0x87654321; // LSB of tRawData[0] is sent first
503507
tRawData[1] = 0xDCBA9;
504508
IrSender.sendPulseDistanceWidthFromArray(38, 8900, 4450, 550, 1700, 550, 600, &tRawData[0], 52, PROTOCOL_IS_LSB_FIRST,
505509
SEND_STOP_BIT, 0, NO_REPEATS);
506510
checkReceivedArray(tRawData, 2);
507-
# else
511+
# else
508512
IrSender.sendPulseDistanceWidth(38, 8900, 4450, 550, 1700, 550, 600, 0xDCBA987654321, 52, PROTOCOL_IS_LSB_FIRST,
509513
SEND_STOP_BIT, 0, NO_REPEATS);
510514
checkReceivedRawData(0xDCBA987654321);
511-
# endif
515+
# endif
512516
delay(DELAY_AFTER_SEND);
513517

514518
Serial.println(F("Send generic 52 bit PulseDistanceWidth 0xDCBA9 87654321 LSB first"));
515519
Serial.flush();
516520
// Real PulseDistanceWidth (constant bit length) does not require a stop bit
517-
# if __INT_WIDTH__ < 32
521+
# if __INT_WIDTH__ < 32
518522
IrSender.sendPulseDistanceWidthFromArray(38, 300, 600, 600, 300, 300, 600, &tRawData[0], 52, PROTOCOL_IS_LSB_FIRST,
519523
SEND_NO_STOP_BIT, 0, 0);
520524
checkReceivedArray(tRawData, 2);
521-
# else
525+
# else
522526
IrSender.sendPulseDistanceWidth(38, 300, 600, 600, 300, 300, 600, 0xDCBA987654321, 52, PROTOCOL_IS_LSB_FIRST,
523527
SEND_NO_STOP_BIT, 0, 0);
524528
checkReceivedRawData(0xDCBA987654321);
525-
# endif
529+
# endif
526530
delay(DELAY_AFTER_SEND);
527-
# endif
531+
# endif // defined(DISTANCE_DO_MSB_DECODING)
532+
# endif // defined(DECODE_DISTANCE_WIDTH)
528533

529534
# if defined(DECODE_MAGIQUEST)
530535
Serial.println(F("Send MagiQuest 0x6BCDFF00, 0x176 as generic 55 bit PulseDistanceWidth MSB first"));

src/digitalWriteFast.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@
278278

279279

280280
// --- ATtinyX4 + ATtinyX7 ---
281-
#elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
281+
#elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) \
282+
|| defined(__AVR_ATtiny441__) || defined(__AVR_ATtiny841__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
282283
# if defined(ARDUINO_AVR_DIGISPARKPRO) || PIN_PA7 == 5
283284
// Strange enumeration of pins on Digispark board and core library
284285
#define __digitalPinToPortReg(P) (((P) <= 4) ? &PORTB : &PORTA)
@@ -291,6 +292,11 @@
291292
#define __digitalPinToPortReg(P) (((P) <= 7) ? &PORTA : &PORTB)
292293
#define __digitalPinToDDRReg(P) (((P) <= 7) ? &DDRA : &DDRB)
293294
#define __digitalPinToPINReg(P) (((P) <= 7) ? &PINA : &PINB)
295+
# if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny441__) || defined(__AVR_ATtiny841__)
296+
// https://github.com/SpenceKonde/ATTinyCore/blob/v2.0.0-devThis-is-the-head-submit-PRs-against-this/avr/variants/tinyx41_cw/pins_arduino.h#L334
297+
// Clockwise layout
298+
#define __digitalPinToBit(P) (((P) <= 7) ? (P) : ((P) == 11 ? (3) : 10 - (P)))
299+
# endif
294300
#define __digitalPinToBit(P) (((P) <= 7) ? (P) : (P) - 8 )
295301
# endif
296302

src/private/IRTimer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ void disableSendPWMByTimer() {
183183
//#define IR_USE_AVR_TIMER_D // use this if you use TinyCore
184184
# endif
185185

186-
// ATmega8u2, ATmega16U2, ATmega32U2
186+
// ATmega8u2, ATmega16U2, ATmega32U2, ATmega8 - Timer 2 does not work with existing code below
187187
#elif defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega8__)
188188
# if !defined(IR_USE_AVR_TIMER1)
189189
#define IR_USE_AVR_TIMER1 // send pin = pin C6

0 commit comments

Comments
 (0)