From a425e43590a02ecc413fc51793afb840854f5ee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Thu, 3 May 2018 12:56:09 +0200 Subject: [PATCH] BV: change LED handling. red LED is for power, blue LED is for activity --- application.c | 2 +- lib/busvoodoo_global.c | 255 +++++++++++++++++++++++++++++++---------- lib/busvoodoo_global.h | 42 ++++++- lib/busvoodoo_hiz.c | 94 +++++++++------ lib/busvoodoo_i2c.c | 27 +++-- lib/busvoodoo_rs232.c | 8 +- lib/busvoodoo_rs485.c | 10 +- lib/busvoodoo_spi.c | 6 +- lib/busvoodoo_uart.c | 8 +- 9 files changed, 321 insertions(+), 131 deletions(-) diff --git a/application.c b/application.c index 255ce59..90ead45 100644 --- a/application.c +++ b/application.c @@ -85,7 +85,7 @@ static void switch_mode(const struct busvoodoo_mode_t* mode) if (busvoodoo_mode) { (*busvoodoo_mode->exit)(); // exit current mode } - led_off(); // switch off LEDs + busvoodoo_leds_off(); // switch off LEDs busvoodoo_safe_state(); // return to safe state // reset pinout for (uint8_t i=0; i0 && busvoodoo_global_led_red_timeout>0) { // both LEDs should be on + timer_set_period(TIM(BUSVOODOO_LED_TIMER), (rcc_ahb_frequency/3296)/1000); // ensure timer is set period to 1 ms for pulsing + timer_set_oc_value(TIM(BUSVOODOO_LED_TIMER), TIM_OC1, rcc_ahb_frequency/3296/1000/2); // set 50% PWM duty cycle + timer_enable_oc_output(TIM(BUSVOODOO_LED_TIMER), TIM_OC1); // enable PWM output + gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO(LED_PIN)); // allow PWM to drive pin + timer_enable_counter(TIM(BUSVOODOO_LED_TIMER)); // ensure the timer is enabled (interrupt should be disabled if not required) + } else if (busvoodoo_global_led_blue_timeout>0) { // only blue LED should be on + timer_disable_oc_output(TIM(BUSVOODOO_LED_TIMER), TIM_OC1); // disable PWM output + gpio_set(GPIO(LED_PORT), GPIO(LED_PIN)); // switch only blue LED on + gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(LED_PIN)); // set LED pin as push-pull to drive either LED + } else if (busvoodoo_global_led_red_timeout>0) { // only red LED should be on + timer_disable_oc_output(TIM(BUSVOODOO_LED_TIMER), TIM_OC1); // disable PWM output + gpio_clear(GPIO(LED_PORT), GPIO(LED_PIN)); // switch only red LED on + gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(LED_PIN)); // set LED pin as push-pull to drive either LED } else { // no LED should be on - led_off(); // disable both LEDs + timer_disable_oc_output(TIM(BUSVOODOO_LED_TIMER), TIM_OC1); // disable PWM output + gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(LED_PIN)); // set LED pin to floating to disable both LEDs + } + busvoodoo_global_led_blinking = false; // setting the LEDs forced blinking mode exit +} + +void busvoodoo_led_blue_on(void) +{ + busvoodoo_global_led_blue_timer = false; // there it no timeout of this LED + busvoodoo_global_led_blue_timeout = 1; // still enable LED + busvoodoo_leds_update(); // update LED status +} + +void busvoodoo_led_blue_off(void) +{ + busvoodoo_global_led_blue_timer = false; // there it no timeout of this LED + busvoodoo_global_led_blue_timeout = 0; // disable LED + busvoodoo_leds_update(); // update LED status +} + +void busvoodoo_led_red_on(void) +{ + busvoodoo_global_led_red_timer = false; // there it no timeout of this LED + busvoodoo_global_led_red_timeout = 1; // still enable LED + busvoodoo_leds_update(); // update LED status +} + +void busvoodoo_led_red_off(void) +{ + busvoodoo_global_led_red_timer = false; // there it no timeout of this LED + busvoodoo_global_led_red_timeout = 0; // disable LED + busvoodoo_leds_update(); // update LED status +} + +void busvoodoo_leds_off(void) +{ + busvoodoo_global_led_blue_timer = false; // there it no timeout of this LED + busvoodoo_global_led_blue_timeout = 0; // disable LED + busvoodoo_global_led_red_timer = false; // there it no timeout of this LED + busvoodoo_global_led_red_timeout = 0; // disable LED + busvoodoo_leds_update(); // update LED status +} + +/** setup the timer for pulsing LEDs */ +static void busvoodoo_led_pulse_setup(void) +{ + if (!busvoodoo_global_led_blinking) { // we are in the blink mode, reconfigure to pulse mode + timer_disable_oc_output(TIM(BUSVOODOO_LED_TIMER), TIM_OC1); // disable PWM output + timer_set_period(TIM(BUSVOODOO_LED_TIMER), (rcc_ahb_frequency/3296)/1000); // set period to 1 ms for pulsing + busvoodoo_global_led_blinking = false; // remember we quite the PWM/blinking mode + } + timer_enable_irq(TIM(BUSVOODOO_LED_TIMER), TIM_DIER_UIE); // enable overflow interrupt used as tick + timer_enable_counter(TIM(BUSVOODOO_LED_TIMER)); // ensure the timer is enabled +} + +void busvoodoo_led_blue_pulse(uint32_t ms) +{ + if (0==ms) { // disable LED + busvoodoo_global_led_blue_timer = false; // no need to use the timer + busvoodoo_global_led_blue_timeout = 0; // disable blue LED + } else { + busvoodoo_global_led_blue_timer = true; // use the timer + busvoodoo_global_led_blue_timeout = ms; // disable blue LED + busvoodoo_led_pulse_setup(); // start timer + } + busvoodoo_leds_update(); // update LED status +} + +void busvoodoo_led_red_pulse(uint32_t ms) +{ + if (0==ms) { // disable LED + busvoodoo_global_led_red_timer = false; // no need to use the timer + busvoodoo_global_led_red_timeout = 0; // disable blue LED + } else { + busvoodoo_global_led_red_timer = true; // use the timer + busvoodoo_global_led_red_timeout = ms; // disable blue LED + busvoodoo_led_pulse_setup(); // start timer + } + busvoodoo_leds_update(); // update LED status +} + +/** interrupt service routine called on LED timeout */ +void tim1_up_isr(void) +{ + if (timer_get_flag(TIM(BUSVOODOO_LED_TIMER), TIM_SR_UIF)) { // tick occurred + timer_clear_flag(TIM(BUSVOODOO_LED_TIMER), TIM_SR_UIF); // clear flag + if (busvoodoo_global_led_blue_timer && busvoodoo_global_led_blue_timeout>0) { // timeout for blue LED is running + busvoodoo_global_led_blue_timeout--; // decrement remaining timeout + } + if (busvoodoo_global_led_red_timer && busvoodoo_global_led_red_timeout>0) { // timeout for red LED is running + busvoodoo_global_led_red_timeout--; // decrement remaining timeout + } + if (0==busvoodoo_global_led_blue_timeout || 0==busvoodoo_global_led_red_timeout) { // a timeout occured + busvoodoo_leds_update(); // update LED status + } } } -void busvoodoo_led_blue_pulse(uint16_t ms) +void busvoodoo_leds_blink(double period, double duty) { - timer_disable_counter(TIM(BUSVOODOO_LED_TIMER)); // disable counter while changing LEDs to avoid coherence errors (at the cost of time precision) - if (ms>UINT16_MAX/2) { // enforce maximum - ms = UINT16_MAX/2; + if (period<0.0 || period>6.0 || duty<0.0 || duty>1.0) { // input argument out of bounds + return; // do nothing } - - if (0==ms) { // disable LED - busvoodoo_global_led_blue = false; // remember we disabled the blue LED - } else { - busvoodoo_global_led_blue = true; // remember the blue LED should be on - timer_set_oc_value(TIM(BUSVOODOO_LED_TIMER), TIM_OC1, timer_get_counter(TIM(BUSVOODOO_LED_TIMER))+ms*2); // use capture 1 to set LED timer - timer_clear_flag(TIM(BUSVOODOO_LED_TIMER), TIM_SR_CC1IF); // clear flag before enabling - timer_enable_irq(TIM(BUSVOODOO_LED_TIMER), TIM_DIER_CC1IE); // enable capture 1 for blue LED + timer_disable_counter(TIM(BUSVOODOO_LED_TIMER)); // disable timer while reconfiguring + timer_disable_irq(TIM(BUSVOODOO_LED_TIMER), TIM_DIER_UIE); // disable overflow interrupt used for pulsing + if (busvoodoo_global_led_blue_timer) { // switch off LED when pulsing + busvoodoo_global_led_blue_timer = false; // stop pulse + busvoodoo_global_led_blue_timeout = 0; // switch off + } + if (busvoodoo_global_led_blue_timer) { // switch off LED when pulsing + busvoodoo_global_led_blue_timer = false; // stop pulse + busvoodoo_global_led_blue_timeout = 0; // switch off + } + if (0.0==period) { // no blinking + if (duty>=0.5) { // only enable blue LED + busvoodoo_global_led_blue_timeout = 1; + } else { // only enable red LED + busvoodoo_global_led_red_timeout = 1; + } + busvoodoo_leds_update(); + } else { + gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO(LED_PIN)); // set LED pin to alternate function for PWM + timer_set_counter(TIM(BUSVOODOO_LED_TIMER), 0); // reset counter + timer_set_period(TIM(BUSVOODOO_LED_TIMER), 0xffff*(period/6.0)); // set period + timer_set_oc_value(TIM(BUSVOODOO_LED_TIMER), TIM_OC1, 0xffff*(period/6.0)*duty); // PWM duty cycle + timer_enable_counter(TIM(BUSVOODOO_LED_TIMER)); // enable timer to start blinking } - busvoodoo_led_update(); // update LED status - timer_enable_counter(TIM(BUSVOODOO_LED_TIMER)); // re-enable timer } -void busvoodoo_led_red_pulse(uint16_t ms) +/** updates the red power LED status + * @note the red LED is used to indicate if power is enabled on Vout, LV, or HV + */ +static void busvoodoo_global_power_led_update(void) { - timer_disable_counter(TIM(BUSVOODOO_LED_TIMER)); // disable counter while changing LEDs to avoid coherence errors (at the cost of time precision) - if (ms>UINT16_MAX/2) { // enforce maximum - ms = UINT16_MAX/2; + bool power_led_on = false; // to calculate the final state of the power LED + power_led_on |= !gpio_get(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // check power rails output + power_led_on |= !gpio_get(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO(BUSVOODOO_5VPULLUP_PIN)); // check 5V output on LV pin + power_led_on |= gpio_get(GPIO(BUSVOODOO_LVEN_PORT), GPIO(BUSVOODOO_LVEN_PIN)); // check if low-voltage regulator is on + if (!busvoodoo_full) { + power_led_on |= !gpio_get(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)); // check if high-voltage regulator is on } - - if (0==ms) { // disable LED - busvoodoo_global_led_red = false; // remember we disabled the blue LED - } else { - busvoodoo_global_led_red = true; // remember the blue LED should be on - timer_set_oc_value(TIM(BUSVOODOO_LED_TIMER), TIM_OC2, timer_get_counter(TIM(BUSVOODOO_LED_TIMER))+ms*2); // use capture 1 to set LED timer - timer_clear_flag(TIM(BUSVOODOO_LED_TIMER), TIM_SR_CC2IF); // clear flag before enabling - timer_enable_irq(TIM(BUSVOODOO_LED_TIMER), TIM_DIER_CC2IE); // enable capture 2 for red LED + if (power_led_on) { + busvoodoo_led_red_on(); // switch on red LED to indicate one of the power output is on + } else { + busvoodoo_led_red_off(); // switch off red LED to indicate no power output is on } - busvoodoo_led_update(); // update LED status - timer_enable_counter(TIM(BUSVOODOO_LED_TIMER)); // re-enable timer } bool busvoodoo_global_actions(char* actions, bool perform, bool (*action_handler)(const char* action, uint32_t repetition, bool perform)) @@ -510,9 +652,10 @@ power_off: } else { printf("option malformed: %s\n", argument); } + busvoodoo_global_power_led_update(); // update power output LED } -/** set lV linear drop-out voltage regulator voltage +/** set LV linear drop-out voltage regulator voltage * @param[in] argument voltage to set (0 to switch off, NULL to get voltage) */ static void busvoodoo_global_lv(void* argument) @@ -547,6 +690,7 @@ static void busvoodoo_global_lv(void* argument) printf(": %.2fV\n", voltage); } } + busvoodoo_global_power_led_update(); // update power output LED } /** set HV step-up voltage regulator voltage @@ -583,6 +727,7 @@ static void busvoodoo_global_hv(void* argument) printf(": %.2fV\n", voltage); } } + busvoodoo_global_power_led_update(); // update power output LED } /** display I/O and RS/CAN connector pinouts @@ -773,19 +918,3 @@ const struct menu_command_t busvoodoo_global_full_commands[] = { }; const uint8_t busvoodoo_global_full_commands_nb = LENGTH(busvoodoo_global_full_commands); - -/** interrupt service routine called on LED timeout */ -void TIM_ISR(BUSVOODOO_LED_TIMER)(void) -{ - if (timer_get_flag(TIM(BUSVOODOO_LED_TIMER), TIM_SR_CC1IF)) { // blue LED timeout - timer_clear_flag(TIM(BUSVOODOO_LED_TIMER), TIM_SR_CC1IF); // clear flag - timer_disable_irq(TIM(BUSVOODOO_LED_TIMER), TIM_DIER_CC1IE); // disable capture 1 for blue LED - busvoodoo_global_led_blue = false; // remember blue LED should be disabled - busvoodoo_led_update(); // update LED status - } else if (timer_get_flag(TIM(BUSVOODOO_LED_TIMER), TIM_SR_CC2IF)) { // red LED timeout - timer_clear_flag(TIM(BUSVOODOO_LED_TIMER), TIM_SR_CC2IF); // clear flag - timer_disable_irq(TIM(BUSVOODOO_LED_TIMER), TIM_DIER_CC2IE); // disable capture 2 for red LED - busvoodoo_global_led_red = false; // remember red LED should be disabled - busvoodoo_led_update(); // update LED status - } -} diff --git a/lib/busvoodoo_global.h b/lib/busvoodoo_global.h index b3c919e..5b85bf0 100644 --- a/lib/busvoodoo_global.h +++ b/lib/busvoodoo_global.h @@ -181,14 +181,48 @@ float busvoodoo_hv_set(float voltage); * @return voltage applied on pull-up resistors, or NaN if channel is invalid (or error happened) */ float busvoodoo_embedded_pullup(bool on); +/** switch on blue LED + * @note the red LED is handled independently + * @note this will stop the blinking pattern + */ +void busvoodoo_led_blue_on(void); +/** switch off blue LED + * @note the red LED is handled independently + * @note this will stop the blinking pattern + */ +void busvoodoo_led_blue_off(void); +/** switch on red LED + * @note the blue LED is handled independently + * @note this will stop the blinking pattern + */ +void busvoodoo_led_red_on(void); +/** switch off red LED + * @note the blue LED is handled independently + * @note this will stop the blinking pattern + */ +void busvoodoo_led_red_off(void); +/** switch off blue and red LEDs + * @note this will stop the blinking pattern + */ +void busvoodoo_leds_off(void); /** pulse blue LED for short duration - * @param[in] ms duration in ms (0-32768) + * @param[in] ms duration in ms + * @note the red LED is handled independently + * @note this will stop the blinking pattern */ -void busvoodoo_led_blue_pulse(uint16_t ms); +void busvoodoo_led_blue_pulse(uint32_t ms); /** pulse red LED for short duration - * @param[in] ms duration in ms (0-32768) + * @param[in] ms duration in ms + * @note the red LED is handled independently + * @note this will stop the blinking pattern */ -void busvoodoo_led_red_pulse(uint16_t ms); +void busvoodoo_led_red_pulse(uint32_t ms); +/** set LED blinking pattern + * @param[in] period blue+red pattern duration in seconds (up to 3+3) + * @param[in] duty blue LED on duty cycle, before switching to red (0-1) + * @note when exiting blink the blue and red LEDs will be off if they were pulsing before + */ +void busvoodoo_leds_blink(double period, double duty); /** parse and perform actions * @note performing action is a common command in mode and this function helps parsing them * @param[in] actions actions to perform diff --git a/lib/busvoodoo_hiz.c b/lib/busvoodoo_hiz.c index 7fe9d23..2e4dc7b 100644 --- a/lib/busvoodoo_hiz.c +++ b/lib/busvoodoo_hiz.c @@ -52,7 +52,8 @@ static bool busvoodoo_hiz_setup(char** prefix, const char* line) { (void)line; // no configuration is required *prefix = "HiZ"; // set command line prefix - led_blue(); // switch blue LED on to show we are ready + 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 && !user_input_available); // wait until pin is shorted to ground - led_blue(); // notify user test is running + busvoodoo_led_red_off(); // clear red LED + busvoodoo_led_blue_on(); // notify user test is running if (user_input_available) { // user interruption goto error; } @@ -442,14 +445,16 @@ static bool busvoodoo_hiz_test_pins(bool halt) // 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 + busvoodoo_leds_off(); // clear LEDs + busvoodoo_led_red_on(); // 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 - led_blue(); // notify user test is running + busvoodoo_led_red_off(); // clear red LED + busvoodoo_led_blue_on(); // notify user test is running if (user_input_available) { // user interruption goto error; } @@ -464,7 +469,8 @@ static bool busvoodoo_hiz_test_pins(bool halt) // 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 + busvoodoo_leds_off(); // clear LEDs + busvoodoo_led_red_on(); // 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 @@ -474,7 +480,8 @@ static bool busvoodoo_hiz_test_pins(bool halt) } 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 sleep_ms(100); // wait for stable connection } while ((busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2 || busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>3.5) && !user_input_available); // check to be sure it really is not on the 5V pin - led_blue(); // notify user test is running + busvoodoo_led_red_on(); // clear red LED + busvoodoo_led_blue_on(); // notify user test is running if (user_input_available) { // user interruption goto error; } @@ -493,14 +500,16 @@ static bool busvoodoo_hiz_test_pins(bool halt) 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 + busvoodoo_leds_off(); // clear LEDs + busvoodoo_led_red_on(); // 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 - led_blue(); // notify user test is running + busvoodoo_led_red_off(); // clear red LED + busvoodoo_led_blue_on(); // notify user test is running if (user_input_available) { // user interruption goto error; } @@ -528,14 +537,16 @@ static bool busvoodoo_hiz_test_pins(bool halt) 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 + busvoodoo_leds_off(); // clear LEDs + busvoodoo_led_red_on(); // 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 - led_blue(); // notify user test is running + busvoodoo_led_red_off(); // clear red LED + busvoodoo_led_blue_on(); // notify user test is running if (user_input_available) { // user interruption goto error; } @@ -554,14 +565,16 @@ static bool busvoodoo_hiz_test_pins(bool halt) 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 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 + busvoodoo_led_off(); // clear LEDs + busvoodoo_led_red_on(); // 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 - led_blue(); // notify user test is running + busvoodoo_led_red_off(); // clear red LED + busvoodoo_led_blue_on(); // notify user test is running if (user_input_available) { // user interruption goto error; } @@ -580,14 +593,16 @@ static bool busvoodoo_hiz_test_pins(bool halt) 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 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 + busvoodoo_leds_off(); // clear LEDs + busvoodoo_led_red_on(); // 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 - led_blue(); // notify user test is running + busvoodoo_led_red_off(); // clear red LED + busvoodoo_led_blue_on(); // notify user test is running if (user_input_available) { // user interruption goto error; } @@ -638,14 +653,16 @@ static bool busvoodoo_hiz_test_pins(bool halt) 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 gpio_set(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX high -> A will be high printf("%sRS/CAN pin 5\n", lv_to); - led_red(); // notify user to perform action + busvoodoo_led_off(); // clear LEDs + busvoodoo_led_red_on(); // notify user to perform action 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 (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<2.0 && !user_input_available); // wait until pin is connected - led_blue(); // notify user test is running + busvoodoo_led_red_off(); // clear red LED + busvoodoo_led_blue_on(); // notify user test is running if (user_input_available) { // user interruption goto error; } @@ -664,14 +681,16 @@ static bool busvoodoo_hiz_test_pins(bool halt) 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 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 + busvoodoo_leds_off(); // clear LEDs + busvoodoo_led_red_on(); // 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 - led_blue(); // notify user test is running + busvoodoo_led_red_off(); // clear red LED + busvoodoo_led_blue_on(); // notify user test is running if (user_input_available) { // user interruption goto error; } @@ -733,7 +752,8 @@ static bool busvoodoo_hiz_test_pins(bool halt) 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 + busvoodoo_leds_off(); // clear LEDs + busvoodoo_led_red_on(); // 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 @@ -741,7 +761,8 @@ static bool busvoodoo_hiz_test_pins(bool halt) 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 + busvoodoo_led_red_off(); // clear red LED + busvoodoo_led_blue_on(); // notify user test is running if (user_input_available) { // user interruption goto error; } @@ -765,7 +786,8 @@ static bool busvoodoo_hiz_test_pins(bool halt) 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 + busvoodoo_leds_off(); // clear LEDs + busvoodoo_led_red_on(); // 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 @@ -773,7 +795,8 @@ static bool busvoodoo_hiz_test_pins(bool halt) 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 + busvoodoo_led_red_off(); // clear red LED + busvoodoo_led_blue_on(); // notify user test is running if (user_input_available) { // user interruption goto error; } @@ -799,7 +822,7 @@ error: printf("user interrupted the test\n"); to_return = true; // we don't consider this as error } else if (halt) { // halt on error if requested - led_blink(0.5, 0.5); // show error on LEDs + busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs while (!user_input_available); // wait for user input } else { printf("the test procedure has been aborted for safety reasons\n"); @@ -857,13 +880,15 @@ static void busvoodoo_hiz_command_test_self(void* argument) printf("WARNING: halting on error can cause hardware damages (press any key to exit halt state)\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 + busvoodoo_leds_off(); // clear LEDs + busvoodoo_led_red_on(); // show red LED to indicate test started if (' '==user_input_get()) { // space entered printf("self-test running\n"); if (busvoodoo_hiz_test_self(halt)) { // perform self-test - led_blue(); // show blue to indicate test passed + busvoodoo_led_red_off(); // clear red LED + busvoodoo_led_blue_on(); // show blue to indicate test passed } else { - led_blink(0.5, 0.5); // show error on LEDs + busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs printf("self-test failed\n"); // notify user if (user_input_available) { user_input_get(); // clear user input @@ -892,7 +917,8 @@ static void busvoodoo_hiz_command_test_pins(void* argument) if (halt) { printf("WARNING: halting on error can cause hardware damages (press any key to exit halt state)\n"); } - led_red(); // show red LED to indicate test started + busvoodoo_leds_off(); // clear LEDs + busvoodoo_led_red_on(); // show red LED to indicate test started 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 @@ -901,10 +927,11 @@ static void busvoodoo_hiz_command_test_pins(void* argument) 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 - led_blue(); // show blue OK LED + busvoodoo_led_red_off(); // clear red LED + busvoodoo_led_blue_on(); // show blue OK LED printf("pins test succeeded\n"); // notify user } else { - led_blink(0.5, 0.5); // show error on LEDs + busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs printf("pins test failed\n"); // notify user if (user_input_available) { user_input_get(); // clear user input @@ -912,7 +939,8 @@ static void busvoodoo_hiz_command_test_pins(void* argument) } } else { printf("pins test aborted\n"); - led_blue(); // switch back to main blue LED + busvoodoo_led_red_off(); // clear red LED + busvoodoo_led_blue_on(); // switch back to main blue LED } busvoodoo_oled_text_left("HiZ"); // reset mode text busvoodoo_oled_text_pinout(busvoodoo_global_pinout_io, true); // reset pinout diff --git a/lib/busvoodoo_i2c.c b/lib/busvoodoo_i2c.c index ce1f2e1..bd5e5d1 100644 --- a/lib/busvoodoo_i2c.c +++ b/lib/busvoodoo_i2c.c @@ -121,7 +121,7 @@ static bool busvoodoo_i2c_setup(char** prefix, const char* line) busvoodoo_embedded_pullup(true); // set pull-up printf("use LV to set pull-up voltage\n"); } - led_off(); // disable LED because there is no activity + busvoodoo_led_blue_off(); // disable blue LED because there is no activity busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_NONE; // restart settings next time *prefix = "I2C"; // display mode busvoodoo_oled_text_left(*prefix); // set mode title on OLED display @@ -191,7 +191,7 @@ static void busvoodoo_i2c_read(void) static void busvoodoo_i2c_write(uint8_t data) { printf("write 0x%02x: ", data); - busvoodoo_led_red_pulse(BUSVOODOO_LED_PULSE); // pulse red LED to show we send data + busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we send data switch (i2c_master_write(BUSVOODOO_I2C, &data, 1)) { case I2C_MASTER_RC_NONE: // all went fine printf("ack"); @@ -230,7 +230,7 @@ static void busvoodoo_i2c_select(uint16_t slave, bool write) printf("0x%02x", slave); } printf(" to %s: ", write ? "write" : "read"); - busvoodoo_led_red_pulse(BUSVOODOO_LED_PULSE); // pulse red LED to show we send the slave address + busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we send the slave address switch (i2c_master_select_slave(BUSVOODOO_I2C, slave, 10==busvoodoo_i2c_addressbits, write)) { case I2C_MASTER_RC_NONE: // all went fine printf("selected"); @@ -282,7 +282,7 @@ static bool busvoodoo_i2c_action(const char* action, uint32_t repetition, bool p } printf("send start condition: "); for (uint32_t i=0; i7) ? "0x%03x " : "0x%02x ", address); // display address i2c_slaves++; // increase slave count break; @@ -495,7 +496,7 @@ static void busvoodoo_i2c_command_scan(void* argument) break; } if (i2c_slaves<0) { // error happened - led_blink(0.5, 0.5); // show error on LEDs + busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs if (-1==i2c_slaves) { // just end communication i2c_master_stop(BUSVOODOO_I2C); // send stop condition } else if (-2==i2c_slaves) { // reset peripheral @@ -506,15 +507,13 @@ static void busvoodoo_i2c_command_scan(void* argument) if (I2C_MASTER_RC_NONE!=i2c_master_stop(BUSVOODOO_I2C)) { // stop stop condition i2c_master_reset(BUSVOODOO_I2C); // reset the I2C peripheral since it might be stuck printf("stop condition failed\n"); // show error to user - led_blink(0.5, 0.5); // show error on LEDs + busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs i2c_slaves = -1; // remember error break; } } } - if (i2c_slaves>0) { - printf("\n"); - } + printf("\n"); if (i2c_slaves>=0) { printf("%u slave(s) found\n", i2c_slaves); // show summary } diff --git a/lib/busvoodoo_rs232.c b/lib/busvoodoo_rs232.c index 0880588..76d2a75 100644 --- a/lib/busvoodoo_rs232.c +++ b/lib/busvoodoo_rs232.c @@ -194,7 +194,7 @@ static bool busvoodoo_rs232_setup(char** prefix, const char* line) gpio_clear(GPIO(BUSVOODOO_RS232_EN_PORT), GPIO(BUSVOODOO_RS232_EN_PIN)); // set low to enable RS-232 transceiver receiver gpio_set(GPIO(BUSVOODOO_RS232_SHDN_PORT), GPIO(BUSVOODOO_RS232_SHDN_PIN)); // set high to enable RS-232 transceiver transmitter usart_enable(USART(BUSVOODOO_RS232_USART)); // enable USART - led_off(); // disable LED because there is no activity + busvoodoo_led_blue_off(); // disable blue LED since there is no activity busvoodoo_rs232_setting = BUSVOODOO_RS232_SETTING_NONE; // restart settings next time *prefix = "RS-232"; // display mode busvoodoo_oled_text_left(*prefix); // set mode title on OLED display @@ -259,7 +259,7 @@ static void busvoodoo_rs232_write(uint16_t value) } } // send data - busvoodoo_led_red_pulse(BUSVOODOO_LED_PULSE); // pulse red LED to show transmission + busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show transmission usart_send(USART(BUSVOODOO_RS232_USART), value); // transmit character // display data send printf("write: '%c'/0x", value); @@ -474,7 +474,7 @@ static void busvoodoo_rs232_command_transmit(void* argument) while ((0==(USART_SR(USART(BUSVOODOO_RS232_USART)) & USART_SR_TXE) && !user_input_available)); // wait for transmit buffer to be empty if (USART_SR(USART(BUSVOODOO_RS232_USART)) & USART_SR_TXE) { // we can send a character printf("%c", ((char*)(argument))[i]); // echo character to transmit - busvoodoo_led_red_pulse(BUSVOODOO_LED_PULSE); // pulse red LED to show transmission + busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show transmission usart_send(USART(BUSVOODOO_RS232_USART), ((char*)(argument))[i]); // transmit character } } @@ -574,7 +574,7 @@ static void busvoodoo_rs232_command_transceive(void* argument) while ((0==(USART_SR(USART(BUSVOODOO_RS232_USART)) & USART_SR_TXE) && !user_input_available)); // wait for transmit buffer to be empty if (USART_SR(USART(BUSVOODOO_RS232_USART)) & USART_SR_TXE) { // we can send a character usart_send_blocking(USART(BUSVOODOO_RS232_USART), c); // send user character - busvoodoo_led_red_pulse(BUSVOODOO_LED_PULSE); // enable red LED to show transmission + busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // enable blue LED to show transmission } } else { // user wants to exit break; // exit infinite loop diff --git a/lib/busvoodoo_rs485.c b/lib/busvoodoo_rs485.c index 48489f4..12b7668 100644 --- a/lib/busvoodoo_rs485.c +++ b/lib/busvoodoo_rs485.c @@ -169,9 +169,9 @@ static bool busvoodoo_rs485_setup(char** prefix, const char* line) gpio_set(GPIO(BUSVOODOO_RS485_RE_PORT), GPIO(BUSVOODOO_RS485_RE_PIN)); // set RS-485 transceiver Receive Enable pin high to disable received gpio_set_mode(GPIO(BUSVOODOO_RS485_RE_PORT), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_RS485_RE_PIN)); // setup RS-485 Receive Enable GPIO as output (pulled high to disable by default) usart_enable(USART(BUSVOODOO_RS485_USART)); // enable USART - led_off(); // disable LED because there is no activity + busvoodoo_led_blue_off(); // disable blue LED since there is no activity busvoodoo_rs485_setting = BUSVOODOO_RS485_SETTING_NONE; // restart settings next time - *prefix = "RS-485"; // display mode + *prefix = "RS-485/422"; // display mode 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}; // RS-485 mode I/O pinout for (uint8_t i=0; i