PaulStoffregen / DmxSimple

99 stars 21 forks source link

Support for Arduino nano Every #31

Open antoniomechas opened 6 months ago

antoniomechas commented 6 months ago

I'm trying to use this library on Arduino Nano Every, because the newer DMXSerial doesn't seem to work with ethernet shield using the EthernetENC library. When compiling I get the following error:

_c:\Users\gizmow\Documents\Arduino\libraries\DmxSimple\DmxSimple.cpp:77:2: error: #error "DmxSimple does not support this CPU"
 #error "DmxSimple does not support this CPU"
  ^~~~~
c:\Users\gizmow\Documents\Arduino\libraries\DmxSimple\DmxSimple.cpp: In function 'void TIMER2_OVF_vect()':
c:\Users\gizmow\Documents\Arduino\libraries\DmxSimple\DmxSimple.cpp:213:23: error: 'BITS_PER_TIMER_TICK' was not declared in this scope
   uint16_t bitsLeft = BITS_PER_TIMER_TICK; // DMX Bit periods per timer tick
                       ^~~~~~~~~~~~~~~~~~~

exit status 1

Compilation error: exit status 1_

There is no configuration for ATmega4809 processor. I tried to find out what could be by following here: https://emalliab.wordpress.com/2022/01/23/arduino-nano-every-timers-and-pwm/

/* TIMER2 has a different register mapping on the ATmega8.
 * The modern chips (168, 328P, 1280) use identical mappings.
 */
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
#define TIMER2_INTERRUPT_ENABLE() TIMSK2 |= _BV(TOIE2)
#define TIMER2_INTERRUPT_DISABLE() TIMSK2 &= ~_BV(TOIE2)
#define ISR_NAME TIMER2_OVF_vect
#define BITS_PER_TIMER_TICK (F_CPU / 31372)

// older ATMEGA8 has slighly different timer2
#elif defined(__AVR_ATmega8__)
#define TIMER2_INTERRUPT_ENABLE() TIMSK |= _BV(TOIE2)
#define TIMER2_INTERRUPT_DISABLE() TIMSK &= ~_BV(TOIE2)
#define ISR_NAME TIMER2_OVF_vect
#define BITS_PER_TIMER_TICK (F_CPU / 31372)

// ATMEGA32U4 on Teensy and Leonardo has no timer2, but has timer4
#elif defined (__AVR_ATmega32U4__)
#define TIMER2_INTERRUPT_ENABLE() TIMSK4 |= _BV(TOIE4)
#define TIMER2_INTERRUPT_DISABLE() TIMSK4 &= ~_BV(TOIE4)
#define ISR_NAME TIMER4_OVF_vect
#define BITS_PER_TIMER_TICK (F_CPU / 31372)

// Teensy 3.0 has IntervalTimer, unrelated to any PWM signals
#elif defined(CORE_TEENSY) && defined(__arm__)
#define TIMER2_INTERRUPT_ENABLE()
#define TIMER2_INTERRUPT_DISABLE()
#define ISR_NAME DMXinterrupt
#define ISR(function, option)  void function(void)
#define BITS_PER_TIMER_TICK 500
void DMXinterrupt(void);
IntervalTimer DMXtimer;

#else
#define TIMER2_INTERRUPT_ENABLE()
#define TIMER2_INTERRUPT_DISABLE()
#define ISR_NAME TIMER2_OVF_vect
/* Produce an error (warnings to not print on Arduino's default settings)
 */
#error "DmxSimple does not support this CPU"
#endif

But my knowledge is not enough to get the info properly.

Anyone could make this library work on Arduino Nano Every? Thanks, Antonio.