stm32f1/lib/busvoodoo_global.h

120 lines
6.6 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
*/
/** @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_DEFAULT (0.8*(1+30.0/10.0)) /**< default (when not driven) xV voltage regulator output voltage based on R1 and R2 */
#define BUSVOODOO_XV_TEST 2.5 /**< target xV output voltage to test if we can set control the xV voltage regulator */
#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_DEFAULT (1.25*(1+100.0/10.0)) /**< default (when not driven) 12V voltage regulator output voltage based on R1 and R2 */
#define BUSVOODOO_12V_TEST 12.0 /**< target 12V output voltage to test if we can set control the 12V voltage regulator */
#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 */
/** @} */
/** @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;
/** setup BusVoodoo board */
void busvoodoo_setup(void);
/** set safe state by disabling all outputs */
void busvoodoo_safe_state(void);
/** 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
* @note only vV and 12V are adjustable voltage regulators
* @param[in] channel which voltage regulator to set voltage on @ref busvoodoo_adc
* @return voltage output, or NaN if channel is invalid (or error happened)
*/
float busvoodoo_vreg_set(uint8_t channel, float voltage);