busvoodoo_hiz: remove features unsupported by dongle

This commit is contained in:
King Kévin 2020-03-09 12:59:48 +01:00
parent d911103ee7
commit 67b7243736
2 changed files with 60 additions and 19 deletions

View File

@ -12,10 +12,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/** BusVoodoo high impedance (HiZ) default mode (code)
* @file busvoodoo_hiz.c
/** BusVoodoo high impedance (HiZ) default mode
* @file
* @author King Kévin <kingkevin@cuvoodoo.info>
* @date 2018
* @date 2018-2020
*/
/* standard libraries */
#include <stdint.h> // standard integer types
@ -35,13 +35,17 @@
#include "print.h" // printing utilities
#include "menu.h" // menu definitions
#include "busvoodoo_global.h" // BusVoodoo definitions
#if BUSVOODOO_HARDWARE_VERSION != 2
#include "busvoodoo_oled.h" // OLED utilities
#endif
#include "busvoodoo_hiz.h" // own definitions
#if BUSVOODOO_HARDWARE_VERSION != 2
#define BUSVOODOO_LV_DEFAULT (0.8*(1+30.0/10.0)) /**< default (when not driven) LV voltage regulator output voltage based on R1 and R2 */
#define BUSVOODOO_LV_TEST 2.5 /**< target LV output voltage to test if we can set control the LV voltage regulator */
#define BUSVOODOO_HV_DEFAULT (1.25*(1+100.0/10.0)) /**< default (when not driven) HV voltage regulator output voltage based on R1 and R2 */
#define BUSVOODOO_HV_TEST 12.0 /**< target HV output voltage to test if we can set control the HV voltage regulator */
#endif
/** setup HiZ mode
* @param[out] prefix terminal prompt prefix
@ -54,19 +58,21 @@ static bool busvoodoo_hiz_setup(char** prefix, const char* line)
*prefix = "HiZ"; // set command line prefix
busvoodoo_leds_off(); // switch off all LEDs
busvoodoo_led_blue_on(); // switch on blue LED
busvoodoo_oled_text_left(*prefix); // set mode title on OLED display
const char* pinout_io[10] = {"GND", "5V", "3V3", "LV", NULL, NULL, NULL, NULL, NULL, NULL}; // HiZ mode I/O pinout
for (uint8_t i=0; i<LENGTH(pinout_io) && i<LENGTH(busvoodoo_global_pinout_io); i++) {
busvoodoo_global_pinout_io[i] = pinout_io[i]; // set pin names
}
#if BUSVOODOO_HARDWARE_VERSION != 2
if (busvoodoo_full) {
const char* pinout_rscan[5] = {"HV", NULL, NULL, NULL, NULL}; // HiZ mode RS/CAN pinout
for (uint8_t i=0; i<LENGTH(pinout_rscan) && i<LENGTH(busvoodoo_global_pinout_rscan); i++) {
busvoodoo_global_pinout_rscan[i] = pinout_rscan[i]; // set pin names
}
}
busvoodoo_oled_text_left(*prefix); // set mode title on OLED display
busvoodoo_oled_text_pinout(busvoodoo_global_pinout_io, true); // set pinout on display
busvoodoo_oled_update(); // update display to show text and pinout
#endif
return true;
}
@ -103,6 +109,7 @@ static bool busvoodoo_hiz_test_self(bool halt)
printf("unknown flash size: this is probably a defective micro-controller\n");
}
#if BUSVOODOO_HARDWARE_VERSION != 2
// check 5V power rail
float voltage = busvoodoo_vreg_get(BUSVOODOO_5V_CHANNEL); // get 5V power rail voltage
if (voltage<4.0) {
@ -206,6 +213,7 @@ static bool busvoodoo_hiz_test_self(bool halt)
}
voltage = busvoodoo_hv_set(0); // disable HV voltage regulator
}
#endif
// pull all pins down and ensure they are low
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
@ -272,6 +280,7 @@ static bool busvoodoo_hiz_test_self(bool halt)
gpio_set(busvoodoo_io_ports[pin1], busvoodoo_io_pins[pin1]); // pull pin back up
}
#if BUSVOODOO_HARDWARE_VERSION != 2
// test 5V pull-up
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin]); // set pin to input
@ -382,7 +391,8 @@ static bool busvoodoo_hiz_test_self(bool halt)
gpio_set_mode(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_TX_PIN)); // set pin to floating
gpio_set_mode(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_RX_PIN)); // set pin to floating
}
#endif
#endif // BUSVOODOO_HARDWARE_VERSION != 0
#endif // BUSVOODOO_HARDWARE_VERSION != 2
to_return = true; // all tests are successful
printf("self-test succeeded\n"); // notify user
@ -410,11 +420,14 @@ static bool busvoodoo_hiz_test_pins(bool halt)
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
#if BUSVOODOO_HARDWARE_VERSION != 2
char* pinout[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; // pinout to display
pinout[3] = "O"; // set main testing pin
busvoodoo_oled_text_right("pins test"); // display test on display
busvoodoo_oled_update(); // update screen
#endif
#if BUSVOODOO_HARDWARE_VERSION != 2
// 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
@ -441,15 +454,24 @@ static bool busvoodoo_hiz_test_pins(bool halt)
}
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
#else
// we can't test ground on pin 1 using pin 4 because it is already pulled low
#endif
// test 5V output on pin 2
#if BUSVOODOO_HARDWARE_VERSION != 2
gpio_clear(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // enable Vout
#else
#define BUSVOODOO_LV_CHANNEL BUSVOODOO_ADC_CHANNEL
#endif
printf("%sI/O pin 2\n", lv_to);
busvoodoo_leds_off(); // clear LEDs
busvoodoo_led_red_on(); // notify user to perform action
#if BUSVOODOO_HARDWARE_VERSION != 2
pinout[1] = "O"; // set target testing pin
busvoodoo_oled_text_pinout((const char**)pinout, true); // display pins to user
busvoodoo_oled_update(); // update screen
#endif
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
@ -458,6 +480,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
if (user_input_available) { // user interruption
goto error;
}
#if BUSVOODOO_HARDWARE_VERSION != 2
gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
sleep_ms(100); // wait for voltage to settle and debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
@ -465,15 +488,20 @@ static bool busvoodoo_hiz_test_pins(bool halt)
goto error;
}
pinout[1] = NULL; // clear pin to test
#endif
// test 3.3V output on pin 3
#if BUSVOODOO_HARDWARE_VERSION != 2
gpio_clear(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // enable Vout
#endif
printf("%sI/O pin 3\n", lv_to);
busvoodoo_leds_off(); // clear LEDs
busvoodoo_led_red_on(); // notify user to perform action
#if BUSVOODOO_HARDWARE_VERSION != 2
pinout[2] = "O"; // set target testing pin
busvoodoo_oled_text_pinout((const char**)pinout, true); // display pins to user
busvoodoo_oled_update(); // update screen
#endif
do {
do {
sleep_ms(100); // wait for user to make connection
@ -485,6 +513,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
if (user_input_available) { // user interruption
goto error;
}
#if BUSVOODOO_HARDWARE_VERSION != 2
gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
sleep_ms(100); // wait for voltage to settle and debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
@ -492,6 +521,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
goto error;
}
pinout[2] = NULL; // clear pin to test
#endif
// test I/O pins
for (uint8_t io=1; io<=6; io++) { // test each I/O pin
@ -502,9 +532,11 @@ static bool busvoodoo_hiz_test_pins(bool halt)
printf("%sI/O pin %u\n", lv_to, io+4);
busvoodoo_leds_off(); // clear LEDs
busvoodoo_led_red_on(); // notify user to perform action
#if BUSVOODOO_HARDWARE_VERSION != 2
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
#endif
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
@ -520,12 +552,15 @@ static bool busvoodoo_hiz_test_pins(bool halt)
goto error;
}
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, busvoodoo_io_pins[pin]); // set pin back to input
#if BUSVOODOO_HARDWARE_VERSION != 2
pinout[io+3] = NULL; // clear pin to test
#endif
break; // stop looking for pin
}
}
}
#if BUSVOODOO_HARDWARE_VERSION != 2
if (busvoodoo_full) {
pinout[3] = NULL; // reset testing pin
@ -559,7 +594,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
}
pinout[0] = NULL; // clear pin to test
#if BUSVOODOO_HARDWARE_VERSION==0
#if BUSVOODOO_HARDWARE_VERSION == 0
// test RS-485 port pin B
gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // enable transmitter
gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX as output
@ -587,7 +622,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
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
#else
#else // BUSVOODOO_HARDWARE_VERSION == 0
// test RS-485 output A
gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // enable transmitter
gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX as output
@ -615,9 +650,9 @@ static bool busvoodoo_hiz_test_pins(bool halt)
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
#endif
#endif // BUSVOODOO_HARDWARE_VERSION == 0
#if BUSVOODOO_HARDWARE_VERSION!=0
#if BUSVOODOO_HARDWARE_VERSION != 0
// test CAN output L
// configure transceiver
gpio_clear(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // pull low to power transceiver
@ -645,9 +680,9 @@ static bool busvoodoo_hiz_test_pins(bool halt)
// release transceiver
gpio_set(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // set high to power off transceiver
gpio_set_mode(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_TX_PIN)); // set pin to floating
#endif
#endif // BUSVOODOO_HARDWARE_VERSION != 0
#if BUSVOODOO_HARDWARE_VERSION==0
#if BUSVOODOO_HARDWARE_VERSION == 0
// test RS-485 output A
gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // enable transmitter
gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX as output
@ -675,7 +710,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
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[8] = NULL; // clear pin to test
#else
#else // BUSVOODOO_HARDWARE_VERSION == 0
// test RS-485 port pin B
gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // enable transmitter
gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX as output
@ -703,9 +738,9 @@ static bool busvoodoo_hiz_test_pins(bool halt)
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
#endif
#endif // BUSVOODOO_HARDWARE_VERSION == 0
#if BUSVOODOO_HARDWARE_VERSION!=0
#if BUSVOODOO_HARDWARE_VERSION != 0
// test CAN output H
// configure transceiver
gpio_clear(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // pull low to power transceiver
@ -734,7 +769,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
// release transceiver
gpio_set(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // set high to power off transceiver
gpio_set_mode(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_TX_PIN)); // set pin to floating
#endif
#endif // BUSVOODOO_HARDWARE_VERSION == 0
// test RS-232 port (with itself)
rcc_periph_clock_enable(RCC_GPIO(BUSVOODOO_RS232_EN_PORT)); // enable clock for GPIO domain
@ -814,6 +849,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
pinout[6] = NULL; // clear pin to test
pinout[8] = NULL; // clear pin to test
}
#endif // BUSVOODOO_HARDWARE_VERSION != 2
to_return = true; // all tests passed
error:
@ -858,13 +894,14 @@ static void busvoodoo_hiz_bootloader(void* argument)
static void busvoodoo_hiz_version(void* argument)
{
(void)argument; // we won't use the argument
#if BUSVOODOO_HARDWARE_VERSION != 2
printf("BusVoodoo flavor: %s\n", busvoodoo_full ? "full" : "light");
#endif
printf("hardware version: %c\n", busvoodoo_version);
printf("firmware date: %04u-%02u-%02u\n", BUILD_YEAR, BUILD_MONTH, BUILD_DAY);
printf("device ID: %08x%08x%08x\n", DESIG_UNIQUE_ID0, DESIG_UNIQUE_ID1, DESIG_UNIQUE_ID2);
}
/** command to perform board self-test
* @param[in] argument "halt" to halt on error
*/
@ -923,11 +960,13 @@ static void busvoodoo_hiz_command_test_pins(void* argument)
}
busvoodoo_leds_off(); // clear LEDs
busvoodoo_led_red_on(); // show red LED to indicate test started
#if BUSVOODOO_HARDWARE_VERSION != 2
char* pinout[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; // pinout to display
pinout[3] = "O"; // set main testing pin
busvoodoo_oled_text_right("pins test"); // display test on display
busvoodoo_oled_text_pinout((const char**)pinout, true); // reset pinout
busvoodoo_oled_update(); // update screen
#endif
printf("connect one lead of jumper wire to I/O pin 4 and press space to start (or any other key to abort)\n");
if (' '==user_input_get()) { // space entered
if (busvoodoo_hiz_test_pins(halt)) { // perform pin test
@ -946,9 +985,11 @@ static void busvoodoo_hiz_command_test_pins(void* argument)
busvoodoo_led_red_off(); // clear red LED
busvoodoo_led_blue_on(); // switch back to main blue LED
}
#if BUSVOODOO_HARDWARE_VERSION != 2
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
#endif
}
/** HiZ menu commands */

View File

@ -12,10 +12,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/** BusVoodoo high impedance (HiZ) default mode (API)
* @file busvoodoo_hiz.h
/** BusVoodoo high impedance (HiZ) default mode
* @file
* @author King Kévin <kingkevin@cuvoodoo.info>
* @date 2018
* @date 2018-2020
*/
/** HiZ mode interface definition */