BV: change LED handling. red LED is for power, blue LED is for activity

This commit is contained in:
King Kévin 2018-05-03 12:56:09 +02:00
parent 6e13f5eadd
commit a425e43590
9 changed files with 321 additions and 131 deletions

View File

@ -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; i<LENGTH(busvoodoo_global_pinout_rscan); i++) {

View File

@ -39,16 +39,22 @@
#include "print.h" // print utilities
#include "busvoodoo_global.h" // BusVoodoo definitions
/** @defgroup busvoodoo_led_timer timer used to blink LED
/** @defgroup busvoodoo_led_timer the blue and red LEDs are connector to TIM1_CH1: user timer 1 to count time for pulses or channel 1 to generate PWM for blinking
* @{
*/
#define BUSVOODOO_LED_TIMER 5 /**< timer peripheral */
#define BUSVOODOO_LED_TIMER 1 /**< timer peripheral ID */
/** @} */
/** blue LED status */
static volatile bool busvoodoo_global_led_blue = false;
/** red LED status */
static volatile bool busvoodoo_global_led_red = false;
/** number of remaining milliseconds the blue LED should stay on */
static volatile uint32_t busvoodoo_global_led_blue_timeout = 0;
/** if the timer for the blue LED is enabled */
static volatile bool busvoodoo_global_led_blue_timer = false;
/** number of remaining milliseconds the red LED should stay on */
static volatile uint32_t busvoodoo_global_led_red_timeout = 0;
/** if the timer for the red LED is enabled */
static volatile bool busvoodoo_global_led_red_timer = false;
/** if the LEDs are in a blinking pattern */
static volatile bool busvoodoo_global_led_blinking = false;
/** hardware version voltages, calculated from divider ratios, starting with version A */
static const float busvoodoo_version_voltages[] = {100.0/(10.0+100.0)*3.3}; // version A start with revision 27
@ -143,13 +149,23 @@ void busvoodoo_setup(void)
dac_set_trigger_source(DAC_CR_TSEL1_SW); // use software to trigger the voltage change
dac_set_trigger_source(DAC_CR_TSEL2_SW); // use software to trigger the voltage change
// enable timer for LED blinking
// enable timer for LED pulsing or blinking
rcc_periph_clock_enable(RCC_TIM(BUSVOODOO_LED_TIMER)); // enable clock for timer domain
timer_reset(TIM(BUSVOODOO_LED_TIMER)); // reset timer configuration
timer_set_mode(TIM(BUSVOODOO_LED_TIMER), TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); // configure timer to up counting mode
timer_set_prescaler(TIM(BUSVOODOO_LED_TIMER), (rcc_ahb_frequency/2000)-1); // set prescaler to have 2kHz ticks (the prescaler is not large enough for 1kHz ticks)
timer_set_period(TIM(BUSVOODOO_LED_TIMER), 0xffff); // set period to maximum
nvic_enable_irq(NVIC_TIM_IRQ(BUSVOODOO_LED_TIMER)); // enable interrupts for this timer
timer_set_prescaler(TIM(BUSVOODOO_LED_TIMER), 3296-1); // set prescaler to allow 3/3 seconds PWM output (72MHz/2^16/3296=0.33Hz)
timer_set_oc_mode(TIM(BUSVOODOO_LED_TIMER), TIM_OC1, TIM_OCM_PWM1); // use PWM output compare mode (for blinking)
timer_disable_oc_output(TIM(BUSVOODOO_LED_TIMER), TIM_OC1); // disable output compare output (for now)
timer_enable_break_main_output(TIM(BUSVOODOO_LED_TIMER)); // required to enable timer 1, even when no dead time is used
timer_set_period(TIM(BUSVOODOO_LED_TIMER), (rcc_ahb_frequency/3296)/1000); // set period to 1 ms for pulsing
nvic_enable_irq(NVIC_TIM1_UP_IRQ); // enable interrupt for timer 1 to catch update event when overflowing
// disable LEDs and reset state
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_blue_timeout = 0; // no timeout needed
busvoodoo_global_led_blue_timer = false; // no timeout needed
busvoodoo_global_led_red_timeout = 0; // no timeout needed
busvoodoo_global_led_red_timer = false; // no timeout needed
busvoodoo_global_led_blinking = false; // start in pulse mode
}
void busvoodoo_safe_state(void)
@ -365,55 +381,181 @@ float busvoodoo_embedded_pullup(bool on)
}
/** update LED status according to LED flags */
static void busvoodoo_led_update(void)
static void busvoodoo_leds_update(void)
{
if (busvoodoo_global_led_blue && busvoodoo_global_led_red) { // both LEDs should be on
led_blink(0.01, 0.5); // enable both LEDs (alternating at 100Hz)
} else if (busvoodoo_global_led_blue) { // only blue LED should be on
led_blue(); // enable only blue LED
} else if (busvoodoo_global_led_red) { // only red LED should be on
led_red(); // enable only red LED
// handle LED timer
if (busvoodoo_global_led_blue_timer && 0==busvoodoo_global_led_blue_timeout) { // timer reached timeout
busvoodoo_global_led_blue_timer = false; // timer it not required anymore
}
if (busvoodoo_global_led_red_timer && 0==busvoodoo_global_led_red_timeout) { // timer reached timeout
busvoodoo_global_led_red_timer = false; // timer it not required anymore
}
if (!busvoodoo_global_led_blue_timer && !busvoodoo_global_led_red_timer) { // timer is not needed anymore
timer_disable_counter(TIM(BUSVOODOO_LED_TIMER)); // disable timer
timer_disable_irq(TIM(BUSVOODOO_LED_TIMER), TIM_DIER_UIE); // disable overflow interrupt used as tick
}
// drive right LED
if (busvoodoo_global_led_blue_timeout>0 && 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
}
}

View File

@ -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

View File

@ -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; i<LENGTH(pinout_io) && i<LENGTH(busvoodoo_global_pinout_io); i++) {
@ -107,7 +108,7 @@ static bool busvoodoo_hiz_test_self(bool halt)
if (voltage<4.0) {
printf("5V power rail voltage is too low: %.2fV\n", voltage);
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
}
goto error;
@ -388,7 +389,7 @@ static bool busvoodoo_hiz_test_self(bool halt)
error:
if (!to_return) {
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");
@ -418,14 +419,16 @@ static bool busvoodoo_hiz_test_pins(bool halt)
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); // ask user for action
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, 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
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

View File

@ -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; i<repetition; i++) {
busvoodoo_led_red_pulse(BUSVOODOO_LED_PULSE); // pulse red LED to show we send start condition
busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we send start condition
printf("%s ", I2C_MASTER_RC_NONE==i2c_master_start(BUSVOODOO_I2C) ? "sent" : "error");
}
printf("\n");
@ -292,7 +292,7 @@ static bool busvoodoo_i2c_action(const char* action, uint32_t repetition, bool p
}
printf("send stop condition: ");
for (uint32_t i=0; i<repetition; i++) {
busvoodoo_led_red_pulse(BUSVOODOO_LED_PULSE); // pulse red LED to show we send stop condition
busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we send stop condition
printf("%s ", I2C_MASTER_RC_NONE==i2c_master_stop(BUSVOODOO_I2C) ? "sent" : "error");
}
printf("\n");
@ -458,19 +458,20 @@ static void busvoodoo_i2c_command_scan(void* argument)
if (busvoodoo_i2c_embedded_pullup) {
printf("set pull-up voltage with LV\n");
}
led_blink(0.5, 0.5); // show error on LEDs
busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs
return; // stop here
} else {
led_off(); // switch LEDs off
busvoodoo_led_blue_off(); // clear blinking
}
printf("scanning for I2C slaves\n");
int16_t i2c_slaves = 0; // number of slaves found
// check for I2C slaves by going through the address space
printf("I2C slaves found: ");
for (uint16_t address=0; address < (1<<busvoodoo_i2c_addressbits); address++) {
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
switch (i2c_master_select_slave(BUSVOODOO_I2C, address, 10==busvoodoo_i2c_addressbits, false)) { // try to select slave (includes start condition)
case I2C_MASTER_RC_NONE: // slave found
busvoodoo_led_red_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we found a slave
busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we found a slave
printf((busvoodoo_i2c_addressbits>7) ? "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
}

View File

@ -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

View File

@ -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<LENGTH(pinout_io) && i<LENGTH(busvoodoo_global_pinout_io); i++) {
@ -232,7 +232,7 @@ static void busvoodoo_rs485_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
gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set high to enable RS-485 transceiver driver
usart_send(USART(BUSVOODOO_RS485_USART), value); // transmit character
// display data send
@ -453,7 +453,7 @@ static void busvoodoo_rs485_command_transmit(void* argument)
while ((0==(USART_SR(USART(BUSVOODOO_RS485_USART)) & USART_SR_TXE) && !user_input_available)); // wait for transmit buffer to be empty
if (USART_SR(USART(BUSVOODOO_RS485_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_RS485_USART), ((char*)(argument))[i]); // transmit character
}
}
@ -561,7 +561,7 @@ static void busvoodoo_rs485_command_transceive(void* argument)
gpio_set(GPIO(BUSVOODOO_RS485_RE_PORT), GPIO(BUSVOODOO_RS485_RE_PIN)); // set high to disable RS-485 transceiver receiver
gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set high to enable RS-485 transceiver driver
usart_send_blocking(USART(BUSVOODOO_RS485_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
while (0==(USART_SR(USART(BUSVOODOO_RS485_USART)) & USART_SR_TC)); // wait for transmission to be complete
gpio_clear(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set low to disable RS-485 transceiver driver
gpio_clear(GPIO(BUSVOODOO_RS485_RE_PORT), GPIO(BUSVOODOO_RS485_RE_PIN)); // set high to low enable RS-485 transceiver receiver

View File

@ -240,7 +240,7 @@ static bool busvoodoo_spi_setup(char** prefix, const char* line)
busvoodoo_embedded_pullup(true); // set embedded pull-ups
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_spi_setting = BUSVOODOO_SPI_SETTING_NONE; // restart settings next time
*prefix = "SPI"; // display mode
busvoodoo_oled_text_left(*prefix); // set mode title on OLED display
@ -280,7 +280,7 @@ static void busvoodoo_spi_write(uint16_t value)
} else {
printf("write: 0x%04x\n", value);
}
busvoodoo_led_red_pulse(BUSVOODOO_LED_PULSE); // pulse red LED to show we are writing
busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we are writing
while (!(SPI_SR(SPI(BUSVOODOO_SPI_ID))&SPI_SR_TXE)); // wait until Tx is empty
(void)SPI_DR(SPI(BUSVOODOO_SPI_ID)); // clear RXNE flag by reading previously received data
spi_send(SPI(BUSVOODOO_SPI_ID), value); // send data
@ -302,7 +302,7 @@ static void busvoodoo_spi_read(void)
if (busvoodoo_spi_duplex) { // in full duplex mode
busvoodoo_spi_write(0xffff); // send any value in order to read
} else { // unidirectional mode
busvoodoo_led_red_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we are reading
busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we are reading
gpio_set_mode(SPI_MOSI_PORT(BUSVOODOO_SPI_ID), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, SPI_MOSI_PIN(BUSVOODOO_SPI_ID)); // set MOSI as input
while (!(SPI_SR(SPI(BUSVOODOO_SPI_ID))&SPI_SR_TXE)); // wait until Tx is empty
(void)SPI_DR(SPI(BUSVOODOO_SPI_ID)); // clear RXNE flag by reading previously received data

View File

@ -231,7 +231,7 @@ static bool busvoodoo_uart_setup(char** prefix, const char* line)
printf("use LV to set pull-up voltage\n");
}
usart_enable(USART(BUSVOODOO_USART_ID)); // enable USART
led_off(); // disable LED because there is no activity
busvoodoo_led_blue_off(); // disable blue LED because there is no activity
busvoodoo_uart_setting = BUSVOODOO_UART_SETTING_NONE; // restart settings next time
*prefix = "UART"; // display mode
busvoodoo_oled_text_left(*prefix); // set mode title on OLED display
@ -296,7 +296,7 @@ static void busvoodoo_uart_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_USART_ID), value); // transmit character
// display data send
printf("write: '%c'/0x", value);
@ -511,7 +511,7 @@ static void busvoodoo_uart_command_transmit(void* argument)
while ((0==(USART_SR(USART(BUSVOODOO_USART_ID)) & USART_SR_TXE) && !user_input_available)); // wait for transmit buffer to be empty
if (USART_SR(USART(BUSVOODOO_USART_ID)) & 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_USART_ID), ((char*)(argument))[i]); // transmit character
}
}
@ -611,7 +611,7 @@ static void busvoodoo_uart_command_transceive(void* argument)
while ((0==(USART_SR(USART(BUSVOODOO_USART_ID)) & USART_SR_TXE) && !user_input_available)); // wait for transmit buffer to be empty
if (USART_SR(USART(BUSVOODOO_USART_ID)) & USART_SR_TXE) { // we can send a character
usart_send_blocking(USART(BUSVOODOO_USART_ID), 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