REKLAMA

keyb_fw.7z

[STM32F407VG][C++/CooCox] - USB Host i Device w tym samym czasie

Witam, Próbuje zrobić urządzenie, które w tym samym czasie będzie wstanie komunikować się z komputerem (USB HID DEVICE), jak i przyjmować komendy z klawiatury, bezpośrednio podpiętej do niego (USB HOST). STM32F407VG ma dwa kontrolery USB: - OTG_FS - wykorzystany do komunikacji z komputerem (tryb HID DEVICE) - OTG_HS - wykorzystany do obsługi klawiatury (tryb HOST) Ze strony: stm32f4-discovery.com/2014/05/all-stm32f429-libraries-at-one-place zaczerpnąłem biblioteki "USB HID DEVICE" oraz "USB HID HOST". Obie biblioteki korzystają po części z tych samych plików, a więc dołączenie obydwóch powoduje konflikty. Rozwiązałem ten problem, dopisując do nazw wszystkich plików z biblioteki "USB HID DEVICE" przedrostek "USBD" oraz tworząc namespace "USBD" i włączając całą zawartość tych plików do niego. Korzystanie z namespace'ów wymusiło zmianę języka na C++, ale umożliwiło mi nie ingerowanie w same biblioteki. Napisałem prosty kod testujący: - włączony TYLKO tryb DEVICE - wysyłanie do komputera "SHIFT" co 1s i przez 1s (symulowanie przytrzymania SHIFT) - włączony TYLKO tryb HOST - wciśnięcie klawisza 'b' i 'c' powoduje odpowiednio zapalenie i zgaszenie diody - włączenie obu trybów na raz - dioda + przekazywanie klawisza do komputera Problem: Pracując w pojedynczym trybie (HOST lub DEVICE) wszystko działa bez zarzutu. Przy włączonych obu trybach pojawia się problem z częścią odpowiedzialną za HOST'a. Debugując znalazłem miejsce w którym jest problem. W pliku "usbh_hid_core.cpp" w funkcji: static USBH_Status USBH_HID_Handle(USB_OTG_CORE_HANDLE *pdev , void *phost) { USBH_HOST *pphost = (USBH_HOST*)phost; USBH_Status status = USBH_OK; switch (HID_Machine.state) { case HID_IDLE: HID_Machine.cb->Init(); HID_Machine.state = HID_SYNC; case HID_SYNC: /* Sync with start of Even Frame */ if(USB_OTG_IsEvenFrame(pdev) == TRUE) { HID_Machine.state = HID_GET_DATA; } break; case HID_GET_DATA: USBH_InterruptReceiveData(pdev, HID_Machine.buff, HID_Machine.length, HID_Machine.hc_num_in); start_toggle = 1; HID_Machine.state = HID_POLL; HID_Machine.timer = HCD_GetCurrentFrame(pdev); timereczek = Millis(); break; case HID_POLL: if(( HCD_GetCurrentFrame(pdev)-HID_Machine.timer) >= HID_Machine.poll) { HID_Machine.state = HID_GET_DATA; } else if(HCD_GetURB_State(pdev , HID_Machine.hc_num_in) == URB_DONE) { if(start_toggle == 1) /* handle data once */ { start_toggle = 0; HID_Machine.cb->Decode(HID_Machine.buff); } } else if(HCD_GetURB_State(pdev, HID_Machine.hc_num_in) == URB_STALL) /* IN Endpoint Stalled */ { /* Issue Clear Feature on interrupt IN endpoint */ if( (USBH_ClrFeature(pdev, pphost, HID_Machine.ep_addr, HID_Machine.hc_num_in)) == USBH_OK) { /* Change state to issue next IN token */ HID_Machine.state = HID_GET_DATA; } } break; default: break; } return status; } ciągle spełnia się warunek: case HID_POLL: if(( HCD_GetCurrentFrame(pdev)-HID_Machine.timer) >= HID_Machine.poll) { HID_Machine.state = HID_GET_DATA; } Gdy w tym pkt postawie breakpoint'a i zajrze do "HID_Machine.buff" okazuje się, że kod wciśniętego klawisza dotarł. Nie mam pomysłu co powoduje wydłużenie czasu "HCD_GetCurrentFrame(pdev)-HID_Machine.timer" ponad "HID_Machine.poll". Próbowałem już zwiększyć priorytet przerwania od HOST'a, bo myślałem że może mu przeszkadzają przerwania od DEVICE, ale nic to nie dało. Ma ktoś jakiś pomysł co może być przyczyną?? Gdzie szukać?? W załączniku zmodyfikowane przeze mnie bilbioteki oraz main.cpp


Pobierz plik - link do postu
  • keyb_fw.7z
    • main.cpp
    • USB_Host
      • tm_stm32f4_usb_hid_host.h
      • usb_hid_host
        • usb_hcd.h
        • usb_hcd.cpp
        • usb_core.h
        • usbh_hid_mouse.cpp
        • usbh_hid_keybd.h
        • usb_regs.h
        • usbh_conf.h
        • usb_bsp.cpp
        • usbh_hid_keybd.cpp
        • usbh_def.h
        • usb_core.cpp
        • usbh_core.h
        • usb_hcd_int.h
        • usbh_ioreq.h
        • usbh_core.cpp
        • usb_hcd_int.cpp
        • usbh_ioreq.cpp
        • usbh_hid_core.h
        • usb_bsp.h
        • usb_host_conf.h
        • usbh_usr.h
        • usb_conf.h
        • usbh_stdreq.h
        • usb_defines.h
        • usbh_hcs.h
        • usbh_hid_core.cpp
        • usbh_hid_mouse.h
        • usbh_usr.cpp
        • usbh_stdreq.cpp
        • usbh_hcs.cpp
      • tm_stm32f4_usb_hid_host.cpp
    • USB_Device
      • tm_stm32f4_usb_hid_device.cpp
      • usb_hid_device
        • USBD_usbd_usr.cpp
        • USBD_usbd_hid_core.h
        • USBD_usbd_req.h
        • USBD_usb_dcd.h
        • USBD_usb_regs.h
        • USBD_usbd_def.h
        • USBD_usb_core.h
        • USBD_usb_bsp.cpp
        • USBD_usb_core.cpp
        • USBD_usb_bsp.h
        • USBD_usbd_req.cpp
        • USBD_usb_defines.h
        • USBD_usbd_core.cpp
        • USBD_usbd_desc.h
        • USBD_usbd_hid_core.cpp
        • USBD_usbd_conf.h
        • USBD_usbd_core.h
        • USBD_usbd_ioreq.cpp
        • USBD_usb_dcd_int.h
        • USBD_usbd_desc.cpp
        • USBD_usb_dcd_int.cpp
        • USBD_usb_conf.h
        • USBD_usbd_usr.h
        • USBD_usbd_ioreq.h
        • USBD_usb_dcd.cpp
      • tm_stm32f4_usb_hid_device.h


keyb_fw.7z > main.cpp

#include " stm32f4xx.h "
#include " system.h "

#define USB_OTG_FS_DEVICE
#define USB_OTG_HS_HOST

#ifdef USB_OTG_HS_HOST
#include " tm_stm32f4_usb_hid_host.h "
#endif

#ifdef USB_OTG_FS_DEVICE
#include " tm_stm32f4_usb_hid_device.h "
#endif

//STM32F407VG

#ifdef USB_OTG_FS_DEVICE
USBD::TM_USB_HIDDEVICE_Keyboard_t Keyboard_Device;
#endif

#ifdef USB_OTG_HS_HOST
TM_USB_HIDHOST_Keyboard_t Keyboard_Host;
#endif

