Hmm, I am coping with the stuff, indeed
I am using 1284p mighty, IDE 1.5.2, and an encoder with pullups on A6/A7, and in "Cosa/Board/mighty.hh" I did following changes (mighty uses a reversed numbering in Ax):
...
/**
* Return Pin Change Mask Register for given Arduino pin number.
* @param[in] pin number.
* @return pin change mask register pointer.
*/
static volatile uint8_t* PCIMR(uint8_t pin)
{
return (pin < 8 ? &PCMSK0 :
pin < 14 ? &PCMSK1 :
pin < 24 ? &PCMSK2 :
&PCMSK3);
}
...
/**
* Analog pin symbols; mapping from name to port<5>:bit<3>.
*/
enum AnalogPin {
A0 = 31,
A1 = 30,
A2 = 29,
A3 = 28,
A4 = 27,
A5 = 26,
A6 = 25,
A7 = 24
} __attribute__((packed));
...
/**
* Pin change interrupt. Number of port registers.
*/
enum InterruptPin {
/*PCI0 = A0,
PCI1 = A1,
PCI2 = A2,
PCI3 = A3,
PCI4 = A4,
PCI5 = A5,
PCI6 = A6,
PCI7 = A7*/
PCI0 = D0,
PCI1 = D1,
PCI2 = D2,
PCI3 = D3,
PCI4 = D4,
PCI5 = D5,
PCI6 = D6,
PCI7 = D7,
PCI8 = D8,
PCI9 = D9,
PCI10 = D10,
PCI11 = D11,
PCI12 = D12,
PCI13 = D13,
PCI14 = D14,
PCI15 = D15,
PCI16 = D16,
PCI17 = D17,
PCI18 = D18,
PCI19 = D19,
PCI20 = D20,
PCI21 = D21,
PCI22 = D22,
PCI23 = D23,
PCI24 = A0,
PCI25 = A1,
PCI26 = A2,
PCI27 = A3,
PCI28 = A4,
PCI29 = A5,
PCI30 = A6,
PCI31 = A7
} __attribute__((packed));
...
/**
* Auxiliary
*/
enum {
VBG = (_BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1)),
EXT_MAX = 3,
PCINT_MAX = 4,
PIN_MAX = A0
} __attribute__((packed));
};
Not sure whether I do understand the Auxiliary well - it seems to me pcint_max = 4(??) and pin_max = A0 (??) (pin code 31).
So the pin change interrupt is set to A6, A7 with the code:
// MIGHTY ATMEL ATMEGA1284P
//
// +---\/---+
// (D 0) PB0 1| |40 PA0 (AI 0 / PCI24 / D24)
// (D 1) PB1 2| |39 PA1 (AI 1 / PCI25 / D25)
// INT2 (D 2) PB2 3| |38 PA2 (AI 2 / PCI26 / D26)
// PWM (D 3) PB3 4| |37 PA3 (AI 3 / PCI27 / D27)
// PWM/SS (D 4) PB4 5| |36 PA4 (AI 4 / PCI28 / D28)
// MOSI (D 5) PB5 6| |35 PA5 (AI 5 / PCI29 / D29)
// PWM/MISO (D 6) PB6 7| |34 PA6 (AI 6 / PCI30 / D30)
// PWM/SCK (D 7) PB7 8| |33 PA7 (AI 7 / PCI31 / D31)
// RST 9| |32 AREF
// VCC 10| |31 GND
// GND 11| |30 AVCC
// XTAL2 12| |29 PC7 (D 23)
// XTAL1 13| |28 PC6 (D 22)
// RX0 (D 8) PD0 14| |27 PC5 (D 21) TDI
// TX0 (D 9) PD1 15| |26 PC4 (D 20) TDO
// RX1/INT0 (D 10) PD2 16| |25 PC3 (D 19) TMS
// TX1/INT1 (D 11) PD3 17| |24 PC2 (D 18) TCK
// PWM (D 12) PD4 18| |23 PC1 (D 17) SDA
// PWM (D 13) PD5 19| |22 PC0 (D 16) SCL
// PWM (D 14) PD6 20| |21 PD7 (D 15) PWM
// +--------+
//
#include "Cosa/Rotary.hh"
#include "Cosa/Trace.hh"
#include "Cosa/IOStream/Driver/UART.hh"
void setup()
{
// Use the UART as output stream
uart.begin(115200);
trace.begin(&uart, PSTR("CosaRotaryEncoder: started"));
// Start the interrupt pin handler
InterruptPin::begin();
}
// Construct Dial connected to interrupt pins (A6 and A7 on mighty), start in full step mode,
// with initial value -100, min -100, and max 10.
Rotary::Dial dial(Board::PCI30, Board::PCI31, Rotary::Encoder::FULL_STEP, -100, -100, 10);
void loop()
{
// Rotary Encoder interrupt pin handler will push an event when a change occurs
Event event;
Event::queue.await(&event);
// Dispatch the event so that the dial value is updated
event.dispatch();
// Change step mode at min and max values
static int old_value = -100;
trace << old_value << endl;
int new_value = dial.get_value();
//if (old_value == -100 && new_value == -99)
// dial.set_step(Rotary::Encoder::FULL_STEP);
//else if (old_value == 10 && new_value == 9)
// dial.set_step(Rotary::Encoder::HALF_STEP);
// old_value = new_value;
// Print the new value
trace << new_value << endl;
}
However it prints only:
CosaRotaryEncoder: started
with whatever I've done above.. It does not even print the old_value..
PS1: it waits/stops/crashes(?) on " Event::queue.await(&event);"
PS2: tried with other pins, no luck yet..
PS3: reading interruptpin.hh I've set PCINT_MAX = 4 in above mighty.hh
PS4: I think we have to have in l.50 interruptpin.hh (as the mighty has got all 4 PCMSKs):
#if !defined(__ARDUINO_MEGA__)
friend void PCINT3_vect(void);
PS5: yea, the interrupt handler has to be fine-tuned for above mighty.hh.. Thanks