|
|
/*------------------------------------------------------------------------------
|
|
|
-- This file is a part of the libuc, microcontroler library
|
|
|
-- Copyright (C) 2014, Alexis Jeandet
|
|
|
--
|
|
|
-- This program is free software; you can redistribute it and/or modify
|
|
|
-- it under the terms of the GNU General Public License as published by
|
|
|
-- the Free Software Foundation; either version 3 of the License, or
|
|
|
-- (at your option) any later version.
|
|
|
--
|
|
|
-- This program is distributed in the hope that it will be useful,
|
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
-- GNU General Public License for more details.
|
|
|
--
|
|
|
-- You should have received a copy of the GNU General Public License
|
|
|
-- along with this program; if not, write to the Free Software
|
|
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
-------------------------------------------------------------------------------
|
|
|
-- Author : Alexis Jeandet
|
|
|
-- Mail : alexis.jeandet@member.fsf.org
|
|
|
-------------------------------------------------------------------------------*/
|
|
|
|
|
|
#include <usbdev.h>
|
|
|
#include <gpio.h>
|
|
|
#include <stm32f4xx_gpio.h>
|
|
|
#include <core.h>
|
|
|
#include <stm32f4xx_rcc.h>
|
|
|
//#include <usb_core.h>
|
|
|
|
|
|
int usbfsopen(uint32_t DATAPpin,uint32_t DATAMpin,uint32_t VBUSpin,uint32_t IDpin)
|
|
|
{
|
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
|
|
|
gpio_t DP,DM,VBUS,ID;
|
|
|
DP = gpioopen(DATAPpin);
|
|
|
DM = gpioopen(DATAMpin);
|
|
|
VBUS = gpioopen(VBUSpin);
|
|
|
ID = gpioopen(IDpin);
|
|
|
DP |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
|
|
|
DM |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
|
|
|
VBUS |= gpiohighspeed | gpioindir | gpioopendraintype | gpionopulltype;
|
|
|
ID |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
|
|
|
gpiosetconfig(&DP);
|
|
|
gpiosetconfig(&DM);
|
|
|
gpiosetconfig(&ID);
|
|
|
gpiosetconfig(&VBUS);
|
|
|
|
|
|
GPIO_PinAFConfig(GPIOGETPORT(DP), (uint8_t)(DP & 0xF), GPIO_AF_OTG1_FS);
|
|
|
GPIO_PinAFConfig(GPIOGETPORT(DM), (uint8_t)(DM & 0xF), GPIO_AF_OTG1_FS);
|
|
|
GPIO_PinAFConfig(GPIOGETPORT(ID), (uint8_t)(ID & 0xF), GPIO_AF_OTG1_FS);
|
|
|
|
|
|
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ;
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
int usbdevopen(usbDev*dev, uint32_t DATAPpin,uint32_t DATAMpin,uint32_t VBUSpin,uint32_t IDpin,int USBSpeed,int usbmode)
|
|
|
{
|
|
|
if(USBSpeed==USB_FullSpeed)
|
|
|
{
|
|
|
return usbfsopen(PA12,PA11,PA9,PA10); //fixed pins on STM32F4
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
|