int main()
{
BasicInit();
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//basic initialization
#ifdef USB_OTG_FS_DEVICE
USBD::TM_USB_HIDDEVICE_Status_t STATUS_D = USBD::TM_USB_HIDDEVICE_Init();
STATUS_D = USBD::TM_USB_HIDDEVICE_GetStatus();
STATUS_D = USBD::TM_USB_HIDDEVICE_KeyboardStructInit( & Keyboard_Device );
#endif

#ifdef USB_OTG_HS_HOST
TM_USB_HIDHOST_Init();
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//

int i = 0;
uint32_t timerek = Millis();
#ifdef USB_OTG_HS_HOST
TM_USB_HIDHOST_Result_t STATUS_H;
#endif
while(1)
{
#ifdef USB_OTG_HS_HOST
STATUS_H = TM_USB_HIDHOST_Process();
#endif
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef USB_OTG_FS_DEVICE
// if( Millis()-timerek & gt; 1000 )
// {
// i++;
//
// Keyboard_Device.L_SHIFT = (USBD::TM_USB_HIDDEVICE_Button_t)1;
// USBD::TM_USB_HIDDEVICE_KeyboardSend( & Keyboard_Device );
//
// Delay_ms(1000);
//
// Keyboard_Device.L_SHIFT = (USBD::TM_USB_HIDDEVICE_Button_t)0;
// USBD::TM_USB_HIDDEVICE_KeyboardSend( & Keyboard_Device );
//
// timerek = Millis();
//
// }
#endif
#ifdef USB_OTG_HS_HOST
//host
#ifdef USB_OTG_FS_DEVICE
if( TM_USB_HIDHOST_ReadKeyboard( & Keyboard_Host ) == TM_USB_HIDHOST_Result_KeyboardConnected
& & USBD::TM_USB_HIDDEVICE_GetStatus() == USBD::TM_USB_HIDDEVICE_Status_Connected )
{
if( Keyboard_Host.ButtonStatus == TM_USB_HIDHOST_Button_Pressed )
{
Keyboard_Device.Key1 = Keyboard_Host.Button;
TM_USB_HIDDEVICE_KeyboardSend( & Keyboard_Device );

if( Keyboard_Host.Button == 'b' )
GPIO_SetBits( GPIOB, GPIO_Pin_2 );
else if( Keyboard_Host.Button == 'c' )
GPIO_ResetBits( GPIOB, GPIO_Pin_2 );
}
else
{
Keyboard_Device.Key1 = 0;
TM_USB_HIDDEVICE_KeyboardSend( & Keyboard_Device );
}
}
#else
if( TM_USB_HIDHOST_ReadKeyboard( & Keyboard_Host ) == TM_USB_HIDHOST_Result_KeyboardConnected )
{
if( Keyboard_Host.ButtonStatus == TM_USB_HIDHOST_Button_Pressed )
{
if( Keyboard_Host.Button == 'b' )
GPIO_SetBits( GPIOB, GPIO_Pin_2 );
else if( Keyboard_Host.Button == 'c' )
GPIO_ResetBits( GPIOB, GPIO_Pin_2 );
}
else
i = 0;
}
#endif
#endif
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}


keyb_fw.7z > usbh_hid_mouse.cpp

/**
******************************************************************************
* @file usbh_hid_mouse.c
* @author MCD Application Team
* @version V2.1.0
* @date 19-March-2012
* @brief This file is the application layer for USB Host HID Mouse Handling.
******************************************************************************
* @attention
*
* & lt; h2 & gt; & lt; center & gt; & copy; COPYRIGHT 2012 STMicroelectronics & lt; /center & gt; & lt; /h2 & gt;
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the " License " );
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an " AS IS " BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/

/* Includes ------------------------------------------------------------------*/
#include " usbh_hid_mouse.h "


/** @addtogroup USBH_LIB
* @{
*/

/** @addtogroup USBH_CLASS
* @{
*/

/** @addtogroup USBH_HID_CLASS
* @{
*/

/** @defgroup USBH_HID_MOUSE
* @brief This file includes HID Layer Handlers for USB Host HID class.
* @{
*/

/** @defgroup USBH_HID_MOUSE_Private_TypesDefinitions
* @{
*/
/**
* @}
*/


/** @defgroup USBH_HID_MOUSE_Private_Defines
* @{
*/
/**
* @}
*/


/** @defgroup USBH_HID_MOUSE_Private_Macros
* @{
*/
/**
* @}
*/

/** @defgroup USBH_HID_MOUSE_Private_FunctionPrototypes
* @{
*/
static void MOUSE_Init (void);
static void MOUSE_Decode(uint8_t *data);
/**
* @}
*/


/** @defgroup USBH_HID_MOUSE_Private_Variables
* @{
*/
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
#if defined (__CC_ARM) /*! & lt; ARM Compiler */
__align(4)
#elif defined ( __ICCARM__ ) /*! & lt; IAR Compiler */
#pragma data_alignment=4
#elif defined (__GNUC__) /*! & lt; GNU Compiler */
#pragma pack(4)
#elif defined (__TASKING__) /*! & lt; TASKING Compiler */
__align(4)
#endif /* __CC_ARM */
#endif


HID_MOUSE_Data_TypeDef HID_MOUSE_Data;
HID_cb_TypeDef HID_MOUSE_cb =
{
MOUSE_Init,
MOUSE_Decode,
};
/**
* @}
*/


/** @defgroup USBH_HID_MOUSE_Private_Functions
* @{
*/

/**
* @brief MOUSE_Init
* Init Mouse State.
* @param None
* @retval None
*/
static void MOUSE_Init ( void)
{
/* Call User Init*/
USR_MOUSE_Init();
}

/**
* @brief MOUSE_Decode
* Decode Mouse data
* @param data : Pointer to Mouse HID data buffer
* @retval None
*/
static void MOUSE_Decode(uint8_t *data)
{
HID_MOUSE_Data.button = data[0];

HID_MOUSE_Data.x = data[1];
HID_MOUSE_Data.y = data[2];

USR_MOUSE_ProcessData( & HID_MOUSE_Data);

}
/**
* @}
*/

/**
* @}
*/

/**
* @}
*/

/**
* @}
*/


/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/


keyb_fw.7z > tm_stm32f4_usb_hid_host.h

/**
* USB HID HOST library for STM32F4xx devices
*
* @author Tilen Majerle
* @email tilen@majerle.eu
* @website http://stm32f4-discovery.com
* @link http://stm32f4-discovery.com/2014/08/library-31-usb-hid-host-for-stm32f4xx-devices
* @version v1.0
* @ide Keil uVision
* @license GNU GPL v3
*
* |----------------------------------------------------------------------
* | Copyright (C) Tilen Majerle, 2014
* |
* | 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
* | 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, see & lt; http://www.gnu.org/licenses/ & gt; .
* |----------------------------------------------------------------------
*
* This library allows you to operate with USB keyboard and USB mouse devices
*
* It works in USB FS or USB HS in FS mode.
*
* By default, library works in USB FS mode (for STM32F4-Discovery board).
* If you want to use this on STM32F429-Discovery board, you have to activate USB HS in FS mode.
* Activate this with lines below in your defines.h file:
*
* //Activate USB HS in FS mode
* #define USE_USB_OTG_HS
*
* Pinout (can not be changed)
*
* USB |STM32F4xx FS mode |STM32F4xx HS in FS mode |Notes
* |STM32F4-Discovery |STM32F429-Discovery
*
* Data + PA12 PB15 Data+ for USB, standard and used pin
* Data - PA11 PB14 Data- for USB, standard and used pin
* ID PA10 PB12 ID pin, used on F4 and F429 discovery boards, not needed if you don't like it
* VBUS PA9 PB13 VBUS pin, used on F4 and F429 discovery board for activating USB chip.
* You have to use VBUS on discovery boards, but on nucleo, it's ok with only Data+ and Data- pins
* Disable necessary pins
*
* USB technically needs only Data+ and Data- pins.
* Also, ID pin can be used, but it is not needed.
*
* Disable ID PIN
*
* If you need pin for something else, where ID is located, you can disable this pin for USB.
* Add lines below in your defines.h file:
*
* //Disable ID pin
* #define USB_HID_HOST_DISABLE_ID
*
* Disable VBUS PIN
*
* VBUS pin is located on Discovery boards, to activate USB chip on board.
* If you are working with Discovery boards, then you need this pin, otherise USB will not work.
* But if you are working on other application (or Nucleo board), you only need Data+ and Data- pins.
* To disable VBUS pin, add lines below in your defines.h file:
*
* //Disable VBUS pin
* #define USB_HID_HOST_DISABLE_VBUS
*
* Default configuration for keyboard is AZERTY style. If you want to use QWERTY keyboard style,
* then add line below in defines.h to activate it.
*
* //Enable QUERTY keyboard style
* #define QWERTY_KEYBOARD
* */
#ifndef TM_USB_HID_HOST_H
#define TM_USB_HID_HOST_H 100
/**
* Library dependencies
* - STM32F4xx
* - STM32F4xx RCC
* - STM32F4xx GPIO
* - defines.h
* - USB HID stack
*/
/**
* Includes
*/
#include " stm32f4xx.h "
#include " stm32f4xx_rcc.h "
#include " stm32f4xx_gpio.h "
#include " usb_host_conf.h "

#include " usb_bsp.h "
#include " usbh_core.h "
#include " usbh_usr.h "
#include " usbh_hid_core.h "

/**
* HID Host result enumeration
*
* Parameters:
* - TM_USB_HIDHOST_Result_Error
* An error occured
* - TM_USB_HIDHOST_Result_KeyboardConnected
* Keyboard is connected and ready to use
* - TM_USB_HIDHOST_Result_MouseConnected
* Mouse is connected and ready to use
* - TM_USB_HIDHOST_Result_Disconnected
* Device is not connected
* - TM_USB_HIDHOST_Result_DeviceNotSupported
* Device is not supported
* - TM_USB_HIDHOST_Result_LibraryNotInitialized
* Library is not initialized
*/
typedef enum {
TM_USB_HIDHOST_Result_Error,
TM_USB_HIDHOST_Result_KeyboardConnected,
TM_USB_HIDHOST_Result_MouseConnected,
TM_USB_HIDHOST_Result_Disconnected,
TM_USB_HIDHOST_Result_DeviceNotSupported,
TM_USB_HIDHOST_Result_LibraryNotInitialized
} TM_USB_HIDHOST_Result_t;

/**
* HID Host Button enumeration
*
* Parameters:
* - TM_USB_HIDHOST_Button_Pressed
* Button was pressed
* - TM_USB_HIDHOST_Button_Released
* Button was released
*/
typedef enum {
TM_USB_HIDHOST_Button_Pressed = 0,
TM_USB_HIDHOST_Button_Released
} TM_USB_HIDHOST_Button_t;

/**
* HID Host keyboard struct
*
* Parameters:
* - TM_USB_HIDHOST_Button_t ButtonStatus
* Indicates if button is pressed or released
* - uint8_t Button
* Button number pressed
*/
typedef struct {
TM_USB_HIDHOST_Button_t ButtonStatus;
uint8_t Button;
} TM_USB_HIDHOST_Keyboard_t;

/**
* HID Host mouse struct
*
* Parameters:
* - int16_t AbsoluteX
* Absolute cursor X position
* - int16_t AbsoluteY
* Absolute cursor Y position
* - int16_t DiffX
* Difference cursor X position from last check
* - int16_t DiffY
* Difference cursor Y position from last check
* - TM_USB_HIDHOST_Button_t LeftButton
* Indicates if left button is pressed or released
* - TM_USB_HIDHOST_Button_t RightButton
* Indicates if right button is pressed or released
* - TM_USB_HIDHOST_Button_t MiddleButton
* Indicates if middle button is pressed or released
*/
typedef struct {
/* Cursor movement */
int16_t AbsoluteX;
int16_t AbsoluteY;
int16_t DiffX;
int16_t DiffY;

/* Buttons */
TM_USB_HIDHOST_Button_t LeftButton;
TM_USB_HIDHOST_Button_t RightButton;
TM_USB_HIDHOST_Button_t MiddleButton;
} TM_USB_HIDHOST_Mouse_t;

/**
* Initialize USB HID Host
*
*
*/
extern void TM_USB_HIDHOST_Init(void);

/**
* Process USB HID library
*
* This function has to be called periodically, as fast as possible
*
* Returns member of TM_USB_HIDHOST_Result_t typedef
*/
extern TM_USB_HIDHOST_Result_t TM_USB_HIDHOST_Process(void);

/**
* Checks device status
*
* Returns member of TM_USB_HIDHOST_Result_t typedef
*/
extern TM_USB_HIDHOST_Result_t TM_USB_HIDHOST_Device(void);

/**
* Read keyboard data
*
* Parameters:
* - TM_USB_HIDHOST_Keyboard_t* Keyboard
* Pointer to TM_USB_HIDHOST_Keyboard_t keyboard struct
*
* Returns TM_USB_HIDHOST_Result_KeyboardConnected if keyboard is connected
*/
extern TM_USB_HIDHOST_Result_t TM_USB_HIDHOST_ReadKeyboard(TM_USB_HIDHOST_Keyboard_t* Keyboard);

/**
* Read mouse data
*
* Parameters:
* - TM_USB_HIDHOST_Mouse_t* Mouse
* Pointer to TM_USB_HIDHOST_Mouse_t mouse struct
*
* Returns TM_USB_HIDHOST_Result_MouseConnected if mouse is connected
*/
extern TM_USB_HIDHOST_Result_t TM_USB_HIDHOST_ReadMouse(TM_USB_HIDHOST_Mouse_t* Mouse);

#endif


keyb_fw.7z > usb_hcd.cpp

/**
******************************************************************************
* @file usb_hcd.c
* @author MCD Application Team
* @version V2.1.0
* @date 19-March-2012
* @brief Host Interface Layer
******************************************************************************
* @attention
*
* & lt; h2 & gt; & lt; center & gt; & copy; COPYRIGHT 2012 STMicroelectronics & lt; /center & gt; & lt; /h2 & gt;
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the " License " );
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an " AS IS " BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/

/* Includes ------------------------------------------------------------------*/
#include " usb_core.h "
#include " usb_hcd.h "
#include " usb_conf.h "
#include " usb_bsp.h "


/** @addtogroup USB_OTG_DRIVER
* @{
*/

/** @defgroup USB_HCD
* @brief This file is the interface between EFSL ans Host mass-storage class
* @{
*/


/** @defgroup USB_HCD_Private_Defines
* @{
*/
/**
* @}
*/


/** @defgroup USB_HCD_Private_TypesDefinitions
* @{
*/
/**
* @}
*/



/** @defgroup USB_HCD_Private_Macros
* @{
*/
/**
* @}
*/


/** @defgroup USB_HCD_Private_Variables
* @{
*/
/**
* @}
*/


/** @defgroup USB_HCD_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/


/** @defgroup USB_HCD_Private_Functions
* @{
*/

/**
* @brief HCD_Init
* Initialize the HOST portion of the driver.
* @param pdev: Selected device
* @param base_address: OTG base address
* @retval Status
*/
uint32_t HCD_Init(USB_OTG_CORE_HANDLE *pdev ,
USB_OTG_CORE_ID_TypeDef coreID)
{
uint8_t i = 0;
pdev- & gt; host.ConnSts = 0;

for (i= 0; i & lt; USB_OTG_MAX_TX_FIFOS; i++)
{
pdev- & gt; host.ErrCnt[i] = 0;
pdev- & gt; host.XferCnt[i] = 0;
pdev- & gt; host.HC_Status[i] = HC_IDLE;
}
pdev- & gt; host.hc[0].max_packet = 8;

USB_OTG_SelectCore(pdev, coreID);
#ifndef DUAL_ROLE_MODE_ENABLED
USB_OTG_DisableGlobalInt(pdev);
USB_OTG_CoreInit(pdev);

/* Force Host Mode*/
USB_OTG_SetCurrentMode(pdev , HOST_MODE);
USB_OTG_CoreInitHost(pdev);
USB_OTG_EnableGlobalInt(pdev);
#endif

return 0;
}


/**
* @brief HCD_GetCurrentSpeed
* Get Current device Speed.
* @param pdev : Selected device
* @retval Status
*/

uint32_t HCD_GetCurrentSpeed (USB_OTG_CORE_HANDLE *pdev)
{
USB_OTG_HPRT0_TypeDef HPRT0;
HPRT0.d32 = USB_OTG_READ_REG32(pdev- & gt; regs.HPRT0);

return HPRT0.b.prtspd;
}

/**
* @brief HCD_ResetPort
* Issues the reset command to device
* @param pdev : Selected device
* @retval Status
*/
uint32_t HCD_ResetPort(USB_OTG_CORE_HANDLE *pdev)
{
/*
Before starting to drive a USB reset, the application waits for the OTG
interrupt triggered by the debounce done bit (DBCDNE bit in OTG_FS_GOTGINT),
which indicates that the bus is stable again after the electrical debounce
caused by the attachment of a pull-up resistor on DP (FS) or DM (LS).
*/

USB_OTG_ResetPort(pdev);
return 0;
}

/**
* @brief HCD_IsDeviceConnected
* Check if the device is connected.
* @param pdev : Selected device
* @retval Device connection status. 1 - & gt; connected and 0 - & gt; disconnected
*
*/
uint32_t HCD_IsDeviceConnected(USB_OTG_CORE_HANDLE *pdev)
{
return (pdev- & gt; host.ConnSts);
}

/**
* @brief HCD_GetCurrentFrame
* This function returns the frame number for sof packet
* @param pdev : Selected device
* @retval Frame number
*
*/
uint32_t HCD_GetCurrentFrame (USB_OTG_CORE_HANDLE *pdev)
{
return (USB_OTG_READ_REG32( & pdev- & gt; regs.HREGS- & gt; HFNUM) & 0xFFFF) ;
}

/**
* @brief HCD_GetURB_State
* This function returns the last URBstate
* @param pdev: Selected device
* @retval URB_STATE
*
*/
URB_STATE HCD_GetURB_State (USB_OTG_CORE_HANDLE *pdev , uint8_t ch_num)
{
return pdev- & gt; host.URB_State[ch_num] ;
}

/**
* @brief HCD_GetXferCnt
* This function returns the last URBstate
* @param pdev: Selected device
* @retval No. of data bytes transferred
*
*/
uint32_t HCD_GetXferCnt (USB_OTG_CORE_HANDLE *pdev, uint8_t ch_num)
{
return pdev- & gt; host.XferCnt[ch_num] ;
}



/**
* @brief HCD_GetHCState
* This function returns the HC Status
* @param pdev: Selected device
* @retval HC_STATUS
*
*/
HC_STATUS HCD_GetHCState (USB_OTG_CORE_HANDLE *pdev , uint8_t ch_num)
{
return pdev- & gt; host.HC_Status[ch_num] ;
}

/**
* @brief HCD_HC_Init
* This function prepare a HC and start a transfer
* @param pdev: Selected device
* @param hc_num: Channel number
* @retval status
*/
uint32_t HCD_HC_Init (USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num)
{
return USB_OTG_HC_Init(pdev, hc_num);
}

/**
* @brief HCD_SubmitRequest
* This function prepare a HC and start a transfer
* @param pdev: Selected device
* @param hc_num: Channel number
* @retval status
*/
uint32_t HCD_SubmitRequest (USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num)
{

pdev- & gt; host.URB_State[hc_num] = URB_IDLE;
pdev- & gt; host.hc[hc_num].xfer_count = 0 ;
return USB_OTG_HC_StartXfer(pdev, hc_num);
}


/**
* @}
*/

/**
* @}
*/

/**
* @}
*/

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/


keyb_fw.7z > usb_core.h

/**
******************************************************************************
* @file usb_core.h
* @author MCD Application Team
* @version V2.1.0
* @date 19-March-2012
* @brief Header of the Core Layer
******************************************************************************
* @attention
*
* & lt; h2 & gt; & lt; center & gt; & copy; COPYRIGHT 2012 STMicroelectronics & lt; /center & gt; & lt; /h2 & gt;
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the " License " );
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an " AS IS " BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USB_CORE_H__
#define __USB_CORE_H__

/* Includes ------------------------------------------------------------------*/
#include " usb_conf.h "
#include " usb_regs.h "
#include " usb_defines.h "


/** @addtogroup USB_OTG_DRIVER
* @{
*/

/** @defgroup USB_CORE
* @brief usb otg driver core layer
* @{
*/


/** @defgroup USB_CORE_Exported_Defines
* @{
*/

#define USB_OTG_EP0_IDLE 0
#define USB_OTG_EP0_SETUP 1
#define USB_OTG_EP0_DATA_IN 2
#define USB_OTG_EP0_DATA_OUT 3
#define USB_OTG_EP0_STATUS_IN 4
#define USB_OTG_EP0_STATUS_OUT 5
#define USB_OTG_EP0_STALL 6

#define USB_OTG_EP_TX_DIS 0x0000
#define USB_OTG_EP_TX_STALL 0x0010
#define USB_OTG_EP_TX_NAK 0x0020
#define USB_OTG_EP_TX_VALID 0x0030

#define USB_OTG_EP_RX_DIS 0x0000
#define USB_OTG_EP_RX_STALL 0x1000
#define USB_OTG_EP_RX_NAK 0x2000
#define USB_OTG_EP_RX_VALID 0x3000
/**
* @}
*/
#define MAX_DATA_LENGTH 0x200

/** @defgroup USB_CORE_Exported_Types
* @{
*/


typedef enum {
USB_OTG_OK = 0,
USB_OTG_FAIL
}USB_OTG_STS;

typedef enum {
HC_IDLE = 0,
HC_XFRC,
HC_HALTED,
HC_NAK,
HC_NYET,
HC_STALL,
HC_XACTERR,
HC_BBLERR,
HC_DATATGLERR,
}HC_STATUS;

typedef enum {
URB_IDLE = 0,
URB_DONE,
URB_NOTREADY,
URB_ERROR,
URB_STALL
}URB_STATE;

typedef enum {
CTRL_START = 0,
CTRL_XFRC,
CTRL_HALTED,
CTRL_NAK,
CTRL_STALL,
CTRL_XACTERR,
CTRL_BBLERR,
CTRL_DATATGLERR,
CTRL_FAIL
}CTRL_STATUS;


typedef struct USB_OTG_hc
{
uint8_t dev_addr ;
uint8_t ep_num;
uint8_t ep_is_in;
uint8_t speed;
uint8_t do_ping;
uint8_t ep_type;
uint16_t max_packet;
uint8_t data_pid;
uint8_t *xfer_buff;
uint32_t xfer_len;
uint32_t xfer_count;
uint8_t toggle_in;
uint8_t toggle_out;
uint32_t dma_addr;
}
USB_OTG_HC , *PUSB_OTG_HC;

typedef struct USB_OTG_ep
{
uint8_t num;
uint8_t is_in;
uint8_t is_stall;
uint8_t type;
uint8_t data_pid_start;
uint8_t even_odd_frame;
uint16_t tx_fifo_num;
uint32_t maxpacket;
/* transaction level variables*/
uint8_t *xfer_buff;
uint32_t dma_addr;
uint32_t xfer_len;
uint32_t xfer_count;
/* Transfer level variables*/
uint32_t rem_data_len;
uint32_t total_data_len;
uint32_t ctl_data_len;

}

USB_OTG_EP , *PUSB_OTG_EP;



typedef struct USB_OTG_core_cfg
{
uint8_t host_channels;
uint8_t dev_endpoints;
uint8_t speed;
uint8_t dma_enable;
uint16_t mps;
uint16_t TotalFifoSize;
uint8_t phy_itface;
uint8_t Sof_output;
uint8_t low_power;
uint8_t coreID;

}
USB_OTG_CORE_CFGS, *PUSB_OTG_CORE_CFGS;



typedef struct usb_setup_req {

uint8_t bmRequest;
uint8_t bRequest;
uint16_t wValue;
uint16_t wIndex;
uint16_t wLength;
} USB_SETUP_REQ;

typedef struct _Device_TypeDef
{
uint8_t *(*GetDeviceDescriptor)( uint8_t speed , uint16_t *length);
uint8_t *(*GetLangIDStrDescriptor)( uint8_t speed , uint16_t *length);
uint8_t *(*GetManufacturerStrDescriptor)( uint8_t speed , uint16_t *length);
uint8_t *(*GetProductStrDescriptor)( uint8_t speed , uint16_t *length);
uint8_t *(*GetSerialStrDescriptor)( uint8_t speed , uint16_t *length);
uint8_t *(*GetConfigurationStrDescriptor)( uint8_t speed , uint16_t *length);
uint8_t *(*GetInterfaceStrDescriptor)( uint8_t speed , uint16_t *length);
} USBD_DEVICE, *pUSBD_DEVICE;

//typedef struct USB_OTG_hPort
//{
// void (*Disconnect) (void *phost);
// void (*Connect) (void *phost);
// uint8_t ConnStatus;
// uint8_t DisconnStatus;
// uint8_t ConnHandled;
// uint8_t DisconnHandled;
//} USB_OTG_hPort_TypeDef;

typedef struct _Device_cb
{
uint8_t (*Init) (void *pdev , uint8_t cfgidx);
uint8_t (*DeInit) (void *pdev , uint8_t cfgidx);
/* Control Endpoints*/
uint8_t (*Setup) (void *pdev , USB_SETUP_REQ *req);
uint8_t (*EP0_TxSent) (void *pdev );
uint8_t (*EP0_RxReady) (void *pdev );
/* Class Specific Endpoints*/
uint8_t (*DataIn) (void *pdev , uint8_t epnum);
uint8_t (*DataOut) (void *pdev , uint8_t epnum);
uint8_t (*SOF) (void *pdev);
uint8_t (*IsoINIncomplete) (void *pdev);
uint8_t (*IsoOUTIncomplete) (void *pdev);

uint8_t *(*GetConfigDescriptor)( uint8_t speed , uint16_t *length);
#ifdef USB_OTG_HS_CORE
uint8_t *(*GetOtherConfigDescriptor)( uint8_t speed , uint16_t *length);
#endif

#ifdef USB_SUPPORT_USER_STRING_DESC
uint8_t *(*GetUsrStrDescriptor)( uint8_t speed ,uint8_t index, uint16_t *length);
#endif

} USBD_Class_cb_TypeDef;



typedef struct _USBD_USR_PROP
{
void (*Init)(void);
void (*DeviceReset)(uint8_t speed);
void (*DeviceConfigured)(void);
void (*DeviceSuspended)(void);
void (*DeviceResumed)(void);

void (*DeviceConnected)(void);
void (*DeviceDisconnected)(void);

}
USBD_Usr_cb_TypeDef;

typedef struct _DCD
{
uint8_t device_config;
uint8_t device_state;
uint8_t device_status;
uint8_t device_old_status;
uint8_t device_address;
uint8_t connection_status;
uint8_t test_mode;
uint32_t DevRemoteWakeup;
USB_OTG_EP in_ep [USB_OTG_MAX_TX_FIFOS];
USB_OTG_EP out_ep [USB_OTG_MAX_TX_FIFOS];
uint8_t setup_packet [8*3];
USBD_Class_cb_TypeDef *class_cb;
USBD_Usr_cb_TypeDef *usr_cb;
USBD_DEVICE *usr_device;
uint8_t *pConfig_descriptor;
}
DCD_DEV , *DCD_PDEV;


typedef struct _HCD
{
uint8_t Rx_Buffer [MAX_DATA_LENGTH];
__IO uint32_t ConnSts;
__IO uint32_t ErrCnt[USB_OTG_MAX_TX_FIFOS];
__IO uint32_t XferCnt[USB_OTG_MAX_TX_FIFOS];
__IO HC_STATUS HC_Status[USB_OTG_MAX_TX_FIFOS];
__IO URB_STATE URB_State[USB_OTG_MAX_TX_FIFOS];
USB_OTG_HC hc [USB_OTG_MAX_TX_FIFOS];
uint16_t channel [USB_OTG_MAX_TX_FIFOS];
// USB_OTG_hPort_TypeDef *port_cb;
}
HCD_DEV , *USB_OTG_USBH_PDEV;


typedef struct _OTG
{
uint8_t OTG_State;
uint8_t OTG_PrevState;
uint8_t OTG_Mode;
}
OTG_DEV , *USB_OTG_USBO_PDEV;

typedef struct USB_OTG_handle
{
USB_OTG_CORE_CFGS cfg;
USB_OTG_CORE_REGS regs;
#ifdef USE_DEVICE_MODE
DCD_DEV dev;
#endif
#ifdef USE_HOST_MODE
HCD_DEV host;
#endif
#ifdef USE_OTG_MODE
OTG_DEV otg;
#endif
}
USB_OTG_CORE_HANDLE , *PUSB_OTG_CORE_HANDLE;

/**
* @}
*/


/** @defgroup USB_CORE_Exported_Macros
* @{
*/

/**
* @}
*/

/** @defgroup USB_CORE_Exported_Variables
* @{
*/
/**
* @}
*/

/** @defgroup USB_CORE_Exported_FunctionsPrototype
* @{
*/


USB_OTG_STS USB_OTG_CoreInit (USB_OTG_CORE_HANDLE *pdev);
USB_OTG_STS USB_OTG_SelectCore (USB_OTG_CORE_HANDLE *pdev,
USB_OTG_CORE_ID_TypeDef coreID);
USB_OTG_STS USB_OTG_EnableGlobalInt (USB_OTG_CORE_HANDLE *pdev);
USB_OTG_STS USB_OTG_DisableGlobalInt(USB_OTG_CORE_HANDLE *pdev);
void* USB_OTG_ReadPacket (USB_OTG_CORE_HANDLE *pdev ,
uint8_t *dest,
uint16_t len);
USB_OTG_STS USB_OTG_WritePacket (USB_OTG_CORE_HANDLE *pdev ,
uint8_t *src,
uint8_t ch_ep_num,
uint16_t len);
USB_OTG_STS USB_OTG_FlushTxFifo (USB_OTG_CORE_HANDLE *pdev , uint32_t num);
USB_OTG_STS USB_OTG_FlushRxFifo (USB_OTG_CORE_HANDLE *pdev);

uint32_t USB_OTG_ReadCoreItr (USB_OTG_CORE_HANDLE *pdev);
uint32_t USB_OTG_ReadOtgItr (USB_OTG_CORE_HANDLE *pdev);
uint8_t USB_OTG_IsHostMode (USB_OTG_CORE_HANDLE *pdev);
uint8_t USB_OTG_IsDeviceMode (USB_OTG_CORE_HANDLE *pdev);
uint32_t USB_OTG_GetMode (USB_OTG_CORE_HANDLE *pdev);
USB_OTG_STS USB_OTG_PhyInit (USB_OTG_CORE_HANDLE *pdev);
USB_OTG_STS USB_OTG_SetCurrentMode (USB_OTG_CORE_HANDLE *pdev,
uint8_t mode);

/*********************** HOST APIs ********************************************/
#ifdef USE_HOST_MODE
USB_OTG_STS USB_OTG_CoreInitHost (USB_OTG_CORE_HANDLE *pdev);
USB_OTG_STS USB_OTG_EnableHostInt (USB_OTG_CORE_HANDLE *pdev);
USB_OTG_STS USB_OTG_HC_Init (USB_OTG_CORE_HANDLE *pdev, uint8_t hc_num);
USB_OTG_STS USB_OTG_HC_Halt (USB_OTG_CORE_HANDLE *pdev, uint8_t hc_num);
USB_OTG_STS USB_OTG_HC_StartXfer (USB_OTG_CORE_HANDLE *pdev, uint8_t hc_num);
USB_OTG_STS USB_OTG_HC_DoPing (USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num);
uint32_t USB_OTG_ReadHostAllChannels_intr (USB_OTG_CORE_HANDLE *pdev);
uint32_t USB_OTG_ResetPort (USB_OTG_CORE_HANDLE *pdev);
uint32_t USB_OTG_ReadHPRT0 (USB_OTG_CORE_HANDLE *pdev);
void USB_OTG_DriveVbus (USB_OTG_CORE_HANDLE *pdev, uint8_t state);
void USB_OTG_InitFSLSPClkSel (USB_OTG_CORE_HANDLE *pdev ,uint8_t freq);
uint8_t USB_OTG_IsEvenFrame (USB_OTG_CORE_HANDLE *pdev) ;
void USB_OTG_StopHost (USB_OTG_CORE_HANDLE *pdev);
#endif
/********************* DEVICE APIs ********************************************/
#ifdef USE_DEVICE_MODE
USB_OTG_STS USB_OTG_CoreInitDev (USB_OTG_CORE_HANDLE *pdev);
USB_OTG_STS USB_OTG_EnableDevInt (USB_OTG_CORE_HANDLE *pdev);
uint32_t USB_OTG_ReadDevAllInEPItr (USB_OTG_CORE_HANDLE *pdev);
enum USB_OTG_SPEED USB_OTG_GetDeviceSpeed (USB_OTG_CORE_HANDLE *pdev);
USB_OTG_STS USB_OTG_EP0Activate (USB_OTG_CORE_HANDLE *pdev);
USB_OTG_STS USB_OTG_EPActivate (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
USB_OTG_STS USB_OTG_EPDeactivate(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
USB_OTG_STS USB_OTG_EPStartXfer (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
USB_OTG_STS USB_OTG_EP0StartXfer(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
USB_OTG_STS USB_OTG_EPSetStall (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
USB_OTG_STS USB_OTG_EPClearStall (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
uint32_t USB_OTG_ReadDevAllOutEp_itr (USB_OTG_CORE_HANDLE *pdev);
uint32_t USB_OTG_ReadDevOutEP_itr (USB_OTG_CORE_HANDLE *pdev , uint8_t epnum);
uint32_t USB_OTG_ReadDevAllInEPItr (USB_OTG_CORE_HANDLE *pdev);
void USB_OTG_InitDevSpeed (USB_OTG_CORE_HANDLE *pdev , uint8_t speed);
uint8_t USBH_IsEvenFrame (USB_OTG_CORE_HANDLE *pdev);
void USB_OTG_EP0_OutStart(USB_OTG_CORE_HANDLE *pdev);
void USB_OTG_ActiveRemoteWakeup(USB_OTG_CORE_HANDLE *pdev);
void USB_OTG_UngateClock(USB_OTG_CORE_HANDLE *pdev);
void USB_OTG_StopDevice(USB_OTG_CORE_HANDLE *pdev);
void USB_OTG_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep , uint32_t Status);
uint32_t USB_OTG_GetEPStatus(USB_OTG_CORE_HANDLE *pdev ,USB_OTG_EP *ep);
#endif
/**
* @}
*/

#endif /* __USB_CORE_H__ */


/**
* @}
*/

/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/


keyb_fw.7z > usbh_hid_keybd.h

/**
******************************************************************************
* @file usbh_hid_keybd.h
* @author MCD Application Team
* @version V2.1.0
* @date 19-March-2012
* @brief This file contains all the prototypes for the usbh_hid_keybd.c
******************************************************************************
* @attention
*
* & lt; h2 & gt; & lt; center & gt; & copy; COPYRIGHT 2012 STMicroelectronics & lt; /center & gt; & lt; /h2 & gt;
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the " License " );
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an " AS IS " BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/

/* Define to prevent recursive -----------------------------------------------*/
#ifndef __USBH_HID_KEYBD_H
#define __USBH_HID_KEYBD_H

/* Includes ------------------------------------------------------------------*/
#include " usb_conf.h "
#include " usbh_hid_core.h "
#include " usb_host_conf.h "

/** @addtogroup USBH_LIB
* @{
*/

/** @addtogroup USBH_CLASS
* @{
*/

/** @addtogroup USBH_HID_CLASS
* @{
*/

/** @defgroup USBH_HID_KEYBD
* @brief This file is the Header file for USBH_HID_KEYBD.c
* @{
*/


/** @defgroup USBH_HID_KEYBD_Exported_Types
* @{
*/


/**
* @}
*/

/** @defgroup USBH_HID_KEYBD_Exported_Defines
* @{
*/
/* Default keyboard configuration is AZERTY */
#if !defined(QWERTY_KEYBOARD) & & !defined(AZERTY_KEYBOARD)
#define AZERTY_KEYBOARD
#endif

#define KBD_LEFT_CTRL 0x01
#define KBD_LEFT_SHIFT 0x02
#define KBD_LEFT_ALT 0x04
#define KBD_LEFT_GUI 0x08
#define KBD_RIGHT_CTRL 0x10
#define KBD_RIGHT_SHIFT 0x20
#define KBD_RIGHT_ALT 0x40
#define KBD_RIGHT_GUI 0x80

#define KBR_MAX_NBR_PRESSED 6

/**
* @}
*/

/** @defgroup USBH_HID_KEYBD_Exported_Macros
* @{
*/
/**
* @}
*/

/** @defgroup USBH_HID_KEYBD_Exported_Variables
* @{
*/

extern HID_cb_TypeDef HID_KEYBRD_cb;
/**
* @}
*/

/** @defgroup USBH_HID_KEYBD_Exported_FunctionsPrototype
* @{
*/
void USR_KEYBRD_Init (void);
void USR_KEYBRD_ProcessData (uint8_t pbuf);
/**
* @}
*/

#endif /* __USBH_HID_KEYBD_H */

/**
* @}
*/

/**
* @}
*/

/**
* @}
*/

/**
* @}
*/

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/


keyb_fw.7z > usb_regs.h

/**
******************************************************************************
* @file usb_regs.h
* @author MCD Application Team
* @version V2.1.0
* @date 19-March-2012
* @brief hardware registers
******************************************************************************
* @attention
*
* & lt; h2 & gt; & lt; center & gt; & copy; COPYRIGHT 2012 STMicroelectronics & lt; /center & gt; & lt; /h2 & gt;
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the " License " );
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an " AS IS " BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USB_OTG_REGS_H__
#define __USB_OTG_REGS_H__

/* Includes ------------------------------------------------------------------*/
#include " usb_conf.h "


/** @addtogroup USB_OTG_DRIVER
* @{
*/

/** @defgroup USB_REGS
* @brief This file is the
* @{
*/


/** @defgroup USB_REGS_Exported_Defines
* @{
*/

#define USB_OTG_HS_BASE_ADDR 0x40040000
#define USB_OTG_FS_BASE_ADDR 0x50000000

#define USB_OTG_CORE_GLOBAL_REGS_OFFSET 0x000
#define USB_OTG_DEV_GLOBAL_REG_OFFSET 0x800
#define USB_OTG_DEV_IN_EP_REG_OFFSET 0x900
#define USB_OTG_EP_REG_OFFSET 0x20
#define USB_OTG_DEV_OUT_EP_REG_OFFSET 0xB00
#define USB_OTG_HOST_GLOBAL_REG_OFFSET 0x400
#define USB_OTG_HOST_PORT_REGS_OFFSET 0x440
#define USB_OTG_HOST_CHAN_REGS_OFFSET 0x500
#define USB_OTG_CHAN_REGS_OFFSET 0x20
#define USB_OTG_PCGCCTL_OFFSET 0xE00
#define USB_OTG_DATA_FIFO_OFFSET 0x1000
#define USB_OTG_DATA_FIFO_SIZE 0x1000


#define USB_OTG_MAX_TX_FIFOS 15

#define USB_OTG_HS_MAX_PACKET_SIZE 512
#define USB_OTG_FS_MAX_PACKET_SIZE 64
#define USB_OTG_MAX_EP0_SIZE 64
/**
* @}
*/

/** @defgroup USB_REGS_Exported_Types
* @{
*/

/** @defgroup __USB_OTG_Core_register
* @{
*/
typedef struct _USB_OTG_GREGS //000h
{
__IO uint32_t GOTGCTL; /* USB_OTG Control and Status Register 000h*/
__IO uint32_t GOTGINT; /* USB_OTG Interrupt Register 004h*/
__IO uint32_t GAHBCFG; /* Core AHB Configuration Register 008h*/
__IO uint32_t GUSBCFG; /* Core USB Configuration Register 00Ch*/
__IO uint32_t GRSTCTL; /* Core Reset Register 010h*/
__IO uint32_t GINTSTS; /* Core Interrupt Register 014h*/
__IO uint32_t GINTMSK; /* Core Interrupt Mask Register 018h*/
__IO uint32_t GRXSTSR; /* Receive Sts Q Read Register 01Ch*/
__IO uint32_t GRXSTSP; /* Receive Sts Q Read & POP Register 020h*/
__IO uint32_t GRXFSIZ; /* Receive FIFO Size Register 024h*/
__IO uint32_t DIEPTXF0_HNPTXFSIZ; /* EP0 / Non Periodic Tx FIFO Size Register 028h*/
__IO uint32_t HNPTXSTS; /* Non Periodic Tx FIFO/Queue Sts reg 02Ch*/
uint32_t Reserved30[2]; /* Reserved 030h*/
__IO uint32_t GCCFG; /* General Purpose IO Register 038h*/
__IO uint32_t CID; /* User ID Register 03Ch*/
uint32_t Reserved40[48]; /* Reserved 040h-0FFh*/
__IO uint32_t HPTXFSIZ; /* Host Periodic Tx FIFO Size Reg 100h*/
__IO uint32_t DIEPTXF[USB_OTG_MAX_TX_FIFOS];/* dev Periodic Transmit FIFO */
}
USB_OTG_GREGS;
/**
* @}
*/


/** @defgroup __device_Registers
* @{
*/
typedef struct _USB_OTG_DREGS // 800h
{
__IO uint32_t DCFG; /* dev Configuration Register 800h*/
__IO uint32_t DCTL; /* dev Control Register 804h*/
__IO uint32_t DSTS; /* dev Status Register (RO) 808h*/
uint32_t Reserved0C; /* Reserved 80Ch*/
__IO uint32_t DIEPMSK; /* dev IN Endpoint Mask 810h*/
__IO uint32_t DOEPMSK; /* dev OUT Endpoint Mask 814h*/
__IO uint32_t DAINT; /* dev All Endpoints Itr Reg 818h*/
__IO uint32_t DAINTMSK; /* dev All Endpoints Itr Mask 81Ch*/
uint32_t Reserved20; /* Reserved 820h*/
uint32_t Reserved9; /* Reserved 824h*/
__IO uint32_t DVBUSDIS; /* dev VBUS discharge Register 828h*/
__IO uint32_t DVBUSPULSE; /* dev VBUS Pulse Register 82Ch*/
__IO uint32_t DTHRCTL; /* dev thr 830h*/
__IO uint32_t DIEPEMPMSK; /* dev empty msk 834h*/
__IO uint32_t DEACHINT; /* dedicated EP interrupt 838h*/
__IO uint32_t DEACHMSK; /* dedicated EP msk 83Ch*/
uint32_t Reserved40; /* dedicated EP mask 840h*/
__IO uint32_t DINEP1MSK; /* dedicated EP mask 844h*/
uint32_t Reserved44[15]; /* Reserved 844-87Ch*/
__IO uint32_t DOUTEP1MSK; /* dedicated EP msk 884h*/
}
USB_OTG_DREGS;
/**
* @}
*/


/** @defgroup __IN_Endpoint-Specific_Register
* @{
*/
typedef struct _USB_OTG_INEPREGS
{
__IO uint32_t DIEPCTL; /* dev IN Endpoint Control Reg 900h + (ep_num * 20h) + 00h*/
uint32_t Reserved04; /* Reserved 900h + (ep_num * 20h) + 04h*/
__IO uint32_t DIEPINT; /* dev IN Endpoint Itr Reg 900h + (ep_num * 20h) + 08h*/
uint32_t Reserved0C; /* Reserved 900h + (ep_num * 20h) + 0Ch*/
__IO uint32_t DIEPTSIZ; /* IN Endpoint Txfer Size 900h + (ep_num * 20h) + 10h*/
__IO uint32_t DIEPDMA; /* IN Endpoint DMA Address Reg 900h + (ep_num * 20h) + 14h*/
__IO uint32_t DTXFSTS;/*IN Endpoint Tx FIFO Status Reg 900h + (ep_num * 20h) + 18h*/
uint32_t Reserved18; /* Reserved 900h+(ep_num*20h)+1Ch-900h+ (ep_num * 20h) + 1Ch*/
}
USB_OTG_INEPREGS;
/**
* @}
*/


/** @defgroup __OUT_Endpoint-Specific_Registers
* @{
*/
typedef struct _USB_OTG_OUTEPREGS
{
__IO uint32_t DOEPCTL; /* dev OUT Endpoint Control Reg B00h + (ep_num * 20h) + 00h*/
uint32_t Reserved04; /* Reserved B00h + (ep_num * 20h) + 04h*/
__IO uint32_t DOEPINT; /* dev OUT Endpoint Itr Reg B00h + (ep_num * 20h) + 08h*/
uint32_t Reserved0C; /* Reserved B00h + (ep_num * 20h) + 0Ch*/
__IO uint32_t DOEPTSIZ; /* dev OUT Endpoint Txfer Size B00h + (ep_num * 20h) + 10h*/
__IO uint32_t DOEPDMA; /* dev OUT Endpoint DMA Address B00h + (ep_num * 20h) + 14h*/
uint32_t Reserved18[2]; /* Reserved B00h + (ep_num * 20h) + 18h - B00h + (ep_num * 20h) + 1Ch*/
}
USB_OTG_OUTEPREGS;
/**
* @}
*/


/** @defgroup __Host_Mode_Register_Structures
* @{
*/
typedef struct _USB_OTG_HREGS
{
__IO uint32_t HCFG; /* Host Configuration Register 400h*/
__IO uint32_t HFIR; /* Host Frame Interval Register 404h*/
__IO uint32_t HFNUM; /* Host Frame Nbr/Frame Remaining 408h*/
uint32_t Reserved40C; /* Reserved 40Ch*/
__IO uint32_t HPTXSTS; /* Host Periodic Tx FIFO/ Queue Status 410h*/
__IO uint32_t HAINT; /* Host All Channels Interrupt Register 414h*/
__IO uint32_t HAINTMSK; /* Host All Channels Interrupt Mask 418h*/
}
USB_OTG_HREGS;
/**
* @}
*/


/** @defgroup __Host_Channel_Specific_Registers
* @{
*/
typedef struct _USB_OTG_HC_REGS
{
__IO uint32_t HCCHAR;
__IO uint32_t HCSPLT;
__IO uint32_t HCINT;
__IO uint32_t HCINTMSK;
__IO uint32_t HCTSIZ;
__IO uint32_t HCDMA;
uint32_t Reserved[2];
}
USB_OTG_HC_REGS;
/**
* @}
*/


/** @defgroup __otg_Core_registers
* @{
*/
typedef struct USB_OTG_core_regs //000h
{
USB_OTG_GREGS *GREGS;
USB_OTG_DREGS *DREGS;
USB_OTG_HREGS *HREGS;
USB_OTG_INEPREGS *INEP_REGS[USB_OTG_MAX_TX_FIFOS];
USB_OTG_OUTEPREGS *OUTEP_REGS[USB_OTG_MAX_TX_FIFOS];
USB_OTG_HC_REGS *HC_REGS[USB_OTG_MAX_TX_FIFOS];
__IO uint32_t *HPRT0;
__IO uint32_t *DFIFO[USB_OTG_MAX_TX_FIFOS];
__IO uint32_t *PCGCCTL;
}
USB_OTG_CORE_REGS , *PUSB_OTG_CORE_REGS;
typedef union _USB_OTG_GOTGCTL_TypeDef
{
uint32_t d32;
struct
{
uint32_t sesreqscs :
1;
uint32_t sesreq :
1;
uint32_t Reserved2_7 :
6;
uint32_t hstnegscs :
1;
uint32_t hnpreq :
1;
uint32_t hstsethnpen :
1;
uint32_t devhnpen :
1;
uint32_t Reserved12_15 :
4;
uint32_t conidsts :
1;
uint32_t dbct :
1;
uint32_t asesvld :
1;
uint32_t bsesvld :
1;
uint32_t Reserved20_31 :
12;
}
b;
} USB_OTG_GOTGCTL_TypeDef ;

typedef union _USB_OTG_GOTGINT_TypeDef
{
uint32_t d32;
struct
{
uint32_t Reserved0_1 :
2;
uint32_t sesenddet :
1;
uint32_t Reserved3_7 :
5;
uint32_t sesreqsucstschng :
1;
uint32_t hstnegsucstschng :
1;
uint32_t reserver10_16 :
7;
uint32_t hstnegdet :
1;
uint32_t adevtoutchng :
1;
uint32_t debdone :
1;
uint32_t Reserved31_20 :
12;
}
b;
} USB_OTG_GOTGINT_TypeDef ;
typedef union _USB_OTG_GAHBCFG_TypeDef
{
uint32_t d32;
struct
{
uint32_t glblintrmsk :
1;
uint32_t hburstlen :
4;
uint32_t dmaenable :
1;
uint32_t Reserved :
1;
uint32_t nptxfemplvl_txfemplvl :
1;
uint32_t ptxfemplvl :
1;
uint32_t Reserved9_31 :
23;
}
b;
} USB_OTG_GAHBCFG_TypeDef ;
typedef union _USB_OTG_GUSBCFG_TypeDef
{
uint32_t d32;
struct
{
uint32_t toutcal :
3;
uint32_t Reserved3_5 :
3;
uint32_t physel :
1;
uint32_t Reserved7 :
1;
uint32_t srpcap :
1;
uint32_t hnpcap :
1;
uint32_t usbtrdtim :
4;
uint32_t Reserved14 :
1;
uint32_t phylpwrclksel :
1;
uint32_t Reserved16 :
1;
uint32_t ulpi_fsls :
1;
uint32_t ulpi_auto_res :
1;
uint32_t ulpi_clk_sus_m :
1;
uint32_t ulpi_ext_vbus_drv :
1;
uint32_t ulpi_int_vbus_ind :
1;
uint32_t term_sel_dl_pulse :
1;
uint32_t ulpi_ind_cpl :
1;
uint32_t ulpi_passthrough :
1;
uint32_t ulpi_protect_disable :
1;
uint32_t Reserved26_28 :
3;
uint32_t force_host :
1;
uint32_t force_dev :
1;
uint32_t corrupt_tx :
1;
}
b;
} USB_OTG_GUSBCFG_TypeDef ;
typedef union _USB_OTG_GRSTCTL_TypeDef
{
uint32_t d32;
struct
{
uint32_t csftrst :
1;
uint32_t hsftrst :
1;
uint32_t hstfrm :
1;
uint32_t Reserved3 :
1;
uint32_t rxfflsh :
1;
uint32_t txfflsh :
1;
uint32_t txfnum :
5;
uint32_t Reserved11_29 :
19;
uint32_t dmareq :
1;
uint32_t ahbidle :
1;
}
b;
} USB_OTG_GRSTCTL_TypeDef ;
typedef union _USB_OTG_GINTMSK_TypeDef
{
uint32_t d32;
struct
{
uint32_t Reserved0 :
1;
uint32_t modemismatch :
1;
uint32_t otgintr :
1;
uint32_t sofintr :
1;
uint32_t rxstsqlvl :
1;
uint32_t nptxfempty :
1;
uint32_t ginnakeff :
1;
uint32_t goutnakeff :
1;
uint32_t Reserved8_9 :
2;
uint32_t erlysuspend :
1;
uint32_t usbsuspend :
1;
uint32_t usbreset :
1;
uint32_t enumdone :
1;
uint32_t isooutdrop :
1;
uint32_t eopframe :
1;
uint32_t Reserved16 :
1;
uint32_t epmismatch :
1;
uint32_t inepintr :
1;
uint32_t outepintr :
1;
uint32_t incomplisoin :
1;
uint32_t incomplisoout :
1;
uint32_t Reserved22_23 :
2;
uint32_t portintr :
1;
uint32_t hcintr :
1;
uint32_t ptxfempty :
1;
uint32_t Reserved27 :
1;
uint32_t conidstschng :
1;
uint32_t disconnect :
1;
uint32_t sessreqintr :
1;
uint32_t wkupintr :
1;
}
b;
} USB_OTG_GINTMSK_TypeDef ;
typedef union _USB_OTG_GINTSTS_TypeDef
{
uint32_t d32;
struct
{
uint32_t curmode :
1;
uint32_t modemismatch :
1;
uint32_t otgintr :
1;
uint32_t sofintr :
1;
uint32_t rxstsqlvl :
1;
uint32_t nptxfempty :
1;
uint32_t ginnakeff :
1;
uint32_t goutnakeff :
1;
uint32_t Reserved8_9 :
2;
uint32_t erlysuspend :
1;
uint32_t usbsuspend :
1;
uint32_t usbreset :
1;
uint32_t enumdone :
1;
uint32_t isooutdrop :
1;
uint32_t eopframe :
1;
uint32_t Reserved16_17 :
2;
uint32_t inepint:
1;
uint32_t outepintr :
1;
uint32_t incomplisoin :
1;
uint32_t incomplisoout :
1;
uint32_t Reserved22_23 :
2;
uint32_t portintr :
1;
uint32_t hcintr :
1;
uint32_t ptxfempty :
1;
uint32_t Reserved27 :
1;
uint32_t conidstschng :
1;
uint32_t disconnect :
1;
uint32_t sessreqintr :
1;
uint32_t wkupintr :
1;
}
b;
} USB_OTG_GINTSTS_TypeDef ;
typedef union _USB_OTG_DRXSTS_TypeDef
{
uint32_t d32;
struct
{
uint32_t epnum :
4;
uint32_t bcnt :
11;
uint32_t dpid :
2;
uint32_t pktsts :
4;
uint32_t fn :
4;
uint32_t Reserved :
7;
}
b;
} USB_OTG_DRXSTS_TypeDef ;
typedef union _USB_OTG_GRXSTS_TypeDef
{
uint32_t d32;
struct
{
uint32_t chnum :
4;
uint32_t bcnt :
11;
uint32_t dpid :
2;
uint32_t pktsts :
4;
uint32_t Reserved :
11;
}
b;
} USB_OTG_GRXFSTS_TypeDef ;
typedef union _USB_OTG_FSIZ_TypeDef
{
uint32_t d32;
struct
{
uint32_t startaddr :
16;
uint32_t depth :
16;
}
b;
} USB_OTG_FSIZ_TypeDef ;
typedef union _USB_OTG_HNPTXSTS_TypeDef
{
uint32_t d32;
struct
{
uint32_t nptxfspcavail :
16;
uint32_t nptxqspcavail :
8;
struct
{
uint32_t terminate :
1;
uint32_t token :
2;
uint32_t chnum :
4;
} nptxqtop;
uint32_t Reserved :
1;
}
b;
} USB_OTG_HNPTXSTS_TypeDef ;
typedef union _USB_OTG_DTXFSTSn_TypeDef
{
uint32_t d32;
struct
{
uint32_t txfspcavail :
16;
uint32_t Reserved :
16;
}
b;
} USB_OTG_DTXFSTSn_TypeDef ;

typedef union _USB_OTG_GCCFG_TypeDef
{
uint32_t d32;
struct
{
uint32_t Reserved_in :
16;
uint32_t pwdn :
1;
uint32_t Reserved_17 :
1;
uint32_t vbussensingA :
1;
uint32_t vbussensingB :
1;
uint32_t sofouten :
1;
uint32_t disablevbussensing :
1;
uint32_t Reserved_out :
10;
}
b;
} USB_OTG_GCCFG_TypeDef ;

typedef union _USB_OTG_DCFG_TypeDef
{
uint32_t d32;
struct
{
uint32_t devspd :
2;
uint32_t nzstsouthshk :
1;
uint32_t Reserved3 :
1;
uint32_t devaddr :
7;
uint32_t perfrint :
2;
uint32_t Reserved12_31 :
19;
}
b;
} USB_OTG_DCFG_TypeDef ;
typedef union _USB_OTG_DCTL_TypeDef
{
uint32_t d32;
struct
{
uint32_t rmtwkupsig :
1;
uint32_t sftdiscon :
1;
uint32_t gnpinnaksts :
1;
uint32_t goutnaksts :
1;
uint32_t tstctl :
3;
uint32_t sgnpinnak :
1;
uint32_t cgnpinnak :
1;
uint32_t sgoutnak :
1;
uint32_t cgoutnak :
1;
uint32_t poprg_done :
1;
uint32_t Reserved :
20;
}
b;
} USB_OTG_DCTL_TypeDef ;
typedef union _USB_OTG_DSTS_TypeDef
{
uint32_t d32;
struct
{
uint32_t suspsts :
1;
uint32_t enumspd :
2;
uint32_t errticerr :
1;
uint32_t Reserved4_7:
4;
uint32_t soffn :
14;
uint32_t Reserved22_31 :
10;
}
b;
} USB_OTG_DSTS_TypeDef ;
typedef union _USB_OTG_DIEPINTn_TypeDef
{
uint32_t d32;
struct
{
uint32_t xfercompl :
1;
uint32_t epdisabled :
1;
uint32_t Reserved2 :
1;
uint32_t timeout :
1;
uint32_t intktxfemp :
1;
uint32_t Reserved5 :
1;
uint32_t inepnakeff :
1;
uint32_t emptyintr :
1;
uint32_t txfifoundrn :
1;
uint32_t Reserved14_31 :
23;
}
b;
} USB_OTG_DIEPINTn_TypeDef ;
typedef union _USB_OTG_DIEPINTn_TypeDef USB_OTG_DIEPMSK_TypeDef ;
typedef union _USB_OTG_DOEPINTn_TypeDef
{
uint32_t d32;
struct
{
uint32_t xfercompl :
1;
uint32_t epdisabled :
1;
uint32_t Reserved2 :
1;
uint32_t setup :
1;
uint32_t Reserved04_31 :
28;
}
b;
} USB_OTG_DOEPINTn_TypeDef ;
typedef union _USB_OTG_DOEPINTn_TypeDef USB_OTG_DOEPMSK_TypeDef ;

typedef union _USB_OTG_DAINT_TypeDef
{
uint32_t d32;
struct
{
uint32_t in :
16;
uint32_t out :
16;
}
ep;
} USB_OTG_DAINT_TypeDef ;

typedef union _USB_OTG_DTHRCTL_TypeDef
{
uint32_t d32;
struct
{
uint32_t non_iso_thr_en :
1;
uint32_t iso_thr_en :
1;
uint32_t tx_thr_len :
9;
uint32_t Reserved11_15 :
5;
uint32_t rx_thr_en :
1;
uint32_t rx_thr_len :
9;
uint32_t Reserved26 :
1;
uint32_t arp_en :
1;
uint32_t Reserved28_31 :
4;
}
b;
} USB_OTG_DTHRCTL_TypeDef ;
typedef union _USB_OTG_DEPCTL_TypeDef
{
uint32_t d32;
struct
{
uint32_t mps :
11;
uint32_t reserved :
4;
uint32_t usbactep :
1;
uint32_t dpid :
1;
uint32_t naksts :
1;
uint32_t eptype :
2;
uint32_t snp :
1;
uint32_t stall :
1;
uint32_t txfnum :
4;
uint32_t cnak :
1;
uint32_t snak :
1;
uint32_t setd0pid :
1;
uint32_t setd1pid :
1;
uint32_t epdis :
1;
uint32_t epena :
1;
}
b;
} USB_OTG_DEPCTL_TypeDef ;
typedef union _USB_OTG_DEPXFRSIZ_TypeDef
{
uint32_t d32;
struct
{
uint32_t xfersize :
19;
uint32_t pktcnt :
10;
uint32_t mc :
2;
uint32_t Reserved :
1;
}
b;
} USB_OTG_DEPXFRSIZ_TypeDef ;
typedef union _USB_OTG_DEP0XFRSIZ_TypeDef
{
uint32_t d32;
struct
{
uint32_t xfersize :
7;
uint32_t Reserved7_18 :
12;
uint32_t pktcnt :
2;
uint32_t Reserved20_28 :
9;
uint32_t supcnt :
2;
uint32_t Reserved31;
}
b;
} USB_OTG_DEP0XFRSIZ_TypeDef ;
typedef union _USB_OTG_HCFG_TypeDef
{
uint32_t d32;
struct
{
uint32_t fslspclksel :
2;
uint32_t fslssupp :
1;
}
b;
} USB_OTG_HCFG_TypeDef ;
typedef union _USB_OTG_HFRMINTRVL_TypeDef
{
uint32_t d32;
struct
{
uint32_t frint :
16;
uint32_t Reserved :
16;
}
b;
} USB_OTG_HFRMINTRVL_TypeDef ;

typedef union _USB_OTG_HFNUM_TypeDef
{
uint32_t d32;
struct
{
uint32_t frnum :
16;
uint32_t frrem :
16;
}
b;
} USB_OTG_HFNUM_TypeDef ;
typedef union _USB_OTG_HPTXSTS_TypeDef
{
uint32_t d32;
struct
{
uint32_t ptxfspcavail :
16;
uint32_t ptxqspcavail :
8;
struct
{
uint32_t terminate :
1;
uint32_t token :
2;
uint32_t chnum :
4;
uint32_t odd_even :
1;
} ptxqtop;
}
b;
} USB_OTG_HPTXSTS_TypeDef ;
typedef union _USB_OTG_HPRT0_TypeDef
{
uint32_t d32;
struct
{
uint32_t prtconnsts :
1;
uint32_t prtconndet :
1;
uint32_t prtena :
1;
uint32_t prtenchng :
1;
uint32_t prtovrcurract :
1;
uint32_t prtovrcurrchng :
1;
uint32_t prtres :
1;
uint32_t prtsusp :
1;
uint32_t prtrst :
1;
uint32_t Reserved9 :
1;
uint32_t prtlnsts :
2;
uint32_t prtpwr :
1;
uint32_t prttstctl :
4;
uint32_t prtspd :
2;
uint32_t Reserved19_31 :
13;
}
b;
} USB_OTG_HPRT0_TypeDef ;
typedef union _USB_OTG_HAINT_TypeDef
{
uint32_t d32;
struct
{
uint32_t chint :
16;
uint32_t Reserved :
16;
}
b;
} USB_OTG_HAINT_TypeDef ;
typedef union _USB_OTG_HAINTMSK_TypeDef
{
uint32_t d32;
struct
{
uint32_t chint :
16;
uint32_t Reserved :
16;
}
b;
} USB_OTG_HAINTMSK_TypeDef ;
typedef union _USB_OTG_HCCHAR_TypeDef
{
uint32_t d32;
struct
{
uint32_t mps :
11;
uint32_t epnum :
4;
uint32_t epdir :
1;
uint32_t Reserved :
1;
uint32_t lspddev :
1;
uint32_t eptype :
2;
uint32_t multicnt :
2;
uint32_t devaddr :
7;
uint32_t oddfrm :
1;
uint32_t chdis :
1;
uint32_t chen :
1;
}
b;
} USB_OTG_HCCHAR_TypeDef ;
typedef union _USB_OTG_HCSPLT_TypeDef
{
uint32_t d32;
struct
{
uint32_t prtaddr :
7;
uint32_t hubaddr :
7;
uint32_t xactpos :
2;
uint32_t compsplt :
1;
uint32_t Reserved :
14;
uint32_t spltena :
1;
}
b;
} USB_OTG_HCSPLT_TypeDef ;
typedef union _USB_OTG_HCINTn_TypeDef
{
uint32_t d32;
struct
{
uint32_t xfercompl :
1;
uint32_t chhltd :
1;
uint32_t ahberr :
1;
uint32_t stall :
1;
uint32_t nak :
1;
uint32_t ack :
1;
uint32_t nyet :
1;
uint32_t xacterr :
1;
uint32_t bblerr :
1;
uint32_t frmovrun :
1;
uint32_t datatglerr :
1;
uint32_t Reserved :
21;
}
b;
} USB_OTG_HCINTn_TypeDef ;
typedef union _USB_OTG_HCTSIZn_TypeDef
{
uint32_t d32;
struct
{
uint32_t xfersize :
19;
uint32_t pktcnt :
10;
uint32_t pid :
2;
uint32_t dopng :
1;
}
b;
} USB_OTG_HCTSIZn_TypeDef ;
typedef union _USB_OTG_HCINTMSK_TypeDef
{
uint32_t d32;
struct
{
uint32_t xfercompl :
1;
uint32_t chhltd :
1;
uint32_t ahberr :
1;
uint32_t stall :
1;
uint32_t nak :
1;
uint32_t ack :
1;
uint32_t nyet :
1;
uint32_t xacterr :
1;
uint32_t bblerr :
1;
uint32_t frmovrun :
1;
uint32_t datatglerr :
1;
uint32_t Reserved :
21;
}
b;
} USB_OTG_HCINTMSK_TypeDef ;

typedef union _USB_OTG_PCGCCTL_TypeDef
{
uint32_t d32;
struct
{
uint32_t stoppclk :
1;
uint32_t gatehclk :
1;
uint32_t Reserved2_3 :
2;
uint32_t phy_susp :
1;
uint32_t Reserved5_31 :
27;
}
b;
} USB_OTG_PCGCCTL_TypeDef ;

/**
* @}
*/


/** @defgroup USB_REGS_Exported_Macros
* @{
*/
/**
* @}
*/

/** @defgroup USB_REGS_Exported_Variables
* @{
*/
/**
* @}
*/

/** @defgroup USB_REGS_Exported_FunctionsPrototype
* @{
*/
/**
* @}
*/


#endif //__USB_OTG_REGS_H__


/**
* @}
*/

/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/


keyb_fw.7z > usbh_conf.h

/**
******************************************************************************
* @file USBH_conf.h
* @author MCD Application Team
* @version V2.1.0
* @date 19-March-2012
* @brief General low level driver configuration
******************************************************************************
* @attention
*
* & lt; h2 & gt; & lt; center & gt; & copy; COPYRIGHT 2012 STMicroelectronics & lt; /center & gt; & lt; /h2 & gt;
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the " License " );
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an " AS IS " BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USBH_CONF__H__
#define __USBH_CONF__H__

/* Includes ------------------------------------------------------------------*/

/** @addtogroup USBH_OTG_DRIVER
* @{
*/

/** @defgroup USBH_CONF
* @brief usb otg low level driver configuration file
* @{
*/

/** @defgroup USBH_CONF_Exported_Defines
* @{
*/

#define USBH_MAX_NUM_ENDPOINTS 2
#define USBH_MAX_NUM_INTERFACES 2
#define USBH_MSC_MPS_SIZE 0x200

/**
* @}
*/


/** @defgroup USBH_CONF_Exported_Types
* @{
*/
/**
* @}
*/


/** @defgroup USBH_CONF_Exported_Macros
* @{
*/
/**
* @}
*/

/** @defgroup USBH_CONF_Exported_Variables
* @{
*/
/**
* @}
*/

/** @defgroup USBH_CONF_Exported_FunctionsPrototype
* @{
*/
/**
* @}
*/


#endif //__USBH_CONF__H__


/**
* @}
*/

/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/


keyb_fw.7z > usb_bsp.cpp

/**
******************************************************************************
* @file usb_bsp.c
* @author MCD Application Team
* @version V2.1.0
* @date 19-March-2012
* @brief This file implements the board support package for the USB host library
******************************************************************************
* @attention
*
* & lt; h2 & gt; & lt; center & gt; & copy; COPYRIGHT 2012 STMicroelectronics & lt; /center & gt; & lt; /h2 & gt;
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the " License " );
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an " AS IS " BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/

/* Includes ------------------------------------------------------------------*/
#include " usb_bsp.h "
#include " usb_conf.h "
#include " usbh_hid_core.h "
#include " usb_hcd_int.h "
#include " usbh_core.h "
#include " usb_host_conf.h "

/* Default NVIC settings */
#ifndef USB_HID_HOST_NVIC_PRIORITY
#define USB_HID_HOST_NVIC_PRIORITY 0x01
#endif

#ifndef USB_HID_HOST_NVIC_SUBPRIORITY
#define USB_HID_HOST_NVIC_SUBPRIORITY 0x03
#endif

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/

USB_OTG_CORE_HANDLE USB_OTG_Core;
USBH_HOST USB_Host;

/**
* @}
*/


/** @defgroup USB_BSP_Private_TypesDefinitions
* @{
*/
/**
* @}
*/



/** @defgroup USB_BSP_Private_Macros
* @{
*/
/**
* @}
*/

/** @defgroup USBH_BSP_Private_Variables
* @{
*/
ErrorStatus HSEStartUpStatus;
/**
* @}
*/

/** @defgroup USBH_BSP_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/

/** @defgroup USB_BSP_Private_Functions
* @{
*/

/**
* @brief USB_OTG_BSP_Init
* Initilizes BSP configurations
* @param None
* @retval None
*/

void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev) {
/* Note: On STM32F4-Discovery board only USB OTG FS core is supported. */

GPIO_InitTypeDef GPIO_InitStructure;
#ifdef USE_USB_OTG_FS

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

/* Configure SOF VBUS ID DM DP Pins */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | // Data -
GPIO_Pin_12; // Data +

#ifndef USB_HID_HOST_DISABLE_VBUS
GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_9; // VBUS
#endif
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, & GPIO_InitStructure);

#ifndef USB_HID_HOST_DISABLE_VBUS
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9, GPIO_AF_OTG1_FS);
#endif
GPIO_PinAFConfig(GPIOA,GPIO_PinSource11, GPIO_AF_OTG1_FS);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource12, GPIO_AF_OTG1_FS);

/* this for ID line debug */
#ifndef USB_HID_HOST_DISABLE_ID
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOA, & GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10, GPIO_AF_OTG1_FS) ;
#endif

RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ;

#else //USE_USB_OTG_HS

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB , ENABLE);

/* Configure SOF VBUS ID DM DP Pins */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | // Data -
GPIO_Pin_15; // Data +

#ifndef USB_HID_HOST_DISABLE_ID
GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_12;
#endif

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, & GPIO_InitStructure);

