openblt preparation

This commit is contained in:
rusefillc 2023-12-29 17:19:50 -05:00 committed by rusefillc
parent 2bcda4450b
commit a3f3f536e8
4 changed files with 376 additions and 130 deletions

View File

@ -817,132 +817,3 @@ void turnAllPinsOff(void) {
}
#endif /* EFI_GPIO_HARDWARE */
#if EFI_PROD_CODE
/**
* this method returns the numeric part of pin name. For instance, for PC13 this would return '13'
*/
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin) {
if (!isBrainPinValid(brainPin))
return EFI_ERROR_CODE;
if (brain_pin_is_onchip(brainPin))
return getBrainPinIndex(brainPin);
firmwareError(ObdCode::CUSTOM_ERR_INVALID_PIN, "%s: Invalid on-chip Gpio: %d", msg, 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];
}
int getBrainPinIndex(brain_pin_e brainPin) {
return (brainPin - Gpio::A0) % PORT_SIZE;
}
ioportid_t getBrainPinPort(brain_pin_e brainPin) {
return getGpioPorts()[(brainPin - Gpio::A0) / PORT_SIZE];
}
/**
* @deprecated - use hwPortname() instead
*/
const char *portname(ioportid_t GPIOx) {
if (GPIOx == GPIOA)
return "PA";
if (GPIOx == GPIOB)
return "PB";
if (GPIOx == GPIOC)
return "PC";
if (GPIOx == GPIOD)
return "PD";
#if defined(GPIOF)
if (GPIOx == GPIOE)
return "PE";
#endif /* GPIOE */
#if defined(GPIOF)
if (GPIOx == GPIOF)
return "PF";
#endif /* GPIOF */
#if defined(GPIOG)
if (GPIOx == GPIOG)
return "PG";
#endif /* GPIOG */
#if defined(GPIOH)
if (GPIOx == GPIOH)
return "PH";
#endif /* GPIOH */
#if defined(GPIOI)
if (GPIOx == GPIOI)
return "PI";
#endif /* GPIOI */
#if defined(GPIOJ_BASE)
if (GPIOx == GPIOJ)
return "PJ";
#endif /* GPIOJ_BASE */
#if defined(GPIOK_BASE)
if (GPIOx == GPIOK)
return "PK";
#endif /* GPIOK_BASE */
return "unknown";
}
static int getPortIndex(ioportid_t port) {
efiAssert(ObdCode::CUSTOM_ERR_ASSERT, port != NULL, "null port", -1);
if (port == GPIOA)
return 0;
if (port == GPIOB)
return 1;
if (port == GPIOC)
return 2;
if (port == GPIOD)
return 3;
#if defined(GPIOF)
if (port == GPIOE)
return 4;
#endif /* GPIOE */
#if defined(GPIOF)
if (port == GPIOF)
return 5;
#endif /* GPIOF */
#if defined(GPIOG)
if (port == GPIOG)
return 6;
#endif /* GPIOG */
#if defined(GPIOH)
if (port == GPIOH)
return 7;
#endif /* GPIOH */
#if defined(GPIOI)
if (port == GPIOI)
return 8;
#endif /* STM32_HAS_GPIOI */
#if defined(GPIOJ_BASE)
if (port == GPIOJ)
return 9;
#endif /* GPIOJ_BASE */
#if defined(GPIOK_BASE)
if (port == GPIOK)
return 10;
#endif /* GPIOK_BASE */
firmwareError(ObdCode::CUSTOM_ERR_UNKNOWN_PORT, "unknown port");
return -1;
}
int getPortPinIndex(ioportid_t port, ioportmask_t pin) {
int portIndex = getPortIndex(port);
return portIndex * PORT_SIZE + pin;
}
#endif // EFI_GPIO_HARDWARE

View File

