From 02be8b122ea4ec206fa7a7346fc59f453d17e9c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Mon, 26 Feb 2018 12:13:45 +0100 Subject: [PATCH] BV: rename revision to version --- lib/busvoodoo_global.c | 70 ++++++++++++++++++++---------------------- lib/busvoodoo_global.h | 12 ++++---- 2 files changed, 40 insertions(+), 42 deletions(-) diff --git a/lib/busvoodoo_global.c b/lib/busvoodoo_global.c index b6331f4..e170fc9 100644 --- a/lib/busvoodoo_global.c +++ b/lib/busvoodoo_global.c @@ -49,11 +49,8 @@ static volatile bool busvoodoo_global_led_blue = false; /** red LED status */ static volatile bool busvoodoo_global_led_red = false; -/** existing hardware revisions identifiable with voltages */ -static const uint8_t busvoodoo_revision_numbers[] = {27}; -/** hardware revision voltages (calculated from divider ratios) */ -static const float busvoodoo_revision_voltages[] = {100.0/(10.0+100.0)*3.3}; - +/** 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 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}; @@ -64,7 +61,7 @@ const uint32_t busvoodoo_io_pins[13] = {GPIO12, GPIO2, GPIO13, GPIO11, GPIO11, G const uint8_t busvoodoo_io_groups[13] = {6, 6, 4, 4, 1, 1, 5, 5, 2, 2, 3, 3, 3}; bool busvoodoo_full = false; -uint8_t busvoodoo_revision = 0; +char busvoodoo_version = '0'; void busvoodoo_setup(void) { @@ -76,7 +73,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) - // check if this BusVoodoo is a full version + // 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 gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_HV_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, ADC12_IN_PIN(BUSVOODOO_HV_CHANNEL)); // set HV channel as digital input with pull-up capabilities @@ -88,47 +85,47 @@ void busvoodoo_setup(void) busvoodoo_safe_state(); // also put the full version pins in safe state } - // setup ADC to measure hardware revision voltage - rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_HW_REV_CHANNEL)); // enable clock for GPIO domain for hardware revision channel - gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_HW_REV_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_HW_REV_CHANNEL)); // set hardware revision channel as analogue input for the ADC + // setup ADC to measure hardware version voltage + 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 rcc_periph_clock_enable(RCC_ADC1); // enable clock for ADC domain adc_off(ADC1); // switch off ADC while configuring it adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC); // use 28.5 cycles to sample (long enough to be stable) adc_enable_temperature_sensor(ADC1); // enable internal voltage reference adc_enable_external_trigger_regular(ADC1, ADC_CR2_EXTSEL_SWSTART); // use software trigger to start conversion - uint8_t rev_channels[] = {ADC_CHANNEL17, ADC_CHANNEL(BUSVOODOO_HW_REV_CHANNEL)}; // voltages to convert: internal, hardware revision - adc_set_regular_sequence(ADC1, LENGTH(rev_channels), rev_channels); // set channels to convert - adc_enable_discontinuous_mode_regular(ADC1, LENGTH(rev_channels)); // convert all channels + uint8_t version_channels[] = {ADC_CHANNEL17, ADC_CHANNEL(BUSVOODOO_HW_VERSION_CHANNEL)}; // voltages to convert: internal, hardware version + adc_set_regular_sequence(ADC1, LENGTH(version_channels), version_channels); // set channels to convert + adc_enable_discontinuous_mode_regular(ADC1, LENGTH(version_channels)); // convert all channels adc_power_on(ADC1); // switch on ADC sleep_us(1); // wait t_stab for the ADC to stabilize adc_reset_calibration(ADC1); // remove previous non-calibration adc_calibration(ADC1); // calibrate ADC for less accuracy errors adc_start_conversion_regular(ADC1); // start conversion to get first voltage - uint16_t channels[LENGTH(rev_channels)] = {0}; // to store the values measured on the channels + uint16_t channels[LENGTH(version_channels)] = {0}; // to store the values measured on the channels for (uint8_t channel_i=0; channel_ibusvoodoo_revision_voltages[i]-0.2 && revision_voltagebusvoodoo_version_voltages[i]-0.2 && version_voltage