2014-09-26 06:02:50 -07:00
|
|
|
/**
|
|
|
|
* @file efiGpio.cpp
|
|
|
|
*
|
|
|
|
* @date Sep 26, 2014
|
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2014
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include "efiGpio.h"
|
|
|
|
#include "io_pins.h"
|
|
|
|
|
|
|
|
// todo: clean this mess, this should become 'static'/private
|
|
|
|
OutputPin outputs[IO_PIN_COUNT];
|
2014-09-27 15:03:08 -07:00
|
|
|
pin_output_mode_e *pinDefaultState[IO_PIN_COUNT];
|
2014-09-26 06:02:50 -07:00
|
|
|
|
2014-09-27 12:03:45 -07:00
|
|
|
int getOutputPinValue(io_pin_e pin) {
|
|
|
|
return getLogicPinValue(&outputs[pin]);
|
|
|
|
}
|
2014-09-26 06:02:50 -07:00
|
|
|
|
|
|
|
int getLogicPinValue(OutputPin * outputPin) {
|
|
|
|
return outputPin->currentLogicValue;
|
|
|
|
}
|
2014-09-27 12:03:45 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return 0 for OM_DEFAULT and OM_OPENDRAIN
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline static int getElectricalValue0(pin_output_mode_e mode) {
|
|
|
|
return mode == OM_INVERTED || mode == OM_OPENDRAIN_INVERTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return 1 for OM_DEFAULT and OM_OPENDRAIN
|
|
|
|
*/
|
|
|
|
inline static int getElectricalValue1(pin_output_mode_e mode) {
|
|
|
|
return mode == OM_DEFAULT || mode == OM_OPENDRAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getElectricalValue(int logicalValue, pin_output_mode_e mode) {
|
|
|
|
efiAssert(mode <= OM_OPENDRAIN_INVERTED, "invalid pin_output_mode_e", -1);
|
|
|
|
|
|
|
|
return logicalValue ? getElectricalValue1(mode) : getElectricalValue0(mode);
|
|
|
|
}
|
|
|
|
|
2014-09-27 15:03:08 -07:00
|
|
|
/**
|
|
|
|
* Set's the value of the pin. On this layer the value is assigned as is, without any conversion.
|
|
|
|
*/
|
|
|
|
void setPinValue(OutputPin * outputPin, int electricalValue, int logicValue) {
|
|
|
|
if (getLogicPinValue(outputPin) == logicValue)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#if EFI_PROD_CODE
|
|
|
|
palWritePad(outputPin->port, outputPin->pin, electricalValue);
|
|
|
|
#endif
|
|
|
|
outputPin->currentLogicValue = logicValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets the value according to current electrical settings
|
|
|
|
*/
|
|
|
|
void setOutputPinValue(io_pin_e pin, int logicValue) {
|
2014-09-27 16:02:54 -07:00
|
|
|
#if EFI_PROD_CODE
|
2014-09-27 15:03:08 -07:00
|
|
|
if (outputs[pin].port == GPIO_NULL)
|
|
|
|
return;
|
|
|
|
efiAssertVoid(pinDefaultState[pin]!=NULL, "pin mode not initialized");
|
|
|
|
pin_output_mode_e mode = *pinDefaultState[pin];
|
2014-10-13 06:03:11 -07:00
|
|
|
#else
|
|
|
|
pin_output_mode_e mode = OM_DEFAULT;
|
|
|
|
#endif
|
2014-09-27 15:03:08 -07:00
|
|
|
setPinValue(&outputs[pin], getElectricalValue(logicValue, mode), logicValue);
|
|
|
|
}
|
|
|
|
|
2014-09-29 17:02:57 -07:00
|
|
|
bool isPinAssigned(io_pin_e pin) {
|
|
|
|
#if EFI_PROD_CODE
|
|
|
|
return outputs[pin].port != GPIO_NULL;
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|