Can't use usbhost shield library with arduino nano every

Hi, I have a project which uses sparkfun usb host shield
I'm using the only available library for it, this one

I've tested my project on Arduino Uno R3 and it works fine, however if I try to recompile my project for arduino nano every I get this:

Arduino: 1.8.13 (Windows 10), Board: "Arduino Nano Every, ATMEGA328"


In file included from C:\Users\Izzy\Documents\Arduino\libraries\USB_Host_Shield_Library_2.0/Usb.h:34:0,

                 from C:\Users\Izzy\Documents\Arduino\libraries\USB_Host_Shield_Library_2.0/usbhid.h:20,

                 from C:\Users\Izzy\Documents\Arduino\libraries\USB_Host_Shield_Library_2.0/hidboot.h:20,

                 from C:\Users\Izzy\Documents\Arduino\libraries\USB_Host_Shield_Library_2.0\examples\HID\USBHIDBootKbd\USBHIDBootKbd.ino:1:

C:\Users\Izzy\Documents\Arduino\libraries\USB_Host_Shield_Library_2.0/avrpins.h:827:2: error: #error "Please define board in avrpins.h"

 #error "Please define board in avrpins.h"

  ^~~~~

exit status 1

Error compiling for board Arduino Nano Every.



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Now, I went to avrpins.h and tried to tweak it a liitle bit, adding this piece (after definition of classic arduino pins):

#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
// "Classic" Arduino pin numbers

#define P0  Pd0
#define P1  Pd1
#define P2  Pd2
#define P3  Pd3
#define P4  Pd4
#define P5  Pd5
#define P6  Pd6
#define P7  Pd7

#define P8  Pb0
#define P9  Pb1
#define P10  Pb2
#define P11  Pb3
#define P12  Pb4
#define P13  Pb5

#define P14  Pc0
#define P15  Pc1
#define P16  Pc2
#define P17  Pc3
#define P18  Pc4
#define P19  Pc5

#elif defined(__AVR_ATmega4809__)
// arduino nano every
#define P0  Pd0
#define P1  Pd1
#define P2  Pd2
#define P3  Pd3
#define P4  Pd4
#define P5  Pd5
#define P6  Pd6
#define P7  Pd7
#define P8  Pd8

#define P9  Pb0
#define P10  Pb1
#define P11  Pb2
#define P12  Pb3
#define P13  Pb4

#define P14  Pc0
#define P15  Pc1
#define P16  Pc2
#define P17  Pc3
#define P18  Pc4
#define P19  Pc5
#define P20  Pc6
#define P21  Pc7

Which is basically a copy of classic arduino pins with a little adjustments considering that ANE has one less pwm out and two more analog in's.

With this I get new error, which is:

C:\Users\Izzy\Documents\Arduino\libraries\USB_Host_Shield_Library_2.0/avrpins.h:94:49: error: no match for 'operator=' (operand types are 'PORT_t {aka PORT_struct}' and 'Porta::DataT {aka unsigned char}')
       static void Write(DataT value){portName = value;}\
                                                 ^
C:\Users\Izzy\Documents\Arduino\libraries\USB_Host_Shield_Library_2.0/avrpins.h:127:1: note: in expansion of macro 'MAKE_PORT'
 MAKE_PORT(PORTA, DDRA, PINA, Porta, 'A')
 ^~~~~~~~~

I think it should be easy to solve since ANE is very similar with Arduino UNO, all standard libraries work no problem. Can someone help me with this? I already opened an issue on the github page of the library but the latest commit was more than a year ago, so I'm not hoping to get some help there.

Which is basically a copy of classic arduino pins with a little adjustments considering that ANE has one less pwm out and two more analog in's.

But the Nano Every doesn't have the same pin names as the UNO. Even as you've chosen register emulation, that doesn't include all low level names, otherwise the emulation wouldn't work after all.

Unfortunately the USB Host Shield 2.0 library didn't get and update for more than a year, so the new boards with the megaAVR series processors didn't get support yet.

Adding it yourself might be quite a bit of work. And you shouldn't use the ATmega328 register emulation when compiling this.

I've kept digging and found out that microcontroller ports on ANE are actually quite diffirent, so I edited my code piece to comply with this drawing

Now it looks like this:

#elif defined(__AVR_ATmega4809__)


#define P0  Pc4
#define P1  Pc5
#define P2  Pa0
#define P3  Pf5
#define P4  Pc6
#define P5  Pb2
#define P6  Pf4
#define P7  Pa1
#define P8  Pe3

#define P9  Pb0
#define P10  Pb1
#define P11  Pe0
#define P12  Pe1
#define P13  Pe2
#define P14  Pd7

#define P15  Pd3
#define P16  Pd2
#define P17  Pd1
#define P18  Pd0
#define P19  Pa2
#define P20  Pa3
#define P21  Pd4
#define P22  Pd5

I've tried to compile my sketch then with and without emulation, unfortunately still no luck :frowning:

At this point it feels that my only hope is that devs would update the library. I've tried to go through the library code and it's waaaaaay to advanced for me.

The problem is that the ATmega4809 is a megaAVR processor and not an AVR, so the predefined constant is not AVR but AVR_XMEGA. So to get support for your board you have to construct the whole platform part which is quite a bit of code unfortunately.

pylon:
The problem is that the ATmega4809 is a megaAVR processor and not an AVR, so the predefined constant is not AVR but AVR_XMEGA. So to get support for your board you have to construct the whole platform part which is quite a bit of code unfortunately.

Got it, thx! It's so sad, since all the other components transitioned to the new board smoothly.