#include "includes.h" //////////////////////封装一下AT接口///////////////////////////////// void msgAtSend(char *at){ #ifndef USE_BND_POC ohpoc_msg_send(at, strlen(at)); #else //broad_send_at(at); ModemSendAt(at); #endif } void msgAtSends(char *at ,int len){ #ifndef USE_BND_POC ohpoc_msg_send(at, len); #else ModemSendAt(at);//发送至模块 #endif } //////日志打印口配置///////////////// void my_usb_evt_cb(lsUSBEvent_t event, unsigned long p){ LSAPI_OSI_Event_t usb_event; usb_event.id = OHPOC_EVENT_USB; usb_event.param1=event; //wlog_info("my_usb_evt_cb:%d",event); osiEventTrySend((LSAPI_OSI_Thread_t *)p, &usb_event, 0); } LSAPI_Device_USBConfig_t usb_cfg = { .name = LSAPI_DEV_USB_COM7, .event_cb = my_usb_evt_cb, }; bool usbThreadExit=false; LSAPI_Device_t *usbdev=NULL; LSAPI_OSI_Thread_t *gUsbWRTd; static void usbPortHandler(void *param){ int ret; unsigned char buffer[100]; LSAPI_OSI_Event_t waitevent; LSAPI_Log_Debug("usb create ok"); while(usbThreadExit==false){ LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &waitevent); if(waitevent.param1==LS_USB_EVENT_RX_ARRIVED){ while(LSAPI_Device_ReadAvail(usbdev)>0){ ret = LSAPI_Device_Read(usbdev, buffer, sizeof(buffer)); if(ret< sizeof(buffer)) buffer[ret]=0; usbCmdHandler(buffer,ret); } //WakeupNow("usbCallBack"); } } LSAPI_Log_Debug("usbPortHandler exit"); LSAPI_Device_Close(usbdev); gUsbWRTd=NULL; LSAPI_OSI_ThreadExit(); } static bool logPortInit(void){ gUsbWRTd=LSAPI_OSI_ThreadCreate("usb", usbPortHandler, NULL, LSAPI_OSI_PRIORITY_NORMAL, 1024*32, 4); if(gUsbWRTd==NULL) return false; usb_cfg.event_cb_ctx = gUsbWRTd; usbdev = LSAPI_Device_USBCreateEx(&usb_cfg); if(usbdev==NULL){ usbThreadExit=true; LSAPI_Log_Debug("usbex create err"); return false; } if(false==LSAPI_Device_Open(usbdev)){ LSAPI_Log_Debug("usb LSAPI_Device_Open failed"); return false; } LSAPI_Device_SetAutoSleep(usbdev, 500); LSAPI_Log_Debug("usbComInit done"); return true; } void usbOutPut(unsigned char *info, int len){ if(NULL==usbdev) return; if(LSAPI_Device_WriteAvail(usbdev) != -1) LSAPI_Device_Write(usbdev, info,len); } void usbOutPutStr(unsigned char *info){ if(NULL==usbdev) return; if(LSAPI_Device_WriteAvail(usbdev) != -1) LSAPI_Device_Write(usbdev, info,strlen(info)); } static void lcdInitTask(void *param){ //MSG_WARN(1,"lcd init thread start"); if(0==lcdDrv_Init(0)) MSG_INFO(1, "lcd init ok"); else MSG_INFO(1, "lcd init failed"); guiInit(); MSG_WARN(1,"lcd init thread end"); sutApp.guiStatus=1; LSAPI_OSI_ThreadExit(); } static void lcdsInit(void){ if(NULL==LSAPI_OSI_ThreadCreate("lcdinit", lcdInitTask, NULL, LSAPI_OSI_PRIORITY_NORMAL, LCD_INIT_TASK_THREAD_STACK, 2)){ MSG_WARN(1,"lcd init thread error"); return; } } //////////////////gpio及定时器///////////////////////////// LSAPI_OSI_Timer_t *pKeytimer_t=NULL; LSAPI_OSI_Timer_t *pBackLightTimer_t=NULL; bool pkeyTimerCtl=false; unsigned short keyStatus=0; unsigned short getKeyValue(){return keyStatus;} static void startKeyTimer(void){ if(NULL==pKeytimer_t) return; if(pkeyTimerCtl==true) return; pkeyTimerCtl=true; LSAPI_OSI_TimerStart(pKeytimer_t,KEY_TIMER_TICK); } void stopKeyTimer(void){ pkeyTimerCtl=false; LSAPI_OSI_TimerStop(pKeytimer_t); } static unsigned int msTick=0;//用于做应用层的非休眠时定时器 unsigned int getAppTick(void){return msTick;} static void Timeroutcallback(void *param){ //毿00秒去检测键值状怿去抖势 //检测按锿 keyCheck(keyStatus); msTick ++; //EarDlyCheck(); if(pkeyTimerCtl==true) LSAPI_OSI_TimerStart(pKeytimer_t,KEY_TIMER_TICK); } LSAPI_Device_t *LcdBlCtl; LSAPI_Device_t *RedGpio; LSAPI_Device_t *GreenGpio; LSAPI_Device_t *SpkGpio; #define RED_GPIO_ID 22 #define GREEN_GPIO_ID 18 #define SPK_GPIO_ID 21 void gpioConfigOutput(void){ bool write_value = false; LSAPI_GpioConfig_t gpioConfig = {0}; // config property gpioConfig.mode = LS_GPIO_OUTPUT; gpioConfig.out_level=true; // create instance gpioConfig.id = GREEN_GPIO_ID; RedGpio = LSAPI_Device_GPIOCreate(&gpioConfig); gpioConfig.id = RED_GPIO_ID; GreenGpio = LSAPI_Device_GPIOCreate(&gpioConfig); gpioConfig.id = SPK_GPIO_ID; SpkGpio = LSAPI_Device_GPIOCreate(&gpioConfig); LSAPI_Device_Open(RedGpio); LSAPI_Device_Write(RedGpio, (void *)&write_value, 1); LSAPI_Device_Open(GreenGpio); LSAPI_Device_Write(GreenGpio, (void *)&write_value, 1); LSAPI_Device_Open(SpkGpio); LSAPI_Device_Write(SpkGpio, (void *)&write_value, 1); LcdBlCtl=LSAPI_Device_LedCreate(LS_LED_1); LSAPI_Device_Open(LcdBlCtl); lcdBackList(0); } void redLedCtl(bool onoff){ bool write_value = onoff; LSAPI_Device_Write(RedGpio, (void *)&write_value, 1); } void greenLedCtl(bool onoff){ bool write_value = onoff; LSAPI_Device_Write(GreenGpio, (void *)&write_value, 1); } void spkCtl(bool onoff){ bool write_value = onoff; //bool write_value = 1; LSAPI_Device_Write(SpkGpio, (void *)&write_value, 1); } void lcdBackList(char onoff){ unsigned int led_value; if(onoff==0) led_value=0; else led_value=1; LSAPI_Device_Write(LcdBlCtl, &led_value, 1); } void startBackLightTimer(int time){ if(NULL==pBackLightTimer_t) return; LSAPI_OSI_TimerStart(pBackLightTimer_t,time); } static void gpioTask(void *param){ unsigned int param1,param2,param3; LSAPI_OSI_Event_t event = {}; //创建一个定时器 if(NULL == pKeytimer_t) pKeytimer_t = LSAPI_OSI_TimerCreate(LSAPI_OSI_ThreadCurrent(), Timeroutcallback, NULL); if(NULL == pKeytimer_t) MSG_WARN(1,"gpio timer init failed"); if(NULL == pBackLightTimer_t) pBackLightTimer_t = LSAPI_OSI_TimerCreate(LSAPI_OSI_ThreadCurrent(), backLightCb, NULL); if(NULL == pBackLightTimer_t) MSG_WARN(1,"backlight timer init failed"); startKeyTimer(); gpioConfigOutput(); uioStatusInit(); for(;;){ LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &event); param1=event.param1; param2=event.param2; param3=event.param3; if(event.id==OHPOC_EVENT_KEY_NOR) keyHandler((unsigned short)param1,(unsigned char)param2); } } LSAPI_OSI_Thread_t *gGpioTd=NULL; static void gpiosInit(void){ gGpioTd=LSAPI_OSI_ThreadCreate("gpio", gpioTask, NULL, LSAPI_OSI_PRIORITY_NORMAL, 1024*32, 5); if(NULL==gGpioTd) MSG_WARN(1,"gpioThread Error"); else MSG_WARN(1,"gpioThread ok"); } void keySendEvent(unsigned short key, unsigned char keyType){ threadSendEvent(gGpioTd,OHPOC_EVENT_KEY_NOR, key,keyType,NULL); tryWakeupApp(); } //////////////////按键实始化////////////////////////// #define POWER_KEY_PRESSED_TIMEOUT (3000) typedef struct ls_key{ bool ready_shutdown; LSAPI_OSI_Timer_t *key_timer; }lsKey_t; static void _lsKeyTimer(void *p){ lsKey_t *key = (lsKey_t *)p; key->ready_shutdown = true; } static void _lsKeyCB(lskeyMap_t id, lskeyState_t evt, void *p){ lsKey_t *key = (lsKey_t *)p; uint8_t status; if (evt & LS_KEY_STATE_PRESS) keyStatus |= (1<key_timer = LSAPI_OSI_TimerCreate(NULL, _lsKeyTimer, key); if (key->key_timer == NULL){ LSAPI_OSI_Free(key); return; } LSAPI_Device_KeypadCreate(_lsKeyCB, key); } //////////////////////////PA控制接口(外放使用免提,耳机FM)/////////////////////////// //8735 //#define PA_MODE_AB //#define PA_MODE_D //#define PA_MODE_FM //#define PA_MODE_K #define PA_MODE_MIANTI void delayUs(int64_t time){ int64_t i; i=LSAPI_OSI_UpTimeUs()+time; while(LSAPI_OSI_UpTimeUs()