When using esp32 with ps2x library, it links some avr libraries which seems to be incompatible or unavailable for esp32.
I cannot find any specific AVR library to be included. It has an include for an AVR header file ("avr/io.h") in PS2X_lib.cpp, but you can safely delete that line as the include is done in the PS2X_lib.h file already if the AVR platform is used. What other libraries is missing on your platform?
I am trying to port this ROV project (http://techmonkeybusiness.com/rov-control-sketches-fourth-edition.html) which I built and had working with an Arduino Nano to 2 NodeMCU ESP32-S because I need the extra memory and processing power to add an external pressure sensor, MPU9250, PID control, and an on-screen display via mavlink and minimOSD.
As instructed above I commented out the AVR/IO.h references in the ps2x_lib.h and ps2x_lib.cpp files but I am stilll getting the following error messages:
Arduino: 1.8.5 (Mac OS X), Board: "NodeMCU-32S, 80MHz, 921600"
/var/folders/1l/fvhdppfn553965nv3tkhpsv40000gn/T/arduino_build_65421/sketch/PS2X_lib.cpp: In member function 'byte PS2X::config_gamepad(uint32_t, uint32_t, uint32_t, uint32_t, bool, bool)':
PS2X_lib.cpp:185: error: '_clk_lport_set' was not declared in this scope
_clk_lport_set = portOutputRegister(lport) + 2;
^
PS2X_lib.cpp:186: error: '_clk_lport_clr' was not declared in this scope
_clk_lport_clr = portOutputRegister(lport) + 1;
^
PS2X_lib.cpp:190: error: '_cmd_lport_set' was not declared in this scope
_cmd_lport_set = portOutputRegister(lport) + 2;
^
PS2X_lib.cpp:191: error: '_cmd_lport_clr' was not declared in this scope
_cmd_lport_clr = portOutputRegister(lport) + 1;
^
PS2X_lib.cpp:195: error: '_att_lport_set' was not declared in this scope
_att_lport_set = portOutputRegister(lport) + 2;
^
PS2X_lib.cpp:196: error: '_att_lport_clr' was not declared in this scope
_att_lport_clr = portOutputRegister(lport) + 1;
^
PS2X_lib.cpp:199: error: '_dat_lport' was not declared in this scope
_dat_lport = portInputRegister(digitalPinToPort(dat));
^
/var/folders/1l/fvhdppfn553965nv3tkhpsv40000gn/T/arduino_build_65421/sketch/PS2X_lib.cpp: In member function 'void PS2X::CLK_SET()':
PS2X_lib.cpp:440: error: '_clk_lport_set' was not declared in this scope _clk_lport_set |= _clk_mask;
^
/var/folders/1l/fvhdppfn553965nv3tkhpsv40000gn/T/arduino_build_65421/sketch/PS2X_lib.cpp: In member function 'void PS2X::CLK_CLR()':
PS2X_lib.cpp:444: error: '_clk_lport_clr' was not declared in this scope _clk_lport_clr |= _clk_mask;
^
/var/folders/1l/fvhdppfn553965nv3tkhpsv40000gn/T/arduino_build_65421/sketch/PS2X_lib.cpp: In member function 'void PS2X::CMD_SET()':
PS2X_lib.cpp:448: error: '_cmd_lport_set' was not declared in this scope _cmd_lport_set |= _cmd_mask;
^
/var/folders/1l/fvhdppfn553965nv3tkhpsv40000gn/T/arduino_build_65421/sketch/PS2X_lib.cpp: In member function 'void PS2X::CMD_CLR()':
PS2X_lib.cpp:452: error: '_cmd_lport_clr' was not declared in this scope _cmd_lport_clr |= _cmd_mask;
^
/var/folders/1l/fvhdppfn553965nv3tkhpsv40000gn/T/arduino_build_65421/sketch/PS2X_lib.cpp: In member function 'void PS2X::ATT_SET()':
PS2X_lib.cpp:456: error: '_att_lport_set' was not declared in this scope _att_lport_set |= _att_mask;
^
/var/folders/1l/fvhdppfn553965nv3tkhpsv40000gn/T/arduino_build_65421/sketch/PS2X_lib.cpp: In member function 'void PS2X::ATT_CLR()':
PS2X_lib.cpp:460: error: '_att_lport_clr' was not declared in this scope _att_lport_clr |= _att_mask;
^
/var/folders/1l/fvhdppfn553965nv3tkhpsv40000gn/T/arduino_build_65421/sketch/PS2X_lib.cpp: In member function 'bool PS2X::DAT_CHK()':
PS2X_lib.cpp:464: error: '_dat_lport' was not declared in this scope
return (_dat_lport & _dat_mask) ? true : false;
^
/Users/Jonathan/Documents/Arduino/libraries/PS2X_lib/PS2X_lib.cpp: In member function 'unsigned char PS2X::_gamepad_shiftinout(char)':
PS2X_lib.cpp:62: error: 'SREG' was not declared in this scope
uint8_t old_sreg = SREG; // *** KJE *** save away the current state of interrupts
^
/Users/Jonathan/Documents/Arduino/libraries/PS2X_lib/PS2X_lib.cpp: In member function 'void PS2X::read_gamepad(boolean, byte)':
PS2X_lib.cpp:93: error: 'SREG' was not declared in this scope
uint8_t old_sreg = SREG; // *** KJE **** save away the current state of interrupts - *** *** KJE *** ***
^
/Users/Jonathan/Documents/Arduino/libraries/PS2X_lib/PS2X_lib.cpp: In member function 'byte PS2X::config_gamepad(uint8_t, uint8_t, uint8_t, uint8_t, bool, bool)':
PS2X_lib.cpp:159: error: 'SREG' was not declared in this scope
uint8_t old_sreg = SREG; // *** KJE *** save away the current state of interrupts
^
PS2X_lib.cpp:163: error: cannot convert 'volatile uint32_t {aka volatile unsigned int}' to 'volatile uint8_t {aka volatile unsigned char}' in assignment
_clk_oreg = portOutputRegister(digitalPinToPort(clk));
^
PS2X_lib.cpp:165: error: cannot convert 'volatile uint32_t {aka volatile unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment
_cmd_oreg = portOutputRegister(digitalPinToPort(cmd));
^
PS2X_lib.cpp:167: error: cannot convert 'volatile uint32_t* {aka volatile unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment
_att_oreg = portOutputRegister(digitalPinToPort(att));
^
PS2X_lib.cpp:169: error: cannot convert 'volatile uint32_t* {aka volatile unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment
_dat_ireg = portInputRegister(digitalPinToPort(dat));
^
/Users/Jonathan/Documents/Arduino/libraries/PS2X_lib/PS2X_lib.cpp: In member function 'void PS2X::sendCommandString(byte*, byte)':
PS2X_lib.cpp:263: error: 'SREG' was not declared in this scope
uint8_t old_sreg = SREG; // *** KJE *** save away the current state of interrupts
It seems that the ESP32 platform doesn't support direct port readings. Convert the button reads into digitalRead()s which every Arduino IDE core must support.