better error handling
This commit is contained in:
parent
c9726a1fff
commit
f53177f5d7
|
@ -363,8 +363,8 @@ void OutputPin::initPin(const char *msg, brain_pin_e brainPin, pin_output_mode_e
|
|||
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
|
||||
if (brainPin == GPIO_UNASSIGNED)
|
||||
return;
|
||||
ioportid_t port = getHwPort(brainPin);
|
||||
int pin = getHwPin(brainPin);
|
||||
ioportid_t port = getHwPort(msg, brainPin);
|
||||
int pin = getHwPin(msg, brainPin);
|
||||
|
||||
/**
|
||||
* This method is used for digital GPIO pins only, for peripheral pins see mySetPadMode
|
||||
|
|
|
@ -158,8 +158,8 @@ public:
|
|||
|
||||
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
|
||||
|
||||
ioportmask_t getHwPin(brain_pin_e brainPin);
|
||||
ioportid_t getHwPort(brain_pin_e brainPin);
|
||||
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin);
|
||||
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin);
|
||||
const char *portname(ioportid_t GPIOx);
|
||||
|
||||
#endif /* EFI_GPIO_HARDWARE */
|
||||
|
|
|
@ -431,8 +431,8 @@ void initHip9011(Logging *sharedLogger) {
|
|||
|
||||
driver = getSpiDevice(engineConfiguration->hip9011SpiDevice);
|
||||
|
||||
hipSpiCfg.ssport = getHwPort(boardConfiguration->hip9011CsPin);
|
||||
hipSpiCfg.sspad = getHwPin(boardConfiguration->hip9011CsPin);
|
||||
hipSpiCfg.ssport = getHwPort("hip", boardConfiguration->hip9011CsPin);
|
||||
hipSpiCfg.sspad = getHwPin("hip", boardConfiguration->hip9011CsPin);
|
||||
|
||||
intHold.initPin("hip int/hold", boardConfiguration->hip9011IntHoldPin,
|
||||
&boardConfiguration->hip9011IntHoldPinMode);
|
||||
|
|
|
@ -114,8 +114,8 @@ int pinsCount = sizeof(BLINK_PINS) / sizeof(brain_pin_e);
|
|||
static THD_WORKING_AREA(btThreadStack, UTILITY_THREAD_STACK_SIZE);
|
||||
|
||||
static void setCurrentPinValue(bool value) {
|
||||
ioportid_t hwPort = getHwPort(currentPin);
|
||||
uint32_t hwPin = getHwPin(currentPin);
|
||||
ioportid_t hwPort = getHwPort("test", currentPin);
|
||||
uint32_t hwPin = getHwPin("test", currentPin);
|
||||
palWritePad(hwPort, hwPin, value);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,36 +33,36 @@ static ioportid_t PORTS[] = { GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, G
|
|||
static ioportid_t PORTS[] = { GPIOA, GPIOB, GPIOC, GPIOD, GPIOF};
|
||||
#endif
|
||||
|
||||
ioportid_t getHwPort(brain_pin_e brainPin) {
|
||||
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) {
|
||||
if (brainPin == GPIO_UNASSIGNED)
|
||||
return GPIO_NULL;
|
||||
if (brainPin > GPIO_UNASSIGNED || brainPin < 0) {
|
||||
firmwareError(CUSTOM_ERR_INVALID_PIN, "Invalid brain_pin_e: %d", brainPin);
|
||||
firmwareError(CUSTOM_ERR_INVALID_PIN, "%s: Invalid brain_pin_e: %d", msgbrainPin);
|
||||
return GPIO_NULL;
|
||||
}
|
||||
return PORTS[brainPin / PORT_SIZE];
|
||||
}
|
||||
|
||||
ioportmask_t getHwPin(brain_pin_e brainPin) {
|
||||
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin) {
|
||||
if (brainPin == GPIO_UNASSIGNED)
|
||||
return EFI_ERROR_CODE;
|
||||
if (brainPin > GPIO_UNASSIGNED || brainPin < 0) {
|
||||
firmwareError(CUSTOM_ERR_INVALID_PIN, "Invalid brain_pin_e: %d", brainPin);
|
||||
firmwareError(CUSTOM_ERR_INVALID_PIN, "%s: Invalid brain_pin_e: %d", msg, brainPin);
|
||||
return EFI_ERROR_CODE;
|
||||
}
|
||||
return brainPin % PORT_SIZE;
|
||||
}
|
||||
|
||||
bool efiReadPin(brain_pin_e pin) {
|
||||
return palReadPad(getHwPort(pin), getHwPin(pin));
|
||||
return palReadPad(getHwPort("readPin", pin), getHwPin("readPin", pin));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method would set an error condition if pin is already used
|
||||
*/
|
||||
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode) {
|
||||
ioportid_t port = getHwPort(brainPin);
|
||||
ioportmask_t pin = getHwPin(brainPin);
|
||||
ioportid_t port = getHwPort(msg, brainPin);
|
||||
ioportmask_t pin = getHwPin(msg, brainPin);
|
||||
|
||||
if (port == GPIO_NULL) {
|
||||
return;
|
||||
|
|
|
@ -37,19 +37,19 @@ static void extCallback(EXTDriver *extp, expchannel_t channel) {
|
|||
joyTotal++;
|
||||
joystick_button_e button;
|
||||
// todo: I guess it's time to reduce code duplication and start working with an array
|
||||
if (channel == getHwPin(boardConfiguration->joystickCenterPin)) {
|
||||
if (channel == getHwPin("joy", boardConfiguration->joystickCenterPin)) {
|
||||
joyCenter++;
|
||||
button = JB_CENTER;
|
||||
} else if (channel == getHwPin(boardConfiguration->joystickAPin)) {
|
||||
} else if (channel == getHwPin("joy", boardConfiguration->joystickAPin)) {
|
||||
joyA++;
|
||||
button = JB_BUTTON_A;
|
||||
} else if (channel == getHwPin(boardConfiguration->joystickBPin)) {
|
||||
} else if (channel == getHwPin("joy", boardConfiguration->joystickBPin)) {
|
||||
joyB++;
|
||||
button = JB_BUTTON_C;
|
||||
} else if (channel == getHwPin(boardConfiguration->joystickCPin)) {
|
||||
} else if (channel == getHwPin("joy", boardConfiguration->joystickCPin)) {
|
||||
joyC++;
|
||||
button = JB_BUTTON_B;
|
||||
} else if (channel == getHwPin(boardConfiguration->joystickDPin)) {
|
||||
} else if (channel == getHwPin("joy", boardConfiguration->joystickDPin)) {
|
||||
joyD++;
|
||||
button = JB_BUTTON_D;
|
||||
} else {
|
||||
|
@ -127,8 +127,8 @@ static void applyPin(brain_pin_e pin) {
|
|||
if (pin == GPIO_UNASSIGNED)
|
||||
return;
|
||||
|
||||
int index = getHwPin(pin);
|
||||
ioportid_t port = getHwPort(pin);
|
||||
int index = getHwPin("joy", pin);
|
||||
ioportid_t port = getHwPort("joy", pin);
|
||||
|
||||
extcfg.channels[index].mode = EXT_CH_MODE_RISING_EDGE | EXT_CH_MODE_AUTOSTART | getExtMode(port);
|
||||
extcfg.channels[index].cb = extCallback;
|
||||
|
|
|
@ -76,21 +76,26 @@ static void lcdSleep(int period) {
|
|||
//static char txbuf[1];
|
||||
#define LCD_PORT_EXP_ADDR 0x20
|
||||
|
||||
// todo: use this method wider!
|
||||
static void writePad(const char *msg, brain_pin_e pin, int bit) {
|
||||
palWritePad(getHwPort(msg, pin), getHwPin(msg, pin), bit);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
static void lcd_HD44780_write(uint8_t data) {
|
||||
if (engineConfiguration->displayMode == DM_HD44780) {
|
||||
palWritePad(getHwPort(boardConfiguration->HD44780_db7), getHwPin(boardConfiguration->HD44780_db7),
|
||||
writePad("lcd", boardConfiguration->HD44780_db7,
|
||||
data & 0x80 ? 1 : 0);
|
||||
palWritePad(getHwPort(boardConfiguration->HD44780_db6), getHwPin(boardConfiguration->HD44780_db6),
|
||||
writePad("lcd", boardConfiguration->HD44780_db6,
|
||||
data & 0x40 ? 1 : 0);
|
||||
palWritePad(getHwPort(boardConfiguration->HD44780_db5), getHwPin(boardConfiguration->HD44780_db5),
|
||||
writePad("lcd", boardConfiguration->HD44780_db5,
|
||||
data & 0x20 ? 1 : 0);
|
||||
palWritePad(getHwPort(boardConfiguration->HD44780_db4), getHwPin(boardConfiguration->HD44780_db4),
|
||||
writePad("lcd", boardConfiguration->HD44780_db4,
|
||||
data & 0x10 ? 1 : 0);
|
||||
|
||||
palSetPad(getHwPort(boardConfiguration->HD44780_e), getHwPin(boardConfiguration->HD44780_e)); // En high
|
||||
writePad("lcd", boardConfiguration->HD44780_e, 1); // En high
|
||||
lcdSleep(10); // enable pulse must be >450ns
|
||||
palClearPad(getHwPort(boardConfiguration->HD44780_e), getHwPin(boardConfiguration->HD44780_e)); // En low
|
||||
writePad("lcd", boardConfiguration->HD44780_e, 0); // En low
|
||||
lcdSleep(40); // commands need > 37us to settle
|
||||
} else {
|
||||
|
||||
|
@ -119,7 +124,7 @@ static void lcd_HD44780_write(uint8_t data) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void lcd_HD44780_write_command(uint8_t data) {
|
||||
palClearPad(getHwPort(boardConfiguration->HD44780_rs), getHwPin(boardConfiguration->HD44780_rs));
|
||||
palClearPad(getHwPort("lcd", boardConfiguration->HD44780_rs), getHwPin("lcd", boardConfiguration->HD44780_rs));
|
||||
|
||||
lcd_HD44780_write(data);
|
||||
lcd_HD44780_write(data << 4);
|
||||
|
@ -127,13 +132,13 @@ void lcd_HD44780_write_command(uint8_t data) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void lcd_HD44780_write_data(uint8_t data) {
|
||||
palSetPad(getHwPort(boardConfiguration->HD44780_rs), getHwPin(boardConfiguration->HD44780_rs));
|
||||
palSetPad(getHwPort("lcd", boardConfiguration->HD44780_rs), getHwPin("lcd", boardConfiguration->HD44780_rs));
|
||||
|
||||
lcd_HD44780_write(data);
|
||||
lcd_HD44780_write(data << 4);
|
||||
currentColumn++;
|
||||
|
||||
palClearPad(getHwPort(boardConfiguration->HD44780_rs), getHwPin(boardConfiguration->HD44780_rs));
|
||||
palClearPad(getHwPort("lcd", boardConfiguration->HD44780_rs), getHwPin("lcd", boardConfiguration->HD44780_rs));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -195,12 +200,12 @@ void lcd_HD44780_init(Logging *sharedLogger) {
|
|||
efiSetPadMode("lcd DB6", boardConfiguration->HD44780_db6, PAL_MODE_OUTPUT_PUSHPULL);
|
||||
efiSetPadMode("lcd DB7", boardConfiguration->HD44780_db7, PAL_MODE_OUTPUT_PUSHPULL);
|
||||
// and zero values
|
||||
palWritePad(getHwPort(boardConfiguration->HD44780_rs), getHwPin(boardConfiguration->HD44780_rs), 0);
|
||||
palWritePad(getHwPort(boardConfiguration->HD44780_e), getHwPin(boardConfiguration->HD44780_e), 0);
|
||||
palWritePad(getHwPort(boardConfiguration->HD44780_db4), getHwPin(boardConfiguration->HD44780_db4), 0);
|
||||
palWritePad(getHwPort(boardConfiguration->HD44780_db5), getHwPin(boardConfiguration->HD44780_db5), 0);
|
||||
palWritePad(getHwPort(boardConfiguration->HD44780_db6), getHwPin(boardConfiguration->HD44780_db6), 0);
|
||||
palWritePad(getHwPort(boardConfiguration->HD44780_db7), getHwPin(boardConfiguration->HD44780_db7), 0);
|
||||
palWritePad(getHwPort("lcd", boardConfiguration->HD44780_rs), getHwPin("lcd", boardConfiguration->HD44780_rs), 0);
|
||||
palWritePad(getHwPort("lcd", boardConfiguration->HD44780_e), getHwPin("lcd", boardConfiguration->HD44780_e), 0);
|
||||
palWritePad(getHwPort("lcd", boardConfiguration->HD44780_db4), getHwPin("lcd", boardConfiguration->HD44780_db4), 0);
|
||||
palWritePad(getHwPort("lcd", boardConfiguration->HD44780_db5), getHwPin("lcd", boardConfiguration->HD44780_db5), 0);
|
||||
palWritePad(getHwPort("lcd", boardConfiguration->HD44780_db6), getHwPin("lcd", boardConfiguration->HD44780_db6), 0);
|
||||
palWritePad(getHwPort("lcd", boardConfiguration->HD44780_db7), getHwPin("lcd", boardConfiguration->HD44780_db7), 0);
|
||||
}
|
||||
|
||||
chThdSleepMilliseconds(20); // LCD needs some time to wake up
|
||||
|
|
|
@ -431,8 +431,8 @@ void initMmcCard(void) {
|
|||
return;
|
||||
}
|
||||
|
||||
hs_spicfg.ssport = ls_spicfg.ssport = getHwPort(boardConfiguration->sdCardCsPin);
|
||||
hs_spicfg.sspad = ls_spicfg.sspad = getHwPin(boardConfiguration->sdCardCsPin);
|
||||
hs_spicfg.ssport = ls_spicfg.ssport = getHwPort("mmc", boardConfiguration->sdCardCsPin);
|
||||
hs_spicfg.sspad = ls_spicfg.sspad = getHwPin("mmc", boardConfiguration->sdCardCsPin);
|
||||
/* todo: un-comment this one day. incompatible configuration change for existing users :(
|
||||
mmccfg.spip = getSpiDevice(engineConfiguration->sdCardSpiDevice);
|
||||
*/
|
||||
|
|
|
@ -107,11 +107,11 @@ const char *hwPortname(brain_pin_e brainPin) {
|
|||
if (brainPin == GPIO_INVALID) {
|
||||
return "INVALID";
|
||||
}
|
||||
ioportid_t hwPort = getHwPort(brainPin);
|
||||
ioportid_t hwPort = getHwPort("hostname", brainPin);
|
||||
if (hwPort == GPIO_NULL) {
|
||||
return "NONE";
|
||||
}
|
||||
int hwPin = getHwPin(brainPin);
|
||||
int hwPin = getHwPin("hostname", brainPin);
|
||||
portNameStream.eos = 0; // reset
|
||||
chprintf((BaseSequentialStream *) &portNameStream, "%s%d", portname(hwPort), hwPin);
|
||||
portNameStream.buffer[portNameStream.eos] = 0; // need to terminate explicitly
|
||||
|
@ -162,8 +162,8 @@ bool markUsed(ioportid_t port, ioportmask_t pin, const char *msg) {
|
|||
}
|
||||
|
||||
const char * getPinFunction(brain_input_pin_e brainPin) {
|
||||
ioportid_t port = getHwPort(brainPin);
|
||||
ioportmask_t pin = getHwPin(brainPin);
|
||||
ioportid_t port = getHwPort("getF", brainPin);
|
||||
ioportmask_t pin = getHwPin("getF", brainPin);
|
||||
|
||||
int index = getIndex(port, pin);
|
||||
return PIN_USED[index];
|
||||
|
@ -174,8 +174,8 @@ void unmarkPin(brain_pin_e brainPin) {
|
|||
if (brainPin == GPIO_UNASSIGNED) {
|
||||
return;
|
||||
}
|
||||
ioportid_t port = getHwPort(brainPin);
|
||||
ioportmask_t pin = getHwPin(brainPin);
|
||||
ioportid_t port = getHwPort("unmark", brainPin);
|
||||
ioportmask_t pin = getHwPin("unmark", brainPin);
|
||||
|
||||
int index = getIndex(port, pin);
|
||||
|
||||
|
|
|
@ -105,8 +105,8 @@ void initCJ125(Logging *sharedLogger) {
|
|||
if (!boardConfiguration->isCJ125Enabled)
|
||||
return;
|
||||
|
||||
cj125spicfg.ssport = getHwPort(boardConfiguration->cj125CsPin);
|
||||
cj125spicfg.sspad = getHwPin(boardConfiguration->cj125CsPin);
|
||||
cj125spicfg.ssport = getHwPort("cj125", boardConfiguration->cj125CsPin);
|
||||
cj125spicfg.sspad = getHwPin("cj125", boardConfiguration->cj125CsPin);
|
||||
|
||||
driver = getSpiDevice(engineConfiguration->cj125SpiDevice);
|
||||
|
||||
|
|
|
@ -92,14 +92,14 @@ void StepperMotor::initialize(brain_pin_e stepPin, brain_pin_e directionPin, pin
|
|||
return;
|
||||
}
|
||||
|
||||
stepPort = getHwPort(stepPin);
|
||||
this->stepPin = getHwPin(stepPin);
|
||||
stepPort = getHwPort("step", stepPin);
|
||||
this->stepPin = getHwPin("step", stepPin);
|
||||
|
||||
this->directionPinMode = directionPinMode;
|
||||
this->directionPin.initPin("stepper dir", directionPin, &this->directionPinMode);
|
||||
|
||||
enablePort = getHwPort(enablePin);
|
||||
this->enablePin = getHwPin(enablePin);
|
||||
enablePort = getHwPort("enable", enablePin);
|
||||
this->enablePin = getHwPin("enable", enablePin);
|
||||
|
||||
efiSetPadMode("stepper step", stepPin, PAL_MODE_OUTPUT_PUSHPULL);
|
||||
efiSetPadMode("stepper enable", enablePin, PAL_MODE_OUTPUT_PUSHPULL);
|
||||
|
|
|
@ -320,8 +320,8 @@ void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso,
|
|||
|
||||
void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin) {
|
||||
spiConfig->end_cb = NULL;
|
||||
ioportid_t port = getHwPort(csPin);
|
||||
ioportmask_t pin = getHwPin(csPin);
|
||||
ioportid_t port = getHwPort("spi", csPin);
|
||||
ioportmask_t pin = getHwPin("spi", csPin);
|
||||
spiConfig->ssport = port;
|
||||
spiConfig->sspad = pin;
|
||||
efiSetPadMode("chip select", csPin, PAL_STM32_MODE_OUTPUT);
|
||||
|
|
|
@ -260,5 +260,5 @@ int getRusEfiVersion(void) {
|
|||
if (initBootloader() != 0)
|
||||
return 123;
|
||||
#endif /* EFI_BOOTLOADER_INCLUDE_CODE */
|
||||
return 20170724;
|
||||
return 20170728;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue