2018-01-14 22:15:00 +01:00
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*
*/
/** BusVoodoo high impedance (HiZ) default mode (code)
2018-01-23 23:41:41 +01:00
* @ file busvoodoo_hiz . c
2018-01-14 22:15:00 +01:00
* @ author King Kévin < kingkevin @ cuvoodoo . info >
* @ date 2018
*/
/* standard libraries */
# include <stdint.h> // standard integer types
# include <math.h> // math utilities
/* STM32 (including CM3) libraries */
2018-03-15 19:20:27 +01:00
# include <libopencmsis/core_cm3.h> // Cortex M3 utilities
2018-01-14 22:15:00 +01:00
# include <libopencm3/stm32/gpio.h> // general purpose input output library
# include <libopencm3/stm32/rcc.h> // real-time control clock library
# include <libopencm3/stm32/dbgmcu.h> // debug utilities
# include <libopencm3/stm32/desig.h> // design utilities
# include <libopencm3/stm32/dac.h> // DAC utilities
/* own libraries */
# include "global.h" // board definitions
# include "print.h" // printing utilities
2018-01-21 23:43:37 +01:00
# include "menu.h" // menu definitions
2018-01-14 22:15:00 +01:00
# include "busvoodoo_global.h" // BusVoodoo definitions
2018-02-06 12:32:44 +01:00
# include "busvoodoo_oled.h" // OLED utilities
2018-01-14 22:15:00 +01:00
# include "busvoodoo_hiz.h" // own definitions
2018-02-06 21:17:37 +01:00
# 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 */
2018-01-17 13:17:08 +01:00
2018-01-23 15:18:41 +01:00
/** setup HiZ mode
* @ param [ out ] prefix terminal prompt prefix
* @ param [ in ] line terminal prompt line to configure mode
* @ return if setup is complete
*/
static bool busvoodoo_hiz_setup ( char * * prefix , const char * line )
{
( void ) line ; // no configuration is required
2018-01-23 23:41:41 +01:00
* prefix = " HiZ " ; // set command line prefix
2018-02-13 17:43:08 +01:00
led_blue ( ) ; // switch blue LED on to show we are ready
2018-03-20 10:42:27 +01:00
busvoodoo_oled_text_left ( * prefix ) ; // set mode title on OLED display
2018-03-20 10:15:36 +01:00
const char * pinout_io [ 10 ] = { " GND " , " 5V " , " 3V3 " , " LV " , NULL , NULL , NULL , NULL , NULL , NULL } ; // HiZ mode I/O pinout
2018-02-06 17:35:05 +01:00
for ( uint8_t i = 0 ; i < LENGTH ( pinout_io ) & & i < LENGTH ( busvoodoo_global_pinout_io ) ; i + + ) {
busvoodoo_global_pinout_io [ i ] = pinout_io [ i ] ; // set pin names
}
2018-03-11 13:37:14 +01:00
if ( busvoodoo_full ) {
const char * pinout_rscan [ 5 ] = { " HV " , NULL , NULL , NULL , NULL } ; // HiZ mode RS/CAN pinout
for ( uint8_t i = 0 ; i < LENGTH ( pinout_rscan ) & & i < LENGTH ( busvoodoo_global_pinout_rscan ) ; i + + ) {
busvoodoo_global_pinout_rscan [ i ] = pinout_rscan [ i ] ; // set pin names
}
}
busvoodoo_oled_text_pinout ( busvoodoo_global_pinout_io , true ) ; // set pinout on display
2018-02-06 12:32:44 +01:00
busvoodoo_oled_update ( ) ; // update display to show text and pinout
2018-01-23 15:18:41 +01:00
return true ;
}
/** exit HiZ mode
*/
static void busvoodoo_hiz_exit ( void )
{
// there is nothing to do
}
2018-01-21 23:43:37 +01:00
/** perform self tests
* @ return if self tests passed
*/
static bool busvoodoo_hiz_test_self ( void )
2018-01-14 22:15:00 +01:00
{
bool to_return = false ; // success of the self-test
busvoodoo_safe_state ( ) ; // start from a safe state
// get device information
// get device identifier (DEV_ID)
// 0x412: low-density, 16-32 kB flash
// 0x410: medium-density, 64-128 kB flash
// 0x414: high-density, 256-512 kB flash
// 0x430: XL-density, 768-1024 kB flash
// 0x418: connectivity
2018-02-13 16:10:31 +01:00
if ( 0 = = ( DBGMCU_IDCODE & DBGMCU_IDCODE_DEV_ID_MASK ) ) { // can't read IDCODE for verification
// this is a known issue document in STM32F10xxC/D/E Errata sheet, without workaround
2018-01-14 22:15:00 +01:00
} else if ( 0x414 ! = ( DBGMCU_IDCODE & DBGMCU_IDCODE_DEV_ID_MASK ) ) {
printf ( " this (DEV_ID=%03x) is not a high-density device: a wrong micro-controller might have been used \n " , ( DBGMCU_IDCODE & DBGMCU_IDCODE_DEV_ID_MASK ) ) ;
}
// ensure flash size is ok
if ( 0xffff = = DESIG_FLASH_SIZE ) {
printf ( " unknown flash size: this is probably a defective micro-controller \n " ) ;
}
// check 5V power rail
2018-01-17 12:28:15 +01:00
float voltage = busvoodoo_vreg_get ( BUSVOODOO_5V_CHANNEL ) ; // get 5V power rail voltage
2018-01-14 22:15:00 +01:00
if ( voltage < 4.0 ) {
printf ( " 5V power rail voltage is too low: %.2fV \n " , voltage ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
} else if ( voltage > 5.5 ) {
printf ( " 5V power rail voltage is too high: %.2fV \n " , voltage ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
// check 3.3V power rail
2018-01-17 12:28:15 +01:00
voltage = busvoodoo_vreg_get ( BUSVOODOO_3V3_CHANNEL ) ; // get 3.3V power rail voltage
2018-01-14 22:15:00 +01:00
if ( voltage < 3.0 ) {
printf ( " 3.3V power rail voltage is too low: %.2fV \n " , voltage ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
} else if ( voltage > 3.6 ) {
printf ( " 3.3V power rail voltage is too high: %.2fV \n " , voltage ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
// test 5V and 3.3V outputs
2018-01-17 13:17:08 +01:00
busvoodoo_vout_switch ( true ) ; // enable Vout
2018-01-17 12:28:15 +01:00
voltage = busvoodoo_vreg_get ( BUSVOODOO_5V_CHANNEL ) ; // get 5V power rail voltage
2018-01-14 22:15:00 +01:00
if ( voltage < 4.0 ) {
printf ( " 5V power rail voltage is too low when 5V output is enabled: %.2fV \n " , voltage ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
} else if ( voltage > 5.5 ) {
printf ( " 5V power rail voltage is too high when 5V output is enabled: %.2fV \n " , voltage ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
2018-01-17 12:28:15 +01:00
voltage = busvoodoo_vreg_get ( BUSVOODOO_3V3_CHANNEL ) ; // get 3.3V power rail voltage
2018-01-14 22:15:00 +01:00
if ( voltage < 3.0 ) {
printf ( " 3.3V power rail voltage is too low when 3V3 output is enabled: %.2fV \n " , voltage ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
} else if ( voltage > 3.6 ) {
printf ( " 3.3V power rail voltage is too high when 3V3 is enabled: %.2fV \n " , voltage ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
2018-01-17 13:17:08 +01:00
busvoodoo_vout_switch ( false ) ; // disable Vout
2018-01-14 22:15:00 +01:00
2018-02-06 21:17:37 +01:00
// check LV voltage regulator
2018-02-06 21:34:29 +01:00
voltage = busvoodoo_lv_set ( 0 ) ; // disable LV voltage regulator
2018-01-14 22:15:00 +01:00
if ( voltage > 0.2 ) { // ensure the output is at 0V when the regulator is not enabled
2018-02-06 21:17:37 +01:00
printf ( " LV voltage is %.2fV instead of 0V when the regulator is disabled \n " , voltage ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
2018-02-06 21:17:37 +01:00
gpio_set ( GPIO ( BUSVOODOO_LVEN_PORT ) , GPIO ( BUSVOODOO_LVEN_PIN ) ) ; // enable LV voltage regulator
2018-01-14 22:15:00 +01:00
sleep_ms ( 5 ) ; // let the voltage regulator start and voltage settle
2018-02-06 21:17:37 +01:00
voltage = busvoodoo_vreg_get ( BUSVOODOO_LV_CHANNEL ) ; // get LV voltage
2018-01-14 22:15:00 +01:00
// without being driven it should be around the default voltage
2018-02-06 21:17:37 +01:00
if ( voltage < BUSVOODOO_LV_DEFAULT - 0.2 ) {
printf ( " LV voltage is lower (%.2fV) than expected (%.2fV) when the regulator is enabled \n " , voltage , BUSVOODOO_LV_DEFAULT ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
2018-02-06 21:17:37 +01:00
} else if ( voltage > BUSVOODOO_LV_DEFAULT + 0.2 ) {
printf ( " LV voltage is higher (%.2fV) than expected (%.2fV) when the regulator is enabled \n " , voltage , BUSVOODOO_LV_DEFAULT ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
2018-02-06 21:17:37 +01:00
// check if we can control LV
2018-02-06 21:34:29 +01:00
voltage = busvoodoo_lv_set ( BUSVOODOO_LV_TEST ) ; // get LV voltage
2018-02-06 21:17:37 +01:00
if ( voltage < BUSVOODOO_LV_TEST - 0.2 ) {
printf ( " LV voltage is lower (%.2fV) than set (%.2fV) \n " , voltage , BUSVOODOO_LV_TEST ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
2018-02-06 21:17:37 +01:00
} else if ( voltage > BUSVOODOO_LV_TEST + 0.2 ) {
printf ( " LV voltage is highed (%.2fV) than set (%.2fV) \n " , voltage , BUSVOODOO_LV_TEST ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
2018-02-06 21:34:29 +01:00
busvoodoo_lv_set ( 0 ) ; // disable LV voltage regulator
2018-01-14 22:15:00 +01:00
2018-02-06 21:17:37 +01:00
// check HV voltage regulator
2018-01-14 22:15:00 +01:00
if ( busvoodoo_full ) {
2018-02-06 21:34:29 +01:00
voltage = busvoodoo_hv_set ( 0 ) ; // disable HV voltage regulator
2018-01-14 22:15:00 +01:00
if ( voltage > 0.2 ) { // ensure the output is at 0V when the regulator is not enabled
2018-02-06 21:17:37 +01:00
printf ( " HV voltage is %.2fV instead of 0V when the regulator is disabled \n " , voltage ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
2018-02-06 21:17:37 +01:00
gpio_clear ( GPIO ( BUSVOODOO_HVEN_PORT ) , GPIO ( BUSVOODOO_HVEN_PIN ) ) ; // enable HV voltage regulator
2018-01-14 22:15:00 +01:00
sleep_ms ( 10 ) ; // let the voltage regulator start and voltage settle
2018-02-06 21:17:37 +01:00
voltage = busvoodoo_vreg_get ( BUSVOODOO_HV_CHANNEL ) ; // get HV voltage
2018-01-14 22:15:00 +01:00
// without being driven it should be around the default voltage
2018-02-06 21:17:37 +01:00
if ( voltage < BUSVOODOO_HV_DEFAULT - 0.3 ) {
printf ( " HV voltage is lower (%.2fV) than expected (%.2fV) when regulator is enabled \n " , voltage , BUSVOODOO_HV_DEFAULT ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
2018-02-06 21:17:37 +01:00
} else if ( voltage > BUSVOODOO_HV_DEFAULT + 0.3 ) {
printf ( " HV voltage is higher (%.2fV) than expected (%.2fV) when regulator is enabled \n " , voltage , BUSVOODOO_HV_DEFAULT ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
2018-02-06 21:17:37 +01:00
// check if we can control HV voltage regulator
2018-02-06 21:34:29 +01:00
voltage = busvoodoo_hv_set ( BUSVOODOO_HV_TEST ) ; // set voltage on HV voltage regulator
2018-02-06 21:17:37 +01:00
if ( voltage < BUSVOODOO_HV_TEST - 0.3 ) {
printf ( " HV voltage is lower (%.2fV) than set (%.2fV) \n " , voltage , BUSVOODOO_HV_TEST ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
2018-02-06 21:17:37 +01:00
} else if ( voltage > BUSVOODOO_HV_TEST + 0.3 ) {
printf ( " HV voltage is higher (%.2fV) than set (%.2fV) \n " , voltage , BUSVOODOO_HV_TEST ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
2018-02-06 21:34:29 +01:00
voltage = busvoodoo_hv_set ( 0 ) ; // disable HV voltage regulator
2018-01-14 22:15:00 +01:00
}
// pull all pins down and ensure they are low
for ( uint8_t pin = 0 ; pin < LENGTH ( busvoodoo_io_ports ) & & pin < LENGTH ( busvoodoo_io_pins ) ; pin + + ) {
gpio_set_mode ( busvoodoo_io_ports [ pin ] , GPIO_MODE_INPUT , GPIO_CNF_INPUT_PULL_UPDOWN , busvoodoo_io_pins [ pin ] ) ; // set pin to input
gpio_clear ( busvoodoo_io_ports [ pin ] , busvoodoo_io_pins [ pin ] ) ; // pull down so it's not floating
}
for ( uint8_t pin = 0 ; pin < LENGTH ( busvoodoo_io_ports ) & & pin < LENGTH ( busvoodoo_io_pins ) & & pin < LENGTH ( busvoodoo_io_names ) ; pin + + ) {
if ( gpio_get ( busvoodoo_io_ports [ pin ] , busvoodoo_io_pins [ pin ] ) ) { // ensure it really is low
printf ( " signal %s is high although it is pulled low (internal) \n " , busvoodoo_io_names [ pin ] ) ; // warn user about the error
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
}
2018-02-14 12:35:23 +01:00
2018-01-14 22:15:00 +01:00
// pull all pins up and ensure they are high
for ( uint8_t pin = 0 ; pin < LENGTH ( busvoodoo_io_ports ) & & pin < LENGTH ( busvoodoo_io_pins ) ; pin + + ) {
gpio_set_mode ( busvoodoo_io_ports [ pin ] , GPIO_MODE_INPUT , GPIO_CNF_INPUT_PULL_UPDOWN , busvoodoo_io_pins [ pin ] ) ; // set pin to input
gpio_set ( busvoodoo_io_ports [ pin ] , busvoodoo_io_pins [ pin ] ) ; // pull up using internal pull-up
}
for ( uint8_t pin = 0 ; pin < LENGTH ( busvoodoo_io_ports ) & & pin < LENGTH ( busvoodoo_io_pins ) & & pin < LENGTH ( busvoodoo_io_names ) ; pin + + ) {
if ( ! gpio_get ( busvoodoo_io_ports [ pin ] , busvoodoo_io_pins [ pin ] ) ) { // ensure it really is high
printf ( " signal %s is low although it is pulled up (internal) \n " , busvoodoo_io_names [ pin ] ) ; // warn user about the error
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
}
// set individual pin high and ensure only pins in the same group are at the same level
for ( uint8_t pin = 0 ; pin < LENGTH ( busvoodoo_io_ports ) & & pin < LENGTH ( busvoodoo_io_pins ) ; pin + + ) {
gpio_set_mode ( busvoodoo_io_ports [ pin ] , GPIO_MODE_INPUT , GPIO_CNF_INPUT_PULL_UPDOWN , busvoodoo_io_pins [ pin ] ) ; // set pin to input
gpio_clear ( busvoodoo_io_ports [ pin ] , busvoodoo_io_pins [ pin ] ) ; // pull down to ensure it is not high by accident
}
for ( uint8_t pin1 = 0 ; pin1 < LENGTH ( busvoodoo_io_ports ) & & pin1 < LENGTH ( busvoodoo_io_pins ) & & pin1 < LENGTH ( busvoodoo_io_groups ) & & pin1 < LENGTH ( busvoodoo_io_names ) ; pin1 + + ) {
gpio_set_mode ( busvoodoo_io_ports [ pin1 ] , GPIO_MODE_OUTPUT_2_MHZ , GPIO_CNF_OUTPUT_PUSHPULL , busvoodoo_io_pins [ pin1 ] ) ; // set button pin to output
gpio_set ( busvoodoo_io_ports [ pin1 ] , busvoodoo_io_pins [ pin1 ] ) ; // set pin high
for ( uint8_t pin2 = 0 ; pin2 < LENGTH ( busvoodoo_io_ports ) & & pin2 < LENGTH ( busvoodoo_io_pins ) & & pin2 < LENGTH ( busvoodoo_io_groups ) & & pin2 < LENGTH ( busvoodoo_io_names ) ; pin2 + + ) {
if ( busvoodoo_io_groups [ pin1 ] = = busvoodoo_io_groups [ pin2 ] & & ! gpio_get ( busvoodoo_io_ports [ pin2 ] , busvoodoo_io_pins [ pin2 ] ) ) {
printf ( " signal %s of I/O-%u is low while it should be set high by signal %s of I/O-%u \n " , busvoodoo_io_names [ pin2 ] , busvoodoo_io_groups [ pin2 ] , busvoodoo_io_names [ pin1 ] , busvoodoo_io_groups [ pin1 ] ) ; // warn user about the error
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
} else if ( busvoodoo_io_groups [ pin1 ] ! = busvoodoo_io_groups [ pin2 ] & & gpio_get ( busvoodoo_io_ports [ pin2 ] , busvoodoo_io_pins [ pin2 ] ) ) {
printf ( " signal %s of I/O-%u is high while it should not be set high by signal %s of I/O-%u \n " , busvoodoo_io_names [ pin2 ] , busvoodoo_io_groups [ pin2 ] , busvoodoo_io_names [ pin1 ] , busvoodoo_io_groups [ pin1 ] ) ; // warn user about the error
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
}
gpio_set_mode ( busvoodoo_io_ports [ pin1 ] , GPIO_MODE_INPUT , GPIO_CNF_INPUT_PULL_UPDOWN , busvoodoo_io_pins [ pin1 ] ) ; // set pin back to input
gpio_clear ( busvoodoo_io_ports [ pin1 ] , busvoodoo_io_pins [ pin1 ] ) ; // pull pin back down
}
// set individual pin low and ensure only pins in the same group are at the same level
for ( uint8_t pin = 0 ; pin < LENGTH ( busvoodoo_io_ports ) & & pin < LENGTH ( busvoodoo_io_pins ) ; pin + + ) {
gpio_set_mode ( busvoodoo_io_ports [ pin ] , GPIO_MODE_INPUT , GPIO_CNF_INPUT_PULL_UPDOWN , busvoodoo_io_pins [ pin ] ) ; // set pin to input
gpio_set ( busvoodoo_io_ports [ pin ] , busvoodoo_io_pins [ pin ] ) ; // pull up to ensure it is not low by accident
}
for ( uint8_t pin1 = 0 ; pin1 < LENGTH ( busvoodoo_io_ports ) & & pin1 < LENGTH ( busvoodoo_io_pins ) & & pin1 < LENGTH ( busvoodoo_io_groups ) & & pin1 < LENGTH ( busvoodoo_io_names ) ; pin1 + + ) {
gpio_set_mode ( busvoodoo_io_ports [ pin1 ] , GPIO_MODE_OUTPUT_2_MHZ , GPIO_CNF_OUTPUT_PUSHPULL , busvoodoo_io_pins [ pin1 ] ) ; // set button pin to output
gpio_clear ( busvoodoo_io_ports [ pin1 ] , busvoodoo_io_pins [ pin1 ] ) ; // set pin low
for ( uint8_t pin2 = 0 ; pin2 < LENGTH ( busvoodoo_io_ports ) & & pin2 < LENGTH ( busvoodoo_io_pins ) & & pin2 < LENGTH ( busvoodoo_io_groups ) & & pin2 < LENGTH ( busvoodoo_io_names ) ; pin2 + + ) {
if ( busvoodoo_io_groups [ pin1 ] = = busvoodoo_io_groups [ pin2 ] & & gpio_get ( busvoodoo_io_ports [ pin2 ] , busvoodoo_io_pins [ pin2 ] ) ) {
printf ( " signal %s of I/O-%u is high while it should be set low by signal %s of I/O-%u \n " , busvoodoo_io_names [ pin2 ] , busvoodoo_io_groups [ pin2 ] , busvoodoo_io_names [ pin1 ] , busvoodoo_io_groups [ pin1 ] ) ; // warn user about the error
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
} else if ( busvoodoo_io_groups [ pin1 ] ! = busvoodoo_io_groups [ pin2 ] & & ! gpio_get ( busvoodoo_io_ports [ pin2 ] , busvoodoo_io_pins [ pin2 ] ) ) {
printf ( " signal %s of I/O-%u is low while it should not be set low by signal %s of I/O-%u \n " , busvoodoo_io_names [ pin2 ] , busvoodoo_io_groups [ pin2 ] , busvoodoo_io_names [ pin1 ] , busvoodoo_io_groups [ pin1 ] ) ; // warn user about the error
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
}
gpio_set_mode ( busvoodoo_io_ports [ pin1 ] , GPIO_MODE_INPUT , GPIO_CNF_INPUT_PULL_UPDOWN , busvoodoo_io_pins [ pin1 ] ) ; // set pin back to input
gpio_set ( busvoodoo_io_ports [ pin1 ] , busvoodoo_io_pins [ pin1 ] ) ; // pull pin back up
}
// test 5V pull-up
for ( uint8_t pin = 0 ; pin < LENGTH ( busvoodoo_io_ports ) & & pin < LENGTH ( busvoodoo_io_pins ) ; pin + + ) {
gpio_set_mode ( busvoodoo_io_ports [ pin ] , GPIO_MODE_INPUT , GPIO_CNF_INPUT_PULL_UPDOWN , busvoodoo_io_pins [ pin ] ) ; // set pin to input
gpio_clear ( busvoodoo_io_ports [ pin ] , busvoodoo_io_pins [ pin ] ) ; // pull down to ensure it is not high by accident
}
2018-02-06 21:34:29 +01:00
busvoodoo_lv_set ( 5.0 ) ; // set LV voltage regulator to use the 5.0V power rail
2018-01-17 18:25:59 +01:00
voltage = busvoodoo_embedded_pullup ( true ) ; // enable 5V pull-up
2018-01-14 22:15:00 +01:00
if ( voltage < 4.0 ) {
printf ( " 5V power rail voltage is too low when used to pull up: %.2fV \n " , voltage ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
} else if ( voltage > 5.5 ) {
printf ( " 5V power rail voltage is too high when used to pull up: %.2fV \n " , voltage ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
for ( uint8_t pin = 0 ; pin < LENGTH ( busvoodoo_io_ports ) & & pin < LENGTH ( busvoodoo_io_pins ) & & pin < LENGTH ( busvoodoo_io_names ) ; pin + + ) {
if ( ! gpio_get ( busvoodoo_io_ports [ pin ] , busvoodoo_io_pins [ pin ] ) ) { // ensure it really is high
printf ( " signal %s is low although it is pulled up by 5V (embedded) \n " , busvoodoo_io_names [ pin ] ) ; // warn user about the error
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
}
2018-01-17 18:25:59 +01:00
busvoodoo_embedded_pullup ( false ) ; // disable pull-ups
2018-02-06 21:34:29 +01:00
voltage = busvoodoo_lv_set ( 0 ) ; // disable LV voltage regulator
2018-01-14 22:15:00 +01:00
2018-02-06 21:17:37 +01:00
// test LV pull-up set to 3.3V
2018-01-14 22:15:00 +01:00
for ( uint8_t pin = 0 ; pin < LENGTH ( busvoodoo_io_ports ) & & pin < LENGTH ( busvoodoo_io_pins ) ; pin + + ) {
gpio_set_mode ( busvoodoo_io_ports [ pin ] , GPIO_MODE_INPUT , GPIO_CNF_INPUT_PULL_UPDOWN , busvoodoo_io_pins [ pin ] ) ; // set pin to input
gpio_clear ( busvoodoo_io_ports [ pin ] , busvoodoo_io_pins [ pin ] ) ; // pull down to ensure it is not high by accident
}
2018-02-06 21:34:29 +01:00
busvoodoo_lv_set ( 3.3 ) ; // set LV voltage regulator
2018-01-17 18:25:59 +01:00
voltage = busvoodoo_embedded_pullup ( 3.3 ) ; // enable pull-up with adjustable regulator
2018-02-06 21:17:37 +01:00
if ( voltage < BUSVOODOO_LV_DEFAULT - 0.2 ) {
printf ( " LV voltage is lower (%.2fV) than expected (%.2fV) when used to pull up \n " , voltage , BUSVOODOO_LV_DEFAULT ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
2018-02-06 21:17:37 +01:00
} else if ( voltage > BUSVOODOO_LV_DEFAULT + 0.2 ) {
printf ( " LV voltage is higher (%.2fV) than expected (%.2fV) when used to pull up \n " , voltage , BUSVOODOO_LV_DEFAULT ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
for ( uint8_t pin = 0 ; pin < LENGTH ( busvoodoo_io_ports ) & & pin < LENGTH ( busvoodoo_io_pins ) & & pin < LENGTH ( busvoodoo_io_names ) ; pin + + ) {
if ( ! gpio_get ( busvoodoo_io_ports [ pin ] , busvoodoo_io_pins [ pin ] ) ) { // ensure it really is high
2018-02-06 21:17:37 +01:00
printf ( " signal %s is low although it is pulled up by LV (embedded) \n " , busvoodoo_io_names [ pin ] ) ; // warn user about the error
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
}
2018-02-06 21:34:29 +01:00
busvoodoo_lv_set ( 0 ) ; // disable LV voltage regulator
2018-01-17 18:25:59 +01:00
busvoodoo_embedded_pullup ( false ) ; // disable pull-ups
2018-01-14 22:15:00 +01:00
2018-02-14 12:35:23 +01:00
// test RS-485 transceiver
if ( busvoodoo_full ) {
// configure transceiver
gpio_set ( GPIO ( BUSVOODOO_RS485_DE_PORT ) , GPIO ( BUSVOODOO_RS485_DE_PIN ) ) ; // enable transmitter
gpio_clear ( GPIO ( BUSVOODOO_RS485_RE_PORT ) , GPIO ( BUSVOODOO_RS485_RE_PIN ) ) ; // enable receiver
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
2018-02-14 14:27:23 +01:00
gpio_set_mode ( GPIO ( BUSVOODOO_RS485_RX_PORT ) , GPIO_MODE_INPUT , GPIO_CNF_INPUT_PULL_UPDOWN , GPIO ( BUSVOODOO_RS485_RX_PIN ) ) ; // set RX as input with pull up/down
2018-02-14 13:14:32 +01:00
// test low signal
2018-02-14 12:35:23 +01:00
gpio_set ( GPIO ( BUSVOODOO_RS485_RX_PORT ) , GPIO ( BUSVOODOO_RS485_RX_PIN ) ) ; // pull RX up
gpio_clear ( GPIO ( BUSVOODOO_RS485_TX_PORT ) , GPIO ( BUSVOODOO_RS485_TX_PIN ) ) ; // set TX low
sleep_us ( 100 ) ; // let voltage settle
if ( gpio_get ( GPIO ( BUSVOODOO_RS485_RX_PORT ) , GPIO ( BUSVOODOO_RS485_RX_PIN ) ) ) { // test if RX is still high
printf ( " RS-485 RX is high while TX is set low \n " ) ; // warn user about the error
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
2018-02-14 13:14:32 +01:00
// test high signal
2018-02-14 12:35:23 +01:00
gpio_clear ( GPIO ( BUSVOODOO_RS485_RX_PORT ) , GPIO ( BUSVOODOO_RS485_RX_PIN ) ) ; // pull RX down
gpio_set ( GPIO ( BUSVOODOO_RS485_TX_PORT ) , GPIO ( BUSVOODOO_RS485_TX_PIN ) ) ; // set TX high
sleep_us ( 100 ) ; // let voltage settle
if ( 0 = = gpio_get ( GPIO ( BUSVOODOO_RS485_RX_PORT ) , GPIO ( BUSVOODOO_RS485_RX_PIN ) ) ) { // test if RX is still low
printf ( " RS-485 RX is low while TX is set high \n " ) ; // warn user about the error
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
// release transceiver
gpio_set ( GPIO ( BUSVOODOO_RS485_RE_PORT ) , GPIO ( BUSVOODOO_RS485_RE_PIN ) ) ; // set high to disable receiver
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
gpio_set_mode ( GPIO ( BUSVOODOO_RS485_RX_PORT ) , GPIO_MODE_INPUT , GPIO_CNF_INPUT_FLOAT , GPIO ( BUSVOODOO_RS485_RX_PIN ) ) ; // set pin to floating
}
2018-02-14 14:27:23 +01:00
// test CAN transceiver
if ( busvoodoo_full ) {
// configure transceiver
gpio_clear ( GPIO ( BUSVOODOO_CAN_EN_PORT ) , GPIO ( BUSVOODOO_CAN_EN_PIN ) ) ; // pull low to power transceiver
gpio_set_mode ( GPIO ( BUSVOODOO_CAN_TX_PORT ) , GPIO_MODE_OUTPUT_2_MHZ , GPIO_CNF_OUTPUT_OPENDRAIN , GPIO ( BUSVOODOO_CAN_TX_PIN ) ) ; // set TX as output (there is a pull-up resistor to 5V)
gpio_set_mode ( GPIO ( BUSVOODOO_CAN_RX_PORT ) , GPIO_MODE_INPUT , GPIO_CNF_INPUT_PULL_UPDOWN , GPIO ( BUSVOODOO_CAN_RX_PIN ) ) ; // set RX as input with pull up/down
// test high signal
gpio_clear ( GPIO ( BUSVOODOO_CAN_RX_PORT ) , GPIO ( BUSVOODOO_CAN_RX_PIN ) ) ; // pull RX down
gpio_set ( GPIO ( BUSVOODOO_CAN_TX_PORT ) , GPIO ( BUSVOODOO_CAN_TX_PIN ) ) ; // set TX high
sleep_us ( 100 ) ; // let voltage settle
if ( 0 = = gpio_get ( GPIO ( BUSVOODOO_CAN_RX_PORT ) , GPIO ( BUSVOODOO_CAN_RX_PIN ) ) ) { // test if RX is still low
printf ( " CAN RX is low while TX is set high \n " ) ; // warn user about the error
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
// test low signal
gpio_set ( GPIO ( BUSVOODOO_CAN_RX_PORT ) , GPIO ( BUSVOODOO_CAN_RX_PIN ) ) ; // pull RX up
gpio_clear ( GPIO ( BUSVOODOO_CAN_TX_PORT ) , GPIO ( BUSVOODOO_CAN_TX_PIN ) ) ; // set TX low
sleep_us ( 100 ) ; // let voltage settle
if ( gpio_get ( GPIO ( BUSVOODOO_CAN_RX_PORT ) , GPIO ( BUSVOODOO_CAN_RX_PIN ) ) ) { // test if RX is still high
printf ( " CAN RX is high while TX is set low \n " ) ; // warn user about the error
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
// test dominant timeout
sleep_ms ( 10 ) ; // after 5 ms the output should be switched back from dominant to recessive respite TX being low
if ( ! gpio_get ( GPIO ( BUSVOODOO_CAN_RX_PORT ) , GPIO ( BUSVOODOO_CAN_RX_PIN ) ) ) { // test if RX is now low
printf ( " CAN RX is low while the output should be back to recessive \n " ) ; // warn user about the error
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
// 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
gpio_set_mode ( GPIO ( BUSVOODOO_CAN_RX_PORT ) , GPIO_MODE_INPUT , GPIO_CNF_INPUT_FLOAT , GPIO ( BUSVOODOO_CAN_RX_PIN ) ) ; // set pin to floating
}
2018-01-14 22:15:00 +01:00
to_return = true ; // all tests are successful
2018-01-17 12:28:15 +01:00
# if DEBUG
# else
2018-01-14 22:15:00 +01:00
error :
2018-01-17 12:28:15 +01:00
# endif
2018-01-14 22:15:00 +01:00
busvoodoo_safe_state ( ) ; // set back to safe state
if ( ! to_return ) {
printf ( " the test procedure has been aborted for safety reasons \n " ) ;
}
return to_return ;
}
2018-01-21 23:43:37 +01:00
/** test if signals are soldered correctly to the connector pins
* @ return if pin test passed
*/
static bool busvoodoo_hiz_test_pins ( void )
2018-01-14 22:15:00 +01:00
{
bool to_return = false ; // test result to return
busvoodoo_safe_state ( ) ; // start from safe state with all outputs switched off
2018-02-06 21:17:37 +01:00
const char * lv_to = " connect I/O pin 4 to " ; // most outputs will be tested using LV ADC
2018-02-16 13:13:11 +01:00
char * pinout [ 10 ] = { NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL } ; // pinout to display
busvoodoo_oled_text_right ( " pins test " ) ; // display test on display
busvoodoo_oled_update ( ) ; // update screen
2018-01-14 22:15:00 +01:00
2018-02-06 21:17:37 +01:00
// test GND on pin 1 by shorting LV_CTL to ground (through 40k resistor) and measure short
gpio_set ( GPIO ( BUSVOODOO_LVCTL_PORT ) , GPIO ( BUSVOODOO_LVCTL_PIN ) ) ; // set pin high
gpio_set_mode ( GPIO ( BUSVOODOO_LVCTL_PORT ) , GPIO_MODE_OUTPUT_2_MHZ , GPIO_CNF_OUTPUT_PUSHPULL , GPIO ( BUSVOODOO_LVCTL_PIN ) ) ; // set LV control pin as output
2018-02-16 13:13:11 +01:00
printf ( " %sI/O pin 1 \n " , lv_to ) ; // ask user for action
2018-02-13 17:43:08 +01:00
led_red ( ) ; // notify user to perform action
2018-02-16 13:13:11 +01:00
pinout [ 3 ] = " O " ; // set main testing pin
pinout [ 0 ] = " O " ; // set target testing pin
busvoodoo_oled_text_pinout ( ( const char * * ) pinout , true ) ; // display pins to user
busvoodoo_oled_update ( ) ; // update screen
2018-02-12 17:03:16 +01:00
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
2018-02-13 17:43:08 +01:00
led_blue ( ) ; // notify user test is running
2018-02-12 17:03:16 +01:00
if ( user_input_available ) { // user interruption
goto error ;
2018-01-14 22:15:00 +01:00
}
2018-02-06 21:17:37 +01:00
gpio_clear ( GPIO ( BUSVOODOO_LVCTL_PORT ) , GPIO ( BUSVOODOO_LVCTL_PIN ) ) ; // set pin low
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
2018-02-12 17:03:16 +01:00
sleep_ms ( 100 ) ; // wait for voltage to settle an debounce
2018-02-06 21:17:37 +01:00
if ( busvoodoo_vreg_get ( BUSVOODOO_LV_CHANNEL ) > 0.2 ) {
2018-02-14 14:06:06 +01:00
printf ( " I/O pin 4 is high while it should be low and shorted to ground \n " ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
2018-02-06 21:17:37 +01:00
gpio_set_mode ( GPIO ( BUSVOODOO_LVCTL_PORT ) , GPIO_MODE_INPUT , GPIO_CNF_INPUT_ANALOG , GPIO ( BUSVOODOO_LVCTL_PIN ) ) ; // set LV control pin back to analog input for DAC
2018-02-16 13:13:11 +01:00
pinout [ 0 ] = NULL ; // clear pin to test
2018-01-14 22:15:00 +01:00
// test 5V output on pin 2
gpio_clear ( GPIO ( BUSVOODOO_VOUTEN_PORT ) , GPIO ( BUSVOODOO_VOUTEN_PIN ) ) ; // enable Vout
2018-02-06 21:17:37 +01:00
printf ( " %sI/O pin 2 \n " , lv_to ) ;
2018-02-13 17:43:08 +01:00
led_red ( ) ; // notify user to perform action
2018-02-16 13:13:11 +01:00
pinout [ 1 ] = " O " ; // set target testing pin
busvoodoo_oled_text_pinout ( ( const char * * ) pinout , true ) ; // display pins to user
busvoodoo_oled_update ( ) ; // update screen
2018-02-12 17:03:16 +01:00
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
2018-02-13 17:43:08 +01:00
led_blue ( ) ; // notify user test is running
2018-02-12 17:03:16 +01:00
if ( user_input_available ) { // user interruption
goto error ;
2018-01-14 22:15:00 +01:00
}
gpio_set ( GPIO ( BUSVOODOO_VOUTEN_PORT ) , GPIO ( BUSVOODOO_VOUTEN_PIN ) ) ; // disable Vout
2018-02-12 17:03:16 +01:00
sleep_ms ( 100 ) ; // wait for voltage to settle and debounce
2018-02-06 21:17:37 +01:00
if ( busvoodoo_vreg_get ( BUSVOODOO_LV_CHANNEL ) > 0.2 ) {
2018-02-14 14:06:06 +01:00
printf ( " 5V output is high while the power output should be switched off \n " ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
2018-02-16 13:13:11 +01:00
pinout [ 1 ] = NULL ; // clear pin to test
2018-01-14 22:15:00 +01:00
// test 3.3V output on pin 3
gpio_clear ( GPIO ( BUSVOODOO_VOUTEN_PORT ) , GPIO ( BUSVOODOO_VOUTEN_PIN ) ) ; // enable Vout
2018-02-06 21:17:37 +01:00
printf ( " %sI/O pin 3 \n " , lv_to ) ;
2018-02-13 17:43:08 +01:00
led_red ( ) ; // notify user to perform action
2018-02-16 13:13:11 +01:00
pinout [ 2 ] = " O " ; // set target testing pin
busvoodoo_oled_text_pinout ( ( const char * * ) pinout , true ) ; // display pins to user
busvoodoo_oled_update ( ) ; // update screen
2018-02-12 17:03:16 +01:00
do {
sleep_ms ( 100 ) ; // wait for user to make connection
} while ( ( busvoodoo_vreg_get ( BUSVOODOO_LV_CHANNEL ) < 0.2 | | busvoodoo_vreg_get ( BUSVOODOO_LV_CHANNEL ) > 3.5 ) & & ! user_input_available ) ; // wait until pin is connected
2018-02-13 17:43:08 +01:00
led_blue ( ) ; // notify user test is running
2018-02-12 17:03:16 +01:00
if ( user_input_available ) { // user interruption
goto error ;
2018-01-14 22:15:00 +01:00
}
gpio_set ( GPIO ( BUSVOODOO_VOUTEN_PORT ) , GPIO ( BUSVOODOO_VOUTEN_PIN ) ) ; // disable Vout
2018-02-12 17:03:16 +01:00
sleep_ms ( 100 ) ; // wait for voltage to settle and debounce
2018-02-06 21:17:37 +01:00
if ( busvoodoo_vreg_get ( BUSVOODOO_LV_CHANNEL ) > 0.2 ) {
2018-02-14 14:06:06 +01:00
printf ( " 3V3 output is high while the power output should be switched off \n " ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
2018-02-16 13:13:11 +01:00
pinout [ 2 ] = NULL ; // clear pin to test
2018-01-14 22:15:00 +01:00
// test I/O pins
for ( uint8_t io = 1 ; io < = 6 ; io + + ) { // test each I/O pin
for ( uint8_t pin = 0 ; pin < LENGTH ( busvoodoo_io_ports ) & & pin < LENGTH ( busvoodoo_io_pins ) & & pin < LENGTH ( busvoodoo_io_groups ) ; pin + + ) { // look for a pin mapped on this I/O
if ( busvoodoo_io_groups [ pin ] = = io ) {
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
2018-02-06 21:17:37 +01:00
printf ( " %sI/O pin %u \n " , lv_to , io + 4 ) ;
2018-02-13 17:43:08 +01:00
led_red ( ) ; // notify user to perform action
2018-02-16 13:13:11 +01:00
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
2018-02-12 17:03:16 +01:00
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
2018-02-13 17:43:08 +01:00
led_blue ( ) ; // notify user test is running
2018-02-12 17:03:16 +01:00
if ( user_input_available ) { // user interruption
goto error ;
2018-01-14 22:15:00 +01:00
}
gpio_clear ( busvoodoo_io_ports [ pin ] , busvoodoo_io_pins [ pin ] ) ; // set pin low
2018-02-12 17:03:16 +01:00
sleep_ms ( 100 ) ; // wait for voltage to settle and debounce
2018-02-06 21:17:37 +01:00
if ( busvoodoo_vreg_get ( BUSVOODOO_LV_CHANNEL ) > 0.2 ) {
2018-02-14 14:06:06 +01:00
printf ( " I/O pin %u is high while it should be low \n " , io + 4 ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
gpio_set_mode ( busvoodoo_io_ports [ pin ] , GPIO_MODE_INPUT , GPIO_CNF_INPUT_FLOAT , busvoodoo_io_pins [ pin ] ) ; // set pin back to input
2018-02-16 13:13:11 +01:00
pinout [ io + 3 ] = NULL ; // clear pin to test
2018-01-14 22:15:00 +01:00
break ; // stop looking for pin
}
}
}
if ( busvoodoo_full ) {
2018-02-16 13:13:11 +01:00
pinout [ 3 ] = NULL ; // reset testing pin
2018-02-06 21:17:37 +01:00
// test HV output on RS/CAN pin 1
2018-01-17 12:28:15 +01:00
double voltage = busvoodoo_vreg_get ( BUSVOODOO_3V3_CHANNEL ) ; // get reference voltage
2018-02-06 21:17:37 +01:00
uint16_t dac_set = BUSVOODOO_HV_SET ( 5.0 ) / voltage * 4095 ; // DAC value corresponding to the voltage
dac_load_data_buffer_single ( dac_set , RIGHT12 , BUSVOODOO_HVCTL_CHANNEL ) ; // set output so the voltage regulator is set to desired output voltage
dac_software_trigger ( BUSVOODOO_HVCTL_CHANNEL ) ; // transfer the value to the DAC
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 ) ;
2018-02-13 17:43:08 +01:00
led_red ( ) ; // notify user to perform action
2018-02-16 13:13:11 +01:00
pinout [ 0 ] = " O " ; // set target testing pin
busvoodoo_oled_text_pinout ( ( const char * * ) pinout , false ) ; // display pins to user
busvoodoo_oled_update ( ) ; // update screen
2018-02-12 17:03:16 +01:00
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
2018-02-13 17:43:08 +01:00
led_blue ( ) ; // notify user test is running
2018-02-12 17:03:16 +01:00
if ( user_input_available ) { // user interruption
goto error ;
2018-01-14 22:15:00 +01:00
}
2018-02-06 21:17:37 +01:00
gpio_set ( GPIO ( BUSVOODOO_HVEN_PORT ) , GPIO ( BUSVOODOO_HVEN_PIN ) ) ; // disable HV voltage regulator
dac_disable ( BUSVOODOO_HVCTL_CHANNEL ) ; // disable HV control
2018-02-12 17:03:16 +01:00
sleep_ms ( 100 ) ; // wait for voltage to settle (and debounce)
2018-02-06 21:17:37 +01:00
if ( busvoodoo_vreg_get ( BUSVOODOO_LV_CHANNEL ) > 0.2 ) {
2018-02-14 13:14:32 +01:00
printf ( " HV output is high while voltage regulator should be switched off \n " ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
2018-02-16 13:13:11 +01:00
pinout [ 0 ] = NULL ; // clear pin to test
2018-01-14 22:15:00 +01:00
2018-02-14 14:27:23 +01:00
// test RS-485 output A
2018-02-14 13:14:32 +01:00
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
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
2018-02-16 13:13:11 +01:00
pinout [ 4 ] = " O " ; // set target testing pin
busvoodoo_oled_text_pinout ( ( const char * * ) pinout , false ) ; // display pins to user
busvoodoo_oled_update ( ) ; // update screen
2018-02-14 13:14:32 +01:00
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
if ( user_input_available ) { // user interruption
goto error ;
}
gpio_clear ( GPIO ( BUSVOODOO_RS485_TX_PORT ) , GPIO ( BUSVOODOO_RS485_TX_PIN ) ) ; // set TX low
sleep_ms ( 100 ) ; // wait for voltage to settle (and debounce)
if ( busvoodoo_vreg_get ( BUSVOODOO_LV_CHANNEL ) > 1.0 ) {
printf ( " RS-485 output A is high while it should be low \n " ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
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
2018-02-16 13:13:11 +01:00
pinout [ 4 ] = NULL ; // clear pin to test
2018-02-14 13:14:32 +01:00
2018-02-14 15:08:23 +01:00
// test CAN output L
// configure transceiver
gpio_clear ( GPIO ( BUSVOODOO_CAN_EN_PORT ) , GPIO ( BUSVOODOO_CAN_EN_PIN ) ) ; // pull low to power transceiver
gpio_set_mode ( GPIO ( BUSVOODOO_CAN_TX_PORT ) , GPIO_MODE_OUTPUT_2_MHZ , GPIO_CNF_OUTPUT_OPENDRAIN , GPIO ( BUSVOODOO_CAN_TX_PIN ) ) ; // set TX as output (there is a pull-up resistor to 5V)
// test recessive output
gpio_set ( GPIO ( BUSVOODOO_CAN_TX_PORT ) , GPIO ( BUSVOODOO_CAN_TX_PIN ) ) ; // set TX high
sleep_us ( 100 ) ; // let voltage settle
voltage = busvoodoo_vreg_get ( BUSVOODOO_LV_CHANNEL ) ; // get output voltage
if ( voltage < 0.5 ) { // normally the lower limit is 2V, put pin 4 pulls it down because it is not strongly driven
printf ( " CAN L output is low while it should be at recessive 2.5V \n " ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
if ( voltage > 3.0 ) { // normally the upper limit is 3V
printf ( " CAN L output is high while it should be at recessive 2.5V \n " ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
// test dominant output
gpio_clear ( GPIO ( BUSVOODOO_CAN_TX_PORT ) , GPIO ( BUSVOODOO_CAN_TX_PIN ) ) ; // set TX low
sleep_us ( 100 ) ; // let voltage settle
voltage = busvoodoo_vreg_get ( BUSVOODOO_LV_CHANNEL ) ; // get output voltage
if ( voltage > 2.5 ) {
printf ( " CAN L output is high while it should at dominant <2.25V \n " ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
// 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
2018-02-14 13:14:32 +01:00
// 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
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
2018-02-16 13:13:11 +01:00
pinout [ 6 ] = " O " ; // set target testing pin
busvoodoo_oled_text_pinout ( ( const char * * ) pinout , false ) ; // display pins to user
busvoodoo_oled_update ( ) ; // update screen
2018-02-14 13:14:32 +01:00
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
if ( user_input_available ) { // user interruption
goto error ;
}
gpio_set ( GPIO ( BUSVOODOO_RS485_TX_PORT ) , GPIO ( BUSVOODOO_RS485_TX_PIN ) ) ; // set TX high
sleep_ms ( 100 ) ; // wait for voltage to settle (and debounce)
if ( busvoodoo_vreg_get ( BUSVOODOO_LV_CHANNEL ) > 1.0 ) {
printf ( " RS-485 output B is high while it should be low \n " ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
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
2018-02-16 13:13:11 +01:00
pinout [ 6 ] = NULL ; // clear pin to test
2018-02-14 13:14:32 +01:00
2018-02-14 15:08:23 +01:00
// test CAN output H
// configure transceiver
gpio_clear ( GPIO ( BUSVOODOO_CAN_EN_PORT ) , GPIO ( BUSVOODOO_CAN_EN_PIN ) ) ; // pull low to power transceiver
gpio_set_mode ( GPIO ( BUSVOODOO_CAN_TX_PORT ) , GPIO_MODE_OUTPUT_2_MHZ , GPIO_CNF_OUTPUT_OPENDRAIN , GPIO ( BUSVOODOO_CAN_TX_PIN ) ) ; // set TX as output (there is a pull-up resistor to 5V)
// test recessive output
gpio_set ( GPIO ( BUSVOODOO_CAN_TX_PORT ) , GPIO ( BUSVOODOO_CAN_TX_PIN ) ) ; // set TX high
sleep_us ( 100 ) ; // let voltage settle
voltage = busvoodoo_vreg_get ( BUSVOODOO_LV_CHANNEL ) ; // get output voltage
if ( voltage < 0.5 ) { // normally the lower limit is 2V, put pin 4 pulls it down because it is not strongly driven
printf ( " CAN H output is low while it should be at recessive 2.5V \n " ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
if ( voltage > 3.0 ) { // normally the upper limit is 3V
printf ( " CAN H output is high while it should be at recessive 2.5V \n " ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
// test dominant output
gpio_clear ( GPIO ( BUSVOODOO_CAN_TX_PORT ) , GPIO ( BUSVOODOO_CAN_TX_PIN ) ) ; // set TX low
sleep_us ( 100 ) ; // let voltage settle
voltage = busvoodoo_vreg_get ( BUSVOODOO_LV_CHANNEL ) ; // get output voltage
if ( voltage < 2.5 ) {
printf ( " CAN H output is low while it dominant >2.75V \n " ) ;
printf ( " %.02f \n " , voltage ) ;
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
// 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
2018-01-14 22:15:00 +01:00
// test RS-232 port (with itself)
rcc_periph_clock_enable ( RCC_GPIO ( BUSVOODOO_RS232_EN_PORT ) ) ; // enable clock for GPIO domain
gpio_clear ( GPIO ( BUSVOODOO_RS232_EN_PORT ) , GPIO ( BUSVOODOO_RS232_EN_PIN ) ) ; // set low to enable receiver
gpio_set_mode ( GPIO ( BUSVOODOO_RS232_EN_PORT ) , GPIO_MODE_OUTPUT_2_MHZ , GPIO_CNF_OUTPUT_OPENDRAIN , GPIO ( BUSVOODOO_RS232_EN_PIN ) ) ; // set pin as output (open-drain pulled high to disable receiver)
rcc_periph_clock_enable ( RCC_GPIO ( BUSVOODOO_RS232_SHDN_PORT ) ) ; // enable clock for GPIO domain
gpio_set ( GPIO ( BUSVOODOO_RS232_SHDN_PORT ) , GPIO ( BUSVOODOO_RS232_SHDN_PIN ) ) ; // set high to enable transmitter
gpio_set_mode ( GPIO ( BUSVOODOO_RS232_SHDN_PORT ) , GPIO_MODE_OUTPUT_2_MHZ , GPIO_CNF_OUTPUT_PUSHPULL , GPIO ( BUSVOODOO_RS232_SHDN_PIN ) ) ; // set pin as output (push-pull pulled low to disable transmitter)
rcc_periph_clock_enable ( RCC_GPIO ( BUSVOODOO_RS232_TX_PORT ) ) ; // enable clock for GPIO
gpio_set_mode ( GPIO ( BUSVOODOO_RS232_TX_PORT ) , GPIO_MODE_OUTPUT_2_MHZ , GPIO_CNF_OUTPUT_PUSHPULL , GPIO ( BUSVOODOO_RS232_TX_PIN ) ) ; // set pin as output (push-pull)
rcc_periph_clock_enable ( RCC_GPIO ( BUSVOODOO_RS232_RX_PORT ) ) ; // enable clock for GPIO
gpio_set_mode ( GPIO ( BUSVOODOO_RS232_RX_PORT ) , GPIO_MODE_INPUT , GPIO_CNF_INPUT_PULL_UPDOWN , GPIO ( BUSVOODOO_RS232_RX_PIN ) ) ; // set pin as input (with pull resistors)
// start by setting low since unconnected (pulled to ground by 3 kO) is considered as high
gpio_clear ( GPIO ( BUSVOODOO_RS232_TX_PORT ) , GPIO ( BUSVOODOO_RS232_TX_PIN ) ) ; // set low
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 " ) ;
2018-02-13 17:43:08 +01:00
led_red ( ) ; // notify user to perform action
2018-02-16 13:13:11 +01:00
pinout [ 2 ] = " O " ; // set target testing pin
pinout [ 4 ] = " O " ; // set target testing pin
busvoodoo_oled_text_pinout ( ( const char * * ) pinout , false ) ; // display pins to user
busvoodoo_oled_update ( ) ; // update screen
2018-02-12 17:03:16 +01:00
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
2018-02-13 17:43:08 +01:00
led_blue ( ) ; // notify user test is running
2018-02-12 17:03:16 +01:00
if ( user_input_available ) { // user interruption
goto error ;
2018-01-14 22:15:00 +01:00
}
gpio_set ( GPIO ( BUSVOODOO_RS232_TX_PORT ) , GPIO ( BUSVOODOO_RS232_TX_PIN ) ) ; // set high
gpio_clear ( GPIO ( BUSVOODOO_RS232_RX_PORT ) , GPIO ( BUSVOODOO_RS232_RX_PIN ) ) ; // pull low to avoid false negative
2018-02-12 17:03:16 +01:00
sleep_ms ( 100 ) ; // wait for voltage to settle and debounce
2018-01-14 22:15:00 +01:00
if ( ! gpio_get ( GPIO ( BUSVOODOO_RS232_RX_PORT ) , GPIO ( BUSVOODOO_RS232_RX_PIN ) ) ) { // check if RX is set low by TX
2018-02-14 14:06:06 +01:00
printf ( " RS-232 RX is high while it should be set low by RS-232 TX \n " ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
gpio_set_mode ( GPIO ( BUSVOODOO_RS232_TX_PORT ) , GPIO_MODE_INPUT , GPIO_CNF_INPUT_FLOAT , GPIO ( BUSVOODOO_RS232_TX_PIN ) ) ; // free pin
gpio_set_mode ( GPIO ( BUSVOODOO_RS232_RX_PORT ) , GPIO_MODE_INPUT , GPIO_CNF_INPUT_FLOAT , GPIO ( BUSVOODOO_RS232_RX_PIN ) ) ; // free pin
2018-02-16 13:13:11 +01:00
pinout [ 2 ] = NULL ; // clear pin to test
pinout [ 4 ] = NULL ; // clear pin to test
2018-01-14 22:15:00 +01:00
rcc_periph_clock_enable ( RCC_GPIO ( BUSVOODOO_RS232_RTS_PORT ) ) ; // enable clock for GPIO
gpio_set_mode ( GPIO ( BUSVOODOO_RS232_RTS_PORT ) , GPIO_MODE_OUTPUT_2_MHZ , GPIO_CNF_OUTPUT_PUSHPULL , GPIO ( BUSVOODOO_RS232_RTS_PIN ) ) ; // set pin as output (push-pull)
rcc_periph_clock_enable ( RCC_GPIO ( BUSVOODOO_RS232_CTS_PORT ) ) ; // enable clock for GPIO
gpio_set_mode ( GPIO ( BUSVOODOO_RS232_CTS_PORT ) , GPIO_MODE_INPUT , GPIO_CNF_INPUT_PULL_UPDOWN , GPIO ( BUSVOODOO_RS232_CTS_PIN ) ) ; // set pin as input (with pull resistors)
// start by setting low since unconnected (pulled to ground by 3 kO) is considered as high
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 " ) ;
2018-02-13 17:43:08 +01:00
led_red ( ) ; // notify user to perform action
2018-02-16 13:13:11 +01:00
pinout [ 6 ] = " O " ; // set target testing pin
pinout [ 8 ] = " O " ; // set target testing pin
busvoodoo_oled_text_pinout ( ( const char * * ) pinout , false ) ; // display pins to user
busvoodoo_oled_update ( ) ; // update screen
2018-02-12 17:03:16 +01:00
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
2018-02-13 17:43:08 +01:00
led_blue ( ) ; // notify user test is running
2018-02-12 17:03:16 +01:00
if ( user_input_available ) { // user interruption
goto error ;
2018-01-14 22:15:00 +01:00
}
gpio_set ( GPIO ( BUSVOODOO_RS232_RTS_PORT ) , GPIO ( BUSVOODOO_RS232_RTS_PIN ) ) ; // set high
gpio_clear ( GPIO ( BUSVOODOO_RS232_CTS_PORT ) , GPIO ( BUSVOODOO_RS232_CTS_PIN ) ) ; // pull low to avoid false negative
2018-02-12 17:03:16 +01:00
sleep_ms ( 100 ) ; // wait for voltage to settle an debounce
2018-01-14 22:15:00 +01:00
if ( ! gpio_get ( GPIO ( BUSVOODOO_RS232_CTS_PORT ) , GPIO ( BUSVOODOO_RS232_CTS_PIN ) ) ) { // check if CTS is set high by RTS
2018-02-14 14:06:06 +01:00
printf ( " RS-232 CTS is high while it should be set low by RS-232 RTS \n " ) ;
2018-01-14 22:15:00 +01:00
# if DEBUG
while ( true ) ;
# else
goto error ;
# endif
}
gpio_set_mode ( GPIO ( BUSVOODOO_RS232_RTS_PORT ) , GPIO_MODE_INPUT , GPIO_CNF_INPUT_FLOAT , GPIO ( BUSVOODOO_RS232_RTS_PIN ) ) ; // free pin
gpio_set_mode ( GPIO ( BUSVOODOO_RS232_CTS_PORT ) , GPIO_MODE_INPUT , GPIO_CNF_INPUT_FLOAT , GPIO ( BUSVOODOO_RS232_CTS_PIN ) ) ; // free pin
gpio_set ( GPIO ( BUSVOODOO_RS232_EN_PORT ) , GPIO ( BUSVOODOO_RS232_EN_PIN ) ) ; // set high to disable receiver
gpio_clear ( GPIO ( BUSVOODOO_RS232_SHDN_PORT ) , GPIO ( BUSVOODOO_RS232_SHDN_PIN ) ) ; // set low to disable transmitter
2018-02-16 13:13:11 +01:00
pinout [ 6 ] = NULL ; // clear pin to test
pinout [ 8 ] = NULL ; // clear pin to test
2018-01-14 22:15:00 +01:00
}
to_return = true ; // all tests passed
error :
busvoodoo_safe_state ( ) ; // go back to safe state
2018-02-16 13:13:11 +01:00
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
2018-02-12 17:03:16 +01:00
if ( user_input_available ) { // user interrupted the test
printf ( " user interrupted the test \n " ) ;
to_return = true ; // we don't consider this as error
}
if ( ! to_return ) { // test has not been completed
2018-01-14 22:15:00 +01:00
printf ( " the test procedure has been aborted for safety reasons \n " ) ;
}
return to_return ;
}
2018-01-21 23:43:37 +01:00
// command handlers
2018-03-15 19:20:27 +01:00
/** switch to DFU bootloader
2018-03-17 19:41:20 +01:00
* @ param [ in ] argument no argument required
2018-03-15 19:20:27 +01:00
* @ note this handler is in HiZ mode only to save shortcut space and reduce menu size
*/
static void busvoodoo_hiz_bootloader ( void * argument )
{
( void ) argument ; // we won't use the argument
RCC_CSR | = RCC_CSR_RMVF ; // clear reset flags
scb_reset_core ( ) ; // reset core (the bootloader will interpret it as starting into DFU)
while ( true ) ; // wait for the reset to happen
}
/** show BusVoodoo version
2018-03-17 19:41:20 +01:00
* @ param [ in ] argument no argument required
2018-03-15 19:20:27 +01:00
* @ note this handler is in HiZ mode only to save shortcut space and reduce menu size
*/
static void busvoodoo_hiz_version ( void * argument )
{
( void ) argument ; // we won't use the argument
printf ( " BusVoodoo flavor: %s \n " , busvoodoo_full ? " full " : " light " ) ;
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 ) ;
}
2018-01-21 23:43:37 +01:00
/** command to perform board self-test
* @ param [ in ] argument no argument required
*/
static void busvoodoo_hiz_command_test_self ( void * argument )
{
( void ) argument ; // we won't use the argument
printf ( " performing self-test \n " ) ;
2018-01-24 22:17:32 +01:00
printf ( " remove all cables from connectors and press space to start (or any other key to abort) \n " ) ;
2018-02-13 17:43:08 +01:00
led_red ( ) ; // show red LED to indicate test started
2018-01-25 10:41:43 +01:00
if ( ' ' = = user_input_get ( ) ) { // space entered
2018-01-21 23:43:37 +01:00
if ( busvoodoo_hiz_test_self ( ) ) { // perform self-test
2018-02-13 17:43:08 +01:00
led_blue ( ) ; // show blue to indicate test passed
2018-01-21 23:43:37 +01:00
printf ( " self-test succeeded \n " ) ; // notify user
} else {
led_blink ( 0.5 , 0.5 ) ; // show error on LEDs
printf ( " self-test failed \n " ) ; // notify user
}
} else {
printf ( " self-test aborted \n " ) ;
}
}
/** command to perform pins test
* @ param [ in ] argument no argument required
*/
static void busvoodoo_hiz_command_test_pins ( void * argument )
{
( void ) argument ; // we won't use the argument
printf ( " performing pins test \n " ) ;
2018-01-24 22:17:32 +01:00
printf ( " remove all cables from connectors and press space to start (or any other key to abort) \n " ) ;
2018-02-13 17:43:08 +01:00
led_red ( ) ; // show red LED to indicate test started
2018-01-25 10:41:43 +01:00
if ( ' ' = = user_input_get ( ) ) { // space entered
2018-01-21 23:43:37 +01:00
if ( busvoodoo_hiz_test_pins ( ) ) { // perform pin test
2018-02-13 17:43:08 +01:00
led_blue ( ) ; // show blue OK LED
2018-01-22 21:40:53 +01:00
printf ( " pins test succeeded \n " ) ; // notify user
2018-01-21 23:43:37 +01:00
} else {
led_blink ( 0.5 , 0.5 ) ; // show error on LEDs
2018-01-22 21:40:53 +01:00
printf ( " pins test failed \n " ) ; // notify user
2018-01-21 23:43:37 +01:00
}
} else {
2018-01-22 21:40:53 +01:00
printf ( " pins test aborted \n " ) ;
2018-01-21 23:43:37 +01:00
}
}
2018-01-23 15:18:41 +01:00
static const struct menu_command_t busvoodoo_hiz_commands [ ] = {
2018-03-15 19:20:27 +01:00
{
' v ' ,
" version " ,
" show hardware and firmware version " ,
MENU_ARGUMENT_NONE ,
NULL ,
& busvoodoo_hiz_version ,
} ,
{
' b ' ,
" bootloader " ,
" reboot into DFU bootloader " ,
MENU_ARGUMENT_NONE ,
NULL ,
& busvoodoo_hiz_bootloader ,
} ,
2018-01-21 23:43:37 +01:00
{
' s ' ,
" self-test " ,
" perform board self-test " ,
MENU_ARGUMENT_NONE ,
NULL ,
& busvoodoo_hiz_command_test_self ,
} ,
{
2018-01-22 21:40:53 +01:00
' t ' ,
2018-01-21 23:43:37 +01:00
" pins-test " ,
" perform connector pins test " ,
MENU_ARGUMENT_NONE ,
NULL ,
& busvoodoo_hiz_command_test_pins ,
} ,
} ;
2018-01-23 15:18:41 +01:00
2018-01-23 15:36:05 +01:00
struct busvoodoo_mode_t busvoodoo_hiz_mode = {
2018-01-23 23:41:41 +01:00
" hiz " ,
2018-01-24 15:57:34 +01:00
" High Impedance (Z) " ,
2018-01-23 15:18:41 +01:00
& busvoodoo_hiz_setup ,
busvoodoo_hiz_commands ,
LENGTH ( busvoodoo_hiz_commands ) ,
& busvoodoo_hiz_exit ,
} ;