Skip to content

Commit 063b390

Browse files
committed
pin register
1 parent a404da0 commit 063b390

File tree

5 files changed

+65
-9
lines changed

5 files changed

+65
-9
lines changed

Encoder.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@
5858
#define ENCODER_ISR_ATTR
5959
#endif
6060

61-
62-
6361
// All the data needed by interrupts is consolidated into this ugly struct
6462
// to facilitate assembly language optimizing of the speed critical update.
6563
// The assembly code uses auto-incrementing addressing modes, so the struct
@@ -76,7 +74,12 @@ typedef struct {
7674
class Encoder
7775
{
7876
public:
79-
Encoder(uint8_t pin1, uint8_t pin2) {
77+
// one step setup like before
78+
Encoder(uint8_t pin1, uint8_t pin2) { begin(pin1, pin2);}
79+
80+
// two step setup for platforms that have issues with constructor ordering
81+
Encoder() { }
82+
void begin(uint8_t pin1, uint8_t pin2) {
8083
#ifdef INPUT_PULLUP
8184
pinMode(pin1, INPUT_PULLUP);
8285
pinMode(pin2, INPUT_PULLUP);
@@ -303,8 +306,12 @@ class Encoder
303306
uint8_t p1val = DIRECT_PIN_READ(arg->pin1_register, arg->pin1_bitmask);
304307
uint8_t p2val = DIRECT_PIN_READ(arg->pin2_register, arg->pin2_bitmask);
305308
uint8_t state = arg->state & 3;
309+
//Serial.print(p1val); Serial.print(", ");
310+
//Serial.print(p2val); Serial.print(", ");
311+
//Serial.print(state); Serial.print(", ");
306312
if (p1val) state |= 4;
307313
if (p2val) state |= 8;
314+
//Serial.print(state); Serial.println(", ");
308315
arg->state = (state >> 2);
309316
switch (state) {
310317
case 1: case 7: case 8: case 14:
@@ -769,7 +776,7 @@ class Encoder
769776
static ENCODER_ISR_ATTR void isr2(void) { update(interruptArgs[2]); }
770777
#endif
771778
#ifdef CORE_INT3_PIN
772-
static ENCODER_ISR_ATTR void isr3(void) { update(interruptArgs[3]); }
779+
static ENCODER_ISR_ATTR void isr3(void) { update(interruptArgs[3]);}
773780
#endif
774781
#ifdef CORE_INT4_PIN
775782
static ENCODER_ISR_ATTR void isr4(void) { update(interruptArgs[4]); }

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Encoder
2-
version=1.4.4
2+
version=1.4.3
33
author=Paul Stoffregen
44
maintainer=Paul Stoffregen
55
sentence=Counts quadrature pulses from rotary & linear position encoders.

utility/direct_pin_read.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#if defined(__AVR__)
55

6-
#define IO_REG_TYPE uint8_t
76
#define PIN_TO_BASEREG(pin) (portInputRegister(digitalPinToPort(pin)))
87
#define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin))
98
#define DIRECT_PIN_READ(base, mask) (((*(base)) & (mask)) ? 1 : 0)
@@ -111,6 +110,25 @@ IO_REG_TYPE directRead(volatile IO_REG_TYPE *base, IO_REG_TYPE pin)
111110
}
112111
#define DIRECT_PIN_READ(base, pin) directRead(base, pin)
113112

113+
#elif defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_UNOR4_MINIMA) /*Arduino UnoR4 */
114+
115+
#define IO_REG_TYPE uint32_t
116+
#define PIN_TO_BASEREG(pin) (volatile uint32_t*)(portInputRegister(digitalPinToPort(pin)))
117+
#define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin))
118+
#define DIRECT_PIN_READ(base, mask) (((*(base)) & (mask)) ? 1 : 0)
119+
120+
#elif defined(ARDUINO_GIGA)
121+
122+
#define digitalPinToPort(P) (digitalPinToPinName(P)/32)
123+
#define digitalPinToBitMask(P) (1 << (digitalPinToPinName(P) % 32))
124+
#define portModeRegister(P) (uint32_t*)P
125+
126+
#define IO_REG_TYPE uint32_t
127+
#define PIN_TO_BASEREG(pin) portModeRegister(digitalPinToPort(pin))
128+
#define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin))
129+
#define DIRECT_PIN_READ(base, pin) digitalRead(pin)
130+
131+
114132
#endif
115133

116134
#endif

utility/interrupt_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if defined(__AVR__)
1+
#if defined(__AVR__)
22

33
#include <avr/io.h>
44
#include <avr/interrupt.h>

utility/interrupt_pins.h

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,38 @@
384384
// #define CORE_INT20_PIN A6
385385
// #define CORE_INT21_PIN A7
386386

387+
// Arduino Uno R4
388+
#elif defined(ARDUINO_UNOR4_MINIMA)
389+
//0, 1, 2, 3, 8, 12, 13, 15, 16, 17, 18 and 19.
390+
#define CORE_NUM_INTERRUPT 20
391+
#define CORE_INT0_PIN 0
392+
#define CORE_INT1_PIN 1
393+
#define CORE_INT2_PIN 2
394+
#define CORE_INT3_PIN 3
395+
#define CORE_INT8_PIN 8
396+
#define CORE_INT12_PIN 12
397+
#define CORE_INT13_PIN 13
398+
#define CORE_INT15_PIN 15
399+
#define CORE_INT16_PIN 16
400+
#define CORE_INT17_PIN 17
401+
#define CORE_INT18_PIN 18
402+
#define CORE_INT19_PIN 19
403+
#elif defined(ARDUINO_UNOR4_WIFI)
404+
//0, 1, 2, 3, 8, 11, 12, 15, 16, 17, 18 and 19.
405+
#define CORE_NUM_INTERRUPT 20
406+
#define CORE_INT0_PIN 0
407+
#define CORE_INT1_PIN 1
408+
#define CORE_INT2_PIN 2
409+
#define CORE_INT3_PIN 3
410+
#define CORE_INT8_PIN 8
411+
#define CORE_INT11_PIN 11
412+
#define CORE_INT12_PIN 12
413+
#define CORE_INT15_PIN 15
414+
#define CORE_INT16_PIN 16
415+
#define CORE_INT17_PIN 17
416+
#define CORE_INT18_PIN 18
417+
#define CORE_INT19_PIN 19
418+
387419

388420
// Arduino Giga R1 WiFi
389421
// All pins are interrupt capable
@@ -466,8 +498,7 @@
466498
#define CORE_INT74_PIN 74
467499
#define CORE_INT75_PIN 75
468500
#define CORE_INT76_PIN 76
469-
470-
501+
471502
#endif
472503
#endif
473504

0 commit comments

Comments
 (0)