@ -25,7 +25,7 @@ static ioportid_t ports[] = {
GPIOK,
};
static brain_pin_e portMap[16] = {
static brain_pin_e portMap[16] = {
Gpio::A0, Gpio::B0, Gpio::C0, Gpio::D0, Gpio::E0, Gpio::F0, Gpio::Invalid, Gpio::G0, Gpio::Invalid, Gpio::Invalid, Gpio::H0, Gpio::I0, Gpio::J0, Gpio::Invalid, Gpio::Invalid, Gpio::K0
};
@ -36,6 +36,131 @@ ioportid_t * getGpioPorts() {
return ports;
}
int getBrainPinIndex(brain_pin_e brainPin) {
return (brainPin - Gpio::A0) % PORT_SIZE;
}
ioportid_t getBrainPinPort(brain_pin_e brainPin) {
return getGpioPorts()[(brainPin - Gpio::A0) / PORT_SIZE];
}
/**
* @deprecated - use hwPortname() instead
*/
const char *portname(ioportid_t GPIOx) {
if (GPIOx == GPIOA)
return "PA";
if (GPIOx == GPIOB)
return "PB";
if (GPIOx == GPIOC)
return "PC";
if (GPIOx == GPIOD)
return "PD";
#if defined(GPIOF)
if (GPIOx == GPIOE)
return "PE";
#endif /* GPIOE */
#if defined(GPIOF)
if (GPIOx == GPIOF)
return "PF";
#endif /* GPIOF */
#if defined(GPIOG)
if (GPIOx == GPIOG)
return "PG";
#endif /* GPIOG */
#if defined(GPIOH)
if (GPIOx == GPIOH)
return "PH";
#endif /* GPIOH */
#if defined(GPIOI)
if (GPIOx == GPIOI)
return "PI";
#endif /* GPIOI */
#if defined(GPIOJ_BASE)
if (GPIOx == GPIOJ)
return "PJ";
#endif /* GPIOJ_BASE */
#if defined(GPIOK_BASE)
if (GPIOx == GPIOK)
return "PK";
#endif /* GPIOK_BASE */
return "unknown";
}
static int getPortIndex(ioportid_t port) {
efiAssert(ObdCode::CUSTOM_ERR_ASSERT, port != NULL, "null port", -1);
if (port == GPIOA)
return 0;
if (port == GPIOB)
return 1;
if (port == GPIOC)
return 2;
if (port == GPIOD)
return 3;
#if defined(GPIOF)
if (port == GPIOE)
return 4;
#endif /* GPIOE */
#if defined(GPIOF)
if (port == GPIOF)
return 5;
#endif /* GPIOF */
#if defined(GPIOG)
if (port == GPIOG)
return 6;
#endif /* GPIOG */
#if defined(GPIOH)
if (port == GPIOH)
return 7;
#endif /* GPIOH */
#if defined(GPIOI)
if (port == GPIOI)
return 8;
#endif /* STM32_HAS_GPIOI */
#if defined(GPIOJ_BASE)
if (port == GPIOJ)
return 9;
#endif /* GPIOJ_BASE */
#if defined(GPIOK_BASE)
if (port == GPIOK)
return 10;
#endif /* GPIOK_BASE */
firmwareError(ObdCode::CUSTOM_ERR_UNKNOWN_PORT, "unknown port");
return -1;
}
int getPortPinIndex(ioportid_t port, ioportmask_t pin) {
int portIndex = getPortIndex(port);
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 getGpioPorts()[(brainPin - Gpio::A0) / PORT_SIZE];
}
/**
* this method returns the numeric part of pin name. For instance, for PC13 this would return '13'
*/
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin) {
if (!isBrainPinValid(brainPin))
return EFI_ERROR_CODE;
if (brain_pin_is_onchip(brainPin))
return getBrainPinIndex(brainPin);
firmwareError(ObdCode::CUSTOM_ERR_INVALID_PIN, "%s: Invalid on-chip Gpio: %d", msg, brainPin);
return EFI_ERROR_CODE;
}
/**
* Parse string representation of physical pin into brain_pin_e ordinal.
*

View File

@ -22,6 +22,131 @@ ioportid_t * getGpioPorts() {
return ports;
}
int getBrainPinIndex(brain_pin_e brainPin) {
return (brainPin - Gpio::A0) % PORT_SIZE;
}
ioportid_t getBrainPinPort(brain_pin_e brainPin) {
return getGpioPorts()[(brainPin - Gpio::A0) / PORT_SIZE];
}
/**
* @deprecated - use hwPortname() instead
*/
const char *portname(ioportid_t GPIOx) {
if (GPIOx == GPIOA)
return "PA";
if (GPIOx == GPIOB)
return "PB";
if (GPIOx == GPIOC)
return "PC";
if (GPIOx == GPIOD)
return "PD";
#if defined(GPIOF)
if (GPIOx == GPIOE)
return "PE";
#endif /* GPIOE */
#if defined(GPIOF)
if (GPIOx == GPIOF)
return "PF";
#endif /* GPIOF */
#if defined(GPIOG)
if (GPIOx == GPIOG)
return "PG";
#endif /* GPIOG */
#if defined(GPIOH)
if (GPIOx == GPIOH)
return "PH";
#endif /* GPIOH */
#if defined(GPIOI)
if (GPIOx == GPIOI)
return "PI";
#endif /* GPIOI */
#if defined(GPIOJ_BASE)
if (GPIOx == GPIOJ)
return "PJ";
#endif /* GPIOJ_BASE */
#if defined(GPIOK_BASE)
if (GPIOx == GPIOK)
return "PK";
#endif /* GPIOK_BASE */
return "unknown";
}
static int getPortIndex(ioportid_t port) {
efiAssert(ObdCode::CUSTOM_ERR_ASSERT, port != NULL, "null port", -1);
if (port == GPIOA)
return 0;
if (port == GPIOB)
return 1;
if (port == GPIOC)
return 2;
if (port == GPIOD)
return 3;
#if defined(GPIOF)
if (port == GPIOE)
return 4;
#endif /* GPIOE */
#if defined(GPIOF)
if (port == GPIOF)
return 5;
#endif /* GPIOF */
#if defined(GPIOG)
if (port == GPIOG)
return 6;
#endif /* GPIOG */
#if defined(GPIOH)
if (port == GPIOH)
return 7;
#endif /* GPIOH */
#if defined(GPIOI)
if (port == GPIOI)
return 8;
#endif /* STM32_HAS_GPIOI */
#if defined(GPIOJ_BASE)
if (port == GPIOJ)
return 9;
#endif /* GPIOJ_BASE */
#if defined(GPIOK_BASE)
if (port == GPIOK)
return 10;
#endif /* GPIOK_BASE */
firmwareError(ObdCode::CUSTOM_ERR_UNKNOWN_PORT, "unknown port");
return -1;
}
int getPortPinIndex(ioportid_t port, ioportmask_t pin) {
int portIndex = getPortIndex(port);
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 getGpioPorts()[(brainPin - Gpio::A0) / PORT_SIZE];
}
/**
* this method returns the numeric part of pin name. For instance, for PC13 this would return '13'
*/
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin) {
if (!isBrainPinValid(brainPin))
return EFI_ERROR_CODE;
if (brain_pin_is_onchip(brainPin))
return getBrainPinIndex(brainPin);
firmwareError(ObdCode::CUSTOM_ERR_INVALID_PIN, "%s: Invalid on-chip Gpio: %d", msg, brainPin);
return EFI_ERROR_CODE;
}
/**
* Parse string representation of physical pin into Gpio ordinal.
*

View File

@ -57,6 +57,131 @@ ioportid_t * getGpioPorts() {
return ports;
}
int getBrainPinIndex(brain_pin_e brainPin) {
return (brainPin - Gpio::A0) % PORT_SIZE;
}
ioportid_t getBrainPinPort(brain_pin_e brainPin) {
return getGpioPorts()[(brainPin - Gpio::A0) / PORT_SIZE];
}
/**
* @deprecated - use hwPortname() instead
*/
const char *portname(ioportid_t GPIOx) {
if (GPIOx == GPIOA)
return "PA";
if (GPIOx == GPIOB)
return "PB";
if (GPIOx == GPIOC)
return "PC";
if (GPIOx == GPIOD)
return "PD";
#if defined(GPIOF)
if (GPIOx == GPIOE)
return "PE";
#endif /* GPIOE */
#if defined(GPIOF)
if (GPIOx == GPIOF)
return "PF";
#endif /* GPIOF */
#if defined(GPIOG)
if (GPIOx == GPIOG)
return "PG";
#endif /* GPIOG */
#if defined(GPIOH)
if (GPIOx == GPIOH)
return "PH";
#endif /* GPIOH */
#if defined(GPIOI)
if (GPIOx == GPIOI)
return "PI";
#endif /* GPIOI */
#if defined(GPIOJ_BASE)
if (GPIOx == GPIOJ)
return "PJ";
#endif /* GPIOJ_BASE */
#if defined(GPIOK_BASE)
if (GPIOx == GPIOK)
return "PK";
#endif /* GPIOK_BASE */
return "unknown";
}
static int getPortIndex(ioportid_t port) {
efiAssert(ObdCode::CUSTOM_ERR_ASSERT, port != NULL, "null port", -1);
if (port == GPIOA)
return 0;
if (port == GPIOB)
return 1;
if (port == GPIOC)
return 2;
if (port == GPIOD)
return 3;
#if defined(GPIOF)
if (port == GPIOE)
return 4;
#endif /* GPIOE */
#if defined(GPIOF)
if (port == GPIOF)
return 5;
#endif /* GPIOF */
#if defined(GPIOG)
if (port == GPIOG)
return 6;
#endif /* GPIOG */
#if defined(GPIOH)
if (port == GPIOH)
return 7;
#endif /* GPIOH */
#if defined(GPIOI)
if (port == GPIOI)
return 8;
#endif /* STM32_HAS_GPIOI */
#if defined(GPIOJ_BASE)
if (port == GPIOJ)
return 9;
#endif /* GPIOJ_BASE */
#if defined(GPIOK_BASE)
if (port == GPIOK)
return 10;
#endif /* GPIOK_BASE */
firmwareError(ObdCode::CUSTOM_ERR_UNKNOWN_PORT, "unknown port");
return -1;
}
int getPortPinIndex(ioportid_t port, ioportmask_t pin) {
int portIndex = getPortIndex(port);
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 getGpioPorts()[(brainPin - Gpio::A0) / PORT_SIZE];
}
/**
* this method returns the numeric part of pin name. For instance, for PC13 this would return '13'
*/
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin) {
if (!isBrainPinValid(brainPin))
return EFI_ERROR_CODE;
if (brain_pin_is_onchip(brainPin))
return getBrainPinIndex(brainPin);
firmwareError(ObdCode::CUSTOM_ERR_INVALID_PIN, "%s: Invalid on-chip Gpio: %d", msg, brainPin);
return EFI_ERROR_CODE;
}
/**
* Parse string representation of physical pin into Gpio ordinal.
*