2018-01-14 22:15:00 +01:00
/* 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
2018-01-24 21:28:45 +01:00
* @ note peripherals used : time @ ref busvoodoo_led_timer
2018-01-14 22:15:00 +01:00
*/
/** @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) */
2018-02-06 21:17:37 +01:00
# define BUSVOODOO_LVEN_PORT A /**< low voltage (LV) enable pin (active high) */
# define BUSVOODOO_LVEN_PIN 6 /**< low voltage (LV) enable pin (active high) */
# define BUSVOODOO_HVEN_PORT A /**< high voltage (HV) enable pin (active low) */
# define BUSVOODOO_HVEN_PIN 7 /**< high voltage (HV) enable pin (active low) */
2018-01-14 22:15:00 +01:00
# 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 */
2018-02-06 21:17:37 +01:00
# define BUSVOODOO_LV_CHANNEL 11 /**< ADC channel to measure LV rail */
# define BUSVOODOO_HV_CHANNEL 15 /**< ADC channel to measure HV rail */
2018-01-14 22:15:00 +01:00
/** @} */
/** @defgroup busvoodoo_dac DAC output to set voltages of voltage regulators
* @ {
*/
2018-02-06 21:17:37 +01:00
# define BUSVOODOO_LVCTL_PORT A /**< pin to control LV output voltage */
# define BUSVOODOO_LVCTL_PIN 4 /**< pin to control LV output voltage */
# define BUSVOODOO_LVCTL_CHANNEL CHANNEL_1 /**< DAC channel to control LV output voltage */
# define BUSVOODOO_LV_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 LV output voltage (based on resistor values on the LV adjust pins and LV voltage reference) */
# define BUSVOODOO_HVCTL_PORT A /**< pin to control HV output voltage */
# define BUSVOODOO_HVCTL_PIN 5 /**< pin to control HV output voltage */
# define BUSVOODOO_HVCTL_CHANNEL CHANNEL_2 /**< DAC channel to control HV output voltage */
# define BUSVOODOO_HV_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 HV output voltage (based on resistor values on the HV adjust pins and HV voltage reference) */
2018-01-14 22:15:00 +01:00
/** @} */
/** @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 */
/** @} */
2018-02-12 14:08:53 +01:00
/** @defgroup busvoodoo_rs485 RS-485 (and RS-422) transceiver connection definition
* @ {
*/
2018-02-13 19:27:15 +01:00
# define BUSVOODOO_RS485_RE_PORT C /**< RS-485 pin to enable receiver (active low, pulled up) */
# define BUSVOODOO_RS485_RE_PIN 13 /**< RS-485 pin to enable receiver (active low, pulled up) */
# define BUSVOODOO_RS485_DE_PORT C /**< RS-485 pin to enable transmitter (active high, pulled low) */
# define BUSVOODOO_RS485_DE_PIN 14 /**< RS-485 pin to enable transmitter (active high, pulled low) */
2018-02-12 14:08:53 +01:00
# define BUSVOODOO_RS485_TX_PORT A /**< RS-485 Transmit output pin */
# define BUSVOODOO_RS485_TX_PIN 2 /**< RS-485 Transmit output pin */
# define BUSVOODOO_RS485_RX_PORT A /**< RS-485 Receive input pin */
# define BUSVOODOO_RS485_RX_PIN 3 /**< RS-485 Receive input pin */
/** @} */
2018-01-14 22:15:00 +01:00
/** @defgroup busvoodoo_can CAN transceiver connection definition
* @ {
*/
2018-02-14 14:25:01 +01:00
# define BUSVOODOO_CAN_EN_PORT C /**< signal to power CAN transceiver (active low, pulled high) */
# define BUSVOODOO_CAN_EN_PIN 7 /**< signal to power CAN transceiver (active low, pulled high) */
2018-01-14 22:15:00 +01:00
# 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 */
/** @} */
2018-02-26 12:13:45 +01:00
/** @defgroup busvoodoo_version ADC pin used to identify hardware version based on voltage
2018-02-13 16:19:45 +01:00
*/
2018-02-26 12:13:45 +01:00
# define BUSVOODOO_HW_VERSION_PORT B /**< pin to identify hardware version */
# define BUSVOODOO_HW_VERSION_PIN 0 /**< pin to identify hardware version */
# define BUSVOODOO_HW_VERSION_CHANNEL 8 /**< ADC to identify hardware version */
2018-02-13 16:19:45 +01:00
/** @} */
2018-01-23 15:17:43 +01:00
/** BusVoodoo mode interface */
struct busvoodoo_mode_t {
2018-01-23 23:41:41 +01:00
const char * name ;
const char * description ;
2018-01-23 15:17:43 +01:00
bool ( * setup ) ( char * * prefix , const char * line ) ;
const struct menu_command_t * commands ;
const uint8_t commands_nb ;
void ( * exit ) ( void ) ;
} ;
2018-01-14 22:15:00 +01:00
/** @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 */
/** @} */
2018-02-06 17:26:35 +01:00
/** is the BusVoodoo board fully populated (with HV voltage regulator, RS-232, RS-485, CAN transceiver on the back side) */
2018-01-14 22:15:00 +01:00
extern bool busvoodoo_full ;
2018-02-26 12:13:45 +01:00
/** version of the hardware board */
extern char busvoodoo_version ;
2018-01-22 21:42:40 +01:00
/** list of supported commands */
2018-02-06 17:26:35 +01:00
extern const struct menu_command_t busvoodoo_global_commands [ 4 ] ;
/** I/O connector pinout */
extern const char * busvoodoo_global_pinout_io [ 10 ] ;
/** RS/CAN connector pinout */
extern const char * busvoodoo_global_pinout_rscan [ 5 ] ;
2018-01-14 22:15:00 +01:00
/** setup BusVoodoo board */
void busvoodoo_setup ( void ) ;
/** set safe state by disabling all outputs */
void busvoodoo_safe_state ( void ) ;
2018-01-17 13:17:08 +01:00
/** 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 ) ;
2018-01-17 12:28:15 +01:00
/** 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 )
2018-01-14 22:15:00 +01:00
*/
2018-01-17 12:28:15 +01:00
float busvoodoo_vreg_get ( uint8_t channel ) ;
2018-02-06 21:34:29 +01:00
/** set voltage on low voltage adjustable voltage regulator
* @ note for voltages above 4.85 V it will use the 5.0 V from USB
* @ param [ in ] voltage voltage to set on adjustable voltage regulator ( 0 , 0.3 - 4.8 , 5 V )
* @ return voltage output , or NaN if error happened
2018-01-17 12:28:15 +01:00
*/
2018-02-06 21:34:29 +01:00
float busvoodoo_lv_set ( float voltage ) ;
/** set voltage on high voltage adjustable voltage regulator
* @ param [ in ] voltage voltage to set on adjustable voltage regulator ( 0 , 3.3 - 24 V )
* @ return voltage output , or NaN if error happened
*/
float busvoodoo_hv_set ( float voltage ) ;
2018-01-17 18:25:59 +01:00
/** enable embedded pull-up resistors
2018-02-06 21:17:37 +01:00
* @ note the embedded pull - up resistor use the voltage on the LV power rail ( set or externally provided )
2018-01-17 18:25:59 +01:00
* @ 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 ) ;
2018-01-24 21:28:45 +01:00
/** 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 ) ;