2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file io_pins.cpp
|
2017-04-21 10:36:51 -07:00
|
|
|
* @brief his file is about general input/output utility methods, not much EFI-specifics
|
|
|
|
*
|
2015-07-10 06:01:56 -07:00
|
|
|
*
|
|
|
|
* @date Jan 24, 2013
|
2017-01-03 03:05:22 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2017
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <board.h>
|
|
|
|
#include "main.h"
|
|
|
|
#include "io_pins.h"
|
|
|
|
#include "efiGpio.h"
|
|
|
|
|
|
|
|
#include "pin_repository.h"
|
|
|
|
#include "status_loop.h"
|
|
|
|
#include "engine_configuration.h"
|
|
|
|
#include "console_io.h"
|
|
|
|
|
2017-04-21 09:01:44 -07:00
|
|
|
EXTERN_ENGINE;
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
|
|
|
|
#include "main_trigger_callback.h"
|
|
|
|
#endif /* EFI_ENGINE_CONTROL */
|
|
|
|
|
|
|
|
static LoggingWithStorage logger("io_pins");
|
|
|
|
|
2016-11-03 20:02:58 -07:00
|
|
|
extern EnginePins enginePins;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#if defined(STM32F4XX)
|
2016-02-04 09:01:41 -08:00
|
|
|
static ioportid_t PORTS[] = { GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH };
|
2015-07-10 06:01:56 -07:00
|
|
|
#else
|
2016-02-04 09:01:41 -08:00
|
|
|
static ioportid_t PORTS[] = { GPIOA, GPIOB, GPIOC, GPIOD, GPIOF};
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif
|
|
|
|
|
2016-02-04 09:01:41 -08:00
|
|
|
ioportid_t getHwPort(brain_pin_e brainPin) {
|
2015-07-10 06:01:56 -07:00
|
|
|
if (brainPin == GPIO_UNASSIGNED)
|
|
|
|
return GPIO_NULL;
|
|
|
|
if (brainPin > GPIO_UNASSIGNED || brainPin < 0) {
|
2016-10-10 13:02:39 -07:00
|
|
|
firmwareError(CUSTOM_ERR_INVALID_PIN, "Invalid brain_pin_e: %d", brainPin);
|
2015-07-10 06:01:56 -07:00
|
|
|
return GPIO_NULL;
|
|
|
|
}
|
|
|
|
return PORTS[brainPin / PORT_SIZE];
|
|
|
|
}
|
|
|
|
|
|
|
|
ioportmask_t getHwPin(brain_pin_e brainPin) {
|
|
|
|
if (brainPin == GPIO_UNASSIGNED)
|
|
|
|
return EFI_ERROR_CODE;
|
|
|
|
if (brainPin > GPIO_UNASSIGNED || brainPin < 0) {
|
2016-10-10 13:02:39 -07:00
|
|
|
firmwareError(CUSTOM_ERR_INVALID_PIN, "Invalid brain_pin_e: %d", brainPin);
|
2015-07-10 06:01:56 -07:00
|
|
|
return EFI_ERROR_CODE;
|
|
|
|
}
|
|
|
|
return brainPin % PORT_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-21 09:01:44 -07:00
|
|
|
/**
|
|
|
|
* @brief Initialize the hardware output pin while also assigning it a logical name
|
|
|
|
*/
|
|
|
|
void initOutputPinExt(const char *msg, OutputPin *outputPin, ioportid_t port, uint32_t pinNumber, iomode_t mode) {
|
|
|
|
if (outputPin->port != NULL && (outputPin->port != port || outputPin->pin != pinNumber)) {
|
|
|
|
/**
|
|
|
|
* here we check if another physical pin is already assigned to this logical output
|
|
|
|
*/
|
|
|
|
// todo: need to clear '&outputs' in io_pins.c
|
|
|
|
warning(CUSTOM_OBD_PIN_CONFLICT, "outputPin [%s] already assigned to %x%d", msg, outputPin->port, outputPin->pin);
|
|
|
|
engine->withError = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
outputPin->currentLogicValue = INITIAL_PIN_STATE;
|
|
|
|
outputPin->port = port;
|
|
|
|
outputPin->pin = pinNumber;
|
|
|
|
|
|
|
|
mySetPadMode(msg, port, pinNumber, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void initOutputPin(const char *msg, OutputPin *outputPin, ioportid_t port, uint32_t pinNumber) {
|
|
|
|
initOutputPinExt(msg, outputPin, port, pinNumber, PAL_MODE_OUTPUT_PUSHPULL);
|
|
|
|
}
|
|
|
|
|