busvoodoo_global: minor, add spaces around operators
This commit is contained in:
parent
01aefc2e19
commit
f28bf07f78
|
@ -13,9 +13,9 @@
|
|||
*
|
||||
*/
|
||||
/** BusVoodoo global definitions and methods (code)
|
||||
* @file busvoodoo_global.c
|
||||
* @file
|
||||
* @author King Kévin <kingkevin@cuvoodoo.info>
|
||||
* @date 2018
|
||||
* @date 2018-2020
|
||||
* @note peripherals used: time @ref busvoodoo_led_timer
|
||||
*/
|
||||
|
||||
|
@ -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, 0.0}; // 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};
|
||||
|
@ -126,18 +126,18 @@ void busvoodoo_setup(void)
|
|||
// find out version of the board
|
||||
gpio_set_mode(GPIO(BUSVOODOO_HW_VERSION_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO(BUSVOODOO_HW_VERSION_PIN)); // use pull up and down to check if a voltage divider is present on the pin
|
||||
gpio_set(GPIO(BUSVOODOO_HW_VERSION_PORT), GPIO(BUSVOODOO_HW_VERSION_PIN)); // pull up
|
||||
bool version_up = (0!=gpio_get(GPIO(BUSVOODOO_HW_VERSION_PORT), GPIO(BUSVOODOO_HW_VERSION_PIN))); // check if the signal is still up
|
||||
bool version_up = (0 != gpio_get(GPIO(BUSVOODOO_HW_VERSION_PORT), GPIO(BUSVOODOO_HW_VERSION_PIN))); // check if the signal is still up
|
||||
gpio_clear(GPIO(BUSVOODOO_HW_VERSION_PORT), GPIO(BUSVOODOO_HW_VERSION_PIN)); // pull down
|
||||
bool version_down = (0==gpio_get(GPIO(BUSVOODOO_HW_VERSION_PORT), GPIO(BUSVOODOO_HW_VERSION_PIN))); // check if the signal is still down
|
||||
bool version_down = (0 == gpio_get(GPIO(BUSVOODOO_HW_VERSION_PORT), GPIO(BUSVOODOO_HW_VERSION_PIN))); // check if the signal is still down
|
||||
gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_HW_VERSION_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_HW_VERSION_CHANNEL)); // put back to analog input
|
||||
// get version
|
||||
if (version_up && version_down) { // no voltage divider on pin
|
||||
busvoodoo_version = '0'; // the pin is floating only for version 0 (= revision 18)
|
||||
} else { // voltage divider on pin
|
||||
float version_voltage = busvoodoo_vreg_get(BUSVOODOO_HW_VERSION_CHANNEL); // measure hardware version voltage
|
||||
for (uint8_t i=0; i<LENGTH(busvoodoo_version_voltages); i++) { // go through expected version voltages
|
||||
if (version_voltage>busvoodoo_version_voltages[i]-0.2 && version_voltage<busvoodoo_version_voltages[i]+0.2) { // verify if voltage matches
|
||||
busvoodoo_version = 'A'+i; // remember version name for matching voltage
|
||||
for (uint8_t i = 0; i < LENGTH(busvoodoo_version_voltages); i++) { // go through expected version voltages
|
||||
if (version_voltage > busvoodoo_version_voltages[i] - 0.2 && version_voltage < busvoodoo_version_voltages[i] + 0.2) { // verify if voltage matches
|
||||
busvoodoo_version = 'A' + i; // remember version name for matching voltage
|
||||
break; // stop searching
|
||||
}
|
||||
}
|
||||
|
@ -162,11 +162,11 @@ void busvoodoo_setup(void)
|
|||
rcc_periph_clock_enable(RCC_TIM(BUSVOODOO_LED_TIMER)); // enable clock for timer domain
|
||||
rcc_periph_reset_pulse(RST_TIM(BUSVOODOO_LED_TIMER)); // reset timer state
|
||||
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), 3296-1); // set prescaler to allow 3/3 seconds PWM output (72MHz/2^16/3296=0.33Hz)
|
||||
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
|
||||
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_PORT(LED_PIN), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO_PIN(LED_PIN)); // set LED pin to floating to disable both LEDs
|
||||
|
@ -203,7 +203,7 @@ void busvoodoo_safe_state(void)
|
|||
#endif
|
||||
|
||||
// disable all signal I/O outputs
|
||||
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
|
||||
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_FLOAT, busvoodoo_io_pins[pin]); // set pin back to input (floating)
|
||||
}
|
||||
|
||||
|
@ -260,9 +260,9 @@ void busvoodoo_text_style(enum busvoodoo_text_style_t style)
|
|||
float busvoodoo_vreg_get(uint8_t channel)
|
||||
{
|
||||
#if BUSVOODOO_HARDWARE_VERSION != 2
|
||||
if (channel!=BUSVOODOO_5V_CHANNEL && channel!=BUSVOODOO_3V3_CHANNEL && channel!=BUSVOODOO_LV_CHANNEL && channel!=BUSVOODOO_HV_CHANNEL && channel!=BUSVOODOO_HW_VERSION_CHANNEL) { // check channel
|
||||
if (channel != BUSVOODOO_5V_CHANNEL && channel != BUSVOODOO_3V3_CHANNEL && channel != BUSVOODOO_LV_CHANNEL && channel != BUSVOODOO_HV_CHANNEL && channel != BUSVOODOO_HW_VERSION_CHANNEL) { // check channel
|
||||
#else
|
||||
if (channel != BUSVOODOO_ADC_CHANNEL && channel!=BUSVOODOO_HW_VERSION_CHANNEL) { // check channel
|
||||
if (channel != BUSVOODOO_ADC_CHANNEL && channel != BUSVOODOO_HW_VERSION_CHANNEL) { // check channel
|
||||
#endif
|
||||
return NAN;
|
||||
}
|
||||
|
@ -312,20 +312,20 @@ float busvoodoo_vreg_get(uint8_t channel)
|
|||
switch (channel) { // get converted value and calculate according to the voltage divider on this channel
|
||||
#if BUSVOODOO_HARDWARE_VERSION != 2
|
||||
case BUSVOODOO_5V_CHANNEL:
|
||||
to_return = desired_value/(10.0/(10.0+10.0));
|
||||
to_return = desired_value / (10.0 / (10.0 + 10.0));
|
||||
break;
|
||||
case BUSVOODOO_3V3_CHANNEL:
|
||||
to_return = desired_value/(10.0/(10.0+10.0));
|
||||
to_return = desired_value / (10.0 / (10.0 + 10.0));
|
||||
break;
|
||||
case BUSVOODOO_LV_CHANNEL:
|
||||
to_return = desired_value/(10.0/(10.0+10.0));
|
||||
to_return = desired_value / (10.0 / (10.0 + 10.0));
|
||||
break;
|
||||
case BUSVOODOO_HV_CHANNEL:
|
||||
to_return = desired_value/(1.5/(10.0+1.5));
|
||||
to_return = desired_value / (1.5 / (10.0 + 1.5));
|
||||
break;
|
||||
#else
|
||||
case BUSVOODOO_ADC_CHANNEL:
|
||||
to_return = desired_value/(1.5/(10.0+1.5));
|
||||
to_return = desired_value / (1.5 / (10.0 + 1.5));
|
||||
break;
|
||||
#endif
|
||||
case BUSVOODOO_HW_VERSION_CHANNEL:
|
||||
|
@ -336,7 +336,7 @@ float busvoodoo_vreg_get(uint8_t channel)
|
|||
break;
|
||||
}
|
||||
if (!isnan(to_return)) {
|
||||
to_return *= 1.2/internal_value; // calculate voltage from converted values using internal 1.2V voltage reference
|
||||
to_return *= 1.2 / internal_value; // calculate voltage from converted values using internal 1.2V voltage reference
|
||||
}
|
||||
return to_return;
|
||||
}
|
||||
|
@ -353,11 +353,11 @@ bool busvoodoo_vout_switch(bool on)
|
|||
bool to_return = true;
|
||||
sleep_ms(1); // wait a bit for voltage to settle
|
||||
float voltage = busvoodoo_vreg_get(BUSVOODOO_5V_CHANNEL); // get 5V power rail voltage
|
||||
if (voltage<4.0 || voltage>5.5) {
|
||||
if (voltage < 4.0 || voltage > 5.5) {
|
||||
to_return = false; // voltage output is not ok
|
||||
}
|
||||
voltage = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get 3.3V power rail voltage
|
||||
if (voltage<3.0 || voltage>3.6) {
|
||||
if (voltage < 3.0 || voltage > 3.6) {
|
||||
to_return = true; // voltage output is not ok
|
||||
}
|
||||
return to_return;
|
||||
|
@ -366,11 +366,11 @@ bool busvoodoo_vout_switch(bool on)
|
|||
float busvoodoo_lv_set(float voltage)
|
||||
{
|
||||
float volt = NAN; // common variable for voltages
|
||||
if (voltage<=0.3) { // disable voltage regulator
|
||||
if (voltage <= 0.3) { // disable voltage regulator
|
||||
gpio_clear(GPIO(BUSVOODOO_LVEN_PORT), GPIO(BUSVOODOO_LVEN_PIN)); // disable LV voltage regulator
|
||||
dac_disable(BUSVOODOO_LVCTL_CHANNEL); // disable LV control
|
||||
} else { // enable voltage regulator
|
||||
if (voltage>4.85) { // use the 5V directly
|
||||
if (voltage > 4.85) { // use the 5V directly
|
||||
gpio_clear(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO(BUSVOODOO_5VPULLUP_PIN)); // put 5V on LV line
|
||||
} else { // use adjustable voltage regulator (5.0V rail minus LDO and diodes)
|
||||
gpio_set(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO(BUSVOODOO_5VPULLUP_PIN)); // disable 5V input
|
||||
|
@ -378,7 +378,7 @@ float busvoodoo_lv_set(float voltage)
|
|||
if (isnan(voltage)) {
|
||||
return NAN;
|
||||
}
|
||||
uint16_t dac_set = BUSVOODOO_LV_SET(voltage)/volt*4095; // DAC value corresponding to the voltage
|
||||
uint16_t dac_set = BUSVOODOO_LV_SET(voltage) / volt * 4095; // DAC value corresponding to the voltage
|
||||
dac_load_data_buffer_single(dac_set, RIGHT12, BUSVOODOO_LVCTL_CHANNEL); // set output so the voltage regulator is set to 2.5V
|
||||
dac_software_trigger(BUSVOODOO_LVCTL_CHANNEL); // transfer the value to the DAC
|
||||
dac_enable(BUSVOODOO_LVCTL_CHANNEL); // enable DAC
|
||||
|
@ -398,18 +398,18 @@ float busvoodoo_hv_set(float voltage)
|
|||
}
|
||||
|
||||
float volt = NAN; // common variable for voltages
|
||||
if (voltage<3.29) { // disable voltage regulator
|
||||
if (voltage < 3.29) { // disable voltage regulator
|
||||
gpio_set(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)); // disable HV voltage regulator
|
||||
dac_disable(BUSVOODOO_HVCTL_CHANNEL); // disable HV control
|
||||
} else {
|
||||
if (voltage>24.0) { // enforce upper voltage limit (diodes limit is 30V, ADC input limit is 25V)
|
||||
if (voltage > 24.0) { // enforce upper voltage limit (diodes limit is 30V, ADC input limit is 25V)
|
||||
voltage = 24.0;
|
||||
}
|
||||
volt = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get reference voltage
|
||||
if (isnan(voltage)) {
|
||||
return NAN;
|
||||
}
|
||||
uint16_t dac_set = BUSVOODOO_HV_SET(voltage)/volt*4095; // DAC value corresponding to the voltage
|
||||
uint16_t dac_set = BUSVOODOO_HV_SET(voltage) / volt * 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
|
||||
|
@ -446,10 +446,10 @@ float busvoodoo_embedded_pullup(bool on)
|
|||
static void busvoodoo_leds_update(void)
|
||||
{
|
||||
// handle LED timer
|
||||
if (busvoodoo_global_led_blue_timer && 0==busvoodoo_global_led_blue_timeout) { // timer reached timeout
|
||||
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
|
||||
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
|
||||
|
@ -457,13 +457,13 @@ static void busvoodoo_leds_update(void)
|
|||
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
|
||||
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_PORT(LED_PIN), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_PIN(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
|
||||
} 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_PORT(LED_PIN), GPIO_PIN(LED_PIN)); // switch only blue LED on
|
||||
gpio_set_mode(GPIO_PORT(LED_PIN), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_PIN(LED_PIN)); // set LED pin as push-pull to drive either LED
|
||||
|
@ -520,7 +520,7 @@ 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
|
||||
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
|
||||
|
@ -529,7 +529,7 @@ static void busvoodoo_led_pulse_setup(void)
|
|||
|
||||
void busvoodoo_led_blue_pulse(uint32_t ms)
|
||||
{
|
||||
if (0==ms) { // disable LED
|
||||
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 {
|
||||
|
@ -542,7 +542,7 @@ void busvoodoo_led_blue_pulse(uint32_t ms)
|
|||
|
||||
void busvoodoo_led_red_pulse(uint32_t ms)
|
||||
{
|
||||
if (0==ms) { // disable LED
|
||||
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 {
|
||||
|
@ -558,13 +558,13 @@ 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
|
||||
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
|
||||
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
|
||||
if (0 == busvoodoo_global_led_blue_timeout || 0 == busvoodoo_global_led_red_timeout) { // a timeout occured
|
||||
busvoodoo_leds_update(); // update LED status
|
||||
}
|
||||
}
|
||||
|
@ -572,7 +572,7 @@ void tim1_up_isr(void)
|
|||
|
||||
void busvoodoo_leds_blink(double period, double duty)
|
||||
{
|
||||
if (period<0.0 || period>6.0 || duty<0.0 || duty>1.0) { // input argument out of bounds
|
||||
if (period < 0.0 || period > 6.0 || duty < 0.0 || duty > 1.0) { // input argument out of bounds
|
||||
return; // do nothing
|
||||
}
|
||||
timer_disable_counter(TIM(BUSVOODOO_LED_TIMER)); // disable timer while reconfiguring
|
||||
|
@ -595,8 +595,8 @@ void busvoodoo_leds_blink(double period, double duty)
|
|||
} else {
|
||||
gpio_set_mode(GPIO_PORT(LED_PIN), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_PIN(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_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
|
||||
}
|
||||
}
|
||||
|
@ -628,11 +628,11 @@ bool busvoodoo_global_actions(char* actions, bool perform, bool (*action_handler
|
|||
{
|
||||
char* action_start = actions; // start of the current action
|
||||
bool last_action = false; // is the current action the last one
|
||||
while ('\0'!=*action_start && !last_action) {
|
||||
while ('\0' != *action_start && !last_action) {
|
||||
// find end of action
|
||||
char* action_end = action_start+1;
|
||||
if ('"'==*action_start || '\''==*action_start) { // start of string
|
||||
while ('\0'!=*action_end && *action_end!=*action_start) {
|
||||
char* action_end = action_start + 1;
|
||||
if ('"' == *action_start || '\'' == *action_start) { // start of string
|
||||
while ('\0' != *action_end && *action_end != *action_start) {
|
||||
action_end++;
|
||||
}
|
||||
if (*action_end!=*action_start) { // action not ended correctly
|
||||
|
@ -640,33 +640,33 @@ bool busvoodoo_global_actions(char* actions, bool perform, bool (*action_handler
|
|||
}
|
||||
action_end++; // go the end of action
|
||||
} else { // just look for a separation
|
||||
while ('\0'!=*action_end && ':'!=*action_end && ' '!=*action_end && ','!=*action_end) {
|
||||
while ('\0' != *action_end && ':' != *action_end && ' ' != *action_end && ',' != *action_end) {
|
||||
action_end++;
|
||||
}
|
||||
}
|
||||
// find start of next action
|
||||
char *separation = action_end; // position of separation to next action
|
||||
while ('\0'!=*separation && ' '!=*separation && ','!=*separation) { // find separation or end
|
||||
while ('\0' != *separation && ' ' != *separation && ',' != *separation) { // find separation or end
|
||||
separation++;
|
||||
}
|
||||
if ('\0'==*separation) {
|
||||
if ('\0' == *separation) {
|
||||
last_action = true; // remember we reached the end of the string
|
||||
} else {
|
||||
*separation = '\0'; // end the action to form a string
|
||||
}
|
||||
// get multiplier
|
||||
uint32_t multiplier = 1; // the number of times the action should be performed
|
||||
if (separation>action_end) { // there is something after the action
|
||||
if (':'==*action_end) { // multiplier sign found
|
||||
if (separation==action_end+1) { // no digit present
|
||||
if (separation > action_end) { // there is something after the action
|
||||
if (':' == *action_end) { // multiplier sign found
|
||||
if (separation == action_end + 1) { // no digit present
|
||||
return false; // malformed action
|
||||
}
|
||||
for (char* digit=action_end+1; digit<separation; digit++) { // check if all the characters are digits
|
||||
if (*digit<'0' || *digit>'9') { // not a digit
|
||||
for (char* digit = action_end + 1; digit < separation; digit++) { // check if all the characters are digits
|
||||
if (*digit < '0' || *digit > '9') { // not a digit
|
||||
return false; // malformed string
|
||||
}
|
||||
}
|
||||
multiplier = strtol(action_end+1, NULL, 10); // parse multiplier number
|
||||
multiplier = strtol(action_end + 1, NULL, 10); // parse multiplier number
|
||||
} else { // unknown sign after action
|
||||
return false; // malformed action
|
||||
}
|
||||
|
@ -678,7 +678,7 @@ bool busvoodoo_global_actions(char* actions, bool perform, bool (*action_handler
|
|||
}
|
||||
// go to next action
|
||||
if (!last_action) {
|
||||
action_start = separation+1;
|
||||
action_start = separation + 1;
|
||||
}
|
||||
}
|
||||
return true; // all went well
|
||||
|
@ -693,13 +693,13 @@ bool busvoodoo_global_actions(char* actions, bool perform, bool (*action_handler
|
|||
static void busvoodoo_global_power(void* argument)
|
||||
{
|
||||
float voltage;
|
||||
if (NULL==argument || 0==strlen(argument)) {
|
||||
if (NULL == argument || 0 == strlen(argument)) {
|
||||
if (gpio_get(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN))) { // check if power rails are switch on (enable low)
|
||||
goto power_off;
|
||||
} else {
|
||||
goto power_on;
|
||||
}
|
||||
} else if (0==strcmp(argument, "on")) {
|
||||
} else if (0 == strcmp(argument, "on")) {
|
||||
if (busvoodoo_vout_switch(true)) { // switch power rail on
|
||||
printf("power rails switched on\n");
|
||||
} else {
|
||||
|
@ -710,7 +710,7 @@ power_on:
|
|||
printf("5V power rail: %.2fV\n", voltage);
|
||||
voltage = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get 3.3V power rail voltage
|
||||
printf("3V3 power rail: %.2fV\n", voltage);
|
||||
} else if (0==strcmp(argument, "off")) {
|
||||
} else if (0 == strcmp(argument, "off")) {
|
||||
busvoodoo_vout_switch(false); // switch power rail off
|
||||
printf("power rails switched off\n");
|
||||
power_off:
|
||||
|
@ -727,7 +727,7 @@ power_off:
|
|||
*/
|
||||
static void busvoodoo_global_lv(void* argument)
|
||||
{
|
||||
if (NULL==argument) {
|
||||
if (NULL == argument) {
|
||||
if (!gpio_get(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO(BUSVOODOO_5VPULLUP_PIN))) { // 5V input enabled
|
||||
printf("5V power rail used");
|
||||
} else if (gpio_get(GPIO(BUSVOODOO_LVEN_PORT), GPIO(BUSVOODOO_LVEN_PIN))) { // LV voltage regulator used
|
||||
|
@ -744,7 +744,7 @@ static void busvoodoo_global_lv(void* argument)
|
|||
}
|
||||
} else {
|
||||
double voltage = *((double*)argument); // get desired voltage
|
||||
if (0==voltage) {
|
||||
if (0 == voltage) {
|
||||
printf("LV rail switched off");
|
||||
} else {
|
||||
printf("LV rail set to %.2fV", voltage);
|
||||
|
@ -769,7 +769,7 @@ static void busvoodoo_global_hv(void* argument)
|
|||
printf("function not available on BusVoodoo light");
|
||||
return;
|
||||
}
|
||||
if (NULL==argument) {
|
||||
if (NULL == argument) {
|
||||
printf("high voltage regulator switched %s: ", gpio_get(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)) ? "off" : "on");
|
||||
float voltage = busvoodoo_vreg_get(BUSVOODOO_HV_CHANNEL); // get HV voltage
|
||||
// print LV voltage
|
||||
|
@ -781,7 +781,7 @@ static void busvoodoo_global_hv(void* argument)
|
|||
} else {
|
||||
double voltage = *((double*)argument); // get desired voltage
|
||||
printf("high voltage rail ");
|
||||
if (voltage<=3.3) {
|
||||
if (voltage <= 3.3) {
|
||||
printf("switched off");
|
||||
} else {
|
||||
printf("set to %.2fV", voltage);
|
||||
|
@ -826,32 +826,32 @@ static void busvoodoo_global_pinout(void* argument)
|
|||
// display RS/CAN connector pinout
|
||||
if (busvoodoo_full) { // only display on full version of the board
|
||||
bool pin_used = false; // if no pins are used
|
||||
for (uint8_t i=0; i<LENGTH(busvoodoo_global_pinout_rscan); i++) { // verify if one of the pins is used
|
||||
pin_used |= (NULL!=busvoodoo_global_pinout_rscan[i]); // verify if pin is used
|
||||
for (uint8_t i = 0; i < LENGTH(busvoodoo_global_pinout_rscan); i++) { // verify if one of the pins is used
|
||||
pin_used |= (NULL != busvoodoo_global_pinout_rscan[i]); // verify if pin is used
|
||||
}
|
||||
if (pin_used) {
|
||||
// count the space used to display the pins
|
||||
uint8_t space = 0; // no integer overflow protected (it's only cosmetic)
|
||||
for (uint8_t i=0; i<LENGTH(busvoodoo_global_pinout_rscan); i++) {
|
||||
if (NULL==busvoodoo_global_pinout_rscan[i]) {
|
||||
for (uint8_t i = 0; i<LENGTH(busvoodoo_global_pinout_rscan); i++) {
|
||||
if (NULL == busvoodoo_global_pinout_rscan[i]) {
|
||||
space += 1; // only x will be shown
|
||||
} else {
|
||||
space += strlen(busvoodoo_global_pinout_rscan[i]); // add size of pin name
|
||||
}
|
||||
}
|
||||
space += LENGTH(busvoodoo_global_pinout_rscan)-1; // add the spaces between the names
|
||||
space += LENGTH(busvoodoo_global_pinout_rscan) - 1; // add the spaces between the names
|
||||
// display pinout
|
||||
printf("RS/CAN connector pinout:\n");
|
||||
// display top line
|
||||
printf("+");
|
||||
for (uint8_t i=0; i<space; i++) {
|
||||
for (uint8_t i = 0; i < space; i++) {
|
||||
printf("-");
|
||||
}
|
||||
printf("+\n");
|
||||
// display pin names
|
||||
printf("|");
|
||||
for (int8_t i=LENGTH(busvoodoo_global_pinout_rscan)-1; i>=0; i--) {
|
||||
if (NULL==busvoodoo_global_pinout_rscan[i]) {
|
||||
for (int8_t i = LENGTH(busvoodoo_global_pinout_rscan) - 1; i >= 0; i--) {
|
||||
if (NULL == busvoodoo_global_pinout_rscan[i]) {
|
||||
printf("x"); // x stands for pin not used
|
||||
} else {
|
||||
printf("%s", busvoodoo_global_pinout_rscan[i]); // print pin name
|
||||
|
@ -863,7 +863,7 @@ static void busvoodoo_global_pinout(void* argument)
|
|||
printf("|\n");
|
||||
// display bottom line
|
||||
printf("+");
|
||||
for (uint8_t i=0; i<space; i++) {
|
||||
for (uint8_t i = 0; i < space; i++) {
|
||||
printf("-");
|
||||
}
|
||||
printf("+\n");
|
||||
|
@ -874,25 +874,25 @@ static void busvoodoo_global_pinout(void* argument)
|
|||
|
||||
// display I/O connector pinout
|
||||
bool pin_used = false; // if no pins are used
|
||||
for (uint8_t i=0; i<LENGTH(busvoodoo_global_pinout_io); i++) { // verify if one of the pins is used
|
||||
pin_used |= (NULL!=busvoodoo_global_pinout_io[i]); // verify if pin is used
|
||||
for (uint8_t i = 0; i < LENGTH(busvoodoo_global_pinout_io); i++) { // verify if one of the pins is used
|
||||
pin_used |= (NULL != busvoodoo_global_pinout_io[i]); // verify if pin is used
|
||||
}
|
||||
if (pin_used) {
|
||||
// count the space used to display the pins (no integer overflow protected, it's only cosmetic)
|
||||
uint8_t spaces[5] = {0}; // maximum spaces used by top and bottom pins
|
||||
for (uint8_t i=0; i<LENGTH(spaces); i++) {
|
||||
if (NULL==busvoodoo_global_pinout_io[i*2]) {
|
||||
for (uint8_t i = 0; i < LENGTH(spaces); i++) {
|
||||
if (NULL == busvoodoo_global_pinout_io[i * 2]) {
|
||||
spaces[i] = 1; // only x will be shown
|
||||
} else {
|
||||
spaces[i] = strlen(busvoodoo_global_pinout_io[i*2]); // remember size of pin name
|
||||
spaces[i] = strlen(busvoodoo_global_pinout_io[i * 2]); // remember size of pin name
|
||||
}
|
||||
if (NULL==busvoodoo_global_pinout_io[i*2+1]) {
|
||||
if (spaces[i]<1) {
|
||||
if (NULL == busvoodoo_global_pinout_io[i * 2 + 1]) {
|
||||
if (spaces[i] < 1) {
|
||||
spaces[i] = 1; // only x will be shown
|
||||
}
|
||||
} else {
|
||||
if (spaces[i]<strlen(busvoodoo_global_pinout_io[i*2+1])) {
|
||||
spaces[i] = strlen(busvoodoo_global_pinout_io[i*2+1]); // remember bigger size of pin name
|
||||
if (spaces[i] < strlen(busvoodoo_global_pinout_io[i * 2 + 1])) {
|
||||
spaces[i] = strlen(busvoodoo_global_pinout_io[i * 2 + 1]); // remember bigger size of pin name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -900,57 +900,57 @@ static void busvoodoo_global_pinout(void* argument)
|
|||
printf("I/O connector pinout:\n");
|
||||
// display top line
|
||||
printf("+");
|
||||
for (uint16_t i=0; i<(uint16_t)(spaces[4]+spaces[3]+1); i++) {
|
||||
for (uint16_t i = 0; i < (uint16_t)(spaces[4] + spaces[3] + 1); i++) {
|
||||
printf("-");
|
||||
}
|
||||
for (uint16_t i=0; i<(uint16_t)(spaces[2]+2); i++) {
|
||||
for (uint16_t i = 0; i < (uint16_t)(spaces[2] + 2); i++) {
|
||||
printf(" ");
|
||||
}
|
||||
for (uint16_t i=0; i<(uint16_t)(spaces[1]+spaces[0]+1); i++) {
|
||||
for (uint16_t i = 0; i < (uint16_t)(spaces[1] + spaces[0] + 1); i++) {
|
||||
printf("-");
|
||||
}
|
||||
printf("+\n");
|
||||
// display top pin names
|
||||
printf("|");
|
||||
for (int8_t i=4; i>=0; i--) {
|
||||
if (NULL==busvoodoo_global_pinout_io[i*2]) {
|
||||
for (int8_t i = 4; i >= 0; i--) {
|
||||
if (NULL == busvoodoo_global_pinout_io[i * 2]) {
|
||||
printf("x"); // x stands for pin not used
|
||||
for (int16_t j=0; j + 1 < spaces[i]; j++) {
|
||||
for (int16_t j = 0; j + 1 < spaces[i]; j++) {
|
||||
printf(" "); // pad to match to bottom pin
|
||||
}
|
||||
} else {
|
||||
printf("%s", busvoodoo_global_pinout_io[i*2]); // print pin name
|
||||
for (int16_t j=0; j+strlen(busvoodoo_global_pinout_io[i*2])<spaces[i]; j++) {
|
||||
printf("%s", busvoodoo_global_pinout_io[i * 2]); // print pin name
|
||||
for (int16_t j = 0; j + strlen(busvoodoo_global_pinout_io[i * 2]) < spaces[i]; j++) {
|
||||
printf(" "); // pad to match to bottom pin
|
||||
}
|
||||
}
|
||||
if (i>0) {
|
||||
if (i > 0) {
|
||||
printf(" "); // print space between the pin names
|
||||
}
|
||||
}
|
||||
printf("|\n");
|
||||
// display bottom pin names
|
||||
printf("|");
|
||||
for (int8_t i=4; i>=0; i--) {
|
||||
if (NULL==busvoodoo_global_pinout_io[i*2+1]) {
|
||||
for (int8_t i = 4 ; i >= 0; i--) {
|
||||
if (NULL == busvoodoo_global_pinout_io[i * 2 + 1]) {
|
||||
printf("x"); // x stands for pin not used
|
||||
for (int16_t j=0; j + 1<spaces[i]; j++) {
|
||||
for (int16_t j = 0; j + 1 < spaces[i]; j++) {
|
||||
printf(" "); // pad to match to bottom pin
|
||||
}
|
||||
} else {
|
||||
printf("%s", busvoodoo_global_pinout_io[i*2+1]); // print pin name
|
||||
for (int16_t j=0; j+strlen(busvoodoo_global_pinout_io[i*2+1])<spaces[i]; j++) {
|
||||
printf("%s", busvoodoo_global_pinout_io[i * 2 + 1]); // print pin name
|
||||
for (int16_t j = 0; j + strlen(busvoodoo_global_pinout_io[i * 2 + 1]) < spaces[i]; j++) {
|
||||
printf(" "); // pad to match to bottom pin
|
||||
}
|
||||
}
|
||||
if (i>0) {
|
||||
if (i > 0) {
|
||||
printf(" "); // print space between the pin names
|
||||
}
|
||||
}
|
||||
printf("|\n");
|
||||
// display bottom line
|
||||
printf("+");
|
||||
for (uint16_t i=0; i<spaces[4]+1+spaces[3]+1+spaces[2]+1+spaces[1]+1+spaces[0]; i++) {
|
||||
for (uint16_t i = 0; i < spaces[4] + 1 + spaces[3] + 1 + spaces[2] + 1 + spaces[1] + 1 + spaces[0]; i++) {
|
||||
printf("-");
|
||||
}
|
||||
printf("+\n");
|
||||
|
|
Loading…
Reference in New Issue