From 67b724373699f254e7790e12dcd15a17d379ec64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Mon, 9 Mar 2020 12:59:48 +0100 Subject: [PATCH] busvoodoo_hiz: remove features unsupported by dongle --- lib/busvoodoo_hiz.c | 73 +++++++++++++++++++++++++++++++++++---------- lib/busvoodoo_hiz.h | 6 ++-- 2 files changed, 60 insertions(+), 19 deletions(-) diff --git a/lib/busvoodoo_hiz.c b/lib/busvoodoo_hiz.c index 9758a27..a6556b9 100644 --- a/lib/busvoodoo_hiz.c +++ b/lib/busvoodoo_hiz.c @@ -12,10 +12,10 @@ * along with this program. If not, see . * */ -/** BusVoodoo high impedance (HiZ) default mode (code) - * @file busvoodoo_hiz.c +/** BusVoodoo high impedance (HiZ) default mode + * @file * @author King Kévin - * @date 2018 + * @date 2018-2020 */ /* standard libraries */ #include // 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; i0.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 */ diff --git a/lib/busvoodoo_hiz.h b/lib/busvoodoo_hiz.h index 5ec6b70..698a14a 100644 --- a/lib/busvoodoo_hiz.h +++ b/lib/busvoodoo_hiz.h @@ -12,10 +12,10 @@ * along with this program. If not, see . * */ -/** BusVoodoo high impedance (HiZ) default mode (API) - * @file busvoodoo_hiz.h +/** BusVoodoo high impedance (HiZ) default mode + * @file * @author King Kévin - * @date 2018 + * @date 2018-2020 */ /** HiZ mode interface definition */