BV HiZ: display pins on OLED for pins test
This commit is contained in:
parent
0e4628532d
commit
c0c6b8f0af
|
@ -530,13 +530,19 @@ static bool busvoodoo_hiz_test_pins(void)
|
|||
busvoodoo_safe_state(); // start from safe state with all outputs switched off
|
||||
|
||||
const char* lv_to = "connect I/O pin 4 to "; // most outputs will be tested using LV ADC
|
||||
//const char* lv_high = "pin 4 is high while it should be low, other pin might be defective\n"; // error message if expect low output is high
|
||||
char* pinout[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; // pinout to display
|
||||
busvoodoo_oled_text_right("pins test"); // display test on display
|
||||
busvoodoo_oled_update(); // update screen
|
||||
|
||||
// test GND on pin 1 by shorting LV_CTL to ground (through 40k resistor) and measure short
|
||||
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);
|
||||
printf("%sI/O pin 1\n", lv_to); // ask user for action
|
||||
led_red(); // notify user to perform action
|
||||
pinout[3] = "O"; // set main testing pin
|
||||
pinout[0] = "O"; // set target testing pin
|
||||
busvoodoo_oled_text_pinout((const char**)pinout, true); // display pins to user
|
||||
busvoodoo_oled_update(); // update screen
|
||||
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
|
||||
|
@ -556,11 +562,15 @@ 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
|
||||
pinout[0] = NULL; // clear pin to test
|
||||
|
||||
// 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
|
||||
pinout[1] = "O"; // set target testing pin
|
||||
busvoodoo_oled_text_pinout((const char**)pinout, true); // display pins to user
|
||||
busvoodoo_oled_update(); // update screen
|
||||
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
|
||||
|
@ -578,11 +588,15 @@ static bool busvoodoo_hiz_test_pins(void)
|
|||
goto error;
|
||||
#endif
|
||||
}
|
||||
pinout[1] = NULL; // clear pin to test
|
||||
|
||||
// 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
|
||||
pinout[2] = "O"; // set target testing pin
|
||||
busvoodoo_oled_text_pinout((const char**)pinout, true); // display pins to user
|
||||
busvoodoo_oled_update(); // update screen
|
||||
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
|
||||
|
@ -600,6 +614,7 @@ static bool busvoodoo_hiz_test_pins(void)
|
|||
goto error;
|
||||
#endif
|
||||
}
|
||||
pinout[2] = NULL; // clear pin to test
|
||||
|
||||
// test I/O pins
|
||||
for (uint8_t io=1; io<=6; io++) { // test each I/O pin
|
||||
|
@ -609,6 +624,9 @@ static bool busvoodoo_hiz_test_pins(void)
|
|||
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
|
||||
pinout[io+3] = "O"; // set target testing pin
|
||||
busvoodoo_oled_text_pinout((const char**)pinout, true); // display pins to user
|
||||
busvoodoo_oled_update(); // update screen
|
||||
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
|
||||
|
@ -627,12 +645,15 @@ 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
|
||||
pinout[io+3] = NULL; // clear pin to test
|
||||
break; // stop looking for pin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (busvoodoo_full) {
|
||||
pinout[3] = NULL; // reset testing pin
|
||||
|
||||
// test HV output on RS/CAN pin 1
|
||||
double voltage = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get reference voltage
|
||||
uint16_t dac_set = BUSVOODOO_HV_SET(5.0)/voltage*4095; // DAC value corresponding to the voltage
|
||||
|
@ -642,6 +663,9 @@ static bool busvoodoo_hiz_test_pins(void)
|
|||
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
|
||||
pinout[0] = "O"; // set target testing pin
|
||||
busvoodoo_oled_text_pinout((const char**)pinout, false); // display pins to user
|
||||
busvoodoo_oled_update(); // update screen
|
||||
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
|
||||
|
@ -660,6 +684,7 @@ static bool busvoodoo_hiz_test_pins(void)
|
|||
goto error;
|
||||
#endif
|
||||
}
|
||||
pinout[0] = NULL; // clear pin to test
|
||||
|
||||
// test RS-485 output A
|
||||
gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // enable transmitter
|
||||
|
@ -667,6 +692,9 @@ static bool busvoodoo_hiz_test_pins(void)
|
|||
gpio_set(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX high -> A will be high
|
||||
printf("%sRS/CAN pin 3\n", lv_to);
|
||||
led_red(); // notify user to perform action
|
||||
pinout[4] = "O"; // set target testing pin
|
||||
busvoodoo_oled_text_pinout((const char**)pinout, false); // display pins to user
|
||||
busvoodoo_oled_update(); // update screen
|
||||
do {
|
||||
sleep_ms(100); // wait for user to make connection
|
||||
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<2.0 && !user_input_available); // wait until pin is connected
|
||||
|
@ -686,6 +714,7 @@ static bool busvoodoo_hiz_test_pins(void)
|
|||
}
|
||||
gpio_clear(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set low to disable transmitter
|
||||
gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_TX_PIN)); // set pin to floating
|
||||
pinout[4] = NULL; // clear pin to test
|
||||
|
||||
// test CAN output L
|
||||
// configure transceiver
|
||||
|
@ -733,6 +762,9 @@ static bool busvoodoo_hiz_test_pins(void)
|
|||
gpio_clear(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX low -> B will be high
|
||||
printf("%sRS/CAN pin 4\n", lv_to);
|
||||
led_red(); // notify user to perform action
|
||||
pinout[6] = "O"; // set target testing pin
|
||||
busvoodoo_oled_text_pinout((const char**)pinout, false); // display pins to user
|
||||
busvoodoo_oled_update(); // update screen
|
||||
do {
|
||||
sleep_ms(100); // wait for user to make connection
|
||||
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<2.0 && !user_input_available); // wait until pin is connected
|
||||
|
@ -752,6 +784,7 @@ static bool busvoodoo_hiz_test_pins(void)
|
|||
}
|
||||
gpio_clear(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set low to disable transmitter
|
||||
gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_TX_PIN)); // set pin to floating
|
||||
pinout[6] = NULL; // clear pin to test
|
||||
|
||||
// test CAN output H
|
||||
// configure transceiver
|
||||
|
@ -811,6 +844,10 @@ static bool busvoodoo_hiz_test_pins(void)
|
|||
sleep_ms(5);
|
||||
printf("connect RS/CAN pin 2 to RS/CAN pin 3\n");
|
||||
led_red(); // notify user to perform action
|
||||
pinout[2] = "O"; // set target testing pin
|
||||
pinout[4] = "O"; // set target testing pin
|
||||
busvoodoo_oled_text_pinout((const char**)pinout, false); // display pins to user
|
||||
busvoodoo_oled_update(); // update screen
|
||||
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
|
||||
|
@ -831,6 +868,8 @@ 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
|
||||
pinout[2] = NULL; // clear pin to test
|
||||
pinout[4] = NULL; // clear pin to test
|
||||
|
||||
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)
|
||||
|
@ -841,6 +880,10 @@ static bool busvoodoo_hiz_test_pins(void)
|
|||
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
|
||||
pinout[6] = "O"; // set target testing pin
|
||||
pinout[8] = "O"; // set target testing pin
|
||||
busvoodoo_oled_text_pinout((const char**)pinout, false); // display pins to user
|
||||
busvoodoo_oled_update(); // update screen
|
||||
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
|
||||
|
@ -861,14 +904,18 @@ 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
|
||||
|
||||
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
|
||||
pinout[6] = NULL; // clear pin to test
|
||||
pinout[8] = NULL; // clear pin to test
|
||||
}
|
||||
|
||||
to_return = true; // all tests passed
|
||||
error:
|
||||
busvoodoo_safe_state(); // go back to safe state
|
||||
busvoodoo_oled_text_left("HiZ"); // reset mode text
|
||||
busvoodoo_oled_text_pinout(busvoodoo_global_pinout_io, true); // reset pinout
|
||||
busvoodoo_oled_update(); // update display to show text and pinout
|
||||
if (user_input_available) { // user interrupted the test
|
||||
printf("user interrupted the test\n");
|
||||
to_return = true; // we don't consider this as error
|
||||
|
|
Loading…
Reference in New Issue