BV HiZ: use red/blue LED to indicate user action is needed for test

This commit is contained in:
King Kévin 2018-02-13 17:43:08 +01:00
parent 6f8bbca2bf
commit 8774be07cd
1 changed files with 19 additions and 17 deletions

View File

@ -50,7 +50,7 @@ static bool busvoodoo_hiz_setup(char** prefix, const char* line)
{
(void)line; // no configuration is required
*prefix = "HiZ"; // set command line prefix
led_blink(0, 1); // switch blue LED on to show we are ready
led_blue(); // switch blue LED on to show we are ready
busvoodoo_oled_text_left("HiZ"); // set mode title on OLED display
const char* pinout_io[10] = {"GND", "3V3", "5V", "LV", NULL, NULL, NULL, NULL, NULL, NULL}; // HiZ mode pinout
for (uint8_t i=0; i<LENGTH(pinout_io) && i<LENGTH(busvoodoo_global_pinout_io); i++) {
@ -451,15 +451,16 @@ static bool busvoodoo_hiz_test_pins(void)
gpio_set(GPIO(BUSVOODOO_LVCTL_PORT), GPIO(BUSVOODOO_LVCTL_PIN)); // set pin high
gpio_set_mode(GPIO(BUSVOODOO_LVCTL_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_LVCTL_PIN)); // set LV control pin as output
printf("%sI/O pin 1\n", lv_to);
led_red(); // notify user to perform action
do {
sleep_ms(100); // wait for user to make connection
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2 && !user_input_available); // wait until pin is shorted to ground
led_blue(); // notify user test is running
if (user_input_available) { // user interruption
goto error;
}
gpio_clear(GPIO(BUSVOODOO_LVCTL_PORT), GPIO(BUSVOODOO_LVCTL_PIN)); // set pin low
gpio_set_mode(GPIO(BUSVOODOO_LVCTL_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_LVCTL_PIN)); // set LV control pin as output
led_toggle(); // notify user test is almost almost
sleep_ms(100); // wait for voltage to settle an debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf(lv_high);
@ -470,19 +471,19 @@ static bool busvoodoo_hiz_test_pins(void)
#endif
}
gpio_set_mode(GPIO(BUSVOODOO_LVCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_LVCTL_PIN)); // set LV control pin back to analog input for DAC
led_toggle(); // notify user test is complete
// test 5V output on pin 2
gpio_clear(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // enable Vout
printf("%sI/O pin 2\n", lv_to);
led_red(); // notify user to perform action
do {
sleep_ms(100); // wait for user to make connection
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2 && !user_input_available); // wait until pin is connected
led_blue(); // notify user test is running
if (user_input_available) { // user interruption
goto error;
}
gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
led_toggle(); // notify user test is almost complete
sleep_ms(100); // wait for voltage to settle and debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf(lv_high);
@ -492,19 +493,19 @@ static bool busvoodoo_hiz_test_pins(void)
goto error;
#endif
}
led_toggle(); // notify user test is complete
// test 3.3V output on pin 3
gpio_clear(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // enable Vout
printf("%sI/O pin 3\n", lv_to);
led_red(); // notify user to perform action
do {
sleep_ms(100); // wait for user to make connection
} while ((busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2 || busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>3.5) && !user_input_available); // wait until pin is connected
led_blue(); // notify user test is running
if (user_input_available) { // user interruption
goto error;
}
gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
led_toggle(); // notify user test is almost complete
sleep_ms(100); // wait for voltage to settle and debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf(lv_high);
@ -514,7 +515,6 @@ static bool busvoodoo_hiz_test_pins(void)
goto error;
#endif
}
led_toggle(); // notify user test is complete
// test I/O pins
for (uint8_t io=1; io<=6; io++) { // test each I/O pin
@ -523,14 +523,15 @@ static bool busvoodoo_hiz_test_pins(void)
gpio_set(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // set pin high
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, busvoodoo_io_pins[pin]); // set pin to output
printf("%sI/O pin %u\n", lv_to, io+4);
led_red(); // notify user to perform action
do {
sleep_ms(100); // wait for user to make connection
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2 && !user_input_available); // wait until pin is connected
led_blue(); // notify user test is running
if (user_input_available) { // user interruption
goto error;
}
gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // set pin low
led_toggle(); // notify user test is almost complete
sleep_ms(100); // wait for voltage to settle and debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf(lv_high);
@ -541,7 +542,6 @@ static bool busvoodoo_hiz_test_pins(void)
#endif
}
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, busvoodoo_io_pins[pin]); // set pin back to input
led_toggle(); // notify user test is complete
break; // stop looking for pin
}
}
@ -556,15 +556,16 @@ static bool busvoodoo_hiz_test_pins(void)
dac_enable(BUSVOODOO_HVCTL_CHANNEL); // enable DAC
gpio_clear(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)); // enable HV voltage regulator
printf("%sRS/CAN pin 1\n", lv_to);
led_red(); // notify user to perform action
do {
sleep_ms(100); // wait for user to make connection
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2 && !user_input_available); // wait until pin is connected
led_blue(); // notify user test is running
if (user_input_available) { // user interruption
goto error;
}
gpio_set(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)); // disable HV voltage regulator
dac_disable(BUSVOODOO_HVCTL_CHANNEL); // disable HV control
led_toggle(); // notify user test is almost complete
sleep_ms(100); // wait for voltage to settle (and debounce)
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf(lv_high);
@ -574,7 +575,6 @@ static bool busvoodoo_hiz_test_pins(void)
goto error;
#endif
}
led_toggle(); // notify user test is complete
// test RS-232 port (with itself)
rcc_periph_clock_enable(RCC_GPIO(BUSVOODOO_RS232_EN_PORT)); // enable clock for GPIO domain
@ -592,15 +592,16 @@ static bool busvoodoo_hiz_test_pins(void)
gpio_set(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO(BUSVOODOO_RS232_RX_PIN)); // pull high to avoid false negative
sleep_ms(5);
printf("connect RS/CAN pin 2 to RS/CAN pin 3\n");
led_red(); // notify user to perform action
do {
sleep_ms(100); // wait for user to make connection
} while (gpio_get(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO(BUSVOODOO_RS232_RX_PIN)) && !user_input_available); // wait until pin is connected
led_blue(); // notify user test is running
if (user_input_available) { // user interruption
goto error;
}
gpio_set(GPIO(BUSVOODOO_RS232_TX_PORT), GPIO(BUSVOODOO_RS232_TX_PIN)); // set high
gpio_clear(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO(BUSVOODOO_RS232_RX_PIN)); // pull low to avoid false negative
led_toggle(); // notify user test is almost complete
sleep_ms(100); // wait for voltage to settle and debounce
if (!gpio_get(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO(BUSVOODOO_RS232_RX_PIN))) { // check if RX is set low by TX
printf("CAN/RS pin 2 is high while it should be set low by pin 3\n");
@ -612,7 +613,6 @@ static bool busvoodoo_hiz_test_pins(void)
}
gpio_set_mode(GPIO(BUSVOODOO_RS232_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_TX_PIN)); // free pin
gpio_set_mode(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_RX_PIN)); // free pin
led_toggle(); // notify user test is complete
rcc_periph_clock_enable(RCC_GPIO(BUSVOODOO_RS232_RTS_PORT)); // enable clock for GPIO
gpio_set_mode(GPIO(BUSVOODOO_RS232_RTS_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS232_RTS_PIN)); // set pin as output (push-pull)
@ -622,15 +622,16 @@ static bool busvoodoo_hiz_test_pins(void)
gpio_clear(GPIO(BUSVOODOO_RS232_RTS_PORT), GPIO(BUSVOODOO_RS232_RTS_PIN)); // set low
gpio_set(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO(BUSVOODOO_RS232_CTS_PIN)); // pull high to avoid false negative
printf("connect RS/CAN pin 4 to RS/CAN pin 5\n");
led_red(); // notify user to perform action
do {
sleep_ms(100); // wait for user to make connection
} while (gpio_get(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO(BUSVOODOO_RS232_CTS_PIN)) && !user_input_available); // wait until pin is connected
led_blue(); // notify user test is running
if (user_input_available) { // user interruption
goto error;
}
gpio_set(GPIO(BUSVOODOO_RS232_RTS_PORT), GPIO(BUSVOODOO_RS232_RTS_PIN)); // set high
gpio_clear(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO(BUSVOODOO_RS232_CTS_PIN)); // pull low to avoid false negative
led_toggle(); // notify user test is almost complete
sleep_ms(100); // wait for voltage to settle an debounce
if (!gpio_get(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO(BUSVOODOO_RS232_CTS_PIN))) { // check if CTS is set high by RTS
printf("CAN/RS pin 5 is high while it should be set low by pin 4\n");
@ -642,7 +643,6 @@ static bool busvoodoo_hiz_test_pins(void)
}
gpio_set_mode(GPIO(BUSVOODOO_RS232_RTS_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_RTS_PIN)); // free pin
gpio_set_mode(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_CTS_PIN)); // free pin
led_toggle(); // notify user test is complete
gpio_set(GPIO(BUSVOODOO_RS232_EN_PORT), GPIO(BUSVOODOO_RS232_EN_PIN)); // set high to disable receiver
gpio_clear(GPIO(BUSVOODOO_RS232_SHDN_PORT), GPIO(BUSVOODOO_RS232_SHDN_PIN)); // set low to disable transmitter
@ -671,9 +671,10 @@ static void busvoodoo_hiz_command_test_self(void* argument)
(void)argument; // we won't use the argument
printf("performing self-test\n");
printf("remove all cables from connectors and press space to start (or any other key to abort)\n");
led_red(); // show red LED to indicate test started
if (' '==user_input_get()) { // space entered
if (busvoodoo_hiz_test_self()) { // perform self-test
led_blink(0, 1.0); // show blue OK LED
led_blue(); // show blue to indicate test passed
printf("self-test succeeded\n"); // notify user
} else {
led_blink(0.5, 0.5); // show error on LEDs
@ -692,9 +693,10 @@ static void busvoodoo_hiz_command_test_pins(void* argument)
(void)argument; // we won't use the argument
printf("performing pins test\n");
printf("remove all cables from connectors and press space to start (or any other key to abort)\n");
led_red(); // show red LED to indicate test started
if (' '==user_input_get()) { // space entered
if (busvoodoo_hiz_test_pins()) { // perform pin test
led_blink(0, 1.0); // show blue OK LED
led_blue(); // show blue OK LED
printf("pins test succeeded\n"); // notify user
} else {
led_blink(0.5, 0.5); // show error on LEDs