#ifndef USB_HID_HOST_DISABLE_ID
GPIO_PinAFConfig(GPIOB,GPIO_PinSource12, GPIO_AF_OTG2_FS);
#endif

GPIO_PinAFConfig(GPIOB,GPIO_PinSource14, GPIO_AF_OTG2_FS);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource15, GPIO_AF_OTG2_FS);

/* VBUS */
#ifndef USB_HID_HOST_DISABLE_VBUS
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_Init(GPIOB, & GPIO_InitStructure);
#endif

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_OTG_HS, ENABLE);

#endif //USB_OTG_HS
}
/**
* @brief USB_OTG_BSP_EnableInterrupt
* Configures USB Global interrupt
* @param None
* @retval None
*/
void USB_OTG_BSP_EnableInterrupt(USB_OTG_CORE_HANDLE *pdev)
{
NVIC_InitTypeDef NVIC_InitStructure;

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
#ifdef USE_USB_OTG_HS
NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_IRQn;
#else
NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;
#endif
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = USB_HID_HOST_NVIC_PRIORITY;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = USB_HID_HOST_NVIC_SUBPRIORITY;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init( & NVIC_InitStructure);
}

/**
* @brief BSP_Drive_VBUS
* Drives the Vbus signal through IO
* @param state : VBUS states
* @retval None
*/

