/* CMSIS-DAP Interface Firmware
* Copyright (c) 2009-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
#include <RTL.h>
#include <rl_usb.h>
#include <..\..\RL\USB\INC\usb.h>
#pragma thumb
#pragma O3
/*------------------------------------------------------------------------------
* Library for usb_config.c
*----------------------------------------------------------------------------*/
#ifdef __USB_CONFIG__
/*------------------------------------------------------------------------------
* USB Device Configuration
*----------------------------------------------------------------------------*/
#if (USBD_ENABLE)
U8 USBD_AltSetting[USBD_IF_NUM];
U8 USBD_EP0Buf [USBD_MAX_PACKET0];
const U8 usbd_power = USBD_POWER;
const U8 usbd_hs_enable = USBD_HS_ENABLE;
const U16 usbd_if_num = USBD_IF_NUM;
const U8 usbd_ep_num = USBD_EP_NUM;
const U8 usbd_max_packet0 = USBD_MAX_PACKET0;
/*------------------------------------------------------------------------------
* USB Device Class Configuration
*----------------------------------------------------------------------------*/
#if (!USBD_HID_BINTERVAL)
#define USBD_HID_INTERVAL 1
#else
#define USBD_HID_INTERVAL USBD_HID_BINTERVAL
#endif
#if (!USBD_HID_HS_BINTERVAL)
#define USBD_HID_HS_INTERVAL 1
#else
#define USBD_HID_HS_INTERVAL (2 << ((USBD_HID_HS_BINTERVAL & 0x0F)-1))
#endif
#if (USBD_HID_ENABLE)
const U8 usbd_hid_if_num = USBD_HID_IF_NUM;
const U8 usbd_hid_ep_intin = USBD_HID_EP_INTIN;
const U8 usbd_hid_ep_intout = USBD_HID_EP_INTOUT;
const U16 usbd_hid_interval [2] = {USBD_HID_INTERVAL, USBD_HID_HS_INTERVAL};
const U16 usbd_hid_maxpacketsize[2] = {USBD_HID_WMAXPACKETSIZE, USBD_HID_HS_WMAXPACKETSIZE};
const U8 usbd_hid_inreport_num = USBD_HID_INREPORT_NUM;
const U8 usbd_hid_outreport_num = USBD_HID_OUTREPORT_NUM;
const U16 usbd_hid_inreport_max_sz = USBD_HID_INREPORT_MAX_SZ;
const U16 usbd_hid_outreport_max_sz = USBD_HID_OUTREPORT_MAX_SZ;
const U16 usbd_hid_featreport_max_sz = USBD_HID_FEATREPORT_MAX_SZ;
U16 USBD_HID_PollingCnt;
U8 USBD_HID_IdleCnt [USBD_HID_INREPORT_NUM];
U8 USBD_HID_IdleReload [USBD_HID_INREPORT_NUM];
U8 USBD_HID_IdleSet [USBD_HID_INREPORT_NUM];
U8 USBD_HID_InReport [USBD_HID_INREPORT_MAX_SZ+1];
U8 USBD_HID_OutReport [USBD_HID_OUTREPORT_MAX_SZ+1];
U8 USBD_HID_FeatReport [USBD_HID_FEATREPORT_MAX_SZ+1];
#endif
#if (USBD_MSC_ENABLE)
const U8 usbd_msc_if_num = USBD_MSC_IF_NUM;
const U8 usbd_msc_ep_bulkin = USBD_MSC_EP_BULKIN;
const U8 usbd_msc_ep_bulkout = USBD_MSC_EP_BULKOUT;
const U16 usbd_msc_maxpacketsize[2] = {USBD_MSC_WMAXPACKETSIZE, USBD_MSC_HS_WMAXPACKETSIZE};
const U8 *usbd_msc_inquiry_data = USBD_MSC_INQUIRY_DATA;
U8 USBD_MSC_BulkBuf [USBD_MSC_MAX_PACKET*USBD_MSC_ENABLE];
#endif
#if (USBD_ADC_ENABLE)
const U8 usbd_adc_cif_num = USBD_ADC_CIF_NUM;
const U8 usbd_adc_sif1_num = USBD_ADC_SIF1_NUM;
const U8 usbd_adc_sif2_num = USBD_ADC_SIF2_NUM;
const U8 usbd_adc_ep_isoout = USBD_ADC_EP_ISOOUT;
const U32 usbd_adc_cfg_datafreq = USBD_ADC_TSAMFREQ;
const U32 usbd_adc_cfg_p_s = USBD_ADC_CFG_P_S;
const U32 usbd_adc_cfg_p_c = USBD_ADC_CFG_P_C;
const U32 usbd_adc_cfg_b_s = (8*USBD_ADC_CFG_P_C*USBD_ADC_CFG_P_S);
S16 USBD_ADC_DataBuf [8*USBD_ADC_CFG_P_C*USBD_ADC_CFG_P_S];
#endif
#ifndef USBD_CDC_ACM_ENABLE
#if (USBD_CDC_ENABLE == 1)
#error "Please update usb_config.c file with new definitions for CDC, as new CDC is incompatible with the old one!"
#else
#define USBD_CDC_ACM_ENABLE 0
#endif
#endif
#if (USBD_CDC_ACM_ENABLE)
const U8 usbd_cdc_acm_cif_num = USBD_CDC_ACM_CIF_NUM;
const U8 usbd_cdc_acm_dif_num = USBD_CDC_ACM_DIF_NUM;
const U8 usbd_cdc_acm_ep_intin = USBD_CDC_ACM_EP_INTIN;
const U8 usbd_cdc_acm_ep_bulkin = USBD_CDC_ACM_EP_BULKIN;
const U8 usbd_cdc_acm_ep_bulkout = USBD_CDC_ACM_EP_BULKOUT;
const U16 usbd_cdc_acm_sendbuf_sz = USBD_CDC_ACM_SENDBUF_SIZE;
const U16 usbd_cdc_acm_receivebuf_sz = USBD_CDC_ACM_RECEIVEBUF_SIZE;
const U16 usbd_cdc_acm_maxpacketsize [2] = {USBD_CDC_ACM_WMAXPACKETSIZE, USBD_CDC_ACM_HS_WMAXPACKETSIZE};
const U16 usbd_cdc_acm_maxpacketsize1[2] = {USBD_CDC_ACM_WMAXPACKETSIZE1, USBD_CDC_ACM_HS_WMAXPACKETSIZE1};
U8 USBD_CDC_ACM_SendBuf [USBD_CDC_ACM_SENDBUF_SIZE];
U8 USBD_CDC_ACM_ReceiveBuf [USBD_CDC_ACM_RECEIVEBUF_SIZE];
U8 USBD_CDC_ACM_NotifyBuf [10];
#endif
/*------------------------------------------------------------------------------
* USB Device Override Event Handler Fuctions
*----------------------------------------------------------------------------*/
#if (USBD_HID_ENABLE)
#ifndef __RTX
void USBD_Configure_Event (void) { USBD_HID_Configure_Event (); }
#endif
#ifdef __RTX
#if ((USBD_HID_EP_INTOUT != 0) && (USBD_HID_EP_INTIN != USBD_HID_EP_INTOUT))
#if (USBD_HID_EP_INTIN == 1)
#define USBD_RTX_EndPoint1 USBD_RTX_HID_EP_INTIN_Event
#elif (USBD_HID_EP_INTIN == 2)
#define USBD_RTX_EndPoint2 USBD_RTX_HID_EP_INTIN_Event
#elif (USBD_HID_EP_INTIN == 3)
#define USBD_RTX_EndPoint3 USBD_RTX_HID_EP_INTIN_Event
#elif (USBD_HID_EP_INTIN == 4)
#define USBD_RTX_EndPoint4 USBD_RTX_HID_EP_INTIN_Event
#elif (USBD_HID_EP_INTIN == 5)
#define USBD_RTX_EndPoint5 USBD_RTX_HID_EP_INTIN_Event
#elif (USBD_HID_EP_INTIN == 6)
#define USBD_RTX_EndPoint6 USBD_RTX_HID_EP_INTIN_Event
#elif (USBD_HID_EP_INTIN == 7)
#define USBD_RTX_EndPoint7 USBD_RTX_HID_EP_INTIN_Event
#elif (USBD_HID_EP_INTIN == 8)
#define USBD_RTX_EndPoint8 USBD_RTX_HID_EP_INTIN_Event
#elif (USBD_HID_EP_INTIN == 9)
#define USBD_RTX_EndPoint9 USBD_RTX_HID_EP_INTIN_Event
#elif (USBD_HID_EP_INTIN == 10)
#define USBD_RTX_EndPoint10 USBD_RTX_HID_EP_INTIN_Event
#elif (USBD_HID_EP_INTIN == 11)
#define USBD_RTX_EndPoint11 USBD_RTX_HID_EP_INTIN_Event
#elif (USBD_HID_EP_INTIN == 12)
#define USBD_RTX_EndPoint12 USBD_RTX_HID_EP_INTIN_Event
#elif (USBD_HID_EP_INTIN == 13)
#define USBD_RTX_EndPoint13 USBD_RTX_HID_EP_INTIN_Event
#elif (USBD_HID_EP_INTIN == 14)
#define USBD_RTX_EndPoint14 USBD_RTX_HID_EP_INTIN_Event
#elif (USBD_HID_EP_INTIN == 15)
#define USBD_RTX_EndPoint15 USBD_RTX_HID_EP_INTIN_Event
#endif
#if (USBD_HID_EP_INTOUT == 1)
#define USBD_RTX_EndPoint1 USBD_RTX_HID_EP_INTOUT_Event
#elif (USBD_HID_EP_INTOUT == 2)
#define USBD_RTX_EndPoint2 USBD_RTX_HID_EP_INTOUT_Event
#elif (USBD_HID_EP_INTOUT == 3)
#de