From 156109bb8895b5ac885bd8f9bdf6578d217daf7d Mon Sep 17 00:00:00 2001 From: Brian Webb Date: Tue, 14 May 2013 20:37:13 -0700 Subject: [PATCH] Added support for an active low USB vsense line. --- flight/pios/inc/pios_usb_priv.h | 1 + flight/pios/stm32f10x/pios_usb.c | 2 +- flight/pios/stm32f4xx/pios_usb.c | 2 +- flight/targets/boards/coptercontrol/board_hw_defs.c | 6 ++++-- flight/targets/boards/oplinkmini/board_hw_defs.c | 3 ++- flight/targets/boards/osd/board_hw_defs.c | 3 ++- flight/targets/boards/revolution/board_hw_defs.c | 6 ++++-- flight/targets/boards/revoproto/board_hw_defs.c | 3 ++- 8 files changed, 17 insertions(+), 9 deletions(-) diff --git a/flight/pios/inc/pios_usb_priv.h b/flight/pios/inc/pios_usb_priv.h index 76b430a99..ee3c26bd9 100644 --- a/flight/pios/inc/pios_usb_priv.h +++ b/flight/pios/inc/pios_usb_priv.h @@ -37,6 +37,7 @@ struct pios_usb_cfg { struct stm32_irq irq; struct stm32_gpio vsense; + bool vsense_active_low; }; extern int32_t PIOS_USB_Init(uint32_t * usb_id, const struct pios_usb_cfg * cfg); diff --git a/flight/pios/stm32f10x/pios_usb.c b/flight/pios/stm32f10x/pios_usb.c index 13fb8c3c5..bfecbe3ff 100644 --- a/flight/pios/stm32f10x/pios_usb.c +++ b/flight/pios/stm32f10x/pios_usb.c @@ -215,7 +215,7 @@ bool PIOS_USB_CableConnected(__attribute__((unused)) uint8_t id) if (PIOS_USB_validate(usb_dev) != 0) return false; - return usb_dev->cfg->vsense.gpio->IDR & usb_dev->cfg->vsense.init.GPIO_Pin; + return ((usb_dev->cfg->vsense.gpio->IDR & usb_dev->cfg->vsense.init.GPIO_Pin) != 0) ^ usb_dev->cfg->vsense_active_low; } /** diff --git a/flight/pios/stm32f4xx/pios_usb.c b/flight/pios/stm32f4xx/pios_usb.c index d0592a815..6666e120d 100644 --- a/flight/pios/stm32f4xx/pios_usb.c +++ b/flight/pios/stm32f4xx/pios_usb.c @@ -162,7 +162,7 @@ bool PIOS_USB_CheckAvailable(__attribute__((unused)) uint32_t id) if(!PIOS_USB_validate(usb_dev)) return false; - usb_found = (usb_dev->cfg->vsense.gpio->IDR & usb_dev->cfg->vsense.init.GPIO_Pin); + usb_found = ((usb_dev->cfg->vsense.gpio->IDR & usb_dev->cfg->vsense.init.GPIO_Pin) != 0) ^ usb_dev->cfg->vsense_active_low; return usb_found; return usb_found != 0 && transfer_possible ? 1 : 0; } diff --git a/flight/targets/boards/coptercontrol/board_hw_defs.c b/flight/targets/boards/coptercontrol/board_hw_defs.c index b4f83f541..ad042fada 100644 --- a/flight/targets/boards/coptercontrol/board_hw_defs.c +++ b/flight/targets/boards/coptercontrol/board_hw_defs.c @@ -1431,7 +1431,8 @@ static const struct pios_usb_cfg pios_usb_main_cfg_cc = { .GPIO_Speed = GPIO_Speed_10MHz, .GPIO_Mode = GPIO_Mode_AF_OD, }, - } + }, + .vsense_active_low = false }; static const struct pios_usb_cfg pios_usb_main_cfg_cc3d = { @@ -1450,7 +1451,8 @@ static const struct pios_usb_cfg pios_usb_main_cfg_cc3d = { .GPIO_Speed = GPIO_Speed_10MHz, .GPIO_Mode = GPIO_Mode_AF_OD, }, - } + }, + .vsense_active_low = false }; #include "pios_usb_board_data_priv.h" diff --git a/flight/targets/boards/oplinkmini/board_hw_defs.c b/flight/targets/boards/oplinkmini/board_hw_defs.c index ad8b4eacc..24464595b 100644 --- a/flight/targets/boards/oplinkmini/board_hw_defs.c +++ b/flight/targets/boards/oplinkmini/board_hw_defs.c @@ -640,7 +640,8 @@ static const struct pios_usb_cfg pios_usb_main_cfg = { .GPIO_Speed = GPIO_Speed_10MHz, .GPIO_Mode = GPIO_Mode_AF_OD, }, - } + }, + .vsense_active_low = false }; #include "pios_usb_board_data_priv.h" diff --git a/flight/targets/boards/osd/board_hw_defs.c b/flight/targets/boards/osd/board_hw_defs.c index 7b433a030..95f142788 100644 --- a/flight/targets/boards/osd/board_hw_defs.c +++ b/flight/targets/boards/osd/board_hw_defs.c @@ -502,7 +502,8 @@ static const struct pios_usb_cfg pios_usb_main_cfg = { .GPIO_Mode = GPIO_Mode_IN, .GPIO_OType = GPIO_OType_OD, }, - } + }, + .vsense_active_low = false }; #include "pios_usb_board_data_priv.h" diff --git a/flight/targets/boards/revolution/board_hw_defs.c b/flight/targets/boards/revolution/board_hw_defs.c index 4ea6bbae8..3f2778838 100644 --- a/flight/targets/boards/revolution/board_hw_defs.c +++ b/flight/targets/boards/revolution/board_hw_defs.c @@ -1837,7 +1837,8 @@ static const struct pios_usb_cfg pios_usb_main_rm1_cfg = { .GPIO_Mode = GPIO_Mode_IN, .GPIO_OType = GPIO_OType_OD, }, - } + }, + .vsense_active_low = false }; static const struct pios_usb_cfg pios_usb_main_rm2_cfg = { @@ -1857,7 +1858,8 @@ static const struct pios_usb_cfg pios_usb_main_rm2_cfg = { .GPIO_Mode = GPIO_Mode_IN, .GPIO_OType = GPIO_OType_OD, }, - } + }, + .vsense_active_low = false }; const struct pios_usb_cfg * PIOS_BOARD_HW_DEFS_GetUsbCfg (uint32_t board_revision) diff --git a/flight/targets/boards/revoproto/board_hw_defs.c b/flight/targets/boards/revoproto/board_hw_defs.c index 0934a5a26..b10ffec6f 100644 --- a/flight/targets/boards/revoproto/board_hw_defs.c +++ b/flight/targets/boards/revoproto/board_hw_defs.c @@ -2003,7 +2003,8 @@ static const struct pios_usb_cfg pios_usb_main_cfg = { .GPIO_Mode = GPIO_Mode_IN, .GPIO_OType = GPIO_OType_OD, }, - } + }, + .vsense_active_low = false }; #include "pios_usb_board_data_priv.h"