void USB_OTG_BSP_DriveVBUS(USB_OTG_CORE_HANDLE *pdev, uint8_t state) {
#ifndef USB_HID_HOST_DISABLE_VBUS
if (0 == state) {
/* DISABLE is needed on output of the Power Switch */
GPIO_SetBits(HOST_POWERSW_PORT, HOST_POWERSW_VBUS);
} else {
/* ENABLE the Power Switch by driving the Enable LOW */
GPIO_ResetBits(HOST_POWERSW_PORT, HOST_POWERSW_VBUS);
}
#endif
}

/**
* @brief USB_OTG_BSP_ConfigVBUS
* Configures the IO for the Vbus and OverCurrent
* @param None
* @retval None
*/

void USB_OTG_BSP_ConfigVBUS(USB_OTG_CORE_HANDLE *pdev) {
#ifndef USB_HID_HOST_DISABLE_VBUS
GPIO_InitTypeDef GPIO_InitStructure;

RCC_AHB1PeriphClockCmd(HOST_POWERSW_PORT_RCC, ENABLE);

GPIO_InitStructure.GPIO_Pin = HOST_POWERSW_VBUS;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(HOST_POWERSW_PORT, & GPIO_InitStructure);

/* By Default, DISABLE is needed on output of the Power Switch */
GPIO_SetBits(HOST_POWERSW_PORT, HOST_POWERSW_VBUS);

USB_OTG_BSP_mDelay(200); /* Delay is need for stabilising the Vbus Low
in Reset Condition, when Vbus=1 and Reset-button is pressed by user */
#endif
}

