rusefi-1/firmware/hw_layer/gpio_helper.cpp

58 lines
1.9 KiB
C++
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file gpio_helper.c
* @brief General I/O helper
*
* @date Aug 25, 2013
2017-01-03 03:05:22 -08:00
* @author Andrey Belomutskiy, (c) 2012-2017
2015-07-10 06:01:56 -07:00
*
* This file is part of rusEfi - see http://rusefi.com
*
* rusEfi is free software; you can redistribute it and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* rusEfi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GPIO_HELPER_C_
#define GPIO_HELPER_C_
#include <hal.h>
#include "pin_repository.h"
#include "gpio_helper.h"
2017-02-24 16:26:00 -08:00
#include "engine.h"
EXTERN_ENGINE;
2015-07-10 06:01:56 -07:00
/**
* @brief Initialize the hardware output pin while also assigning it a logical name
*/
2016-02-04 09:01:41 -08:00
void initOutputPinExt(const char *msg, OutputPin *outputPin, ioportid_t port, uint32_t pinNumber, iomode_t mode) {
2016-09-13 20:01:50 -07:00
if (outputPin->port != NULL && (outputPin->port != port || outputPin->pin != pinNumber)) {
2015-07-10 06:01:56 -07:00
/**
* here we check if another physical pin is already assigned to this logical output
*/
// todo: need to clear '&outputs' in io_pins.c
2017-02-24 16:26:00 -08:00
warning(CUSTOM_OBD_PIN_CONFLICT, "outputPin [%s] already assigned to %x%d", msg, outputPin->port, outputPin->pin);
engine->withError = true;
2015-07-10 06:01:56 -07:00
return;
}
outputPin->currentLogicValue = INITIAL_PIN_STATE;
outputPin->port = port;
outputPin->pin = pinNumber;
mySetPadMode(msg, port, pinNumber, mode);
}
2016-02-04 09:01:41 -08:00
void initOutputPin(const char *msg, OutputPin *outputPin, ioportid_t port, uint32_t pinNumber) {
2015-07-10 06:01:56 -07:00
initOutputPinExt(msg, outputPin, port, pinNumber, PAL_MODE_OUTPUT_PUSHPULL);
}
#endif /* GPIO_HELPER_C_ */