1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

USB: Update the USB configuration structure to include the GPIO that is used

for sensing and then load different config for CC and CC3D.  Updated the
bootloader as well.  Also changed the PIOS_USB_CheckAvailability function to
only return the sense signal and not the transfer_possible flag as this is not
set in time for the bootloader on CC3D for some reason.
This commit is contained in:
James Cotton 2012-01-24 22:15:43 -06:00
parent bc3703ce33
commit 5ad37e691c
8 changed files with 104 additions and 39 deletions

View File

@ -105,6 +105,7 @@ SRC += $(PIOSSTM32F10X)/pios_irq.c
SRC += $(PIOSSTM32F10X)/pios_debug.c
SRC += $(PIOSSTM32F10X)/pios_gpio.c
SRC += $(PIOSSTM32F10X)/pios_iap.c
SRC += $(PIOSSTM32F10X)/pios_bl_helper.c
# PIOS USB related files (seperated to make code maintenance more easy)
SRC += $(PIOSSTM32F10X)/pios_usb.c
@ -118,7 +119,6 @@ SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c
## PIOS Hardware (Common)
SRC += $(PIOSCOMMON)/pios_board_info.c
SRC += $(PIOSCOMMON)/pios_com_msg.c
SRC += $(PIOSCOMMON)/pios_bl_helper.c
SRC += $(PIOSCOMMON)/printf-stdarg.c
## Libraries for flight calculations

View File

@ -70,25 +70,13 @@ uint8_t processRX();
void jump_to_app();
int main() {
PIOS_SYS_Init();
if (BSL_HOLD_STATE == 0)
USB_connected = TRUE;
const struct pios_board_info * bdinfo = &pios_board_info_blob;
switch(bdinfo->board_rev) {
case 0x01:
// Original LED, no problem
break;
case 0x02:
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
break;
}
PIOS_SYS_Init();
PIOS_Board_Init();
PIOS_IAP_Init();
USB_connected = PIOS_USB_CheckAvailable(0);
if (PIOS_IAP_CheckRequest() == TRUE) {
PIOS_Board_Init();
PIOS_DELAY_WaitmS(1000);
User_DFU_request = TRUE;
PIOS_IAP_ClearRequest();

View File

@ -31,7 +31,7 @@
* NOTE: THIS IS THE ONLY PLACE THAT SHOULD EVER INCLUDE THIS FILE
*/
#include "board_hw_defs.c"
#include <pios_board_info.h>
#include <pios.h>
uint32_t pios_com_telem_usb_id;
@ -59,8 +59,20 @@ void PIOS_Board_Init(void) {
/* Initialize the PiOS library */
PIOS_GPIO_Init();
const struct pios_board_info * bdinfo = &pios_board_info_blob;
#if defined(PIOS_INCLUDE_LED)
PIOS_LED_Init(&pios_led_cfg);
switch(bdinfo->board_rev) {
case 0x01: // Revision 1
PIOS_LED_Init(&pios_led_cfg_cc);
break;
case 0x02: // Revision 2
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
PIOS_LED_Init(&pios_led_cfg_cc3d);
break;
default:
PIOS_Assert(0);
}
#endif /* PIOS_INCLUDE_LED */
#if defined(PIOS_INCLUDE_USB)
@ -71,8 +83,15 @@ void PIOS_Board_Init(void) {
PIOS_USB_DESC_HID_ONLY_Init();
uint32_t pios_usb_id;
if (PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg)) {
PIOS_Assert(0);
switch(bdinfo->board_rev) {
case 0x01: // Revision 1
PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg_cc);
break;
case 0x02: // Revision 2
PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg_cc3d);
break;
default:
PIOS_Assert(0);
}
#if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_COM_MSG)
uint32_t pios_usb_hid_id;
@ -90,3 +109,7 @@ void PIOS_Board_Init(void) {
board_init_complete = true;
}
void PIOS_ADC_DMA_Handler()
{
}

View File

@ -270,7 +270,17 @@ void PIOS_Board_Init(void) {
}
uint32_t pios_usb_id;
PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg);
switch(bdinfo->board_rev) {
case 0x01: // Revision 1
PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg_cc);
break;
case 0x02: // Revision 2
PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg_cc3d);
break;
default:
PIOS_Assert(0);
}
#if defined(PIOS_INCLUDE_USB_CDC)

View File

@ -51,12 +51,20 @@ struct pios_usb_dev {
const struct pios_usb_cfg * cfg;
};
#if 0
static bool PIOS_USB_validate(struct pios_usb_dev * usb_dev)
/**
* @brief Validate the usb device structure
* @returns 0 if valid device or -1 otherwise
*/
static int32_t PIOS_USB_validate(struct pios_usb_dev * usb_dev)
{
return (usb_dev->magic == PIOS_USB_DEV_MAGIC);
if(usb_dev == NULL)
return -1;
if (usb_dev->magic != PIOS_USB_DEV_MAGIC)
return -1;
return 0;
}
#endif
#if defined(PIOS_INCLUDE_FREERTOS)
static struct pios_usb_dev * PIOS_USB_alloc(void)
@ -205,9 +213,17 @@ int32_t PIOS_USB_Reenumerate()
* \return 0: interface not available
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
*/
uint32_t usb_found;
bool PIOS_USB_CheckAvailable(uint8_t id)
{
return (PIOS_USB_DETECT_GPIO_PORT->IDR & PIOS_USB_DETECT_GPIO_PIN) != 0 && transfer_possible ? 1 : 0;
struct pios_usb_dev * usb_dev = (struct pios_usb_dev *) pios_usb_com_id;
if(PIOS_USB_validate(usb_dev) != 0)
return 0;
usb_found = (usb_dev->cfg->vsense.gpio->IDR & usb_dev->cfg->vsense.init.GPIO_Pin);
return usb_found;
return usb_found != 0 && transfer_possible ? 1 : 0;
}
#endif

