38 #if defined(PIOS_INCLUDE_USB)
41 static uint8_t transfer_possible = 0;
43 enum pios_usb_dev_magic {
44 PIOS_USB_DEV_MAGIC = 0x17365904,
48 enum pios_usb_dev_magic
magic;
56 static bool PIOS_USB_validate(
struct pios_usb_dev * usb_dev)
58 return (usb_dev && (usb_dev->magic == PIOS_USB_DEV_MAGIC));
61 static struct pios_usb_dev * PIOS_USB_alloc(
void)
63 struct pios_usb_dev * usb_dev;
65 usb_dev = (
struct pios_usb_dev *)
PIOS_malloc(
sizeof(*usb_dev));
66 if (!usb_dev)
return(NULL);
68 usb_dev->magic = PIOS_USB_DEV_MAGIC;
76 static uintptr_t pios_usb_id;
82 struct pios_usb_dev * usb_dev;
84 usb_dev = (
struct pios_usb_dev *) PIOS_USB_alloc();
85 if (!usb_dev)
goto out_fail;
94 pios_usb_id = (uintptr_t) usb_dev;
96 *usb_id = (uintptr_t) usb_dev;
114 transfer_possible = 1;
118 #if defined(USB_LED_ON)
123 transfer_possible = 0;
125 #if defined(USB_LED_OFF)
140 struct pios_usb_dev * usb_dev = (
struct pios_usb_dev *) pios_usb_id;
142 if (!PIOS_USB_validate(usb_dev))
145 if (usb_dev->cfg->vsense.gpio != NULL)
146 return GPIO_ReadInputDataBit(usb_dev->cfg->vsense.gpio, usb_dev->cfg->vsense.init.GPIO_Pin) == Bit_SET;
148 return transfer_possible == 1;
162 struct pios_usb_dev * usb_dev = (
struct pios_usb_dev *) pios_usb_id;
164 if (PIOS_USB_validate(usb_dev) != 0)
167 return usb_dev->cfg->vsense.gpio != NULL;
178 void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
180 struct pios_usb_dev * usb_dev = (
struct pios_usb_dev *) pios_usb_id;
182 bool valid = PIOS_USB_validate(usb_dev);
185 #define FORCE_DISABLE_USB_IRQ 1
186 #if FORCE_DISABLE_USB_IRQ
188 NVIC_InitTypeDef NVIC_InitStructure;
189 NVIC_InitStructure = usb_dev->cfg->irq.init;
190 NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
191 NVIC_Init(&NVIC_InitStructure);
195 GPIO_InitTypeDef GPIO_InitStructure;
196 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
197 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
198 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
199 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
200 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
201 GPIO_Init(GPIOA, &GPIO_InitStructure);
203 GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_OTG1_FS);
204 GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_OTG1_FS);
207 if (usb_dev->cfg->vsense.gpio)
208 GPIO_Init(usb_dev->cfg->vsense.gpio, (GPIO_InitTypeDef*)&usb_dev->cfg->vsense.init);
211 RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE);
214 void USB_OTG_BSP_EnableInterrupt(USB_OTG_CORE_HANDLE *pdev)
216 struct pios_usb_dev * usb_dev = (
struct pios_usb_dev *) pios_usb_id;
218 bool valid = PIOS_USB_validate(usb_dev);
221 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
223 NVIC_Init((NVIC_InitTypeDef*)&usb_dev->cfg->irq.init);
227 void USB_OTG_BSP_DriveVBUS(USB_OTG_CORE_HANDLE *pdev, uint8_t
state)
232 void USB_OTG_BSP_ConfigVBUS(USB_OTG_CORE_HANDLE *pdev)
238 void USB_OTG_BSP_TimeInit (
void )
243 void USB_OTG_BSP_uDelay (
const uint32_t usec)
246 const uint32_t utime = (120 * usec / 7);
248 if (++count > utime) {
255 void USB_OTG_BSP_mDelay (
const uint32_t msec)
257 USB_OTG_BSP_uDelay(msec * 1000);
260 void USB_OTG_BSP_TimerIRQ (
void)
Main PiOS header to include all the compiled in PiOS options.
void * PIOS_malloc(size_t size)
bool PIOS_USB_CheckAvailable(uintptr_t id)
static struct flyingpicmd_cfg_fa cfg
int32_t PIOS_USB_ChangeConnectionState(bool connected)
USB HID layer functions header.
bool PIOS_USB_HaveVSense(uintptr_t id)
int32_t PIOS_USB_Init(uintptr_t *usb_id, const struct pios_usb_cfg *cfg)
bool PIOS_USB_CableConnected(uintptr_t id)
#define PIOS_Assert(test)