/**
* @brief USB_OTG_BSP_uDelay
* This function provides delay time in micro sec
* @param usec : Value of delay required in micro sec
* @retval None
*/
void USB_OTG_BSP_uDelay (const uint32_t usec) {
__IO uint32_t count = 0;
const uint32_t utime = (120 * usec / 7);
do
{
if ( ++count & gt; utime )
{
return ;
}
}
while (1);
}


/**
* @brief USB_OTG_BSP_mDelay
* This function provides delay time in milli sec
* @param msec : Value of delay required in milli sec
* @retval None
*/
void USB_OTG_BSP_mDelay (const uint32_t msec) {
USB_OTG_BSP_uDelay(msec * 1000);
}

#ifdef __cplusplus
extern " C " {
#endif

#ifdef USE_USB_OTG_FS
void OTG_FS_IRQHandler(void) {
#else
void OTG_HS_IRQHandler(void) {
#endif
USBH_OTG_ISR_Handler( & USB_OTG_Core);
}

#ifdef __cplusplus
}
#endif

/**
* @}
*/

/**
* @}
*/

/**
* @}
*/

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/


keyb_fw.7z > usbh_hid_keybd.cpp

/**
******************************************************************************
* @file usbh_hid_keybd.c
* @author MCD Application Team
* @version V2.1.0
* @date 19-March-2012
* @brief This file is the application layer for USB Host HID Keyboard handling
* QWERTY and AZERTY Keyboard are supported as per the selection in
* usbh_hid_keybd.h
******************************************************************************
* @attention
*
* & lt; h2 & gt; & lt; center & gt; & copy; COPYRIGHT 2012 STMicroelectronics & lt; /center & gt; & lt; /h2 & gt;
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the " License " );
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an " AS IS " BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/


/* Includes ------------------------------------------------------------------*/
#include " usbh_hid_keybd.h "

/** @addtogroup USBH_LIB
* @{
*/

/** @addtogroup USBH_CLASS
* @{
*/

/** @addtogroup USBH_HID_CLASS
* @{
*/

/** @defgroup USBH_HID_KEYBD
* @brief This file includes HID Layer Handlers for USB Host HID class.
* @{
*/

/** @defgroup USBH_HID_KEYBD_Private_TypesDefinitions
* @{
*/
/**
* @}
*/


/** @defgroup USBH_HID_KEYBD_Private_Defines
* @{
*/
/**
* @}
*/


/** @defgroup USBH_HID_KEYBD_Private_Macros
* @{
*/
/**
* @}
*/

/** @defgroup USBH_HID_KEYBD_Private_FunctionPrototypes
* @{
*/
static void KEYBRD_Init (void);
static void KEYBRD_Decode(uint8_t *data);

/**
* @}
*/

#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
#if defined (__CC_ARM) /*! & lt; ARM Compiler */
__align(4)
#elif defined ( __ICCARM__ ) /*! & lt; IAR Compiler */
#pragma data_alignment=4
#elif defined (__GNUC__) /*! & lt; GNU Compiler */
#pragma pack(4)
#elif defined (__TASKING__) /*! & lt; TASKING Compiler */
__align(4)
#endif /* __CC_ARM */
#endif

/** @defgroup USBH_HID_KEYBD_Private_Variables
* @{
*/
HID_cb_TypeDef HID_KEYBRD_cb=
{
KEYBRD_Init,
KEYBRD_Decode
};

/*
*******************************************************************************
* LOCAL CONSTANTS
*******************************************************************************
*/

static const uint8_t HID_KEYBRD_Codes[] = {
0, 0, 0, 0, 31, 50, 48, 33,
19, 34, 35, 36, 24, 37, 38, 39, /* 0x00 - 0x0F */
52, 51, 25, 26, 17, 20, 32, 21,
23, 49, 18, 47, 22, 46, 2, 3, /* 0x10 - 0x1F */
4, 5, 6, 7, 8, 9, 10, 11,
43, 110, 15, 16, 61, 12, 13, 27, /* 0x20 - 0x2F */
28, 29, 42, 40, 41, 1, 53, 54,
55, 30, 112, 113, 114, 115, 116, 117, /* 0x30 - 0x3F */
118, 119, 120, 121, 122, 123, 124, 125,
126, 75, 80, 85, 76, 81, 86, 89, /* 0x40 - 0x4F */
79, 84, 83, 90, 95, 100, 105, 106,
108, 93, 98, 103, 92, 97, 102, 91, /* 0x50 - 0x5F */
96, 101, 99, 104, 45, 129, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x6F */
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 - 0x7F */
0, 0, 0, 0, 0, 107, 0, 56,
0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 - 0x8F */
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 - 0x9F */
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, /* 0xA0 - 0xAF */
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, /* 0xB0 - 0xBF */
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, /* 0xC0 - 0xCF */
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, /* 0xD0 - 0xDF */
58, 44, 60, 127, 64, 57, 62, 128 /* 0xE0 - 0xE7 */
};

#ifdef QWERTY_KEYBOARD
static const int8_t HID_KEYBRD_Key[] = {
'\0', '`', '1', '2', '3', '4', '5', '6',
'7', '8', '9', '0', '-', '=', '\0', '\r',
'\t', 'q', 'w', 'e', 'r', 't', 'y', 'u',
'i', 'o', 'p', '[', ']', '\\',
'\0', 'a', 's', 'd', 'f', 'g', 'h', 'j',
'k', 'l', ';', '\'', '\0', '\n',
'\0', '\0', 'z', 'x', 'c', 'v', 'b', 'n',
'm', ',', '.', '/', '\0', '\0',
'\0', '\0', '\0', ' ', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\r', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '7', '4', '1',
'\0', '/', '8', '5', '2',
'0', '*', '9', '6', '3',
'.', '-', '+', '\0', '\n', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0'
};

static const int8_t HID_KEYBRD_ShiftKey[] = {
'\0', '~', '!', '@', '#', '$', '%', '^', ' & ', '*', '(', ')',
'_', '+', '\0', '\0', '\0', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U',
'I', 'O', 'P', '{', '}', '|', '\0', 'A', 'S', 'D', 'F', 'G',
'H', 'J', 'K', 'L', ':', ' " ', '\0', '\n', '\0', '\0', 'Z', 'X',
'C', 'V', 'B', 'N', 'M', ' & lt; ', ' & gt; ', '?', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
};

#else

static const int8_t HID_KEYBRD_Key[] = {
'\0', '`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'-', '=', '\0', '\r', '\t', 'a', 'z', 'e', 'r', 't', 'y', 'u',
'i', 'o', 'p', '[', ']', '\\', '\0', 'q', 's', 'd', 'f', 'g',
'h', 'j', 'k', 'l', 'm', '\0', '\0', '\n', '\0', '\0', 'w', 'x',
'c', 'v', 'b', 'n', ',', ';', ':', '!', '\0', '\0', '\0', '\0',
'\0', ' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\r', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '7', '4', '1','\0', '/',
'8', '5', '2', '0', '*', '9', '6', '3', '.', '-', '+', '\0',
'\n', '\0', '\0', '\0', '\0', '\0', '\0','\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
};

static const int8_t HID_KEYBRD_ShiftKey[] = {
'\0', '~', '!', '@', '#', '$', '%', '^', ' & ', '*', '(', ')', '_',
'+', '\0', '\0', '\0', 'A', 'Z', 'E', 'R', 'T', 'Y', 'U', 'I', 'O',
'P', '{', '}', '*', '\0', 'Q', 'S', 'D', 'F', 'G', 'H', 'J', 'K',
'L', 'M', '%', '\0', '\n', '\0', '\0', 'W', 'X', 'C', 'V', 'B', 'N',
'?', '.', '/', '\0', '\0', '\0','\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
};
#endif

/**
* @}
*/


/** @defgroup USBH_HID_KEYBD_Private_Functions
* @{
*/


/**
* @brief KEYBRD_Init.
* Initialize the keyboard function.
* @param None
* @retval None
*/
static void KEYBRD_Init (void)
{
/* Call User Init*/
USR_KEYBRD_Init();
}

/**
* @brief KEYBRD_ProcessData.
* The function is to decode the pressed keys.
* @param pbuf : Pointer to the HID IN report data buffer
* @retval None
*/

static void KEYBRD_Decode(uint8_t *pbuf)
{
static uint8_t shift;
static uint8_t keys[KBR_MAX_NBR_PRESSED];
static uint8_t keys_new[KBR_MAX_NBR_PRESSED];
static uint8_t keys_last[KBR_MAX_NBR_PRESSED];
static uint8_t key_newest;
static uint8_t nbr_keys;
static uint8_t nbr_keys_new;
static uint8_t nbr_keys_last;
uint8_t ix;
uint8_t jx;
uint8_t error;
uint8_t output;

nbr_keys = 0;
nbr_keys_new = 0;
nbr_keys_last = 0;
key_newest = 0x00;


/* Check if Shift key is pressed */
if ((pbuf[0] == KBD_LEFT_SHIFT) || (pbuf[0] == KBD_RIGHT_SHIFT)) {
shift = TRUE;
} else {
shift = FALSE;
}

error = FALSE;

/* Check for the value of pressed key */
for (ix = 2; ix & lt; 2 + KBR_MAX_NBR_PRESSED; ix++) {
if ((pbuf[ix] == 0x01) ||
(pbuf[ix] == 0x02) ||
(pbuf[ix] == 0x03)) {
error = TRUE;
}
}

if (error == TRUE) {
return;
}

nbr_keys = 0;
nbr_keys_new = 0;
for (ix = 2; ix & lt; 2 + KBR_MAX_NBR_PRESSED; ix++) {
if (pbuf[ix] != 0) {
keys[nbr_keys] = pbuf[ix];
nbr_keys++;
for (jx = 0; jx & lt; nbr_keys_last; jx++) {
if (pbuf[ix] == keys_last[jx]) {
break;
}
}

if (jx == nbr_keys_last) {
keys_new[nbr_keys_new] = pbuf[ix];
nbr_keys_new++;
}
}
}

if (nbr_keys_new == 1) {
key_newest = keys_new[0];

if (shift == TRUE) {
output = HID_KEYBRD_ShiftKey[HID_KEYBRD_Codes[key_newest]];
} else {
output = HID_KEYBRD_Key[HID_KEYBRD_Codes[key_newest]];
}

/* call user process handle */
USR_KEYBRD_ProcessData(output);
} else {
key_newest = 0x00;
}


nbr_keys_last = nbr_keys;
for (ix = 0; ix & lt; KBR_MAX_NBR_PRESSED; ix++) {
keys_last[ix] = keys[ix];
}
}

/**
* @}
*/

/**
* @}
*/

/**
* @}
*/

/**
* @}
*/


/**
* @}
*/

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/


keyb_fw.7z > usbh_def.h

/**
******************************************************************************
* @file usbh_def.h
* @author MCD Application Team
* @version V2.1.0
* @date 19-March-2012
* @brief Definitions used in the USB host library
******************************************************************************
* @attention
*
* & lt; h2 & gt; & lt; center & gt; & copy; COPYRIGHT 2012 STMicroelectronics & lt; /center & gt; & lt; /h2 & gt;
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the " License " );
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an " AS IS " BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/

/** @addtogroup USBH_LIB
* @{
*/

/** @addtogroup USBH_LIB_CORE
* @{
*/

/** @defgroup USBH_DEF
* @brief This file is includes USB descriptors
* @{
*/

#ifndef USBH_DEF_H
#define USBH_DEF_H

#ifndef USBH_NULL
#define USBH_NULL ((void *)0)
#endif

#ifndef FALSE
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE 1
#endif


#define ValBit(VAR,POS) (VAR & (1 & lt; & lt; POS))
#define SetBit(VAR,POS) (VAR |= (1 & lt; & lt; POS))
#define ClrBit(VAR,POS) (VAR & = ((1 & lt; & lt; POS)^255))

#define LE16(addr) (((u16)(*((u8 *)(addr))))\
+ (((u16)(*(((u8 *)(addr)) + 1))) & lt; & lt; 8))