View File

@ -36,6 +36,7 @@
struct pios_usb_cfg {
struct stm32_irq irq;
struct stm32_gpio vsense;
};
extern int32_t PIOS_USB_Init(uint32_t * usb_id, const struct pios_usb_cfg * cfg);

View File

@ -83,6 +83,7 @@
6543A04914CF1823004EEC4C /* board_hw_defs.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = board_hw_defs.c; sourceTree = "<group>"; };
6543A04B14CF1823004EEC4C /* board_hw_defs.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = board_hw_defs.c; sourceTree = "<group>"; };
6543A04C14CF717E004EEC4C /* pios_usb.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_usb.c; sourceTree = "<group>"; };
6543A04D14CF9F5E004EEC4C /* pios_usb_priv.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_usb_priv.h; sourceTree = "<group>"; };
6549E0D21279B3C800C5476F /* fifo_buffer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = fifo_buffer.c; sourceTree = "<group>"; };
6549E0D31279B3CF00C5476F /* fifo_buffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fifo_buffer.h; sourceTree = "<group>"; };
655268BC121FBD2900410C6E /* ahrscalibration.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = ahrscalibration.xml; sourceTree = "<group>"; };
@ -3340,7 +3341,6 @@
65FF4BCD13791C3300146BE4 /* common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = common.h; sourceTree = "<group>"; };
65FF4BCE13791C3300146BE4 /* op_dfu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = op_dfu.h; sourceTree = "<group>"; };
65FF4BCF13791C3300146BE4 /* pios_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_config.h; sourceTree = "<group>"; };
65FF4BD013791C3300146BE4 /* pios_usb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_usb.h; sourceTree = "<group>"; };
65FF4BD113791C3300146BE4 /* main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
65FF4BD213791C3300146BE4 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
65FF4BD313791C3300146BE4 /* op_dfu.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = op_dfu.c; sourceTree = "<group>"; };
@ -8482,7 +8482,6 @@
65E8F03811EFF25C00BBF654 /* inc */ = {
isa = PBXGroup;
children = (
65FA9B8514709E9F0019A260 /* pios_usb_hid_priv.h */,
65DEA78513F0FE6000095B06 /* stm32f2xx_conf.h */,
65F5FBAB14CA08FD00261DE0 /* pios_board_info.h */,
6528CCE212E40F6700CF5144 /* pios_adxl345.h */,
@ -8543,7 +8542,9 @@
65E8F05111EFF25C00BBF654 /* pios_usart.h */,
65E8F05211EFF25C00BBF654 /* pios_usart_priv.h */,
65E8F05311EFF25C00BBF654 /* pios_usb.h */,
6543A04D14CF9F5E004EEC4C /* pios_usb_priv.h */,
65E8F05511EFF25C00BBF654 /* pios_usb_hid.h */,
65FA9B8514709E9F0019A260 /* pios_usb_hid_priv.h */,
651CF9F0120B700D00EEFD70 /* pios_usb_hid_istr.h */,
651CF9F2120B700D00EEFD70 /* pios_usb_hid_pwr.h */,
6526645B122DF972006F9A3C /* pios_wdg.h */,
@ -9280,7 +9281,6 @@
65FF4BCD13791C3300146BE4 /* common.h */,
65FF4BCE13791C3300146BE4 /* op_dfu.h */,
65FF4BCF13791C3300146BE4 /* pios_config.h */,
65FF4BD013791C3300146BE4 /* pios_usb.h */,
);
path = inc;
sourceTree = "<group>";

View File

@ -1216,15 +1216,42 @@ void PIOS_I2C_flexi_adapter_er_irq_handler(void)
#if defined(PIOS_INCLUDE_USB)
#include "pios_usb_priv.h"
static const struct pios_usb_cfg pios_usb_main_cfg = {
.irq = {
.init = {
.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
.NVIC_IRQChannelSubPriority = 0,
.NVIC_IRQChannelCmd = ENABLE,
},
},
static const struct pios_usb_cfg pios_usb_main_cfg_cc = {
.irq = {
.init = {
.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
.NVIC_IRQChannelSubPriority = 0,
.NVIC_IRQChannelCmd = ENABLE,
},
},
.vsense = {
.gpio = GPIOC,
.init = {
.GPIO_Pin = GPIO_Pin_15,
.GPIO_Speed = GPIO_Speed_10MHz,
.GPIO_Mode = GPIO_Mode_AF_OD,
},
}
};
static const struct pios_usb_cfg pios_usb_main_cfg_cc3d = {
.irq = {
.init = {
.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
.NVIC_IRQChannelSubPriority = 0,
.NVIC_IRQChannelCmd = ENABLE,
},
},
.vsense = {
.gpio = GPIOC,
.init = {
.GPIO_Pin = GPIO_Pin_14,
.GPIO_Speed = GPIO_Speed_10MHz,
.GPIO_Mode = GPIO_Mode_AF_OD,
},
}
};
#include "pios_usb_board_data_priv.h"