35 #include "stm32f10x.h"
40 #if defined(PIOS_INCLUDE_USB_HID)
43 static bool transfer_possible =
false;
46 static volatile bool sof_seen_since_reset =
false;
48 enum pios_usb_dev_magic {
49 PIOS_USB_DEV_MAGIC = 0x17365904,
53 enum pios_usb_dev_magic
magic;
61 static int32_t PIOS_USB_validate(
struct pios_usb_dev * usb_dev)
66 if (usb_dev->magic != PIOS_USB_DEV_MAGIC)
72 static struct pios_usb_dev * PIOS_USB_alloc(
void)
74 struct pios_usb_dev * usb_dev;
76 usb_dev = (
struct pios_usb_dev *)
PIOS_malloc(
sizeof(*usb_dev));
77 if (!usb_dev)
return(NULL);
79 usb_dev->magic = PIOS_USB_DEV_MAGIC;
88 static uintptr_t pios_usb_com_id;
94 struct pios_usb_dev * usb_dev;
96 usb_dev = (
struct pios_usb_dev *) PIOS_USB_alloc();
97 if (!usb_dev)
goto out_fail;
108 pios_usb_com_id = (uintptr_t) usb_dev;
111 NVIC_Init((NVIC_InitTypeDef*)&usb_dev->cfg->irq.init);
114 RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
116 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
121 *usb_id = (uintptr_t) usb_dev;
139 transfer_possible =
true;
143 #if defined(USB_LED_ON)
148 transfer_possible =
false;
150 #if defined(USB_LED_OFF)
161 _SetCNTR(CNTR_FRES | CNTR_PDWN);
166 GPIO_InitTypeDef GPIO_InitStructure;
167 GPIO_StructInit(&GPIO_InitStructure);
168 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
169 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
170 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
171 GPIO_Init(GPIOA, &GPIO_InitStructure);
187 RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
189 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
196 struct pios_usb_dev * usb_dev = (
struct pios_usb_dev *) pios_usb_com_id;
198 if (PIOS_USB_validate(usb_dev) != 0)
201 if (usb_dev->cfg->vsense.gpio != NULL)
202 return GPIO_ReadInputDataBit(usb_dev->cfg->vsense.gpio, usb_dev->cfg->vsense.init.GPIO_Pin) == Bit_SET;
204 return sof_seen_since_reset;
209 struct pios_usb_dev * usb_dev = (
struct pios_usb_dev *) pios_usb_com_id;
211 if (PIOS_USB_validate(usb_dev) != 0)
214 return usb_dev->cfg->vsense.gpio != NULL;
225 struct pios_usb_dev * usb_dev = (
struct pios_usb_dev *) pios_usb_com_id;
227 if (PIOS_USB_validate(usb_dev) != 0)
233 void SOF_Callback(
void)
235 sof_seen_since_reset =
true;
238 void SUSP_Callback(
void)
240 sof_seen_since_reset =
false;
Main PiOS header to include all the compiled in PiOS options.
int32_t PIOS_USB_Reenumerate()
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)
int32_t PIOS_DELAY_WaitmS(uint32_t mS)
int32_t PIOS_DELAY_WaituS(uint32_t uS)