#define USB_LEN_DESC_HDR 0x02
#define USB_LEN_DEV_DESC 0x12
#define USB_LEN_CFG_DESC 0x09
#define USB_LEN_IF_DESC 0x09
#define USB_LEN_EP_DESC 0x07
#define USB_LEN_OTG_DESC 0x03
#define USB_LEN_SETUP_PKT 0x08

/* bmRequestType :D7 Data Phase Transfer Direction */
#define USB_REQ_DIR_MASK 0x80
#define USB_H2D 0x00
#define USB_D2H 0x80

/* bmRequestType D6..5 Type */
#define USB_REQ_TYPE_STANDARD 0x00
#define USB_REQ_TYPE_CLASS 0x20
#define USB_REQ_TYPE_VENDOR 0x40
#define USB_REQ_TYPE_RESERVED 0x60

/* bmRequestType D4..0 Recipient */
#define USB_REQ_RECIPIENT_DEVICE 0x00
#define USB_REQ_RECIPIENT_INTERFACE 0x01
#define USB_REQ_RECIPIENT_ENDPOINT 0x02
#define USB_REQ_RECIPIENT_OTHER 0x03

/* Table 9-4. Standard Request Codes */
/* bRequest , Value */
#define USB_REQ_GET_STATUS 0x00
#define USB_REQ_CLEAR_FEATURE 0x01
#define USB_REQ_SET_FEATURE 0x03
#define USB_REQ_SET_ADDRESS 0x05
#define USB_REQ_GET_DESCRIPTOR 0x06
#define USB_REQ_SET_DESCRIPTOR 0x07
#define USB_REQ_GET_CONFIGURATION 0x08
#define USB_REQ_SET_CONFIGURATION 0x09
#define USB_REQ_GET_INTERFACE 0x0A
#define USB_REQ_SET_INTERFACE 0x0B
#define USB_REQ_SYNCH_FRAME 0x0C

