auto-sync

This commit is contained in:
rusEfi 2015-01-02 22:03:41 -06:00
parent c430e1b315
commit 38b1c86854
5 changed files with 160 additions and 87 deletions

View File

@ -16,8 +16,10 @@
#include "io_pins.h"
#include "efiGpio.h"
#include "svnversion.h"
#include "joystick.h"
EXTERN_ENGINE;
EXTERN_ENGINE
;
extern bool hasFirmwareErrorFlag;
@ -25,6 +27,12 @@ extern bool hasFirmwareErrorFlag;
// this value should be even
#define NUMBER_OF_DIFFERENT_LINES 4
static int infoIndex = 0;
void onJoystick(joystick_button_e button) {
}
char * appendStr(char *ptr, const char *suffix) {
for (uint32_t i = 0; i < efiStrlen(suffix); i++) {
*ptr++ = suffix[i];
@ -140,69 +148,93 @@ static void prepareCurrentSecondLine(Engine *engine, int index) {
*ptr = ' ';
}
void updateHD44780lcd(Engine *engine) {
lcd_HD44780_set_position(0, 0);
bool_t isEven = getTimeNowSeconds() % 2 == 0;
if (isEven) {
lcd_HD44780_print_string (VCS_VERSION);
} else {
static void showLine(lcd_line_e line) {
switch (line) {
case LL_VERSION:
lcd_HD44780_print_string("version ");
lcd_HD44780_print_string(VCS_VERSION);
return;
case LL_CONFIG:
lcd_HD44780_print_string("config ");
lcd_HD44780_print_string(getConfigurationName(engine->engineConfiguration->engineType));
}
lcd_HD44780_set_position(0, 9);
/**
* this would blink so that we know the LCD is alive
*/
if (isEven) {
lcd_HD44780_print_char('R');
} else {
lcd_HD44780_print_char(' ');
}
lcd_HD44780_set_position(0, 10);
char * ptr = itoa10(buffer, getRpmE(engine));
ptr[0] = 0;
int len = ptr - buffer;
for (int i = 0; i < 6 - len; i++) {
lcd_HD44780_print_char(' ');
}
lcd_HD44780_print_string(buffer);
if (hasFirmwareError()) {
memcpy(buffer, getFirmwareError(), LCD_WIDTH);
buffer[LCD_WIDTH] = 0;
lcd_HD44780_set_position(1, 0);
lcd_HD44780_print_string(buffer);
return;
}
lcd_HD44780_set_position(1, 0);
memset(buffer, ' ', LCD_WIDTH);
memcpy(buffer, getWarninig(), LCD_WIDTH);
buffer[LCD_WIDTH] = 0;
lcd_HD44780_print_string(buffer);
if (engineConfiguration->HD44780height < 3) {
return;
}
int index = (getTimeNowSeconds() / 2) % (NUMBER_OF_DIFFERENT_LINES / 2);
prepareCurrentSecondLine(engine, index);
buffer[LCD_WIDTH] = 0;
lcd_HD44780_set_position(2, 0);
lcd_HD44780_print_string(buffer);
prepareCurrentSecondLine(engine, index + NUMBER_OF_DIFFERENT_LINES / 2);
buffer[LCD_WIDTH] = 0;
lcd_HD44780_set_position(3, 0);
lcd_HD44780_print_string(buffer);
#if EFI_PROD_CODE
dateToString(dateBuffer);
lcd_HD44780_set_position(1, 0);
lcd_HD44780_print_string(dateBuffer);
#endif /* EFI_PROD_CODE */
}
void updateHD44780lcd(Engine *engine) {
for (int i = infoIndex; i < infoIndex + engineConfiguration->HD44780height - 1; i++) {
lcd_HD44780_set_position(i - infoIndex, 0);
showLine((lcd_line_e) i);
int column = getCurrentHD44780column();
for (int r = column; r < 20; r++) {
lcd_HD44780_print_char('*');
}
}
// lcd_HD44780_set_position(0, 0);
// bool_t isEven = getTimeNowSeconds() % 2 == 0;
//
// if (isEven) {
//
// } else {
//
// }
//
// lcd_HD44780_set_position(0, 9);
// /**
// * this would blink so that we know the LCD is alive
// */
// if (isEven) {
// lcd_HD44780_print_char('R');
// } else {
// lcd_HD44780_print_char(' ');
// }
// lcd_HD44780_set_position(0, 10);
//
// char * ptr = itoa10(buffer, getRpmE(engine));
// ptr[0] = 0;
// int len = ptr - buffer;
// for (int i = 0; i < 6 - len; i++) {
// lcd_HD44780_print_char(' ');
// }
// lcd_HD44780_print_string(buffer);
//
// if (hasFirmwareError()) {
// memcpy(buffer, getFirmwareError(), LCD_WIDTH);
// buffer[LCD_WIDTH] = 0;
// lcd_HD44780_set_position(1, 0);
// lcd_HD44780_print_string(buffer);
// return;
// }
//
// lcd_HD44780_set_position(1, 0);
// memset(buffer, ' ', LCD_WIDTH);
// memcpy(buffer, getWarninig(), LCD_WIDTH);
// buffer[LCD_WIDTH] = 0;
// lcd_HD44780_print_string(buffer);
//
// if (engineConfiguration->HD44780height < 3) {
// return;
// }
//
// int index = (getTimeNowSeconds() / 2) % (NUMBER_OF_DIFFERENT_LINES / 2);
//
// prepareCurrentSecondLine(engine, index);
// buffer[LCD_WIDTH] = 0;
// lcd_HD44780_set_position(2, 0);
// lcd_HD44780_print_string(buffer);
//
// prepareCurrentSecondLine(engine, index + NUMBER_OF_DIFFERENT_LINES / 2);
// buffer[LCD_WIDTH] = 0;
// lcd_HD44780_set_position(3, 0);
// lcd_HD44780_print_string(buffer);
//
//#if EFI_PROD_CODE
// dateToString(dateBuffer);
// lcd_HD44780_set_position(1, 0);
// lcd_HD44780_print_string(dateBuffer);
//#endif /* EFI_PROD_CODE */
}

View File

@ -12,33 +12,42 @@
#if HAL_USE_EXT || defined(__DOXYGEN__)
EXTERN_ENGINE;
EXTERN_ENGINE
;
static int joyTotal = 0;
static int joyCenter;
static int joyA = 0;
static int joyB = 0;
static int joyC = 0;
static int joyD = 0;;
static int joyD = 0;
#define NT_EVENT_GAP US2NT(1000)
static Logging *sharedLogger;
// {EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOA, extcb1},
static efitick_t lastEventTime = 0;
static void extCallback(EXTDriver *extp, expchannel_t channel) {
efitick_t now = getTimeNowNt();
if (now - lastEventTime < NT_EVENT_GAP)
return; // two consecutive events are probably just jitter
joyTotal++;
if (channel == getHwPin(boardConfiguration->joystickAPin)) {
if (channel == getHwPin(boardConfiguration->joystickCenterPin)) {
joyCenter++;
} else if (channel == getHwPin(boardConfiguration->joystickAPin)) {
joyA++;
} else if (channel == 9) {
} else if (channel == getHwPin(boardConfiguration->joystickBPin)) {
joyB++;
} else if (channel == 10) {
} else if (channel == getHwPin(boardConfiguration->joystickCPin)) {
joyC++;
} else if (channel == getHwPin(boardConfiguration->joystickDPin)) {
joyD++;
}
}
static void joystickInfo(void) {
scheduleMsg(sharedLogger, "total %d center=%d@%s", joyTotal,
joyCenter, hwPortname(boardConfiguration->joystickCenterPin));
scheduleMsg(sharedLogger, "total %d center=%d@%s", joyTotal, joyCenter,
hwPortname(boardConfiguration->joystickCenterPin));
scheduleMsg(sharedLogger, "a=%d@%s", joyA, hwPortname(boardConfiguration->joystickAPin));
scheduleMsg(sharedLogger, "b=%d@%s", joyB, hwPortname(boardConfiguration->joystickBPin));
scheduleMsg(sharedLogger, "c=%d@%s", joyC, hwPortname(boardConfiguration->joystickCPin));
@ -78,31 +87,55 @@ static EXTConfig extcfg = { {
/* CH#21 */{ EXT_CH_MODE_DISABLED, NULL },
/* CH#22 */{ EXT_CH_MODE_DISABLED, NULL } } };
static uint32_t getExtMode(GPIO_TypeDef * port) {
if (port == GPIOA) {
return EXT_MODE_GPIOA;
} else if (port == GPIOB) {
return EXT_MODE_GPIOB;
} else if (port == GPIOC) {
return EXT_MODE_GPIOC;
} else if (port == GPIOD) {
return EXT_MODE_GPIOD;
} else if (port == GPIOE) {
return EXT_MODE_GPIOE;
} else if (port == GPIOF) {
return EXT_MODE_GPIOF;
}
firmwareError("Unsupported %d", port);
return 0;
}
static void applyPin(brain_pin_e pin) {
if (pin == GPIO_UNASSIGNED)
return;
int index = getHwPin(pin);
GPIO_TypeDef * port = getHwPort(pin);
extcfg.channels[index].mode = EXT_CH_MODE_RISING_EDGE | EXT_CH_MODE_AUTOSTART | getExtMode(port);
extcfg.channels[index].cb = extCallback;
}
void initJoystick(Logging *shared) {
if (!engineConfiguration->isJoystickEnabled)
return;
sharedLogger = shared;
extcfg.channels[8].mode = EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART
| EXT_MODE_GPIOC; // PC8
extcfg.channels[8].cb = extCallback;
extcfg.channels[10].mode = EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART
| EXT_MODE_GPIOD; // PD10
extcfg.channels[10].cb = extCallback;
extcfg.channels[11].mode = EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART
| EXT_MODE_GPIOD; // PD11
extcfg.channels[11].cb = extCallback;
applyPin(boardConfiguration->joystickCenterPin);
applyPin(boardConfiguration->joystickAPin);
applyPin(boardConfiguration->joystickBPin);
applyPin(boardConfiguration->joystickCPin);
applyPin(boardConfiguration->joystickDPin);
mySetPadMode2("joy center", boardConfiguration->joystickCenterPin, PAL_MODE_INPUT_PULLUP);
mySetPadMode("joy B", GPIOC, 8, PAL_MODE_INPUT_PULLUP);
mySetPadMode("joy D", GPIOD, 11, PAL_MODE_INPUT_PULLUP);
mySetPadMode2("joy A", boardConfiguration->joystickAPin, PAL_MODE_INPUT_PULLUP);
mySetPadMode2("joy B", boardConfiguration->joystickBPin, PAL_MODE_INPUT_PULLUP);
mySetPadMode2("joy C", boardConfiguration->joystickCPin, PAL_MODE_INPUT_PULLUP);
mySetPadMode2("joy D", boardConfiguration->joystickDPin, PAL_MODE_INPUT_PULLUP);
addConsoleAction("joystickinfo", joystickInfo);
extStart(&EXTD1, &extcfg);
}
#endif

View File

@ -55,6 +55,7 @@ static const int lineStart[] = { 0, 0x40, 0x14, 0x54 };
static int BUSY_WAIT_DELAY = FALSE;
static int currentRow = 0;
static int currentColumn = 0;
static void lcdSleep(int period) {
if (BUSY_WAIT_DELAY) {
@ -130,6 +131,7 @@ void lcd_HD44780_write_data(uint8_t data) {
lcd_HD44780_write(data);
lcd_HD44780_write(data << 4);
currentColumn++;
palClearPad(getHwPort(boardConfiguration->HD44780_rs), getHwPin(boardConfiguration->HD44780_rs));
}
@ -138,6 +140,7 @@ void lcd_HD44780_write_data(uint8_t data) {
void lcd_HD44780_set_position(uint8_t row, uint8_t column) {
efiAssertVoid(row <= engineConfiguration->HD44780height, "invalid row");
currentRow = row;
currentColumn = column;
lcd_HD44780_write_command(LCD_HD44780_DDRAM_ADDR + lineStart[row] + column);
}
@ -145,6 +148,10 @@ int getCurrentHD44780row(void) {
return currentRow;
}
int getCurrentHD44780column(void) {
return currentColumn;
}
void lcd_HD44780_print_char(char data) {
if (data == '\n') {
lcd_HD44780_set_position(++currentRow, 0);

View File

@ -18,6 +18,7 @@ void lcd_HD44780_set_position(uint8_t row, uint8_t column);
void lcd_HD44780_print_char(char data);
void lcd_HD44780_print_string(const char *string);
int getCurrentHD44780row(void);
int getCurrentHD44780column(void);
void lcdShowFatalMessage(char *message);

View File

@ -152,7 +152,7 @@ void mySetPadMode(const char *msg, ioportid_t port, ioportmask_t pin, iomode_t m
firmwareError("repository not initialized");
return;
}
if (GPIO_NULL == NULL)
if (port == GPIO_NULL)
return;
print("%s on %s:%d\r\n", msg, portname(port), pin);