Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
#define ENCODER_ISR_ATTR
#endif



// All the data needed by interrupts is consolidated into this ugly struct
// to facilitate assembly language optimizing of the speed critical update.
// The assembly code uses auto-incrementing addressing modes, so the struct
Expand All @@ -76,7 +74,12 @@ typedef struct {
class Encoder
{
public:
Encoder(uint8_t pin1, uint8_t pin2) {
// one step setup like before
Encoder(uint8_t pin1, uint8_t pin2) { begin(pin1, pin2);}

// two step setup for platforms that have issues with constructor ordering
Encoder() { }
void begin(uint8_t pin1, uint8_t pin2) {
#ifdef INPUT_PULLUP
pinMode(pin1, INPUT_PULLUP);
pinMode(pin2, INPUT_PULLUP);
Expand Down Expand Up @@ -303,8 +306,12 @@ class Encoder
uint8_t p1val = DIRECT_PIN_READ(arg->pin1_register, arg->pin1_bitmask);
uint8_t p2val = DIRECT_PIN_READ(arg->pin2_register, arg->pin2_bitmask);
uint8_t state = arg->state & 3;
//Serial.print(p1val); Serial.print(", ");
//Serial.print(p2val); Serial.print(", ");
//Serial.print(state); Serial.print(", ");
if (p1val) state |= 4;
if (p2val) state |= 8;
//Serial.print(state); Serial.println(", ");
arg->state = (state >> 2);
switch (state) {
case 1: case 7: case 8: case 14:
Expand Down Expand Up @@ -769,7 +776,7 @@ class Encoder
static ENCODER_ISR_ATTR void isr2(void) { update(interruptArgs[2]); }
#endif
#ifdef CORE_INT3_PIN
static ENCODER_ISR_ATTR void isr3(void) { update(interruptArgs[3]); }
static ENCODER_ISR_ATTR void isr3(void) { update(interruptArgs[3]);}
#endif
#ifdef CORE_INT4_PIN
static ENCODER_ISR_ATTR void isr4(void) { update(interruptArgs[4]); }
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Encoder
version=1.4.4
version=1.4.3
author=Paul Stoffregen
maintainer=Paul Stoffregen
sentence=Counts quadrature pulses from rotary & linear position encoders.
Expand Down
20 changes: 19 additions & 1 deletion utility/direct_pin_read.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#if defined(__AVR__)

#define IO_REG_TYPE uint8_t
#define PIN_TO_BASEREG(pin) (portInputRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin))
#define DIRECT_PIN_READ(base, mask) (((*(base)) & (mask)) ? 1 : 0)
Expand Down Expand Up @@ -111,6 +110,25 @@ IO_REG_TYPE directRead(volatile IO_REG_TYPE *base, IO_REG_TYPE pin)
}
#define DIRECT_PIN_READ(base, pin) directRead(base, pin)

#elif defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_UNOR4_MINIMA) /*Arduino UnoR4 */

#define IO_REG_TYPE uint32_t
#define PIN_TO_BASEREG(pin) (volatile uint32_t*)(portInputRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin))
#define DIRECT_PIN_READ(base, mask) (((*(base)) & (mask)) ? 1 : 0)

#elif defined(ARDUINO_GIGA)

#define digitalPinToPort(P) (digitalPinToPinName(P)/32)
#define digitalPinToBitMask(P) (1 << (digitalPinToPinName(P) % 32))
#define portModeRegister(P) (uint32_t*)P

#define IO_REG_TYPE uint32_t
#define PIN_TO_BASEREG(pin) portModeRegister(digitalPinToPort(pin))
#define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin))
#define DIRECT_PIN_READ(base, pin) digitalRead(pin)


#endif

#endif
2 changes: 1 addition & 1 deletion utility/interrupt_config.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if defined(__AVR__)
#if defined(__AVR__)

#include <avr/io.h>
#include <avr/interrupt.h>
Expand Down
116 changes: 116 additions & 0 deletions utility/interrupt_pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,122 @@
#define CORE_INT19_PIN 19
// #define CORE_INT20_PIN A6
// #define CORE_INT21_PIN A7

// Arduino Uno R4
#elif defined(ARDUINO_UNOR4_MINIMA)
//0, 1, 2, 3, 8, 12, 13, 15, 16, 17, 18 and 19.
#define CORE_NUM_INTERRUPT 20
#define CORE_INT0_PIN 0
#define CORE_INT1_PIN 1
#define CORE_INT2_PIN 2
#define CORE_INT3_PIN 3
#define CORE_INT8_PIN 8
#define CORE_INT12_PIN 12
#define CORE_INT13_PIN 13
#define CORE_INT15_PIN 15
#define CORE_INT16_PIN 16
#define CORE_INT17_PIN 17
#define CORE_INT18_PIN 18
#define CORE_INT19_PIN 19
#elif defined(ARDUINO_UNOR4_WIFI)
//0, 1, 2, 3, 8, 11, 12, 15, 16, 17, 18 and 19.
#define CORE_NUM_INTERRUPT 20
#define CORE_INT0_PIN 0
#define CORE_INT1_PIN 1
#define CORE_INT2_PIN 2
#define CORE_INT3_PIN 3
#define CORE_INT8_PIN 8
#define CORE_INT11_PIN 11
#define CORE_INT12_PIN 12
#define CORE_INT15_PIN 15
#define CORE_INT16_PIN 16
#define CORE_INT17_PIN 17
#define CORE_INT18_PIN 18
#define CORE_INT19_PIN 19


// Arduino Giga R1 WiFi
// All pins are interrupt capable
#elif defined(ARDUINO_GIGA)
#define CORE_NUM_INTERRUPT 76
#define CORE_INT0_PIN 0
#define CORE_INT1_PIN 1
#define CORE_INT2_PIN 2
#define CORE_INT3_PIN 3
#define CORE_INT4_PIN 4
#define CORE_INT5_PIN 5
#define CORE_INT6_PIN 6
#define CORE_INT7_PIN 7
#define CORE_INT8_PIN 8
#define CORE_INT9_PIN 9
#define CORE_INT10_PIN 10
#define CORE_INT11_PIN 11
#define CORE_INT12_PIN 12
#define CORE_INT13_PIN 13
#define CORE_INT14_PIN 14
#define CORE_INT15_PIN 15
#define CORE_INT16_PIN 16
#define CORE_INT17_PIN 17
#define CORE_INT18_PIN 18
#define CORE_INT19_PIN 19
#define CORE_INT20_PIN 20
#define CORE_INT21_PIN 21
#define CORE_INT22_PIN 22
#define CORE_INT23_PIN 23
#define CORE_INT24_PIN 24
#define CORE_INT25_PIN 25
#define CORE_INT26_PIN 26
#define CORE_INT27_PIN 27
#define CORE_INT28_PIN 28
#define CORE_INT29_PIN 29
#define CORE_INT30_PIN 30
#define CORE_INT31_PIN 31
#define CORE_INT32_PIN 32
#define CORE_INT33_PIN 33
#define CORE_INT34_PIN 34
#define CORE_INT35_PIN 35
#define CORE_INT36_PIN 36
#define CORE_INT37_PIN 37
#define CORE_INT38_PIN 38
#define CORE_INT39_PIN 39
#define CORE_INT40_PIN 40
#define CORE_INT41_PIN 41
#define CORE_INT42_PIN 42
#define CORE_INT43_PIN 43
#define CORE_INT44_PIN 44
#define CORE_INT45_PIN 45
#define CORE_INT46_PIN 46
#define CORE_INT47_PIN 47
#define CORE_INT48_PIN 48
#define CORE_INT49_PIN 49
#define CORE_INT50_PIN 50
#define CORE_INT51_PIN 51
#define CORE_INT52_PIN 52
#define CORE_INT53_PIN 53
#define CORE_INT54_PIN 54
#define CORE_INT55_PIN 55
#define CORE_INT56_PIN 56
#define CORE_INT57_PIN 57
#define CORE_INT58_PIN 58
#define CORE_INT59_PIN 59
#define CORE_INT60_PIN 60
#define CORE_INT61_PIN 61
#define CORE_INT62_PIN 62
#define CORE_INT63_PIN 63
#define CORE_INT64_PIN 64
#define CORE_INT65_PIN 65
#define CORE_INT66_PIN 66
#define CORE_INT67_PIN 67
#define CORE_INT68_PIN 68
#define CORE_INT69_PIN 69
#define CORE_INT70_PIN 70
#define CORE_INT71_PIN 71
#define CORE_INT72_PIN 72
#define CORE_INT73_PIN 73
#define CORE_INT74_PIN 74
#define CORE_INT75_PIN 75
#define CORE_INT76_PIN 76

#endif
#endif

Expand Down