/* Table 9-5. Descriptor Types of USB Specifications */
#define USB_DESC_TYPE_DEVICE 1
#define USB_DESC_TYPE_CONFIGURATION 2
#define USB_DESC_TYPE_STRING 3
#define USB_DESC_TYPE_INTERFACE 4
#define USB_DESC_TYPE_ENDPOINT 5
#define USB_DESC_TYPE_DEVICE_QUALIFIER 6
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7
#define USB_DESC_TYPE_INTERFACE_POWER 8
#define USB_DESC_TYPE_HID 0x21
#define USB_DESC_TYPE_HID_REPORT 0x22


#define USB_DEVICE_DESC_SIZE 18
#define USB_CONFIGURATION_DESC_SIZE 9
#define USB_HID_DESC_SIZE 9
#define USB_INTERFACE_DESC_SIZE 9
#define USB_ENDPOINT_DESC_SIZE 7

/* Descriptor Type and Descriptor Index */
/* Use the following values when calling the function USBH_GetDescriptor */
#define USB_DESC_DEVICE ((USB_DESC_TYPE_DEVICE & lt; & lt; 8) & 0xFF00)
#define USB_DESC_CONFIGURATION ((USB_DESC_TYPE_CONFIGURATION & lt; & lt; 8) & 0xFF00)
#define USB_DESC_STRING ((USB_DESC_TYPE_STRING & lt; & lt; 8) & 0xFF00)
#define USB_DESC_INTERFACE ((USB_DESC_TYPE_INTERFACE & lt; & lt; 8) & 0xFF00)
#define USB_DESC_ENDPOINT ((USB_DESC_TYPE_INTERFACE & lt; & lt; 8) & 0xFF00)
#define USB_DESC_DEVICE_QUALIFIER ((USB_DESC_TYPE_DEVICE_QUALIFIER & lt; & lt; 8) & 0xFF00)
#define USB_DESC_OTHER_SPEED_CONFIGURATION ((USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION & lt; & lt; 8) & 0xFF00)
#define USB_DESC_INTERFACE_POWER ((USB_DESC_TYPE_INTERFACE_POWER & lt; & lt; 8) & 0xFF00)
#define USB_DESC_HID_REPORT ((USB_DESC_TYPE_HID_REPORT & lt; & lt; 8) & 0xFF00)
#define USB_DESC_HID ((USB_DESC_TYPE_HID & lt; & lt; 8) & 0xFF00)


