rusefi-1/firmware/hw_layer/io_pins.cpp

92 lines
2.2 KiB
C++
Raw Normal View History

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
2018-01-20 17:55:31 -08:00
* @author Andrey Belomutskiy, (c) 2012-2018
2015-07-10 06:01:56 -07:00
*/
2018-09-16 19:26:57 -07:00
#include "global.h"
2019-01-03 21:16:08 -08:00
#if EFI_PROD_CODE
2015-07-10 06:01:56 -07:00
#include "io_pins.h"
2019-03-29 06:11:13 -07:00
#include "efi_gpio.h"
2015-07-10 06:01:56 -07:00
#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;
extern ioportid_t PORTS[];
2015-07-10 06:01:56 -07:00
2017-07-28 11:27:37 -07:00
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) {
if (brainPin == GPIO_UNASSIGNED || brainPin == GPIO_INVALID)
2015-07-10 06:01:56 -07:00
return GPIO_NULL;
if (brainPin < GPIOA_0 || brainPin > GPIOH_15) {
2017-07-28 11:32:51 -07:00
firmwareError(CUSTOM_ERR_INVALID_PIN, "%s: Invalid brain_pin_e: %d", msg, brainPin);
2015-07-10 06:01:56 -07:00
return GPIO_NULL;
}
return PORTS[(brainPin - GPIOA_0)/ PORT_SIZE];
2015-07-10 06:01:56 -07:00
}
2017-05-15 02:03:40 -07:00
bool efiReadPin(brain_pin_e pin) {
2017-07-28 11:27:37 -07:00
return palReadPad(getHwPort("readPin", pin), getHwPin("readPin", pin));
2017-05-15 02:03:40 -07:00
}
2017-04-21 13:30:14 -07:00
/**
* This method would set an error condition if pin is already used
*/
2017-05-15 05:40:54 -07:00
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode) {
2017-07-28 11:27:37 -07:00
ioportid_t port = getHwPort(msg, brainPin);
ioportmask_t pin = getHwPin(msg, brainPin);
2017-04-21 17:12:11 -07:00
2017-04-21 13:30:14 -07:00
if (port == GPIO_NULL) {
return;
}
efiAssertVoid(OBD_PCM_Processor_Fault, pin != EFI_ERROR_CODE, "pin_error");
2017-04-21 13:30:14 -07:00
scheduleMsg(&logger, "%s on %s%d", msg, portname(port), pin);
bool wasUsed = gpio_pin_markUsed(port, pin, msg);
2017-04-21 13:30:14 -07:00
if (wasUsed) {
return;
}
palSetPadMode(port, pin, mode);
}
iomode_t getInputMode(pin_input_mode_e mode) {
switch (mode) {
case PI_PULLUP:
return PAL_MODE_INPUT_PULLUP;
case PI_PULLDOWN:
return PAL_MODE_INPUT_PULLDOWN;
case PI_DEFAULT:
default:
return PAL_MODE_INPUT;
}
}
2017-05-30 12:43:33 -07:00
#if HAL_USE_ICU || defined(__DOXYGEN__)
2019-04-07 15:25:46 -07:00
void efiIcuStart(const char *msg, ICUDriver *icup, const ICUConfig *config) {
if (icup->state != ICU_STOP && icup->state != ICU_READY) {
static char icuError[30];
sprintf(icuError, "ICU already used %s", msg);
firmwareError(CUSTOM_ERR_6679, icuError);
return;
}
2017-04-21 13:30:14 -07:00
icuStart(icup, config);
}
2017-05-30 12:46:02 -07:00
#endif /* HAL_USE_ICU */
2019-01-03 21:16:08 -08:00
#endif