reducing GPIO code duplication

This commit is contained in:
rusefillc 2023-05-24 09:30:19 -04:00
parent c1cdf77f3a
commit 61f840fcc3
5 changed files with 22 additions and 31 deletions

View File

@ -729,3 +729,18 @@ ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin) {
return EFI_ERROR_CODE;
}
#endif // EFI_PROD_CODE
#if EFI_GPIO_HARDWARE && !EFI_UNIT_TEST
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) {
(void)msg;
if (!isBrainPinValid(brainPin)) {
/*
* https://github.com/dron0gus please help
firmwareError(ObdCode::CUSTOM_ERR_INVALID_PIN, "%s: Invalid Gpio: %d", msg, brainPin);
*/
return GPIO_NULL;
}
return getGpioPorts()[(brainPin - Gpio::A0) / PORT_SIZE];
}
#endif // EFI_GPIO_HARDWARE

View File

@ -152,6 +152,7 @@ private:
EXTERNC ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin);
EXTERNC ioportid_t getHwPort(const char *msg, brain_pin_e brainPin);
ioportid_t * getGpioPorts();
const char *portname(ioportid_t GPIOx);
#endif /* EFI_GPIO_HARDWARE */

View File

@ -102,14 +102,6 @@ int getBrainPinIndex(ioportid_t port, ioportmask_t pin) {
return portIndex * PORT_SIZE + pin;
}
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) {
if (!isBrainPinValid(brainPin)) {
firmwareError(ObdCode::CUSTOM_ERR_INVALID_PIN, "%s: Invalid Gpio: %d", msg, brainPin);
return GPIO_NULL;
}
return ports[(brainPin - Gpio::A0) / PORT_SIZE];
}
/**
* Parse string representation of physical pin into brain_pin_e ordinal.
*

View File

@ -52,7 +52,7 @@ static int getPortIndex(ioportid_t port) {
}
ioportid_t getBrainPinPort(brain_pin_e brainPin) {
return ports[(brainPin - Gpio::A0) / PORT_SIZE];
return getGpioPorts()[(brainPin - Gpio::A0) / PORT_SIZE];
}
int getBrainPinIndex(brain_pin_e brainPin) {
@ -64,14 +64,6 @@ int getPortPinIndex(ioportid_t port, ioportmask_t pin) {
return portIndex * PORT_SIZE + pin;
}
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) {
if (!isBrainPinValid(brainPin)) {
firmwareError(ObdCode::CUSTOM_ERR_INVALID_PIN, "%s: Invalid Gpio: %d", msg, brainPin);
return GPIO_NULL;
}
return ports[(brainPin - Gpio::A0) / PORT_SIZE];
}
/**
* Parse string representation of physical pin into Gpio ordinal.
*

View File

@ -53,6 +53,10 @@ static ioportid_t ports[] = {GPIOA,
#endif /* STM32_HAS_GPIOK */
};
ioportid_t * getGpioPorts() {
return ports;
}
/**
* @deprecated - use hwPortname() instead
*/
@ -139,7 +143,7 @@ static int getPortIndex(ioportid_t port) {
}
ioportid_t getBrainPinPort(brain_pin_e brainPin) {
return ports[(brainPin - Gpio::A0) / PORT_SIZE];
return getGpioPorts()[(brainPin - Gpio::A0) / PORT_SIZE];
}
int getBrainPinIndex(brain_pin_e brainPin) {
@ -151,19 +155,6 @@ int getPortPinIndex(ioportid_t port, ioportmask_t pin) {
return portIndex * PORT_SIZE + pin;
}
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) {
(void)msg;
if (!isBrainPinValid(brainPin)) {
/*
* https://github.com/dron0gus please help
firmwareError(ObdCode::CUSTOM_ERR_INVALID_PIN, "%s: Invalid Gpio: %d", msg, brainPin);
*/
return GPIO_NULL;
}
return ports[(brainPin - Gpio::A0) / PORT_SIZE];
}
/**
* Parse string representation of physical pin into Gpio ordinal.
*