busvoodoo: add global commands to control power rails
This commit is contained in:
parent
8c983712b0
commit
5b57060802
|
@ -20,6 +20,7 @@
|
|||
|
||||
/* standard libraries */
|
||||
#include <stdint.h> // standard integer types
|
||||
#include <string.h> // string utilities
|
||||
#include <math.h> // math utilities
|
||||
|
||||
/* STM32 (including CM3) libraries */
|
||||
|
@ -30,6 +31,8 @@
|
|||
|
||||
/* own libraries */
|
||||
#include "global.h" // board definitions
|
||||
#include "menu.h" // command definitions
|
||||
#include "print.h" // print utilities
|
||||
#include "busvoodoo_global.h" // BusVoodoo definitions
|
||||
|
||||
const char* busvoodoo_io_names[13] = {"I2C_SMBA/SPI_NSS/I2S_WS", "SDIO_CMD", "USART_CTS/SPI_SCK/I2S_CK", "SDIO_D3/UART_RX", "I2C_SDA/USART_RX", "SDIO_D0", "SPI_MOSI/I2S_SD", "SDIO_CK/USART_CK", "I2C_SCL/USART_TX", "SDIO_D1", "I2S_MCK", "USART_RTS/SPI_MISO", "SDIO_D2/UART_TX"};
|
||||
|
@ -212,7 +215,7 @@ float busvoodoo_vreg_set(uint8_t channel, float voltage)
|
|||
if (voltage>4.7) { // use the 5V directly
|
||||
gpio_clear(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO(BUSVOODOO_5VPULLUP_PIN)); // put 5V on xV 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 pull-up
|
||||
gpio_set(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO(BUSVOODOO_5VPULLUP_PIN)); // disable 5V input
|
||||
volt = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get reference voltage
|
||||
if (isnan(voltage)) {
|
||||
return NAN;
|
||||
|
@ -224,12 +227,12 @@ float busvoodoo_vreg_set(uint8_t channel, float voltage)
|
|||
gpio_set(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN)); // enable xV voltage regulator
|
||||
}
|
||||
}
|
||||
sleep_ms(5); // let voltage settle
|
||||
sleep_ms(10); // let voltage settle
|
||||
volt = busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL); // get xV voltage to return
|
||||
} else if (BUSVOODOO_12V_CHANNEL==channel && busvoodoo_full) {// set voltage on 12V boost voltage regulator
|
||||
if (voltage<=0.0) { // disable voltage regulator
|
||||
if (voltage<=3.3) { // disable voltage regulator
|
||||
gpio_set(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // disable 12V voltage regulator
|
||||
dac_disable(BUSVOODOO_12VCTL_CHANNEL); // disable 12V control
|
||||
dac_disable(BUSVOODOO_12VCTL_CHANNEL); // disable 12V control
|
||||
} else {
|
||||
if (voltage>24.0) { // enforce upper voltage limit (diodes limit is 30V, ADC input limit is 25V)
|
||||
voltage = 24.0;
|
||||
|
@ -244,7 +247,7 @@ float busvoodoo_vreg_set(uint8_t channel, float voltage)
|
|||
dac_enable(BUSVOODOO_12VCTL_CHANNEL); // enable DAC
|
||||
gpio_clear(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // enable 12V voltage regulator
|
||||
}
|
||||
sleep_ms(10); // let the voltage regulator start and voltage settle
|
||||
sleep_ms(20); // let the voltage regulator start and voltage settle
|
||||
volt = busvoodoo_vreg_get(BUSVOODOO_12V_CHANNEL); // get 12V voltage
|
||||
} else { // don't know about other voltage regulators
|
||||
volt = NAN;
|
||||
|
@ -262,3 +265,136 @@ float busvoodoo_embedded_pullup(bool on)
|
|||
}
|
||||
return busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL); // set voltage on adjustable voltage regulator to be used by the embedded pull-ups
|
||||
}
|
||||
|
||||
/** switch 3V3 and 5V power rails on/off
|
||||
* @param[in] argument string: "on" to switch on, "off" to switch off, NULL to get status
|
||||
*/
|
||||
static void busvoodoo_global_power(void* argument) {
|
||||
float voltage;
|
||||
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")) {
|
||||
if (busvoodoo_vout_switch(true)) { // switch power rail on
|
||||
printf("power rails switched on\n");
|
||||
} else {
|
||||
printf("power rails switched on but malfunctioning\n");
|
||||
}
|
||||
power_on:
|
||||
voltage = busvoodoo_vreg_get(BUSVOODOO_5V_CHANNEL); // get 5V power rail voltage
|
||||
printf("5V power rail: %.2f\n", voltage);
|
||||
voltage = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get 3.3V power rail voltage
|
||||
printf("3V3 power rail: %.2f\n", voltage);
|
||||
} else if (0==strcmp(argument, "off")) {
|
||||
busvoodoo_vout_switch(false); // switch power rail off
|
||||
printf("power rails switched off\n");
|
||||
power_off:
|
||||
printf("5V power rail: off\n");
|
||||
printf("3V3 power rail: off\n");
|
||||
} else {
|
||||
printf("option malformed: %s\n", argument);
|
||||
}
|
||||
}
|
||||
|
||||
/** set xV voltage
|
||||
* @param[in] argument voltage to set (0 to switch off, NULL to get voltage)
|
||||
*/
|
||||
static void busvoodoo_global_lv(void* 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_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN))) { // xV voltage regulator used
|
||||
printf("adjustable voltage regulator used");
|
||||
} else {
|
||||
printf("external voltage input");
|
||||
}
|
||||
float voltage = busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL); // get xV voltage
|
||||
// print xV voltage
|
||||
if (voltage < 0.01) {
|
||||
printf(": 0.00V\n");
|
||||
} else {
|
||||
printf(": %.2fV\n", voltage);
|
||||
}
|
||||
} else {
|
||||
double voltage = *((double*)argument); // get desired voltage
|
||||
if (0==voltage) {
|
||||
printf("xV rail switched off");
|
||||
} else {
|
||||
printf("xV rail set to %.2fV", voltage);
|
||||
}
|
||||
voltage = busvoodoo_vreg_set(BUSVOODOO_XV_CHANNEL, voltage); // set xV voltage
|
||||
// print xV voltage
|
||||
if (voltage < 0.01) {
|
||||
printf(": 0.00V\n");
|
||||
} else {
|
||||
printf(": %.2fV\n", voltage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** set 12V voltage
|
||||
* @param[in] argument voltage to set (0 to switch off, NULL to get voltage)
|
||||
*/
|
||||
static void busvoodoo_global_hv(void* argument) {
|
||||
if (!busvoodoo_full) {
|
||||
printf("function not available on BusVoodoo light");
|
||||
return;
|
||||
}
|
||||
if (NULL==argument) {
|
||||
printf("high voltage regulator switched %s: ", gpio_get(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)) ? "off" : "on");
|
||||
float voltage = busvoodoo_vreg_get(BUSVOODOO_12V_CHANNEL); // get 12V voltage
|
||||
// print xV voltage
|
||||
if (voltage < 0.01) {
|
||||
printf(": 0.00V\n");
|
||||
} else {
|
||||
printf(": %.2fV\n", voltage);
|
||||
}
|
||||
} else {
|
||||
double voltage = *((double*)argument); // get desired voltage
|
||||
printf("high voltage rail ");
|
||||
if (voltage<=3.3) {
|
||||
printf("switched off");
|
||||
} else {
|
||||
printf("set to %.2fV", voltage);
|
||||
}
|
||||
voltage = busvoodoo_vreg_set(BUSVOODOO_12V_CHANNEL, voltage); // set 12V voltage
|
||||
// print xV voltage
|
||||
if (voltage < 0.01) {
|
||||
printf(": 0.00V\n");
|
||||
} else {
|
||||
printf(": %.2fV\n", voltage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** list of supported commands */
|
||||
const struct menu_command_t busvoodoo_global_commands[] = {
|
||||
{
|
||||
'p',
|
||||
"power",
|
||||
"switch 3V3 and 5V power rails on/off",
|
||||
MENU_ARGUMENT_STRING,
|
||||
"[on|off]",
|
||||
&busvoodoo_global_power,
|
||||
},
|
||||
{
|
||||
'l',
|
||||
"lV",
|
||||
"set voltage on low voltage power rail (0-5V)",
|
||||
MENU_ARGUMENT_FLOAT,
|
||||
"[voltage]",
|
||||
&busvoodoo_global_lv,
|
||||
},
|
||||
{
|
||||
'H',
|
||||
"HV",
|
||||
"set voltage on high voltage power rail (0, 3.3-24V)",
|
||||
MENU_ARGUMENT_FLOAT,
|
||||
"[voltage]",
|
||||
&busvoodoo_global_hv,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -97,6 +97,8 @@ extern const uint8_t busvoodoo_io_groups[13]; /**< which I/O pin (group) does th
|
|||
|
||||
/** is the BusVoodoo board fully populated (with 12V voltage regulator, RS-232, RS-485, CAN transceiver on the back side) */
|
||||
extern bool busvoodoo_full;
|
||||
/** list of supported commands */
|
||||
extern const struct menu_command_t busvoodoo_global_commands[3];
|
||||
|
||||
/** setup BusVoodoo board */
|
||||
void busvoodoo_setup(void);
|
||||
|
|
Loading…
Reference in New Issue