diff --git a/flight/Project/OpenPilotOSX/OpenPilotOSX.xcodeproj/project.pbxproj b/flight/Project/OpenPilotOSX/OpenPilotOSX.xcodeproj/project.pbxproj index 1bdc89da6..7e01ae919 100644 --- a/flight/Project/OpenPilotOSX/OpenPilotOSX.xcodeproj/project.pbxproj +++ b/flight/Project/OpenPilotOSX/OpenPilotOSX.xcodeproj/project.pbxproj @@ -184,7 +184,7 @@ /* Begin PBXLegacyTarget section */ 6581071511DE809D0049FB12 /* OpenPilotOSX */ = { isa = PBXLegacyTarget; - buildArgumentsString = ef_coptercontrol; + buildArgumentsString = ef_revolution; buildConfigurationList = 6581071A11DE80A30049FB12 /* Build configuration list for PBXLegacyTarget "OpenPilotOSX" */; buildPhases = ( ); diff --git a/flight/modules/UAVOHottBridge/uavohottbridge.c b/flight/modules/UAVOHottBridge/uavohottbridge.c index 9342e0eab..663045d08 100644 --- a/flight/modules/UAVOHottBridge/uavohottbridge.c +++ b/flight/modules/UAVOHottBridge/uavohottbridge.c @@ -55,6 +55,8 @@ #include "pios_sensors.h" #include "uavohottbridge.h" +#include "pios_board_io.h" + #if defined(PIOS_INCLUDE_HOTT_BRIDGE) #if defined(PIOS_HoTT_STACK_SIZE) diff --git a/flight/pios/common/pios_board_io.c b/flight/pios/common/pios_board_io.c index 7fa5c327e..0848531fb 100644 --- a/flight/pios/common/pios_board_io.c +++ b/flight/pios/common/pios_board_io.c @@ -105,6 +105,10 @@ uint32_t pios_com_vcp_id; /* USB VCP */ uint32_t pios_com_debug_id; /* DebugConsole */ #endif /* PIOS_INCLUDE_DEBUG_CONSOLE */ +#ifdef PIOS_INCLUDE_HOTT_BRIDGE +uint32_t pios_com_hott_id; +#endif + #ifdef PIOS_INCLUDE_USB uint32_t pios_com_telem_usb_id; /* USB telemetry */ @@ -134,105 +138,83 @@ pios_hmc5x83_dev_t pios_hmc5x83_internal_id; #endif /* PIOS_INCLUDE_COM_MSG */ +#if defined(PIOS_INCLUDE_USB_CDC) +static void PIOS_BOARD_IO_VCP_Init(uint32_t *com_id, uint16_t rx_buf_len, uint16_t tx_buf_len, uint32_t pios_usb_id) +{ +#if defined(PIOS_INCLUDE_COM) + uint32_t pios_usb_cdc_id = 0; + if (PIOS_USB_CDC_Init(&pios_usb_cdc_id, &pios_usb_cdc_cfg, pios_usb_id)) { + PIOS_Assert(0); + } + if (PIOS_COM_Init(com_id, &pios_usb_cdc_com_driver, pios_usb_cdc_id, + 0, rx_buf_len, /* Let Init() allocate this buffer */ + 0, tx_buf_len)) { /* Let Init() allocate this buffer */ + PIOS_Assert(0); + } +#endif /* PIOS_INCLUDE_COM */ +} +#endif + +static void PIOS_BOARD_IO_HID_Init(uint32_t *com_id, uint16_t rx_buf_len, uint16_t tx_buf_len, uint32_t pios_usb_id) +{ +#ifdef PIOS_INCLUDE_USB_CDC + const struct pios_usb_hid_cfg *hid_cfg = &pios_usb_hid_cfg; +#else + const struct pios_usb_hid_cfg *hid_cfg = &pios_usb_hid_only_cfg; +#endif + uint32_t pios_usb_hid_id; + if (PIOS_USB_HID_Init(&pios_usb_hid_id, hid_cfg, pios_usb_id)) { + PIOS_Assert(0); + } + + if (PIOS_COM_Init(com_id, &pios_usb_hid_com_driver, pios_usb_hid_id, + 0, rx_buf_len, /* Let Init() allocate this buffer */ + 0, tx_buf_len)) { /* Let Init() allocate this buffer */ + PIOS_Assert(0); + } +} + void PIOS_BOARD_IO_Configure_USB() { /* Initialize board specific USB data */ PIOS_USB_BOARD_DATA_Init(); - /* Flags to determine if various USB interfaces are advertised */ - bool usb_hid_present = false; - bool usb_cdc_present = false; + uint8_t hwsettings_usb_hidport; + HwSettingsUSB_HIDPortGet(&hwsettings_usb_hidport); #if defined(PIOS_INCLUDE_USB_CDC) + uint8_t hwsettings_usb_vcpport; + HwSettingsUSB_VCPPortGet(&hwsettings_usb_vcpport); + if (PIOS_USB_DESC_HID_CDC_Init()) { PIOS_Assert(0); } - usb_hid_present = true; - usb_cdc_present = true; #else if (PIOS_USB_DESC_HID_ONLY_Init()) { PIOS_Assert(0); } - usb_hid_present = true; #endif uint32_t pios_usb_id; PIOS_USB_Init(&pios_usb_id, PIOS_BOARD_HW_DEFS_GetUsbCfg(pios_board_info_blob.board_rev)); - uint8_t hwsettings_usb_vcpport; - uint8_t hwsettings_usb_hidport; - - HwSettingsUSB_VCPPortGet(&hwsettings_usb_vcpport); - HwSettingsUSB_HIDPortGet(&hwsettings_usb_hidport); - #if defined(PIOS_INCLUDE_USB_CDC) - - if (!usb_cdc_present) { - /* Force VCP port function to disabled if we haven't advertised VCP in our USB descriptor */ - hwsettings_usb_vcpport = HWSETTINGS_USB_VCPPORT_DISABLED; - } - - if (!usb_hid_present) { - /* Force HID port function to disabled if we haven't advertised HID in our USB descriptor */ - hwsettings_usb_hidport = HWSETTINGS_USB_HIDPORT_DISABLED; - } - - /* Why do we need to init these if function is *NONE* ?? */ -#if defined(PIOS_INCLUDE_USB_CDC) - uint32_t pios_usb_cdc_id; - if (PIOS_USB_CDC_Init(&pios_usb_cdc_id, &pios_usb_cdc_cfg, pios_usb_id)) { - PIOS_Assert(0); - } - - uint32_t pios_usb_hid_id; - if (PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_cfg, pios_usb_id)) { - PIOS_Assert(0); - } -#else - uint32_t pios_usb_hid_id; - if (PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_only_cfg, pios_usb_id)) { - PIOS_Assert(0); - } -#endif - switch (hwsettings_usb_vcpport) { case HWSETTINGS_USB_VCPPORT_DISABLED: break; case HWSETTINGS_USB_VCPPORT_USBTELEMETRY: -#if defined(PIOS_INCLUDE_COM) - if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_cdc_com_driver, pios_usb_cdc_id, - 0, PIOS_COM_TELEM_USB_RX_BUF_LEN, /* Let Init() allocate this buffer */ - 0, PIOS_COM_TELEM_USB_TX_BUF_LEN)) { /* Let Init() allocate this buffer */ - PIOS_Assert(0); - } -#endif /* PIOS_INCLUDE_COM */ + PIOS_BOARD_IO_VCP_Init(&pios_com_telem_usb_id, PIOS_COM_TELEM_USB_RX_BUF_LEN, PIOS_COM_TELEM_USB_TX_BUF_LEN, pios_usb_id); break; case HWSETTINGS_USB_VCPPORT_COMBRIDGE: -#if defined(PIOS_INCLUDE_COM) - if (PIOS_COM_Init(&pios_com_vcp_id, &pios_usb_cdc_com_driver, pios_usb_cdc_id, - 0, PIOS_COM_BRIDGE_RX_BUF_LEN, /* Let Init() allocate this buffer */ - 0, PIOS_COM_BRIDGE_TX_BUF_LEN)) { /* Let Init() allocate this buffer */ - PIOS_Assert(0); - } -#endif /* PIOS_INCLUDE_COM */ + PIOS_BOARD_IO_VCP_Init(&pios_com_vcp_id, PIOS_COM_BRIDGE_RX_BUF_LEN, PIOS_COM_BRIDGE_TX_BUF_LEN, pios_usb_id); break; case HWSETTINGS_USB_VCPPORT_DEBUGCONSOLE: -#if defined(PIOS_INCLUDE_COM) #if defined(PIOS_INCLUDE_DEBUG_CONSOLE) - if (PIOS_COM_Init(&pios_com_debug_id, &pios_usb_cdc_com_driver, pios_usb_cdc_id, - 0, 0, /* No RX buffer */ - 0, PIOS_COM_BRIDGE_TX_BUF_LEN)) { /* Let Init() allocate this buffer */ - PIOS_Assert(0); - } + PIOS_BOARD_IO_VCP_Init(&pios_com_debug_id, 0, PIOS_COM_BRIDGE_TX_BUF_LEN, pios_usb_id); #endif /* PIOS_INCLUDE_DEBUG_CONSOLE */ -#endif /* PIOS_INCLUDE_COM */ break; case HWSETTINGS_USB_VCPPORT_MAVLINK: - if (PIOS_COM_Init(&pios_com_mavlink_id, &pios_usb_cdc_com_driver, pios_usb_cdc_id, - 0, PIOS_COM_MAVLINK_RX_BUF_LEN, /* Let Init() allocate this buffer */ - 0, PIOS_COM_MAVLINK_TX_BUF_LEN)) { /* Let Init() allocate this buffer */ - PIOS_Assert(0); - } + PIOS_BOARD_IO_VCP_Init(&pios_com_mavlink_id, PIOS_COM_MAVLINK_RX_BUF_LEN, PIOS_COM_MAVLINK_TX_BUF_LEN, pios_usb_id); break; } #endif /* PIOS_INCLUDE_USB_CDC */ @@ -244,19 +226,11 @@ void PIOS_BOARD_IO_Configure_USB() case HWSETTINGS_USB_HIDPORT_DISABLED: break; case HWSETTINGS_USB_HIDPORT_USBTELEMETRY: -#if defined(PIOS_INCLUDE_COM) - { - if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_hid_id, - 0, PIOS_COM_TELEM_USB_RX_BUF_LEN, /* Let Init() allocate this buffer */ - 0, PIOS_COM_TELEM_USB_TX_BUF_LEN)) { /* Let Init() allocate this buffer */ - PIOS_Assert(0); - } - } -#endif /* PIOS_INCLUDE_COM */ + PIOS_BOARD_IO_HID_Init(&pios_com_telem_usb_id, PIOS_COM_TELEM_USB_RX_BUF_LEN, PIOS_COM_TELEM_USB_TX_BUF_LEN, pios_usb_id); break; case HWSETTINGS_USB_HIDPORT_RCTRANSMITTER: #if defined(PIOS_INCLUDE_USB_RCTX) - if (PIOS_USB_RCTX_Init(&pios_usb_rctx_id, &pios_usb_rctx_cfg, pios_usb_id)) { /* this will reinstall endpoint callbacks */ + if (PIOS_USB_RCTX_Init(&pios_usb_rctx_id, &pios_usb_rctx_cfg, pios_usb_id)) { PIOS_Assert(0); } #endif /* PIOS_INCLUDE_USB_RCTX */ @@ -266,9 +240,7 @@ void PIOS_BOARD_IO_Configure_USB() #endif /* PIOS_INCLUDE_USB_HID */ #ifndef STM32F10X - if (usb_hid_present || usb_cdc_present) { - PIOS_USBHOOK_Activate(); - } + PIOS_USBHOOK_Activate(); #endif } @@ -354,6 +326,13 @@ static const struct uart_function uart_function_map[] = { .com_rx_buf_len = PIOS_COM_HKOSD_RX_BUF_LEN, .com_tx_buf_len = PIOS_COM_HKOSD_TX_BUF_LEN, }, +#ifdef PIOS_INCLUDE_HOTT_BRIDGE + [PIOS_BOARD_IO_UART_HOTT_BRIDGE] = { + .com_id = &pios_com_hott_id, + .com_rx_buf_len = PIOS_COM_HOTT_BRIDGE_RX_BUF_LEN, + .com_tx_buf_len = PIOS_COM_HOTT_BRIDGE_TX_BUF_LEN, + }, +#endif #ifdef PIOS_INCLUDE_DEBUG_CONSOLE [PIOS_BOARD_IO_UART_DEBUGCONSOLE] = { .com_id = &pios_com_debug_id, @@ -554,7 +533,6 @@ void PIOS_BOARD_IO_Configure_RFM22B(uint32_t spi_id, PIOS_BOARD_IO_RADIOAUX_Func uint32_t openlrs_id; const struct pios_openlrs_cfg *openlrs_cfg = PIOS_BOARD_HW_DEFS_GetOpenLRSCfg(pios_board_info_blob.board_rev); - uint32_t openlrs_id; PIOS_OpenLRS_Init(&openlrs_id, spi_id, 0, openlrs_cfg); uint32_t openlrsrcvr_id; @@ -564,6 +542,7 @@ void PIOS_BOARD_IO_Configure_RFM22B(uint32_t spi_id, PIOS_BOARD_IO_RADIOAUX_Func if (PIOS_RCVR_Init(&openlrsrcvr_rcvr_id, &pios_openlrs_rcvr_driver, openlrsrcvr_id)) { PIOS_Assert(0); } + pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_OPENLRS] = openlrsrcvr_rcvr_id; #endif /* PIOS_INCLUDE_OPENLRS_RCVR && PIOS_INCLUDE_RCVR */ } else { /* Configure the RFM22B device. */ @@ -572,6 +551,15 @@ void PIOS_BOARD_IO_Configure_RFM22B(uint32_t spi_id, PIOS_BOARD_IO_RADIOAUX_Func if (PIOS_RFM22B_Init(&pios_rfm22b_id, spi_id, rfm22b_cfg->slave_num, rfm22b_cfg, oplinkSettings.RFBand)) { PIOS_Assert(0); } +#if defined(PIOS_INCLUDE_OPLINKRCVR) && defined(PIOS_INCLUDE_RCVR) + uint32_t pios_oplinkrcvr_id; + PIOS_OPLinkRCVR_Init(&pios_oplinkrcvr_id, pios_rfm22b_id); + uint32_t pios_oplinkrcvr_rcvr_id; + if (PIOS_RCVR_Init(&pios_oplinkrcvr_rcvr_id, &pios_oplinkrcvr_rcvr_driver, pios_oplinkrcvr_id)) { + PIOS_Assert(0); + } + pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_OPLINK] = pios_oplinkrcvr_rcvr_id; +#endif /* PIOS_INCLUDE_OPLINKRCVR && PIOS_INCLUDE_RCVR */ /* Configure the radio com interface */ if (PIOS_COM_Init(&pios_com_rf_id, &pios_rfm22b_com_driver, pios_rfm22b_id, @@ -689,16 +677,6 @@ void PIOS_BOARD_IO_Configure_RFM22B(uint32_t spi_id, PIOS_BOARD_IO_RADIOAUX_Func } OPLinkStatusSet(&oplinkStatus); - -#if defined(PIOS_INCLUDE_OPLINKRCVR) && defined(PIOS_INCLUDE_RCVR) - uint32_t pios_oplinkrcvr_id; - PIOS_OPLinkRCVR_Init(&pios_oplinkrcvr_id); - uint32_t pios_oplinkrcvr_rcvr_id; - if (PIOS_RCVR_Init(&pios_oplinkrcvr_rcvr_id, &pios_oplinkrcvr_rcvr_driver, pios_oplinkrcvr_id)) { - PIOS_Assert(0); - } - pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_OPLINK] = pios_oplinkrcvr_rcvr_id; -#endif /* PIOS_INCLUDE_OPLINKRCVR && PIOS_INCLUDE_RCVR */ } #endif /* ifdef PIOS_INCLUDE_RFM22B */ diff --git a/flight/pios/inc/pios_board_io.h b/flight/pios/inc/pios_board_io.h index 6b374deba..57dd3736e 100644 --- a/flight/pios/inc/pios_board_io.h +++ b/flight/pios/inc/pios_board_io.h @@ -140,6 +140,18 @@ extern uint32_t pios_com_mavlink_id; # define PIOS_COM_MAVLINK_RX_BUF_LEN 128 #endif +/* HoTT Telemetry */ +#ifdef PIOS_INCLUDE_HOTT_BRIDGE +# ifndef PIOS_COM_HOTT_BRIDGE_RX_BUF_LEN +# define PIOS_COM_HOTT_BRIDGE_RX_BUF_LEN 512 +# endif +# ifndef PIOS_COM_HOTT_BRIDGE_TX_BUF_LEN +# define PIOS_COM_HOTT_BRIDGE_TX_BUF_LEN 512 +# endif +extern uint32_t pios_com_hott_id; +# define PIOS_COM_HOTT (pios_com_hott_id) +#endif + /* USB VCP */ extern uint32_t pios_com_vcp_id; #define PIOS_COM_VCP (pios_com_vcp_id) @@ -181,6 +193,7 @@ typedef enum { PIOS_BOARD_IO_UART_IBUS, /* rcvr */ PIOS_BOARD_IO_UART_EXBUS, /* rcvr */ // PIOS_BOARD_IO_UART_FRSKY_SPORT_TELEMETRY, /* com */ + PIOS_BOARD_IO_UART_HOTT_BRIDGE, /* com */ } PIOS_BOARD_IO_UART_Function; typedef enum { @@ -191,27 +204,12 @@ typedef enum { // PIOS_BOARD_IO_RADIOAUX_FRSKY_SPORT_TELEMETRY, } PIOS_BOARD_IO_RADIOAUX_Function; -typedef enum { - PIOS_BOARD_IO_USB_HID_NONE, - PIOS_BOARD_IO_USB_HID_TELEMETRY, - PIOS_BOARD_IO_USB_HID_RCTX, -} PIOS_BOARD_IO_USB_HID_Function; - -typedef enum { - PIOS_BOARD_IO_USB_CDC_NONE, - PIOS_BOARD_IO_USB_CDC_TELEMETRY, - PIOS_BOARD_IO_USB_CDC_COMBRIDGE, - PIOS_BOARD_IO_USB_CDC_MAVLINK, - PIOS_BOARD_IO_USB_CDC_DEBUGCONSOLE, -// PIOS_BOARD_IO_USB_CDC_MSP, -} PIOS_BOARD_IO_USB_CDC_Function; - #ifdef PIOS_INCLUDE_USB -void PIOS_BOARD_IO_Configure_USB(PIOS_BOARD_IO_USB_HID_Function hid_function, PIOS_BOARD_IO_USB_CDC_Function cdc_function); -# if defined(PIOS_INCLUDE_USB_HID) -# include -extern const struct pios_usb_hid_cfg pios_usb_hid_cfg; -# endif /* PIOS_INCLUDE_USB_HID */ +void PIOS_BOARD_IO_Configure_USB(); +//# if defined(PIOS_INCLUDE_USB_HID) +//# include +//extern const struct pios_usb_hid_cfg pios_usb_hid_cfg; +//# endif /* PIOS_INCLUDE_USB_HID */ #endif /* PIOS_INCLUDE_USB */ #ifdef PIOS_INCLUDE_PWM void PIOS_BOARD_IO_Configure_PWM(const struct pios_pwm_cfg *pwm_cfg); diff --git a/flight/pios/stm32f10x/pios_sys.c b/flight/pios/stm32f10x/pios_sys.c index 19a6061b6..4644293b2 100644 --- a/flight/pios/stm32f10x/pios_sys.c +++ b/flight/pios/stm32f10x/pios_sys.c @@ -82,8 +82,8 @@ void PIOS_SYS_Init(void) RCC_APB1Periph_I2C1 | RCC_APB1Periph_I2C2 | RCC_APB1Periph_USB | - RCC_APB1Periph_CAN1 | - RCC_APB1Periph_CAN2 | +// RCC_APB1Periph_CAN1 | /* bxCAN unfortunately interferes with USB */ +// RCC_APB1Periph_CAN2 | RCC_APB1Periph_BKP | RCC_APB1Periph_PWR | RCC_APB1Periph_DAC, diff --git a/flight/targets/boards/coptercontrol/board_hw_defs.c b/flight/targets/boards/coptercontrol/board_hw_defs.c index f44e552f5..d4d97f589 100644 --- a/flight/targets/boards/coptercontrol/board_hw_defs.c +++ b/flight/targets/boards/coptercontrol/board_hw_defs.c @@ -981,18 +981,8 @@ const struct pios_usb_cfg *PIOS_BOARD_HW_DEFS_GetUsbCfg(uint32_t board_revision) return NULL; } -#include "pios_usb_board_data_priv.h" -#include "pios_usb_desc_hid_cdc_priv.h" -#include "pios_usb_desc_hid_only_priv.h" - #endif /* PIOS_INCLUDE_USB */ -#if defined(PIOS_INCLUDE_COM_MSG) - -#include - -#endif /* PIOS_INCLUDE_COM_MSG */ - /** * Configuration for MPU6000 chip */ diff --git a/flight/targets/boards/coptercontrol/bootloader/pios_board.c b/flight/targets/boards/coptercontrol/bootloader/pios_board.c index dda9fa5f5..466566d55 100644 --- a/flight/targets/boards/coptercontrol/bootloader/pios_board.c +++ b/flight/targets/boards/coptercontrol/bootloader/pios_board.c @@ -36,6 +36,10 @@ */ #include "../board_hw_defs.c" +#include "pios_usb_board_data_priv.h" +#include "pios_usb_desc_hid_only_priv.h" +#include + uint32_t pios_com_telem_usb_id; /** diff --git a/flight/targets/boards/revolution/bootloader/main.c b/flight/targets/boards/revolution/bootloader/main.c index 09a54a094..aa5c7999a 100644 --- a/flight/targets/boards/revolution/bootloader/main.c +++ b/flight/targets/boards/revolution/bootloader/main.c @@ -35,6 +35,7 @@ #include /* PIOS_USBHOOK_* */ #include #include +#include extern void FLASH_Download(); void check_bor(); diff --git a/flight/targets/boards/revonano/bootloader/main.c b/flight/targets/boards/revonano/bootloader/main.c index 09a54a094..aa5c7999a 100644 --- a/flight/targets/boards/revonano/bootloader/main.c +++ b/flight/targets/boards/revonano/bootloader/main.c @@ -35,6 +35,7 @@ #include /* PIOS_USBHOOK_* */ #include #include +#include extern void FLASH_Download(); void check_bor();