Skip to content

Commit

Permalink
Merge pull request #9 from NicoHood/dev
Browse files Browse the repository at this point in the history
Release 1.2.4
  • Loading branch information
NicoHood committed Apr 16, 2016
2 parents e32ce0b + d7c91a6 commit 00cf36d
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 37 deletions.
7 changes: 5 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PinChangeInterrupt Library 1.2.3
PinChangeInterrupt Library 1.2.4
================================

![Header Picture](header.png)
Expand All @@ -25,7 +25,7 @@ See [PCINT pin table](https://github.com/NicoHood/PinChangeInterrupt/#pinchangei
A11 (65), A12 (66), A13 (67), A14 (68), A15 (69)
Arduino Leonardo/Micro: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI)
HoodLoader2: All (broken out 1-7) pins are usable
Attiny 24/44/84: All pins are usable
Attiny 24/44/84: All pins are usable
Attiny 25/45/85: All pins are usable
Attiny 13: All pins are usable
Attiny 441/841: All pins are usable
Expand Down Expand Up @@ -283,6 +283,9 @@ the new PinChangeInterrupts may help you a lot.
Version History
===============
```
1.2.4 Release (16.04.2016)
* Fixed Attinyx4/x5 Issue #8

1.2.3 Release (24.12.2015)
* Added Attiny441/841 support

Expand Down
48 changes: 24 additions & 24 deletions examples/PinChangeInterrupt_Led/PinChangeInterrupt_Led.ino
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
/*
Copyright (c) 2014-2015 NicoHood
See the readme for credit to other people.
Copyright (c) 2014-2015 NicoHood
See the readme for credit to other people.
PinChangeInterrupt_TickTock
Demonstrates how to use the library
PinChangeInterrupt_TickTock
Demonstrates how to use the library
Connect a button/cable to pin 7 and ground.
The Led state will change if the pin state does.
Connect a button/cable to pin 7 and ground.
The Led state will change if the pin state does.
PinChangeInterrupts are different than normal Interrupts.
See readme for more information.
Dont use Serial or delay inside interrupts!
This library is not compatible with SoftSerial.
PinChangeInterrupts are different than normal Interrupts.
See readme for more information.
Dont use Serial or delay inside interrupts!
This library is not compatible with SoftSerial.
The following pins are usable for PinChangeInterrupt:
Arduino Uno/Nano/Mini: All pins are usable
Arduino Mega: 10, 11, 12, 13, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64),
The following pins are usable for PinChangeInterrupt:
Arduino Uno/Nano/Mini: All pins are usable
Arduino Mega: 10, 11, 12, 13, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64),
A11 (65), A12 (66), A13 (67), A14 (68), A15 (69)
Arduino Leonardo/Micro: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI)
HoodLoader2: All (broken out 1-7) pins are usable
Attiny 24/44/84: All pins are usable
Attiny 25/45/85: All pins are usable
Attiny 13: All pins are usable
Attiny 441/841: All pins are usable
ATmega644P/ATmega1284P: All pins are usable
Arduino Leonardo/Micro: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI)
HoodLoader2: All (broken out 1-7) pins are usable
Attiny 24/44/84: All pins are usable
Attiny 25/45/85: All pins are usable
Attiny 13: All pins are usable
Attiny 441/841: All pins are usable
ATmega644P/ATmega1284P: All pins are usable
*/

#include "PinChangeInterrupt.h"

// choose a valid PinChangeInterrupt pin of your Arduino board
// Choose a valid PinChangeInterrupt pin of your Arduino board
#define pinBlink 7

void setup() {
// set pin to input with a pullup, led to output
pinMode(pinBlink, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);

// attach the new PinChangeInterrupt and enable event function below
// Attach the new PinChangeInterrupt and enable event function below
attachPCINT(digitalPinToPCINT(pinBlink), blinkLed, CHANGE);
}

void blinkLed(void) {
// switch Led state
// Switch Led state
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}

void loop() {
// nothing to do here
// Nothing to do here
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=PinChangeInterrupt
version=1.2.3
version=1.2.4
author=NicoHood
maintainer=NicoHood <[email protected]>
sentence=A simple & compact PinChangeInterrupt library for Arduino.
Expand Down
90 changes: 85 additions & 5 deletions src/PinChangeInterrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,34 @@ void enablePinChangeInterruptHelper(const uint8_t pcintPort, const uint8_t pcint

// Pin change mask registers decide which pins are ENABLE as triggers
#ifdef PCMSK0
*(&PCMSK0 + pcintPort) |= pcintMask;
#ifdef PCMSK1
// Special case for Attinyx4 where PCMSK1 and PCMSK0 are not next to each other
if(&PCMSK1 - &PCMSK0 == 1){
#endif
*(&PCMSK0 + pcintPort) |= pcintMask;
#ifdef PCMSK1
}
else{
switch(pcintPort){
case 0:
PCMSK0 |= pcintMask;
break;
case 1:
PCMSK1 |= pcintMask;
break;
#ifdef PCMSK2
case 2:
PCMSK2 |= pcintMask;
break;
#endif
#ifdef PCMSK3
case 3:
PCMSK3 |= pcintMask;
break;
#endif
}
}
#endif
#elif defined(PCMSK)
*(&PCMSK + pcintPort) |= pcintMask;
#endif
Expand All @@ -141,19 +168,71 @@ void enablePinChangeInterruptHelper(const uint8_t pcintPort, const uint8_t pcint
}

void disablePinChangeInterruptHelper(const uint8_t pcintPort, const uint8_t pcintMask) {
bool disable = false;
#ifdef PCMSK0
// disable the mask.
*(&PCMSK0 + pcintPort) &= ~pcintMask;
#ifdef PCMSK1
// Special case for Attinyx4 where PCMSK1 and PCMSK0 are not next to each other
if(&PCMSK1 - &PCMSK0 == 1){
#endif
// disable the mask.
*(&PCMSK0 + pcintPort) &= ~pcintMask;

// if that's the last one, disable the interrupt.
if (*(&PCMSK0 + pcintPort) == 0)
// if that's the last one, disable the interrupt.
if (*(&PCMSK0 + pcintPort) == 0)
disable = true;
#ifdef PCMSK1
}
else{
switch(pcintPort){
case 0:
// disable the mask.
PCMSK0 &= ~pcintMask;

// if that's the last one, disable the interrupt.
if (!PCMSK0)
disable = true;
break;
case 1:
// disable the mask.
PCMSK1 &= ~pcintMask;

// if that's the last one, disable the interrupt.
if (!PCMSK1)
disable = true;
break;
#ifdef PCMSK2
case 2:
// disable the mask.
PCMSK2 &= ~pcintMask;

// if that's the last one, disable the interrupt.
if (!PCMSK2)
disable = true;
break;
#endif
#ifdef PCMSK3
case 3:
// disable the mask.
PCMSK3 &= ~pcintMask;

// if that's the last one, disable the interrupt.
if (!PCMSK3)
disable = true;
break;
#endif
}
}
#endif
#elif defined(PCMSK)
// disable the mask.
*(&PCMSK + pcintPort) &= ~pcintMask;

// if that's the last one, disable the interrupt.
if (*(&PCMSK + pcintPort) == 0)
disable = true;
#endif
if(disable)
{
#ifdef PCICR
PCICR &= ~(1 << (pcintPort + PCIE0));
#elif defined(GIMSK) && defined(PCIE0) /* e.g. ATtiny X4 */
Expand All @@ -163,6 +242,7 @@ void disablePinChangeInterruptHelper(const uint8_t pcintPort, const uint8_t pcin
#else
#error MCU has no such a register
#endif
}
}

/*
Expand Down
10 changes: 8 additions & 2 deletions src/PinChangeInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ THE SOFTWARE.
#pragma once

// software version
#define PCINT_VERSION 123
#define PCINT_VERSION 124

#include "Arduino.h"

Expand Down Expand Up @@ -78,7 +78,13 @@ PinChangeInterruptEventPCINT ## pcint PCINT_MACRO_BRACKETS

// convert a normal pin to its PCINT number (0 - max 23), used by the user
// calculates the pin by the Arduino definitions
#define digitalPinToPinChangeInterrupt(p) (digitalPinToPCICR(p) ? ((8 * digitalPinToPCICRbit(p)) + digitalPinToPCMSKbit(p)) : NOT_AN_INTERRUPT)
#if defined(PCIE0)
#define digitalPinToPinChangeInterrupt(p) (digitalPinToPCICR(p) ? ((8 * (digitalPinToPCICRbit(p) - PCIE0)) + digitalPinToPCMSKbit(p)) : NOT_AN_INTERRUPT)
#elif defined(PCIE)
#define digitalPinToPinChangeInterrupt(p) (digitalPinToPCICR(p) ? ((8 * (digitalPinToPCICRbit(p) - PCIE)) + digitalPinToPCMSKbit(p)) : NOT_AN_INTERRUPT)
#else
#error MCU has no such a register
#endif

// alias for shorter writing
#define PCINTEvent(n) PinChangeInterruptEvent_Wrapper(n)
Expand Down
6 changes: 3 additions & 3 deletions src/PinChangeInterruptSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ The order is also okay. */

#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
// Port1 is connected to reset, crystal and Pin Interrupt 0
// deactivate it by default
#if defined(PCINT_ENABLE_PCINT1)
#undef PCINT_ENABLE_PCINT1
// Deactivate it by default
#if defined(PCINT_ENABLE_PORT1)
#undef PCINT_ENABLE_PORT1
#endif
#endif

0 comments on commit 00cf36d

Please sign in to comment.