#define USB_EP_TYPE_CTRL 0x00
#define USB_EP_TYPE_ISOC 0x01
#define USB_EP_TYPE_BULK 0x02
#define USB_EP_TYPE_INTR 0x03

#define USB_EP_DIR_OUT 0x00
#define USB_EP_DIR_IN 0x80
#define USB_EP_DIR_MSK 0x80

/* supported classes */
#define USB_MSC_CLASS 0x08
#define USB_HID_CLASS 0x03

/* Interface Descriptor field values for HID Boot Protocol */
#define HID_BOOT_CODE 0x01
#define HID_KEYBRD_BOOT_CODE 0x01
#define HID_MOUSE_BOOT_CODE 0x02

/* As per USB specs 9.2.6.4 :Standard request with data request timeout: 5sec
Standard request with no data stage timeout : 50ms */
#define DATA_STAGE_TIMEOUT 5000
#define NODATA_STAGE_TIMEOUT 50

/**
* @}
*/


#define USBH_CONFIGURATION_DESCRIPTOR_SIZE (USB_CONFIGURATION_DESC_SIZE \
+ USB_INTERFACE_DESC_SIZE\
+ (USBH_MAX_NUM_ENDPOINTS * USB_ENDPOINT_DESC_SIZE))


#define CONFIG_DESC_wTOTAL_LENGTH (ConfigurationDescriptorData.ConfigDescfield.\
ConfigurationDescriptor.wTotalLength)


/* This Union is copied from usb_core.h */
typedef union
{
uint16_t w;
struct BW
{
uint8_t msb;
uint8_t lsb;
}
bw;
}
uint16_t_uint8_t;


typedef union _USB_Setup
{
uint8_t d8[8];

struct _SetupPkt_Struc
{
uint8_t bmRequestType;
uint8_t bRequest;
uint16_t_uint8_t wValue;
uint16_t_uint8_t wIndex;
uint16_t_uint8_t wLength;
} b;
}
USB_Setup_TypeDef;

typedef struct _DescHeader
{
uint8_t bLength;
uint8_t bDescriptorType;
}
USBH_DescHeader_t;

typedef struct _DeviceDescriptor
{
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t bcdUSB; /* USB Specification Number which device complies too */
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
/* If equal to Zero, each interface specifies its own class
code if equal to 0xFF, the class code is vendor specified.
Otherwise field is valid Class Code.*/
uint8_t bMaxPacketSize;
uint16_t idVendor; /* Vendor ID (Assigned by USB Org) */
uint16_t idProduct; /* Product ID (Assigned by Manufacturer) */
uint16_t bcdDevice; /* Device Release Number */
uint8_t iManufacturer; /* Index of Manufacturer String Descriptor */
uint8_t iProduct; /* Index of Product String Descriptor */
uint8_t iSerialNumber; /* Index of Serial Number String Descriptor */
uint8_t bNumConfigurations; /* Number of Possible Configurations */
}
USBH_DevDesc_TypeDef;


typedef struct _ConfigurationDescriptor
{
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t wTotalLength; /* Total Length of Data Returned */
uint8_t bNumInterfaces; /* Number of Interfaces */
uint8_t bConfigurationValue; /* Value to use as an argument to select this configuration*/
uint8_t iConfiguration; /*Index of String Descriptor Describing this configuration */
uint8_t bmAttributes; /* D7 Bus Powered , D6 Self Powered, D5 Remote Wakeup , D4..0 Reserved (0)*/
uint8_t bMaxPower; /*Maximum Power Consumption */
}
USBH_CfgDesc_TypeDef;


typedef struct _HIDDescriptor
{
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t bcdHID; /* indicates what endpoint this descriptor is describing */
uint8_t bCountryCode; /* specifies the transfer type. */
uint8_t bNumDescriptors; /* specifies the transfer type. */
uint8_t bReportDescriptorType; /* Maximum Packet Size this endpoint is capable of sending or receiving */
uint16_t wItemLength; /* is used to specify the polling interval of certain transfers. */
}
USBH_HIDDesc_TypeDef;


typedef struct _InterfaceDescriptor
{
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bInterfaceNumber;
uint8_t bAlternateSetting; /* Value used to select alternative setting */
uint8_t bNumEndpoints; /* Number of Endpoints used for this interface */
uint8_t bInterfaceClass; /* Class Code (Assigned by USB Org) */
uint8_t bInterfaceSubClass; /* Subclass Code (Assigned by USB Org) */
uint8_t bInterfaceProtocol; /* Protocol Code */
uint8_t iInterface; /* Index of String Descriptor Describing this interface */

}
USBH_InterfaceDesc_TypeDef;


typedef struct _EndpointDescriptor
{
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bEndpointAddress; /* indicates what endpoint this descriptor is describing */
uint8_t bmAttributes; /* specifies the transfer type. */
uint16_t wMaxPacketSize; /* Maximum Packet Size this endpoint is capable of sending or receiving */
uint8_t bInterval; /* is used to specify the polling interval of certain transfers. */
}
USBH_EpDesc_TypeDef;
#endif

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/