Compilation Error Porting a GPIO code from ProMicro to Due

Hi All, following on from my previous topic, I have one further issue when trying to compile code written for AVR arduinos on the SAMD Due.

I will include the Background and setup from my previous post for those who haven't read it. Otherwise, feel free to skip to the Problem

Background: I do a bit of sim racing and am building a button box where I want to use Sim Hub's base code for arduino and expand on it. Sim Hub only supports some of the arduinos but I would like to use Arduino Due as it has the most pins and also allows using Joystick library for native HID support as a game controller. However, Due is not an option in Sim Hub configurator. Sim Hub software has a GUI configurator which allows configuring various inputs and outputs of the arduino, which can then be directly uploaded to the arduino. You can also configure everything and open the sketch allowing you to modify the code and change the arduino target.

Setup: I have configured everything for Arduino Leonardo within the Sim Hub GUI and then opened up the code in the Arduino IDE to change the arduino from Leonardo to Due (since Due is not available within Sim Hub GUI).

Problem Compiling the code gives the following errors:

In file included from C:\MEGA\Electronics\Projects\F023 - Sim Racing Button Box\Simhub\Arduino\DisplayClientV2\SHButton.h:5:0,
                 from C:\MEGA\Electronics\Projects\F023 - Sim Racing Button Box\Simhub\Arduino\DisplayClientV2\DisplayClientV2.ino:74:
C:\MEGA\Electronics\Projects\F023 - Sim Racing Button Box\Simhub\Arduino\DisplayClientV2\SHFastIO.h: In member function 'void FastDigitalPin::begin(int)':
C:\MEGA\Electronics\Projects\F023 - Sim Racing Button Box\Simhub\Arduino\DisplayClientV2\SHFastIO.h:22:9: error: invalid conversion from 'Pio*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    port = digitalPinToPort(pin);
         ^
In file included from C:\Users\filip\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\libraries\SPI\src/SPI.h:15:0,
                 from C:\MEGA\Electronics\Projects\F023 - Sim Racing Button Box\Simhub\Arduino\DisplayClientV2\DisplayClientV2.ino:66:
C:\MEGA\Electronics\Projects\F023 - Sim Racing Button Box\Simhub\Arduino\DisplayClientV2\SHFastIO.h: In member function 'int FastDigitalPin::digitalRead()':
C:\Users\filip\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x/variant.h:67:44: error: base operand of '->' is not a pointer
 #define portInputRegister(port)    ( &(port->PIO_PDSR) )
                                            ^
C:\MEGA\Electronics\Projects\F023 - Sim Racing Button Box\Simhub\Arduino\DisplayClientV2\SHFastIO.h:28:8: note: in expansion of macro 'portInputRegister'
   if (*portInputRegister(port) & bit) return HIGH;
        ^

exit status 1

Compilation error: invalid conversion from 'Pio*' to 'uint8_t {aka unsigned char}' [-fpermissive]

Ufortunately I was not able to upload the zipped 50+ Files in this project since I'm a new user and the forum doesn't allow me to.

Here are some snippets I believe are relevant. Feel free to request more.

SHFastIO.h:

#ifndef __SHFASTIO_H__
#define __SHFASTIO_H__
#include <Arduino.h>

class FastDigitalPin {
private:
	uint8_t bit = 0;
	uint8_t port = 0;
	bool pinIsValid = false;
public:

	bool isValid() {
		return pinIsValid;
	}
	void begin(int pin) {
		if (pin < 0) {
			pinIsValid = false;
		}
		else {
			pinIsValid = true;
			bit = digitalPinToBitMask(pin);
			port = digitalPinToPort(pin);
		}
	}

	int digitalRead()
	{
		if (*portInputRegister(port) & bit) return HIGH;
		return LOW; //Filip Setting this to low will set the corresponding button
	}
};

#endif

SHButton.h

#ifndef __SHBUTTON_H__
#define __SHBUTTON_H__

#include <Arduino.h>
#include "SHFastIO.h"

typedef void(*SHButtonChanged) (int, byte);

class SHButton {
private:

	FastDigitalPin button;
	uint8_t buttonState;
	int buttonLastState = -1;
	bool vccToPinWiring;
	unsigned long buttonLastStateChanged;
	byte id;
	SHButtonChanged shButtonChangedCallback;
	int logicMode;

	int getState(int value) {
		int res = 0;
		if (!vccToPinWiring) {
			res = value == HIGH ? 0 : 1;
		}
		else {
			res = value == HIGH ? 1 : 0;
		}
		if (logicMode == 1) {
			res = res ? 0 : 1;
		}
		return res;
	}

public:

	void begin(byte buttonid, uint8_t buttonPin, SHButtonChanged changedcallback, bool vccToPinWiring, int logicMode) {
		button.begin(buttonPin);
		this->vccToPinWiring = vccToPinWiring;
		this->logicMode = logicMode;

		if (buttonPin > 0) {
			if (!vccToPinWiring) {
				pinMode(buttonPin, INPUT_PULLUP);
			}
			else {
				pinMode(buttonPin, INPUT);
			}
		}
		id = buttonid;
		buttonLastState = getState(button.digitalRead());
		shButtonChangedCallback = changedcallback;
		
		if (buttonLastState)
			shButtonChangedCallback(id, buttonLastState);
	}

	uint8_t getPressed() {
		return !buttonLastState;
	}

	void read() {
		buttonState = getState(button.digitalRead());
		if (buttonState != buttonLastState && buttonLastStateChanged - millis() > 50) {
			shButtonChangedCallback(id, buttonState);
			buttonLastState = buttonState;
			buttonLastStateChanged = millis();
		}
	}
};

#endif

Any help is appreciated.

Thank you!

I'm now allowed to upload files. Here is the project.
SimHubDueButtonBox.zip (4.9 MB)

No need, you have a basic compile error in your first post. Although I am not familiar with your sketch, or all your hardware, I will bet that 'digitalPinToPort' is declared differently in the board library of the two boards. It should be straight forward to just cast that function to Pio*

Hi, could you give an example please? Thanks.

You don't know how to use google?