/* Includes ------------------------------------------------------------------*/
#include "stm32f2xx.h"
#include "stm32f2xx_conf.h"
#include "stm32f2xx_gpio.h"
#include "stm32f2xx_rcc.h"
//#include "display.h"
#include "lcd.h"
#include "lcd_log.h"
#include "fonts.h"
//#include "data.h"
#include "usbd_usr.h"
#include "usb_conf.h"
#include "usbd_desc.h"
#include "usb_core.h"
#include "usbd_core.h"
#include "usbd_cdc_core.h"
#include "sdio_sd.h"
#include "stm32f2xx_it.h"
//volatile CDC_BUF_T buf_to_host;
volatile CDC_BUF_T buf_from_host;
volatile int usb_connect = 0;
__ALIGN_BEGIN USB_OTG_CORE_HANDLE USB_OTG_dev __ALIGN_END ;
static volatile uint32_t TimingDelay,t100us,sec;
//----------------------------------------------------------------------------
#define CH_COUNT 16
#define FIL2_LEN 256
#define DECIM_FACTOR 5
int bptr;
const int32_t filter2[FIL2_LEN] = {1, 1, 2, 3, 4, 6, 7, 8, 9, 9, 8, 7, 4, 1, -3, -9, -16, -23, -31, -38, -45, -50, -53, -52, -48, -40, -27, -10, 12, 38, 67, 97, 128, 156, 180, 198, 206, 204, 188, 158, 114, 55, -15, -98, -188, -282, -373, -457, -527, -577, -601, -594, -552, -472, -355, -200, -13, 198, 429, 665, 895, 1105, 1280, 1405, 1469, 1460, 1369, 1191, 927, 582, 164, -310, -823, -1348, -1860, -2329, -2723, -3014, -3173, -3180, -3015, -2672, -2148, -1454, -609, 357, 1406, 2490, 3555, 4541, 5389, 6039, 6436, 6533, 6293, 5694, 4730, 3411, 1770, -143, -2261, -4495, -6744, -8894, -10824, -12411, -13532, -14074, -13937, -13036, -11312, -8732, -5291, -1018, 4028, 9757, 16049, 22758, 29716, 36739, 43635, 50207, 56264, 61624, 66125, 69629, 72028, 73247, 73247, 72028, 69629, 66125, 61624, 56264, 50207, 43635, 36739, 29716, 22758, 16049, 9757, 4028, -1018, -5291, -8732, -11312, -13036, -13937, -14074, -13532, -12411, -10824, -8894, -6744, -4495, -2261, -143, 1770, 3411, 4730, 5694, 6293, 6533, 6436, 6039, 5389, 4541, 3555, 2490, 1406, 357, -609, -1454, -2148, -2672, -3015, -3180, -3173, -3014, -2723, -2329, -1860, -1348, -823, -310, 164, 582, 927, 1191, 1369, 1460, 1469, 1405, 1280, 1105, 895, 665, 429, 198, -13, -200, -355, -472, -552, -594, -601, -577, -527, -457, -373, -282, -188, -98, -15, 55, 114, 158, 188, 204, 206, 198, 180, 156, 128, 97, 67, 38, 12, -10, -27, -40, -48, -52, -53, -50, -45, -38, -31, -23, -16, -9, -3, 1, 4, 7, 8, 9, 9, 8, 7, 6, 4, 3, 2, 1, 1};
//----------------------------------------------------------------------------
#define DWT_CYCCNT *(volatile uint32_t *)0xE0001004
#define DWT_CONTROL *(volatile uint32_t *)0xE0001000
#define SCB_DEMCR *(volatile uint32_t *)0xE000EDFC
//----------------------------------------------------------------------------
static inline void DWT_Init()
{
SCB_DEMCR |= 0x01000000;
DWT_CYCCNT = 0;
DWT_CONTROL|= 1; // enable the counter
}
//----------------------------------------------------------------------------
void Delay(__IO uint32_t nTime)
{
TimingDelay = nTime+1;
while(TimingDelay != 0) __WFI();
}
//----------------------------------------------------------------------------
void SysTick_Handler(void)
{
t100us++;
if(t100us >= 1000){t100us -= 1000; sec++;}
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
//----------------------------------------------------------------------------
void sputhex(int inp,short size,char * buf)
{
// char buf[9];
int j;
for(j=size-1;j>=0;j--)
{char dig = (inp&0xf);
if(dig<10){buf[j]=0x30+dig;}else{buf[j]=0x41+dig-10;}
inp >>=4;
}
buf[size]=0;
}