stm32f1/lib/busvoodoo_global.h

150 lines
7.4 KiB
C

/* 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 global definitions and methods (API)
* @file busvoodoo_global.h
* @author King Kévin <kingkevin@cuvoodoo.info>
* @date 2018
* @note peripherals used: time @ref busvoodoo_led_timer
*/
/** @defgroup busvoodoo_voltages pin to control voltage regulators and pull-ups definitions
* @{
*/
#define BUSVOODOO_5VPULLUP_PORT B /**< 5V pull-up enable pin (active low) */
#define BUSVOODOO_5VPULLUP_PIN 4 /**< 5V pull-up enable pin (active low) */
#define BUSVOODOO_OEPULLUP_PORT A /**< bus switch output enable pin to enable embedded pull-ups (active low) */
#define BUSVOODOO_OEPULLUP_PIN 15 /**< bus switch output enable pin to enable embedded pull-ups (active low) */
#define BUSVOODOO_XVEN_PORT A /**< xV enable pin (active high) */
#define BUSVOODOO_XVEN_PIN 6 /**< xV enable pin (active high) */
#define BUSVOODOO_12VEN_PORT A /**< 12V enable pin (active low) */
#define BUSVOODOO_12VEN_PIN 7 /**< 12V enable pin (active low) */
#define BUSVOODOO_VOUTEN_PORT B /**< voltage output (5V and 3.3V) enable pin (active low) */
#define BUSVOODOO_VOUTEN_PIN 3 /**< voltage output (5V and 3.3V) enable pin (active low) */
/** @} */
/** @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_XV_CHANNEL 11 /**< ADC channel to measure xV rail */
#define BUSVOODOO_12V_CHANNEL 15 /**< ADC channel to measure 12V rail */
/** @} */
/** @defgroup busvoodoo_dac DAC output to set voltages of voltage regulators
* @{
*/
#define BUSVOODOO_XVCTL_PORT A /**< pin to control xV output voltage */
#define BUSVOODOO_XVCTL_PIN 4 /**< pin to control xV output voltage */
#define BUSVOODOO_XVCTL_CHANNEL CHANNEL_1 /**< DAC channel to control xV output voltage */
#define BUSVOODOO_XV_SET(x) ((0.8*(1+30.0/10.0)-x)*(10.0/30.0)+0.8) /**< voltage to output for the DAC to set the desired xV output voltage (based on resistor values on the xV adjust pins and xV voltage reference) */
#define BUSVOODOO_12VCTL_PORT A /**< pin to control 12V output voltage */
#define BUSVOODOO_12VCTL_PIN 5 /**< pin to control 12V output voltage */
#define BUSVOODOO_12VCTL_CHANNEL CHANNEL_2 /**< DAC channel to control 12V output voltage */
#define BUSVOODOO_12V_SET(x) ((1.25*(1+100.0/10.0)-x)*(10.0/100.0)+1.25) /**< voltage to output for the DAC to set the desired
12V output voltage (based on resistor values on the 12V adjust pins and 12V voltage reference) */
/** @} */
/** @defgroup busvoodoo_rs232 RS-232 transceiver connection definition
* @{
*/
#define BUSVOODOO_RS232_EN_PORT B /**< RS-232 pin to enable receiver (active low, pulled up) */
#define BUSVOODOO_RS232_EN_PIN 5 /**< RS-232 pin to enable receiver (active low, pulled up) */
#define BUSVOODOO_RS232_SHDN_PORT C /**< RS-232 pin to enable transmitter (active high, pulled low) */
#define BUSVOODOO_RS232_SHDN_PIN 15 /**< RS-232 pin to enable transmitter (active high, pulled low) */
#define BUSVOODOO_RS232_RTS_PORT A /**< RS-232 Request-To-Send output pin */
#define BUSVOODOO_RS232_RTS_PIN 1 /**< RS-232 Request-To-Send output pin */
#define BUSVOODOO_RS232_CTS_PORT A /**< RS-232 Clear-To-Send input pin */
#define BUSVOODOO_RS232_CTS_PIN 0 /**< RS-232 Clear-To-Send input pin */
#define BUSVOODOO_RS232_TX_PORT A /**< RS-232 Transmit output pin */
#define BUSVOODOO_RS232_TX_PIN 2 /**< RS-232 Transmit output pin */
#define BUSVOODOO_RS232_RX_PORT A /**< RS-232 Receive input pin */
#define BUSVOODOO_RS232_RX_PIN 3 /**< RS-232 Receive input pin */
/** @} */
/** @defgroup busvoodoo_can CAN transceiver connection definition
* @{
*/
#define BUSVOODOO_CAN_EN_PORT C /**< CAN pin to enable transceiver (active high, pulled low) */
#define BUSVOODOO_CAN_EN_PIN 14 /**< CAN pin to enable transceiver (active high, pulled low) */
#define BUSVOODOO_CAN_S_PORT C /**< CAN pin to set to silent mode (active low, pulled high) */
#define BUSVOODOO_CAN_S_PIN 13 /**< CAN pin to set to silent mode (active low, pulled high) */
#define BUSVOODOO_CAN_TX_PORT B /**< CAN Transmit output pin */
#define BUSVOODOO_CAN_TX_PIN 9 /**< CAN Transmit output pin */
#define BUSVOODOO_CAN_RX_PORT B /**< CAN Receive input pin */
#define BUSVOODOO_CAN_RX_PIN 8 /**< CAN Receive input pin */
/** @} */
/** BusVoodoo mode interface */
struct busvoodoo_mode_t {
const char* name;
const char* description;
bool (*setup)(char** prefix, const char* line);
const struct menu_command_t* commands;
const uint8_t commands_nb;
void (*exit)(void);
};
/** @defgroup busvoodoo_io I/O connector pin definition
* @{
*/
extern const char* busvoodoo_io_names[13]; /**< I/O individual signal names */
extern const uint32_t busvoodoo_io_ports[13]; /**< port of individual signals */
extern const uint32_t busvoodoo_io_pins[13]; /**< pin of individual signals */
extern const uint8_t busvoodoo_io_groups[13]; /**< which I/O pin (group) does the signal belong to */
/** @} */
/** 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);
/** set safe state by disabling all outputs */
void busvoodoo_safe_state(void);
/** 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);
/** set voltage on adjustable voltage regulator
* @warning only xV and 12V are adjustable voltage regulators
* @note for voltages above 4.7V on xV it will use the 5.0V from USB
* @param[in] channel which voltage regulator to set voltage on @ref busvoodoo_adc
* @param[in] voltage voltage to set on adjustable voltage regulator
* @return voltage output, or NaN if channel is invalid (or error happened)
*/
float busvoodoo_vreg_set(uint8_t channel, float voltage);
/** enable embedded pull-up resistors
* @note the embedded pull-up resistor use the voltage on the xV 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);
/** enable blue LED for short duration
* @param[in] ms duration in ms (0-32768)
*/
void busvoodoo_led_blue(uint16_t ms);
/** enable red LED for short duration
* @param[in] ms duration in ms (0-32768)
*/
void busvoodoo_led_red(uint16_t ms);