diff --git a/lib/busvoodoo_global.c b/lib/busvoodoo_global.c index d3a158d..b233406 100644 --- a/lib/busvoodoo_global.c +++ b/lib/busvoodoo_global.c @@ -57,7 +57,7 @@ static volatile bool busvoodoo_global_led_red_timer = false; 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 +static const float busvoodoo_version_voltages[] = {100.0/(10.0+100.0)*3.3, 0.0}; // version A start with revision 27 const char* busvoodoo_global_pinout_io[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; const char* busvoodoo_global_pinout_rscan[5] = {NULL, NULL, NULL, NULL, NULL}; @@ -81,6 +81,7 @@ void busvoodoo_setup(void) rcc_periph_clock_enable(RCC_AFIO); // enable clock for alternate function (for communication) busvoodoo_safe_state(); // put pins in safe state (for common light version) +#if BUSVOODOO_HARDWARE_VERSION != 2 // check if this BusVoodoo is a full flavor rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_HV_CHANNEL)); // enable clock for GPIO domain for HV channel gpio_set(ADC12_IN_PORT(BUSVOODOO_HV_CHANNEL), ADC12_IN_PIN(BUSVOODOO_HV_CHANNEL)); // pull ADC HV high @@ -92,8 +93,10 @@ void busvoodoo_setup(void) busvoodoo_full = true; busvoodoo_safe_state(); // also put the full version pins in safe state } +#endif // setup ADC to measure the 5V, 3.3V, LV, and HV power rails voltages, and hardware version channel +#if BUSVOODOO_HARDWARE_VERSION != 2 rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_5V_CHANNEL)); // enable clock for GPIO domain for 5V channel gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_5V_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_5V_CHANNEL)); // set 5V channel as analogue input for the ADC rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_3V3_CHANNEL)); // enable clock for GPIO domain for 3.3V channel @@ -104,6 +107,10 @@ void busvoodoo_setup(void) gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_HV_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_HV_CHANNEL)); // set HV channel as analogue input for the ADC rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_HW_VERSION_CHANNEL)); // enable clock for GPIO domain for hardware version channel gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_HW_VERSION_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_HW_VERSION_CHANNEL)); // set hardware version channel as analogue input for the ADC +#else + rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_ADC_CHANNEL)); // enable clock for GPIO domain for ADC channel + gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_ADC_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_ADC_CHANNEL)); // set ADC channel as analogue input for the ADC +#endif rcc_periph_clock_enable(RCC_ADC1); // enable clock for ADC domain adc_power_off(ADC1); // switch off ADC while configuring it adc_disable_scan_mode(ADC1); // ensure scan mode is disabled @@ -136,6 +143,7 @@ void busvoodoo_setup(void) } } +#if BUSVOODOO_HARDWARE_VERSION != 2 // setup DAC to control LV and HV voltage outputs gpio_set_mode(GPIO(BUSVOODOO_LVCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_LVCTL_PIN)); // set LV pin as analog (the DAC will use it as output) rcc_periph_clock_enable(RCC_DAC); // enable clock for DAC domain @@ -148,6 +156,7 @@ 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 +#endif // enable timer for LED pulsing or blinking rcc_periph_clock_enable(RCC_TIM(BUSVOODOO_LED_TIMER)); // enable clock for timer domain @@ -170,6 +179,7 @@ void busvoodoo_setup(void) void busvoodoo_safe_state(void) { +#if BUSVOODOO_HARDWARE_VERSION != 2 // disable voltage outputs gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable 5V and 3.3V output on connector gpio_set_mode(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_VOUTEN_PIN)); // set pin as output (open-drain pulled high to disable the pMOS) @@ -188,12 +198,16 @@ void busvoodoo_safe_state(void) gpio_set_mode(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_5VPULLUP_PIN)); // set pin as output (open-drain pulled high to disable the pMOS) gpio_set(GPIO(BUSVOODOO_OEPULLUP_PORT), GPIO(BUSVOODOO_OEPULLUP_PIN)); // set pin high to disable embedded pull-up bus switch gpio_set_mode(GPIO(BUSVOODOO_OEPULLUP_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_OEPULLUP_PIN)); // set pin as output (open-drain pulled high to disable the bus switch) +#else + gpio_set_mode(GPIO_PORT(BUSVOODOO_I2C_PULLUP_PIN), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO_PIN(BUSVOODOO_I2C_PULLUP_PIN)); // per default don't drive to pull up +#endif // disable all signal I/O outputs for (uint8_t pin=0; pin. * */ -/** BusVoodoo global definitions and methods (API) - * @file busvoodoo_global.h +/** BusVoodoo global definitions and methods + * @file * @author King Kévin - * @date 2018 + * @date 2018-2020 * @note peripherals used: time @ref busvoodoo_led_timer */ #pragma once #include "menu.h" +#if BUSVOODOO_HARDWARE_VERSION != 2 /** @defgroup busvoodoo_voltages pin to control voltage regulators and pull-ups definitions * @{ */ @@ -39,8 +40,8 @@ /** @defgroup busvoodoo_adc ADC inputs to measure voltages from voltage regulators * @{ */ -#define BUSVOODOO_3V3_CHANNEL 12 /**< ADC channel to measure 5V rail */ -#define BUSVOODOO_5V_CHANNEL 9 /**< ADC channel to measure 3.3V rail */ +#define BUSVOODOO_3V3_CHANNEL 12 /**< ADC channel to measure 3.3VV rail */ +#define BUSVOODOO_5V_CHANNEL 9 /**< ADC channel to measure 5V rail */ #define BUSVOODOO_LV_CHANNEL 11 /**< ADC channel to measure LV rail */ #define BUSVOODOO_HV_CHANNEL 15 /**< ADC channel to measure HV rail */ /** @} */ @@ -88,7 +89,7 @@ #define BUSVOODOO_RS485_RX_PIN 3 /**< RS-485 Receive input pin */ /** @} */ -#if BUSVOODOO_HARDWARE_VERSION!=0 +#if BUSVOODOO_HARDWARE_VERSION != 0 /** @defgroup busvoodoo_can CAN transceiver connection definition * @{ */ @@ -99,7 +100,16 @@ #define BUSVOODOO_CAN_RX_PORT B /**< CAN Receive input pin */ #define BUSVOODOO_CAN_RX_PIN 8 /**< CAN Receive input pin */ /** @} */ -#endif +#endif // BUSVOODOO_HARDWARE_VERSION != 0 +#else // BUSVOODOO_HARDWARE_VERSION != 2 +/** pin to directly pull up I²C lines (resistors are optional) */ +#define BUSVOODOO_I2C_PULLUP_PIN PA15 +/** @defgroup busvoodoo_adc ADC inputs to measure voltages + * @{ + */ +#define BUSVOODOO_ADC_CHANNEL 9 /**< ADC channel to measure ADC input */ +/** @} */ +#endif // BUSVOODOO_HARDWARE_VERSION != 2 /** @defgroup busvoodoo_version ADC pin used to identify hardware version based on voltage */ @@ -147,15 +157,19 @@ extern char busvoodoo_version; extern const struct menu_command_t busvoodoo_global_commands[]; /** number supported commands for base BusVoodoo */ extern const uint8_t busvoodoo_global_commands_nb; +#if BUSVOODOO_HARDWARE_VERSION != 2 /** list of supported commands for BusVoodoo full only */ extern const struct menu_command_t busvoodoo_global_full_commands[]; /** number supported commands for BusVoodoo full only */ extern const uint8_t busvoodoo_global_full_commands_nb; +#endif /** I/O connector pinout */ extern const char* busvoodoo_global_pinout_io[10]; +#if BUSVOODOO_HARDWARE_VERSION != 2 /** RS/CAN connector pinout */ extern const char* busvoodoo_global_pinout_rscan[5]; +#endif /** shared string buffer, i.e. used when configuring modes */ extern char busvoodoo_global_string[64]; @@ -169,16 +183,18 @@ void busvoodoo_safe_state(void); * @note uses ANSII escape codes */ void busvoodoo_text_style(enum busvoodoo_text_style_t style); -/** switch 3V3 and 5V power outputs on I/O connector - * @param[in] on switch on (true) or off (false) power output - * @return if switching succeeded. else it means there is a probably a short on one of the outputs - */ -bool busvoodoo_vout_switch(bool on); /** read voltage from power rail * @param[in] channel which power rail to read voltage from @ref busvoodoo_adc * @return voltage, or NaN if channel is invalid (or error happened) */ float busvoodoo_vreg_get(uint8_t channel); + +#if BUSVOODOO_HARDWARE_VERSION != 2 +/** switch 3V3 and 5V power outputs on I/O connector + * @param[in] on switch on (true) or off (false) power output + * @return if switching succeeded. else it means there is a probably a short on one of the outputs + */ +bool busvoodoo_vout_switch(bool on); /** set voltage on low voltage adjustable voltage regulator * @note for voltages above 4.85V it will use the 5.0V from USB * @param[in] voltage voltage to set on adjustable voltage regulator (0, 0.3-4.8, 5V) @@ -190,12 +206,14 @@ float busvoodoo_lv_set(float voltage); * @return voltage output, or NaN if error happened */ float busvoodoo_hv_set(float voltage); +#endif // BUSVOODOO_HARDWARE_VERSION != 2 /** enable embedded pull-up resistors * @note the embedded pull-up resistor use the voltage on the LV power rail (set or externally provided) * @param[in] on enable (true) or disable (false) embedded pull-up resistors * @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